'no-undef' error with optional chaining operator in v7.5.0
See original GitHub issueHi,
In our code, we often use the optional chaining operator
E.g: const valid = formContext?.formState?.isSubmitSuccessful
But every time we do need to disable the ‘no-undef’ rule in order to not get any error.
We have then decided to update Eslint to v 7.5.0 and it’s plugging too, where needed.
After updating the EsLint version to 7.5.0 we expected to do not get anymore the no-undef
error; but we still do
EXPECTATION
Shouldn’t eslint be able to recognize we are using the optional chaining operator and do not return any no-undef
error?
We are using the default parser and, as suggested in the docs, added the parserOption proper config.
I am aware there are few similar errors, but they used Bable as a parser or had an older version. Thank you!
- **ESLint Version: 7.5.0
- **Node Version: 10.15.0
- **npm Version: 6.4.1
- **Operating System: macOS Catalina
**What parser: default
CONFIG:
module.exports = {
parserOptions: {
ecmaVersion: 2020,
},
extends: ['airbnb-typescript', 'plugin:prettier/recommended', 'prettier'],
plugins: ['cup', 'header', 'prettier', 'react-hooks'],
env: {
jest: true,
},
globals: {
page: true,
browser: true,
context: true,
cy: true,
Cypress: true,
window: true,
},
rules: {
'no-undef': 'off',
'react/prop-types': 'off',
'react/forbid-prop-types': 'error',
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'warn',
'import/no-extraneous-dependencies': [
'error',
{optionalDependencies: false, devDependencies: true},
],
'import/prefer-default-export': 'off',
'arrow-body-style': ['error', 'as-needed'],
'react/jsx-one-expression-per-line': 'off',
'@typescript-eslint/no-explicit-any': 'error',
'import/no-unresolved': ['error', {ignore: ['csstype']}],
'prettier/prettier': [
'error',
{
singleQuote: true,
trailingComma: 'all',
bracketSpacing: false,
},
],
},
overrides: [
{
files: ['*.js'],
rules: {
'@typescript-eslint/no-var-requires': 'off',
},
},
{
files: ['*.tsx'],
env: {
browser: true,
},
},
{
files: ['*.test.ts', '*.test.tsx'],
rules: {
'@typescript-eslint/no-explicit-any': 'off',
},
},
{
files: ['src/!(test)/*.ts', 'src/!(test)/*.tsx'],
rules: {
'import/no-extraneous-dependencies': [
'error',
{optionalDependencies: false, devDependencies: false},
],
},
},
{
files: ['site/**/*.ts', 'site/**/*.tsx'],
rules: {
'react/display-name': 'off',
'import/no-unresolved': [
'error',
{ignore: ['newskit', 'csstype', '@components/page-title']},
],
},
},
{
files: ['cypress/**/*.spec.js'],
env: {
mocha: true,
},
},
],
};
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (6 by maintainers)
Will do, thanks for your guidance 🙏
Yes, the important bits are the parser setting. Please update (wrap it in
<details>
/</details>
and it won’t be as bothersome to readers, but make sure there’s a blank line before the output or it won’t highlight properly) with the entire result. You can| pbcopy
and it’ll dump the entire output directly in your clipboard.