-
Notifications
You must be signed in to change notification settings - Fork 660
☂️ First batch of Linter Rules #2642
Comments
Would it be better if we use |
@leops Rome classic used to define categories for lint rules ( |
@ematipico , Would you mind open task for
and assgin them to me ? |
I'd like to take over |
@ematipico , would you mind assigning me the task |
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 |
@ematipico , would you mind assigning me the task |
@ematipico , would you mind assigning me the task |
Sorry, I found original implementation need the https://github.com/rome/tools/blob/6b47011c5f3d5ed783855b821cdbc9cf1d687266/internal/compiler/lint/utils/react/doesNodeMatchReactPattern.ts#L25, |
@ematipico , would you mind assigning me the task |
@ematipico , would you mind assigning me the task |
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 |
@ematipico , would you mind assigning me the eslint task |
@ematipico , would you mind assigning me the eslint task |
@ematipico , would you mind assigning me the task |
@IWANABETHATGUY Please rename the rule to |
Ok |
I am going to close this issue. We have implemented most of the rules, the ones that remain will be moved to #2743, with their requirements. The rule |
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
Fixable Rules
Rome JS
Disallow comparing against
-0
Example fix:
1 >= -0
->1 >= 0
Disallow the use of
debugger
Disallow unnecessary boolean casts
Example fix:
if (Boolean(foo)) {}
->if (foo) {}
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;}
Disallow the use of single character alternations in regular expressions
Example fix:
/a|b/
->/[ab]/
Disallow sparse arrays
Example fix:
[1,,2]
->[1,undefined,2]
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++) {}
Disallow negating the left operand of relational operators
Example fix:
!1 in [1, 2]
->!(1 in [1, 2])
Disallow template literals if interpolation and special-character handling are not needed
Example fix:
const foo = `bar`;
->const foo = "bar";
Use optional chaining to manual checks
Example fix:
foo && foo.bar;
->foo?.bar;
Prefer block statements to inline statements
Example fix:
if (x) x;
->if (x) { x; }
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
Enforces case clauses have a single statement
Example fix:
switch (foo) { case 1: foo; foo; }
->switch (foo) { case 1: { foo; foo; } }
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";
Prefer template literals to string concatenation
Example fix:
foo + "baz"
->`${foo}baz`
Comments inside children section of tag should be placed inside braces
Example fix:
<div>// comment</div>
-><div>{/** comment*/}</div>
Use explicit boolean values for boolean JSX props
Example fix:
<input disabled />
-><input disabled={true} />
Prevent extra closing tags for components without children
Example fix:
<div></div>
-><div />
Disallow multiple consecutive space characters in regular expressions
Example fix:
/ /
->/ {3}/
Prefer shorthand
T[]
syntax instead ofArray<T>
syntaxExample fix:
let a: Array<foo>;
->let a: foo[];
Prefer
@ts-expect-error
to get notified when suppression is no longer necessaryExample fix:
// @ts-ignore
->// @ts-expect-error
The text was updated successfully, but these errors were encountered: