Skip to content
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

[eslint-config] Support optional chaining #1223

Closed
ghost opened this issue Jan 13, 2020 · 6 comments · Fixed by #1399
Closed

[eslint-config] Support optional chaining #1223

ghost opened this issue Jan 13, 2020 · 6 comments · Fixed by #1399
Labels
enhancement New feature or request

Comments

@ghost
Copy link

ghost commented Jan 13, 2020

As of right now, eslint erroneously shows a no-unused-expression error on optional chaining function calls / field access.

In eslint-config/index.js there's this rule:

  overrides: [
    {
      files: ['**/test/**/*.js', '**/demo/**/*.js', '**/stories/**/*.js'],
      rules: {
        'no-console': 'off',
        'no-unused-expressions': 'off',
        'class-methods-use-this': 'off',
      },
    },
  ],

Why was no-unused-expressions disabled for those cases? I'm trying to evaluate the best workaround to support optional chaining. Right now the best option seems to be eslint/eslint#11045 (comment) but it would add a dependency on eslint-plugin-babel

@ghost
Copy link
Author

ghost commented Jan 13, 2020

Just realized babel-parser already depends on eslint-babel-plugin, so that particular fix would be a 2 line change. Shall we go with it?

@LarsDenBakker
Copy link
Member

Babel is about to release optional chaining support by default, I wonder if we get this out of the box then?

@stale
Copy link

stale bot commented Feb 3, 2020

Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks!

@stale stale bot added the inactive label Feb 3, 2020
@tmsns
Copy link
Contributor

tmsns commented Mar 4, 2020

Unfortunately, we will not get this out of the box, until eslint supports this by default. As mentioned by @doplumi, we can use/add babel's eslint plugin (eslint-plugin-babel). The idea would be to use their specific rule (babel/no-unused-expressions) instead of the regular one (no-unused-expression).

I just tested this today in my project and it works great (only 3 extra deps) It would be even better though our eslint-config supported this out of the box. Care for a PR, @LarsDenBakker ? 😃

@LarsDenBakker
Copy link
Member

Doesnt eslint do stage 4 by default? But lets use babel eslint then.

@LarsDenBakker LarsDenBakker reopened this Mar 4, 2020
@stale stale bot removed the inactive label Mar 4, 2020
@LarsDenBakker LarsDenBakker added the enhancement New feature or request label Mar 4, 2020
@tmsns
Copy link
Contributor

tmsns commented Mar 4, 2020

Yes, they are working on it: eslint/eslint#12642, but they are blocked for now.

Also, some teams might not be able to upgrade to the latest eslint yet. The bug will probably only be fixed in one of the upcoming 7.x releases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants