-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lint using 🐊Putout: part 7 #4118
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@coderaiser Went only halfway through and have 2 remarks:
- Imho turning left/right side of conditionals is mostly unwanted. I think we want the local changing part on the left side, comparing to a more static right side.
- Some conditionals do border testing against a left and a right side. Imho thats easier to grasp, if the the numbers stay in mathematically logical order. (thus
left < var < right
, which translates toleft < v && v < right
in JS).
If we can agree on my remarks above, I think the changelist will get much shorter.
@@ -4,7 +4,7 @@ | |||
*/ | |||
|
|||
export class GridCache<T> { | |||
public cache: (T | undefined)[][]; | |||
public cache: T[] | undefined[][]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this got the dimension wrong on T
? Should be T[][] | undefined[][]
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Plus this doesn't feel like an improvement to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This transformation decrease cognitive load while reading the code. I can turn it of, that's not a problem :). But about benefit, here it is:
let info: (Info | SuperInfo | MagicInfo)[];
vs
let info: Info[] | SuperInfo[] | MagicInfo[];
In first case you need to unwrap types in your brain while reading the code. In second case you just reading the type information without unnecessary unwrapping the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find the former easier to read and less error prone; info
is an array of things, where things = Info | SuperInfo | MagicInfo
result.col + result.term.length >= this._terminal.cols ? result.row + 1 : result.row, | ||
result.col + result.term.length >= this._terminal.cols ? 0 : result.col + 1, | ||
this._terminal.cols <= result.col + result.term.length ? result.row + 1 : result.row, | ||
this._terminal.cols <= result.col + result.term.length ? 0 : result.col + 1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Over the years I've develop a habit/tendency for conditionals to write the changing entity on the left side comparing to something more statically on the right side, thus I'd prefer the old variant here. In the end its a matter of taste.
Same for several more occasions down below...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a fan too, this rule would best be ignored
@@ -311,7 +311,7 @@ describe('Search Tests', function (): void { | |||
.replace(/\n/g, '\\n\\r'); | |||
} | |||
fixture = fixture | |||
.replace(/'/g, `\\'`); | |||
.replace(/'/g, `'`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks wrong to me compared to the original.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a code scanning alert for the PR now, it does nothing in its current state
Math.abs(imageData.data[offset + 1] - g) + | ||
Math.abs(imageData.data[offset + 2] - b)) < threshold) { | ||
threshold > (Math.abs(imageData.data[offset] - r) + | ||
Math.abs(imageData.data[offset + 1] - g) + Math.abs(imageData.data[offset + 2] - b))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically same as above. Additionally if readability is an issue here, maybe introduce an interim variable? (No issue for me though...)
bin/test_mousemodes.js
Outdated
@@ -96,7 +96,7 @@ function evalButtonCode(code) { | |||
} | |||
if (move) { | |||
action = 'move'; | |||
} else if (4 <= button && button <= 7) { | |||
} else if (button >= 4 && button <= 7) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, here comes the exclusion from my habit above - if things test left/right borders, I prefer to write it with numbers to left and right side and variable in the middle. Always found that easier to grasp, visually resembling the "in the middle" aspect. Thus I'd prefer the original variant here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do this too as it's similar to 4 <= button <= 7
in maths
} | ||
|
||
function isBoxOrBlockGlyph(codepoint: number): boolean { | ||
return 0x2500 <= codepoint && codepoint <= 0x259F; | ||
return codepoint >= 0x2500 && codepoint <= 0x259F; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again left/right border testing...
@@ -231,11 +231,11 @@ export class DomRenderer extends Disposable implements IRenderer { | |||
` background-color: ${this._colors.selectionInactiveBackgroundOpaque.css};` + | |||
`}`; | |||
// Colors | |||
this._colors.ansi.forEach((c, i) => { | |||
for (const [i, c] of this._colors.ansi.entries()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes much better, and since we are now on ES2015, should be officially supported. Also the for
statement is way faster in general than the lisp style function mappers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another benefit is this works properly when debugging, instead of needing a breakpoint in the loop block
src/common/InputHandler.ts
Outdated
@@ -2286,7 +2286,7 @@ export class InputHandler extends Disposable implements IInputHandler { | |||
cSpace = 1; | |||
} | |||
accu[advance + i + 1 + cSpace] = subparams[i]; | |||
} while (++i < subparams.length && i + advance + 1 + cSpace < accu.length); | |||
} while (subparams.length > ++i && accu.length > i + advance + 1 + cSpace); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not touch this and the following similar cases, as the execution order is very important. (The inline ++i
in a conditional would even generate a warning in C/C++ for that reason).
cfc1ed2
to
25eb7d6
Compare
Just disabled unneeded rules :). |
The time is come for a new report of Xterm linting by 🐊v27:
☝️ As usual, any rule can be disabled.
Command used:
putout . --fix
Applied rules:
Current config for 🐊Putout v27:
Previous reports: