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
[prefer-optional-chain] Breaking change in v5.16.0 - requires type information #4755
Comments
The rule does not require type information. Our tests for the rule do not run with type information and are all passing. Likely there is something else at play here. |
Sorry for my initial assumption. Indeed it does not require type information. However when used together with the Reproducible with: https://gist.github.com/avaly/674f8bc818b2493ff54260090e9f73aa
If I disable the |
I'm having the same error with version v5.16.0. |
Using our rules on files that are not TypeScript files or with parsers that are not The fact that it used to work and now that it doesn't is not a breaking change because we never defined that our rules would work for this usecase. This is the danger of relying upon undefined behaviour - it may break at any time and without warning. You can use overrides to specify which rules should or should not be run on files. |
Fwiw, I ran into this issue as well, and took this as an opportunity to finally move my top-level plugins & rules to a JS/TS specific override so they do not by default also apply to other file types. It doesn't make a lot of sense to have @typescript-eslint and its rules run on GraphQL files, as @bradzacher says. In essence, it means moving all your global config to a JS/TS override, i.e. module.exports = {
files: '**/*.{js,ts,jsx,tsx}',
parser: '@typescript-eslint/parser',
parserOptions: {
sourceType: 'module',
project: './tsconfig.json'
},
plugins: ['@typescript-eslint'],
rules: {
// ...
},
overrides: [
{
files: '**/*.gql',
parserOptions: {
operations: './src/**/*.gql'
},
extends: ['plugin:@graphql-eslint/operations-recommended']
}
]
} to module.exports = {
overrides: [
{
files: '**/*.{js,ts,jsx,tsx}',
parser: '@typescript-eslint/parser',
parserOptions: {
sourceType: 'module',
project: './tsconfig.json'
},
plugins: ['@typescript-eslint'],
rules: {
// ...
}
},
{
files: '**/*.gql',
parserOptions: {
operations: './src/**/*.gql'
},
extends: ['plugin:@graphql-eslint/operations-recommended']
}
]
} Everything should keep working as before, and probably a little faster as well. |
Repro
// your repro code case
Expected Result
This rule used to work without type information before v5.16.0
Actual Result
Upgrading to v5.16.0, it now requires type information.
Additional Info
This is a breaking change and should be included in a major version bump.
Also, the documentation table on the rules do not mention this rule requires type information: https://github.com/typescript-eslint/typescript-eslint/tree/main/packages/eslint-plugin
Regression introduced in #4430
Versions
@typescript-eslint/eslint-plugin
5.16.0
@typescript-eslint/parser
5.16.0
TypeScript
4.6.2
ESLint
8.11.0
node
14.19.1
The text was updated successfully, but these errors were encountered: