-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Repo: enable more core ESLint rules internally #9523
Comments
I'm guessing a fair amount can be pruned from this list.... At a glance,
But, I'm sure there are some that would make sense to enable! |
It would be |
🥴 |
I'm +1 on the following rules:
I'm +0.5 on the following rules:
I'm -1 on the following rules:
|
I basically agree with @Josh-Cena. Only notable differences in opinion are
Note that, in my experience, |
How is that different from using |
If it interests you: I have written down my opinion on every ESLint rule here: https://jc-verse.github.io/js-style-guide/eslint-base/ ;) (WIP) |
@Josh-Cena very cool! love that |
For all the stylistic rules - throw them all away straight away - unless they have a fixer for all cases. Why? Migration effort for starters. Maintenance burden (eg copying in forked code). Contributor pains (having to manually adjust their natural code style to meet our preference). I'm a -1 on I'm a -1 on -1 on -1 on -1000 on -0.1 on -1 on -0.5 on |
Good question - took me a minute to remember when and why I formed this opinion. The reason is I was working in a project where we had lots of code roughly like this
IMO the second variant ("after fix") is by far the least readable, and it's really hard to notice the space in the middle compared to the other two forms. In retrospect, I think this readability pitfall might have been pretty specific to that codebase due to the |
The rule doesn't report on this. It also doesn't report on I think the rule works very nicely with object properties and I would recommend. The only reservations I have are with array indices, where the reports are neither always better nor always correct (it transforms code using array-like protocol to iterable protocol).
Exhaustiveness should be asserted or with a fallback guard; but I agree it's less useful in TS because TS also checks this.
Disagree—it increases code entropy for no clear reason. I'm in the camp that "if you remove something, you must remove all other extra syntax that was necessitated by it until your code is reduced to absolute minimum".
You should definitely do
I agree that sometimes it's good to be defensive and preemptively terminate all possible branches, but I also think it's extra syntax to create confusion.
Well, either fix the types or assert? |
I do see @bradzacher's points, but tend to agree most with @Josh-Cena here. At any rate, I'll open some draft PRs for some of these so we can start seeing what these individual rule changesets look like. |
Which is my point! My point is that if I write this code: const bar = foo.bar;
const bar = foo?.bar;
const bar: T = foo.bar; Then the rule would force me to instead write const { bar } = foo;
const bar = foo?.bar;
const bar: T = foo.bar; And now I've got inconsistently styled code. |
Ummm... Sure? People can also opt into |
You say
And you also say
So is the exhaustive pre-emption confusing extra syntax, or is it required? The case I specifically mentioned was this, which is the last statement in a function: I think we've got our exhaustive switch rule turned on in our codebase, don't we? The rule reports on the last case's return - saying its useless. It's not wrong but also the options are:
It's just an example of where the extra syntax isn't noise and it isn't confusing. TBH it took me a second to realise why the rule reported on it - cos the function decl header is many lines above and wasn't on my screen - so all I could see was the closing curlies. It's why I'm a strong -1. I'd even bump it to a -2 on |
This won't appear like a bug to anyone and is there to be future-proof: switch (x) {
case ...:
default:
throw new Error("Unreachable");
} This is unnecessary syntax, is trivially refactorable, but isn't likely a bug: doSomething(() => {
return ...
}); This is unnecessary syntax, and is likely a bug: for (const x of y) {
...
return;
} This is unnecessary syntax, could be preventing bugs, but the bug vector is unclear and more implicit, because it isn't meant to catch effect-at-a-distance kind of bug like switch exhaustiveness check does. function x() {
if (...) {
...
return;
} else {
...
return;
}
} |
My point is that the rule flags this: switch (v) {
case a:
return;
case b:
return; // flagged as unnecessary
} My argument is that this is technically unnecessary but it:
Eg case b:
+ return;
+
+case c: Vs case b:
return;
+
+case c:
+ return; Smaller diffs are nicer. I just don't personally see any positives with deleting a We can agree to disagree here - I'm still a -1 on the rule. |
Practically, in this case, I would suggest changing it to |
Summary(Someone please yell if any of these are wrong) AcceptedSounds like there is no objection for
And sufficient consensus to proceed if someone wants to champion
Rejected/vetoed
EDIT - moved some around to reflect #9523 (comment) |
I'm personally -0.5 on The rule bans that pattern and forces you to move the function outside the class entirely as a standalone declararion - which I disagree with, personally.
|
Doesn't |
Looks like we have a plan of action! 🙂 I would just like to remind implementers of PRs for this issue (i.e. @abrahamguo 🙂) to pls double check for typescript-eslint extension rules for any of these. Might have missed some in the list. |
That's an API change and if you look at the reports I don't think they make sense. |
Suggestion
I was looking through the core ESLint rules that we do not have turned on internally, and I found these rules that might be beneficial to enable. Thoughts?
array-callback-return (2 occurrences)
docs
Array.prototype.filter() expects a value to be returned at the end of arrow function.
eslint-plugin/tests/configs.test.ts:60
typescript-eslint/tests/configs.test.ts:64
arrow-body-style (41 occurrences)
docs
Unexpected block statement surrounding arrow body; move the returned value immediately after the
=>
.eslint-plugin/src/rules/class-literal-property-style.ts:173
eslint-plugin/src/rules/max-params.ts:81
eslint-plugin/src/rules/naming-convention.ts:714
eslint-plugin/src/rules/no-array-delete.ts:92
eslint-plugin/src/rules/no-duplicate-type-constituents.ts:189
eslint-plugin/src/rules/no-extraneous-class.ts:72
eslint-plugin/src/rules/no-meaningless-void-operator.ts:52
eslint-plugin/src/rules/no-type-alias.ts:229
eslint-plugin/src/rules/no-unnecessary-template-expression.ts:41
eslint-plugin/src/rules/no-useless-template-literals.ts:42
eslint-plugin/src/rules/non-nullable-type-assertion-style.ts:94
eslint-plugin/src/rules/prefer-enum-initializers.ts:42
eslint-plugin/src/rules/prefer-enum-initializers.ts:49
eslint-plugin/src/rules/prefer-enum-initializers.ts:56
eslint-plugin/src/rules/prefer-find.ts:258
eslint-plugin/src/rules/prefer-find.ts:298
eslint-plugin/src/rules/prefer-function-type.ts:145
eslint-plugin/tests/rules/block-spacing.test.ts:78
type-utils/src/builtinSymbolLikes.ts:81
website/plugins/blog-footer.ts:6
website/plugins/generated-rule-docs/index.ts:17
website/src/components/ErrorsViewer.tsx:136
website/src/components/config/ConfigEditor.tsx:99
website/src/components/config/ConfigTypeScript.tsx:33
website/src/components/editor/LoadedEditor.tsx:270
website/src/components/hooks/useResizeObserver.ts:7
website/src/components/inputs/Text.tsx:17
website/src/components/linter/createParser.ts:27
website/src/pages/play.tsx:16
Unexpected block statement surrounding arrow body; parenthesize the returned value and move it immediately after the
=>
.eslint-plugin/src/rules/ban-tslint-comment.ts:33
eslint-plugin/tests/rules/prefer-readonly-parameter-types.test.ts:530
rule-tester/src/RuleTester.ts:327
rule-tester/tests/RuleTester.test.ts:95
rule-tester/tests/RuleTester.test.ts:138
typescript-estree/tests/lib/semanticInfo-singleRun.test.ts:23
typescript-estree/tests/lib/semanticInfo-singleRun.test.ts:35
typescript-estree/tests/lib/semanticInfo-singleRun.test.ts:51
typescript-estree/tests/lib/semanticInfo-singleRun.test.ts:56
typescript-estree/tests/lib/semanticInfo-singleRun.test.ts:66
website/sidebars/sidebar.rules.js:3
website/sidebars/sidebar.rules.js:13
class-methods-use-this (13 occurrences)
docs
Expected
this
to be used by class methodBreakStatement
.scope-manager/src/referencer/Referencer.ts:386
Expected
this
to be used by class methodContinueStatement
.scope-manager/src/referencer/Referencer.ts:425
Expected
this
to be used by class methodDecorator
.scope-manager/src/referencer/PatternVisitor.ts:90
Expected
this
to be used by class methodExportAllDeclaration
.scope-manager/src/referencer/Referencer.ts:429
Expected
this
to be used by class methodImportAttribute
.scope-manager/src/referencer/Referencer.ts:813
Expected
this
to be used by class methodisES6
.scope-manager/src/ScopeManager.ts:87
Expected
this
to be used by class methodisStrictModeSupported
.scope-manager/src/ScopeManager.ts:83
Expected
this
to be used by class methodisValidResolution
.scope-manager/src/scope/ScopeBase.ts:374
Expected
this
to be used by class methodJSXClosingElement
.scope-manager/src/referencer/Referencer.ts:517
Expected
this
to be used by class methodMetaProperty
.scope-manager/src/referencer/Referencer.ts:575
Expected
this
to be used by class methodPrivateIdentifier
.scope-manager/src/referencer/ClassVisitor.ts:319
scope-manager/src/referencer/Referencer.ts:584
Expected
this
to be used by class methodTSTypeAnnotation
.scope-manager/src/referencer/PatternVisitor.ts:136
default-param-last (1 occurrence)
docs
Default parameters should be last.
scope-manager/src/scope/ScopeBase.ts:444
no-await-in-loop (2 occurrences)
docs
Unexpected
await
inside a loop.repo-tools/src/generate-contributors.mts:59
repo-tools/src/generate-lib.mts:250
no-lonely-if (9 occurrences)
docs
Unexpected if as the only statement in an else block.
eslint-plugin/src/rules/consistent-type-imports.ts:181
eslint-plugin/src/rules/consistent-type-imports.ts:735
eslint-plugin/src/rules/func-call-spacing.ts:155
eslint-plugin/src/rules/member-delimiter-style.ts:276
eslint-plugin/src/rules/no-non-null-assertion.ts:83
eslint-plugin/src/rules/no-unused-vars.ts:272
eslint-plugin/src/rules/prefer-optional-chain-utils/analyzeChain.ts:228
scope-manager/src/referencer/Referencer.ts:535
typescript-estree/src/convert.ts:986
no-negated-condition (44 occurrences)
docs
Unexpected negated condition.
ast-spec/tests/fixtures.test.ts:210
ast-spec/tests/fixtures.test.ts:314
eslint-plugin/src/rules/consistent-type-assertions.ts:119
eslint-plugin/src/rules/consistent-type-exports.ts:363
eslint-plugin/src/rules/key-spacing.ts:122
eslint-plugin/src/rules/member-ordering.ts:1056
eslint-plugin/src/rules/naming-convention-utils/parse-options.ts:43
eslint-plugin/src/rules/naming-convention-utils/parse-options.ts:47
eslint-plugin/src/rules/naming-convention-utils/parse-options.ts:55
eslint-plugin/src/rules/no-empty-interface.ts:98
eslint-plugin/src/rules/no-non-null-assertion.ts:57
eslint-plugin/src/rules/no-non-null-assertion.ts:101
eslint-plugin/src/rules/no-unnecessary-condition.ts:283
eslint-plugin/src/rules/no-unnecessary-condition.ts:285
eslint-plugin/src/rules/prefer-function-type.ts:126
eslint-plugin/src/rules/prefer-function-type.ts:164
eslint-plugin/src/rules/type-annotation-spacing.ts:44
eslint-plugin/src/rules/type-annotation-spacing.ts:45
eslint-plugin/src/rules/unified-signatures.ts:214
eslint-plugin/src/rules/unified-signatures.ts:216
eslint-plugin/src/rules/unified-signatures.ts:534
eslint-plugin/src/util/getFunctionHeadLoc.ts:40
eslint-plugin/src/util/getMemberHeadLoc.ts:52
eslint-plugin/tests/rules/prefer-optional-chain/base-cases.ts:274
rule-schema-to-typescript-types/src/generateArrayType.ts:47
scope-manager/src/referencer/ExportVisitor.ts:61
scope-manager/src/referencer/Referencer.ts:180
scope-manager/src/referencer/Referencer.ts:343
scope-manager/src/referencer/Referencer.ts:532
scope-manager/src/scope/ScopeBase.ts:356
scope-manager/tests/test-utils/serializers/baseSerializer.ts:34
typescript-estree/src/convert.ts:998
typescript-estree/src/convert.ts:1326
typescript-estree/src/convert.ts:1427
typescript-estree/src/convert.ts:2335
typescript-estree/src/convert.ts:2995
typescript-estree/src/create-program/getWatchProgramsForProjects.ts:336
typescript-estree/src/create-program/shared.ts:59
typescript-estree/tests/lib/parse.test.ts:206
website/src/components/ast/PropertyValue.tsx:70
website/src/components/ast/PropertyValue.tsx:79
website/src/components/inputs/CopyButton.tsx:41
website/src/components/inputs/Dropdown.tsx:24
website/src/components/layout/EditorTabs.tsx:25
no-undef-init (3 occurrences)
docs
It
s not necessary to initialize
previousRank: number | undefined` to undefined.eslint-plugin/src/rules/member-ordering.ts:656
It
s not necessary to initialize
prevNode: TSESTree.Node | undefined` to undefined.eslint-plugin/src/rules/key-spacing.ts:392
It
s not necessary to initialize
primitive: number | undefined` to undefined.eslint-plugin/src/rules/no-redundant-type-constituents.ts:345
no-unreachable-loop (2 occurrences)
docs
Invalid loop. Its body allows only one iteration.
eslint-plugin/src/rules/no-mixed-enums.ts:174
eslint-plugin/src/rules/no-unsafe-return.ts:169
no-unused-expressions (7 occurrences)
docs
Expected an assignment or function call and instead saw an expression.
eslint-plugin/src/rules/strict-boolean-expressions.ts:851
eslint-plugin/src/rules/unified-signatures.ts:502
typescript-estree/tests/lib/convert.test.ts:309
typescript-estree/tests/lib/convert.test.ts:326
typescript-estree/tests/lib/convert.test.ts:327
typescript-estree/tests/lib/convert.test.ts:342
typescript-estree/tests/lib/persistentParse.test.ts:68
no-useless-call (1 occurrence)
docs
Unnecessary
.call()
.website/src/components/lib/debounce.ts:12
no-useless-computed-key (1 occurrence)
docs
Unnecessarily computed property [
MemberExpression[computed=true]
] found.eslint-plugin/src/rules/prefer-find.ts:285
no-useless-concat (4 occurrences)
docs
Unexpected string concatenation of literals.
eslint-plugin/tests/rules/dot-notation.test.ts:242
eslint-plugin/tests/rules/dot-notation.test.ts:243
eslint-plugin/tests/rules/dot-notation.test.ts:282
eslint-plugin/tests/rules/dot-notation.test.ts:283
no-useless-return (12 occurrences)
docs
Unnecessary return statement.
eslint-plugin/src/rules/explicit-module-boundary-types.ts:240
eslint-plugin/src/rules/no-misused-promises.ts:346
eslint-plugin/src/rules/no-unnecessary-condition.ts:403
eslint-plugin/src/rules/prefer-reduce-type-parameter.ts:116
eslint-plugin/src/rules/prefer-return-this-type.ts:115
eslint-plugin/src/rules/prefer-return-this-type.ts:118
eslint-plugin/src/rules/return-await.ts:359
eslint-plugin/src/util/getThisExpression.ts:21
rule-schema-to-typescript-types/src/optimizeAST.ts:51
typescript-estree/tests/lib/semanticInfo-singleRun.test.ts:13
typescript-estree/tests/lib/semanticInfo-singleRun.test.ts:16
website/src/components/lib/scroll-into.ts:32
no-var (1 occurrence)
docs
Unexpected var, use let or const instead.
website-eslint/src/mock/path.js:150
no-void (1 occurrence)
docs
Expected
undefined
and instead sawvoid
.rule-tester/src/RuleTester.ts:974
object-shorthand (41 occurrences)
docs
Expected method shorthand.
eslint-plugin/src/rules/no-unnecessary-boolean-literal-compare.ts:219
eslint-plugin/src/rules/no-unnecessary-qualifier.ts:179
Expected property shorthand.
eslint-plugin/src/rules/indent.ts:282
eslint-plugin/src/rules/index.ts:177
eslint-plugin/src/rules/index.ts:281
eslint-plugin/src/rules/index.ts:287
eslint-plugin/src/rules/index.ts:296
eslint-plugin/src/rules/no-unsafe-assignment.ts:404
eslint-plugin/src/rules/no-unsafe-call.ts:72
eslint-plugin/src/rules/type-annotation-spacing.ts:60
eslint-plugin/src/rules/type-annotation-spacing.ts:61
eslint-plugin/tests/rules/naming-convention/cases/createTestCases.ts:288
rule-tester/src/utils/validationHelpers.ts:114
typescript-estree/src/convert.ts:2339
typescript-estree/src/convert.ts:2907
typescript-estree/src/convert.ts:3047
typescript-estree/src/parseSettings/createParseSettings.ts:167
website-eslint/src/mock/assert.js:70
website-eslint/src/mock/assert.js:71
website-eslint/src/mock/assert.js:72
website-eslint/src/mock/assert.js:73
website-eslint/src/mock/assert.js:74
website-eslint/src/mock/path.js:220
website-eslint/src/mock/path.js:221
website-eslint/src/mock/path.js:222
website-eslint/src/mock/path.js:223
website-eslint/src/mock/path.js:224
website-eslint/src/mock/path.js:225
website-eslint/src/mock/path.js:226
website-eslint/src/mock/path.js:227
website-eslint/src/mock/path.js:228
website-eslint/src/mock/path.js:229
website/sidebars/sidebar.rules.js:5
website/src/components/ast/DataRenderer.tsx:146
website/src/components/lib/jsonSchema.ts:128
website/src/components/lib/jsonSchema.ts:209
website/src/components/linter/createLinter.ts:69
website/src/components/linter/createLinter.ts:107
website/src/components/linter/createParser.ts:60
website/src/components/linter/createParser.ts:62
website/src/components/linter/utils.ts:98
operator-assignment (1 occurrence)
docs
Assignment (=) can be replaced with operator assignment (+=).
rule-schema-to-typescript-types/src/index.ts:53
prefer-arrow-callback (3 occurrences)
docs
Unexpected function expression.
website-eslint/src/mock/path.js:85
website-eslint/src/mock/path.js:102
website-eslint/src/mock/path.js:127
prefer-const (2 occurrences)
docs
isPathAbsolute
is never reassigned. Useconst
instead.website-eslint/src/mock/path.js:97
trailingSlash
is never reassigned. Useconst
instead.website-eslint/src/mock/path.js:98
prefer-object-has-own (11 occurrences)
docs
Use
Object.hasOwn()
instead ofObject.prototype.hasOwnProperty.call()
.eslint-plugin-internal/src/rules/prefer-ast-types-enum.ts:58
eslint-plugin-internal/src/rules/prefer-ast-types-enum.ts:62
eslint-plugin-internal/src/rules/prefer-ast-types-enum.ts:66
eslint-plugin/src/rules/no-duplicate-type-constituents.ts:48
eslint-plugin/src/rules/no-restricted-imports.ts:175
eslint-plugin/src/rules/no-restricted-imports.ts:181
rule-tester/src/utils/cloneDeeplyExcludesParent.ts:14
rule-tester/src/utils/freezeDeeply.ts:10
rule-tester/src/utils/serialization.ts:29
type-utils/src/isTypeReadonly.ts:47
typescript-estree/tests/test-utils/test-utils.ts:127
prefer-object-spread (9 occurrences)
docs
Use an object spread instead of
Object.assign
eg:{ ...foo }
.eslint-plugin/src/rules/ban-types.ts:210
eslint-plugin/src/rules/indent.ts:184
eslint-plugin/src/rules/no-extra-parens.ts:306
eslint-plugin/src/util/getFunctionHeadLoc.ts:200
eslint-plugin/src/util/getFunctionHeadLoc.ts:201
parser/tests/test-utils/test-utils.ts:43
parser/tests/test-utils/test-utils.ts:75
rule-tester/src/RuleTester.ts:404
utils/tests/eslint-utils/deepMerge.test.ts:41
prefer-rest-params (2 occurrences)
docs
Use the rest parameters instead of
arguments
.website-eslint/src/mock/path.js:67
website-eslint/src/mock/path.js:125
prefer-template (36 occurrences)
docs
Unexpected string concatenation.
ast-spec/tests/util/serialize-error.ts:17
ast-spec/tests/util/snapshot-diff.ts:60
eslint-plugin-internal/src/rules/plugin-test-formatting.ts:66
eslint-plugin/src/rules/consistent-generic-constructors.ts:106
eslint-plugin/src/rules/no-floating-promises.ts:70
eslint-plugin/src/rules/no-floating-promises.ts:72
eslint-plugin/src/rules/no-unsafe-assignment.ts:327
eslint-plugin/src/rules/no-unsafe-assignment.ts:328
eslint-plugin/src/rules/prefer-function-type.ts:147
eslint-plugin/src/rules/prefer-optional-chain-utils/analyzeChain.ts:348
eslint-plugin/src/rules/prefer-optional-chain-utils/analyzeChain.ts:358
eslint-plugin/src/rules/unbound-method.ts:107
eslint-plugin/src/rules/use-unknown-in-catch-callback-variable.ts:45
eslint-plugin/src/rules/use-unknown-in-catch-callback-variable.ts:47
eslint-plugin/src/rules/use-unknown-in-catch-callback-variable.ts:50
eslint-plugin/tests/docs.test.ts:86
eslint-plugin/tests/docs.test.ts:90
eslint-plugin/tests/docs.test.ts:100
eslint-plugin/tests/docs.test.ts:455
eslint-plugin/tests/docs.test.ts:461
eslint-plugin/tests/docs.test.ts:469
eslint-plugin/tests/docs.test.ts:475
eslint-plugin/tests/docs.test.ts:485
eslint-plugin/tools/generate-breaking-changes.mts:42
parser/tests/test-utils/test-utils.ts:90
rule-schema-to-typescript-types/src/index.ts:53
typescript-estree/tests/test-utils/test-utils.ts:61
utils/tests/eslint-utils/getParserServices.test.ts:36
website-eslint/build.ts:26
website-eslint/build.ts:33
website-eslint/src/mock/assert.js:54
website-eslint/src/mock/path.js:76
website/src/components/editor/createProvideTwoslashInlay.ts:71
website/src/components/editor/createProvideTwoslashInlay.ts:83
website/src/components/editor/useSandboxServices.ts:88
website/tools/generate-website-dts.ts:56
radix (2 occurrences)
docs
Missing radix parameter.
eslint-plugin/src/util/misc.ts:163
eslint-plugin/tests/schemas.test.ts:172
The text was updated successfully, but these errors were encountered: