tools
tools copied to clipboard
☂️ First batch of Linter Rules
Description
This umbrella task aims to track the list of lint rules we need to implement in order to get the linter ready for release (aka. provide helpful hints and fixes in real world code)
This list was assembled by collecting lint rules from various linter projects (the Rome JS linter, ESLint and popular plugins, and some concepts from the Clippy linter for Rust that also apply to JS), but more specifically I prioritized rules that are part of the recommended configurations and can be automatically fixed (some rules with no auto fixes but that still provide useful errors are included at the end). I also purposefully excluded most styling-related rules, since we have a formatter for that, as well as most rules that rely on type information (mainly in the ESLint TypeScript rules) as type checking is not part of the plan for the initial release of the analyzer.
Note that while this is an umbrella issue aimed at tracking the implementation work, the list is also open to discussion: I may have accidentally missed some rules (also as of 02 Jun. 2022 I haven't gone over and included rules from the ESLint React plugin yet), and we may also decide that some of these rules aren't required for the initial release and can be de-prioritized.
If you want to contribute
- make sure you understand the requirements of the rule you would like to implement;
- comment on this very issue telling saying which rule you would like to implement;
- create a new task issue and link to this very umbrella issue (a member of the team will eventually assign it to you);
- open a PR;
Note: please make sure to comment the issue saying which rule you'd like to implement, this would allow better coordination between contributors. Failing to do so would penalize yourselves against contributors that had followed these simple guildelines
Note: follow the naming convention guidelines: https://github.com/rome/tools/blob/archived-js/CONTRIBUTING.md#naming-patterns
Fixable Rules
Rome JS
- [x] #2647
Disallow comparing against
-0
Example fix:1 >= -0
->1 >= 0
- [x] #2651
Disallow the use of
debugger
- [x] #2660
Disallow unnecessary boolean casts
Example fix:
if (Boolean(foo)) {}
->if (foo) {}
- [x] #2656
Disallow negation in the condition of an if statement if it has an else clause
Example fix:
if (!true) {consequent;} else {alternate;}
->if (true) {alternate;} else {consequent;}
- [ ] #2754
Disallow the use of single character alternations in regular expressions
Example fix:
/a|b/
->/[ab]/
- [x] #2652
Disallow sparse arrays
Example fix:
[1,,2]
->[1,undefined,2]
- [x] #2746
This rule detects continue statements that can be marked as unnecessary. These statements can be safely removed
Example fix:
loop: for (let i = 0; i < 5; i++) { continue loop; }
->loop: for (let i = 0; i < 5; i++) {}
- [x] #2747
Disallow negating the left operand of relational operators
Example fix:
!1 in [1, 2]
->!(1 in [1, 2])
- [x] #2654
Disallow template literals if interpolation and special-character handling are not needed
Example fix:
const foo = `bar`;
->const foo = "bar";
- [ ] #2748
Use optional chaining to manual checks
Example fix:
foo && foo.bar;
->foo?.bar;
- [x] #2658
Prefer block statements to inline statements
Example fix:
if (x) x;
->if (x) { x; }
- [x] #2749
Discard redundant terms from logical expressions
Example fixes:
true && cond
->cond
true || cond
->true
null ?? exp
->exp
(!boolExpr1) || (!boolExpr2)
->!(boolExpr1 && boolExpr2)
Possible addition:!(a === b)
->a !== b
- [x] #2648
Enforces case clauses have a single statement
Example fix:
switch (foo) { case 1: foo; foo; }
->switch (foo) { case 1: { foo; foo; } }
- [ ] #2755
Enforces the specifiers in import declarations are sorted alphabetically
Example fix:
import {b, a, c, D} from 'mod';
->import {D, a, b, c} from "mod";
- [x] #2750
Prefer template literals to string concatenation
Example fix:
foo + "baz"
->`${foo}baz`
- [x] #2751
Comments inside children section of tag should be placed inside braces
Example fix:
<div>// comment</div>
-><div>{/** comment*/}</div>
- [x] noImplicitBoolean
Use explicit boolean values for boolean JSX props
Example fix:
<input disabled />
-><input disabled={true} />
- [x] useSelfClosingElements
Prevent extra closing tags for components without children
Example fix:
<div></div>
-><div />
- [x] noMultipleSpacesInRegularExpressionLiterals
Disallow multiple consecutive space characters in regular expressions
Example fix:
/ /
->/ {3}/
- [x] #2744
Prefer shorthand
T[]
syntax instead ofArray<T>
syntax Example fix:let a: Array<foo>;
->let a: foo[];
- [ ] #2753
Prefer
@ts-expect-error
to get notified when suppression is no longer necessary Example fix:// @ts-ignore
->// @ts-expect-error
Would it be better if we use task
or todo instead of markdown li
to mark each analysis rule, currently contributor has no idea which rule has been implemented.
@leops Rome classic used to define categories for lint rules (js
, regex
, ts
, react
, etc.). Is it something we are also doing here with this rewrite?
@ematipico , Would you mind open task for
- useBlockStatements
- noNegationElse
- noUnusedTemplateLiteral
- noSparseArray
- noCompareNegZero
- noDebugger
and assgin them to me ? Feel free to close tasks that i opened before.
I'd like to take over noExtraBooleanCast
:)
@ematipico , would you mind assigning me the task useSortedSpecifiers
?
@ematipico , would you mind assigning me the task
useSortedSpecifiers
?
Sure, please open the issue first
@ematipico , would you mind assigning me the task
useSortedSpecifiers
?Sure, please open the issue first
IIRC, you could convert the todo to a new issue, and after I finish the task, the checkbox will be automatically checked, maybe that would be a better way to manage the task?
@ematipico , would you mind assigning me the task noImplicitBoolean
?
https://github.com/rome/tools/issues/2699
@ematipico , would you mind assigning me the task useSelfClosingElements
?
@ematipico , would you mind assigning me the task useFragmentSyntax
?
https://github.com/rome/tools/issues/2712
Sorry, I found original implementation need the https://github.com/rome/tools/blob/6b47011c5f3d5ed783855b821cdbc9cf1d687266/internal/compiler/lint/utils/react/doesNodeMatchReactPattern.ts#L25, getBinding
which not support now, so just ignore me for now.
@ematipico , would you mind assigning me the task noMultipleSpacesInRegularExpressionLiterals
?
https://github.com/rome/tools/issues/2716
@ematipico , would you mind assigning me the task noUnsafeNegation
https://github.com/rome/tools/issues/2722
This could be nice to add some rules of denolint.
In particular, explicit-module-boundary-types. This is certainly a rule that will be enforced by TypeScript in declaration isolation mode. This is very close to type-first approach of flow.
@ematipico, Would you mind assigning me the eslint task noEmptyPattern
, in this page it should be no-empty-pattern
?
https://github.com/rome/tools/issues/2730
@ematipico , would you mind assigning me the eslint task noAsyncPromiseExecutor
, in this page it should be no-async-promise-executor
?
https://github.com/rome/tools/issues/2732
@ematipico , would you mind assigning me the eslint task no-dupe-args
?
https://github.com/rome/tools/issues/2735
@ematipico , would you mind assigning me the task preferShorthandArraytype
?
https://github.com/rome/tools/issues/2744
@ematipico , would you mind assigning me the task
preferShorthandArraytype
?
@IWANABETHATGUY Please rename the rule to useShorthandArraytype
Ok
I am going to close this issue. We have implemented most of the rules, the ones that remain will be moved to https://github.com/rome/tools/issues/2743, with their requirements.
The rule useSortedSpecifiers
is mostly a styling rule and it might be implemented in the formatter.