[eslint-config-react-app] Can't disable rule "@typescript-eslint/no-unused-vars" in config, outside of CRA
See original GitHub issueRelated
https://github.com/facebook/create-react-app/issues/6871 https://github.com/facebook/create-react-app/issues/6915
Is this a bug report?
Yes
Did you try recovering your dependencies?
Yes
Which terms did you search for in User Guide?
no-unused-vars, etc.
Environment
eslint-config-react-app@^4.0.0:
version "4.0.0"
eslint@^5.16.0:
version "5.16.0"
"@typescript-eslint/eslint-plugin@^1.7.0":
version "1.7.0"
"@typescript-eslint/parser@1.7.0", "@typescript-eslint/parser@^1.7.0":
version "1.7.0"
Steps to Reproduce
In .eslintrc.js, when react-app
is extended, e.g.
extends: ['plugin:@typescript-eslint/recommended', "react-app"],
it is impossible to disable the @typescript-eslint/no-unused-vars
rule, e.g.,
"rules": {
"no-unused-vars":"off",
"@typescript-eslint/no-unused-vars": "off",
eslint is invoked at the command line using
npx eslint --ext .js,.jsx,.ts,.tsx src
No error message regarding the configuration is emitted; it simply ignores the configuration.
After reading the code, I suspect that these rules also suffer from the same petrification.
- @typescript-eslint/no-angle-bracket-type-assertion
- @typescript-eslint/no-array-constructor
- @typescript-eslint/no-namespace
- @typescript-eslint/no-useless-constructor
Workaround
Include this at the top level of the config object:
"overrides": {
files: ['**/*.ts', '**/*.tsx'],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
ecmaFeatures: {
jsx: true,
},
// typescript-eslint specific options
warnOnUnsupportedTypeScriptVersion: true,
},
plugins: ['@typescript-eslint'],
rules: {
"@typescript-eslint/no-unused-vars": "off",
}
},
This workaround is probably much more verbose than is wise or necessary, but it is sufficient.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:30
- Comments:18 (1 by maintainers)
Top Results From Across the Web
Typescript eslint disable no-unused-vars - Stack Overflow
"eslintConfig": { "extends": "react-app", "rules": { "@typescript-eslint/no-unused-vars": "off" } },. I tried moving the rules into a .eslintrc.
Read more >12 essential ESLint rules for React - LogRocket Blog
All versions of react-scripts (one of CRA's packages) from v3 and later utilize an inbuilt Create React App ESLint configuration which is ...
Read more >Setting Up Your Editor | Create React App
Note that even if you customise your ESLint config, these changes will ... note that any rules that are set to "error" will...
Read more >How to Setup ESLint and Prettier for Your React Apps
It means it checks out the code without executing it. But why use a linter, you might think? Because you can build an...
Read more >Strict Mode - React
StrictMode is a tool for highlighting potential problems in an application. Like Fragment , StrictMode does not render any visible UI.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
solipsistic
[ˌsäləpˈsistik] DEFINITION adjective form of solipsism
solipsism
[ˈsäləpˌsizəm] NOUN the view or theory that the self is all that can be known to exist.
Actually this can be solved easily via putting this at the start of the file.(although we’d need to do it for all files) /* eslint-disable @typescript-eslint/no-unused-vars */