-
Notifications
You must be signed in to change notification settings - Fork 27.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
chore: enable typescript-eslint's recommended and stylistic configs internally #52948
Changes from 9 commits
82c36ad
532a1aa
6e124d0
e66cf37
bf8552f
7785336
e83fd0a
8ffc882
2e767c5
3210ea5
1dd34cb
fd0a6b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,36 +43,51 @@ | |
}, | ||
{ "files": ["**/__tests__/**"], "env": { "jest": true } }, | ||
{ | ||
"extends": [ | ||
"plugin:@typescript-eslint/recommended", | ||
"plugin:@typescript-eslint/stylistic" | ||
], | ||
"files": ["**/*.ts", "**/*.tsx"], | ||
"parser": "@typescript-eslint/parser", | ||
"parserOptions": { | ||
"ecmaVersion": 2018, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unnecessary configuration line. Per https://typescript-eslint.io/packages/parser#ecmaversion, 2018 is the default now. |
||
"sourceType": "module", | ||
"ecmaFeatures": { | ||
"jsx": true | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unnecessary configuration line, I think (are there odd situations I didn't notice?). Per https://typescript-eslint.io/packages/parser#jsx, although it defaults to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about I think its best to keep There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
From the same docs link: I'm curious: are you doing anything contrary to the default TypeScript behavior?
I'm under the impression this file only impacts Next.js repo development, not end-user development. Just to make sure we're on the same page: am I wrong about that? If so, how would this impact end users? |
||
"warnOnUnsupportedTypeScriptVersion": false | ||
}, | ||
"plugins": ["@typescript-eslint"], | ||
"rules": { | ||
// Already handled by TS | ||
"no-dupe-class-members": "off", | ||
"no-undef": "off", | ||
|
||
// Add TypeScript specific rules (and turn off ESLint equivalents) | ||
"@typescript-eslint/consistent-type-assertions": "warn", | ||
"no-array-constructor": "off", | ||
"@typescript-eslint/no-array-constructor": "warn", | ||
// Todo: investigate, for each of these rules, whether we want them. | ||
"@typescript-eslint/array-type": "off", | ||
"@typescript-eslint/ban-ts-comment": "off", | ||
"@typescript-eslint/ban-tslint-comment": "off", | ||
"@typescript-eslint/ban-types": "off", | ||
"@typescript-eslint/class-literal-property-style": "off", | ||
"@typescript-eslint/consistent-generic-constructors": "off", | ||
"@typescript-eslint/consistent-indexed-object-style": "off", | ||
"@typescript-eslint/consistent-type-definitions": "off", | ||
"@typescript-eslint/no-empty-function": "off", | ||
"@typescript-eslint/no-namespace": "off", | ||
"no-use-before-define": "off", | ||
"@typescript-eslint/no-use-before-define": [ | ||
"warn", | ||
"@typescript-eslint/no-shadow": "off", | ||
"@typescript-eslint/no-empty-interface": "off", | ||
"@typescript-eslint/no-explicit-any": "off", | ||
"@typescript-eslint/no-inferrable-types": "off", | ||
"@typescript-eslint/no-var-requires": "off", | ||
"@typescript-eslint/prefer-for-of": "off", | ||
"@typescript-eslint/prefer-function-type": "off", | ||
"@typescript-eslint/no-this-alias": "off", | ||
"@typescript-eslint/triple-slash-reference": "off", | ||
"no-var": "off", | ||
"prefer-const": "off", | ||
"prefer-rest-params": "off", | ||
"prefer-spread": "off", | ||
|
||
// These off- or differently-configured rules work well for us. | ||
"no-unused-expressions": "off", | ||
"@typescript-eslint/no-unused-expressions": [ | ||
"error", | ||
{ | ||
"functions": true, | ||
"classes": true, | ||
"variables": true, | ||
"enums": true, | ||
"typedefs": true | ||
"allowShortCircuit": true, | ||
"allowTernary": true, | ||
"allowTaggedTemplates": true | ||
} | ||
], | ||
"no-unused-vars": "off", | ||
|
@@ -83,19 +98,20 @@ | |
"ignoreRestSiblings": true | ||
} | ||
], | ||
"no-unused-expressions": "off", | ||
"@typescript-eslint/no-unused-expressions": [ | ||
"error", | ||
"no-use-before-define": "off", | ||
"@typescript-eslint/no-use-before-define": [ | ||
"warn", | ||
{ | ||
"allowShortCircuit": true, | ||
"allowTernary": true, | ||
"allowTaggedTemplates": true | ||
"functions": true, | ||
"classes": true, | ||
"variables": true, | ||
"enums": true, | ||
"typedefs": true | ||
} | ||
], | ||
"no-useless-constructor": "off", | ||
"@typescript-eslint/no-useless-constructor": "warn", | ||
"@typescript-eslint/prefer-literal-enum-member": "error", | ||
"@typescript-eslint/prefer-namespace-keyword": "error" | ||
"@typescript-eslint/prefer-literal-enum-member": "error" | ||
}, | ||
"overrides": [ | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,7 +77,7 @@ export function getUrlFromPagesDirectories( | |
}) | ||
} | ||
|
||
export function execOnce<TArgs extends any[], TResult extends unknown>( | ||
export function execOnce<TArgs extends any[], TResult>( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://typescript-eslint.io/rules/no-unnecessary-type-constraint: |
||
fn: (...args: TArgs) => TResult | ||
): (...args: TArgs) => TResult { | ||
let used = false | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,6 +80,8 @@ export function processEnv( | |
typeof parsed[key] === 'undefined' && | ||
typeof origEnv[key] === 'undefined' | ||
) { | ||
// We're being imprecise in the type system - assume parsed[key] can be undefined | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See https://twitter.com/mattpocockuk/status/1681267079977000961 from our friend @mattpocock about why I'm not going to try to get this working perfectly 😄 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about changing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That might work! I've learned the hard way to not try to change runtime behavior in static analysis oriented PRs like this one. If you really want me to make this change I can - but would suggest moving it to a separate PR as a separate cleanup item. |
||
parsed[key] = result.parsed?.[key]! | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -465,7 +465,7 @@ function getCodeAnalyzer(params: { | |
buildInfo.importLocByPath = new Map() | ||
} | ||
|
||
const importedModule = node.source.value?.toString()! | ||
const importedModule = node.source.value?.toString() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://typescript-eslint.io/rules/no-non-null-asserted-optional-chain: putting a |
||
buildInfo.importLocByPath.set(importedModule, { | ||
sourcePosition: { | ||
...node.loc.start, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
// source: https://github.com/sindresorhus/fnv1a | ||
// FNV_PRIMES and FNV_OFFSETS from | ||
// http://www.isthe.com/chongo/tech/comp/fnv/index.html#FNV-param | ||
/* eslint-disable @typescript-eslint/no-loss-of-precision */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because this is copy & pasted from an external source that deals with numbers, I don't think we really needed to flag for correct behavior around numeric precision. 😄 For reference, https://typescript-eslint.io/rules/no-loss-of-precision/ (and also typescript-eslint/typescript-eslint#7277 noting that the typescript-eslint extension might not be necessary anymore) |
||
|
||
const FNV_PRIMES = { | ||
32: BigInt(16_777_619), | ||
|
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.
Note that this doesn't enable type checked rules internally. I tried and they OOMd (typescript-eslint/typescript-eslint#1192). 😞
As a followup I'd love to try tinkering with the monorepo configuration (https://typescript-eslint.io/linting/typed-linting/monorepos) and/or using our new
EXPERIMENTAL_useProjectService
option (typescript-eslint/typescript-eslint#6754)