question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'no-undef' error with optional chaining operator in v7.5.0

See original GitHub issue

Hi,

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:closed
  • Created 2 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
Vanalscommented, Mar 30, 2021

In that case it seems like it might be a bug on that parser. Can you file an issue with this information on that repo?

Will do, thanks for your guidance 🙏

1reaction
ljharbcommented, Mar 30, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

eslint - Optional chaining error with vscode - Stack Overflow
All versions of Node.js above 12 support the optional-chaining operator (a ECMAScript 2020 feature). Try to use this:
Read more >
ESLint v7.5.0 released - ESLint - Pluggable JavaScript Linter
This release adds some new features and fixes several bugs found in the previous release. Highlights. Optional Chaining Support. Support for ...
Read more >
eslint-plugin-ember | Yarn - Package Manager
An ESLint plugin that provides a set of rules for Ember applications based on commonly known good practices. ❗️Requirements. ESLint >= 7; Node.js...
Read more >
@xwtec/eslint-config-legacy - npm package | Snyk
17, error, no-undef, disallow the use of undeclared variables unless ... 33, warn, no-unsafe-optional-chaining, disallow use of optional chaining in ...
Read more >
Tutorial: Release notes - Handsontable Documentation
Fixed an issue where the CSS files could be eliminated during tree-shaking. ... to use private methods, optional chaining and nullish coalescing operator....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found