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

Consolidating strict rule definition between airbnb and airbnb-base #1582

Closed
edmorley opened this issue Oct 9, 2017 · 6 comments · Fixed by #1962
Closed

Consolidating strict rule definition between airbnb and airbnb-base #1582

edmorley opened this issue Oct 9, 2017 · 6 comments · Fixed by #1962

Comments

@edmorley
Copy link
Contributor

edmorley commented Oct 9, 2017

Hi!

I've spotted some inconsistency/duplication with the strict rule and wondered if this was intentional?

Currently:

  • There's the eslint-config-airbnb-base/rules/strict file that declares strict: ['error', 'never'].
  • That file is only used in eslint-config-airbnb and not eslint-config-airbnb-base.
  • Instead eslint-config-airbnb-base sets strict: 'error' manually in its rules directive (which results in the ESLint default of strict: ['error', 'safe']).
  • However both eslint-config-airbnb-base and eslint-config-airbnb set sourceType: 'module', which causes the ESLint strict rule to "disallow[s] strict mode directives, no matter which option is specified" regardless of those options - ie: strict: ['error', 'never'] (docs).

Issues:

  • It was my understanding that for the most part, the generic (ie non react, non-AirBnb-as-as-company specific) rules/configuration belong in eslint-config-airbnb-base rather than eslint-config-airbnb, but yet the eslint-config-airbnb-base/rules/strict extends is contrary to that, and confusing to the end user if it actually resulted in different strict mode behaviour.
  • However unless people override sourceType: 'module', both eslint-config-airbnb-base and eslint-config-airbnb actually result in the same strict mode behaviour (ie: equivalent of strict: ['error', 'never']) anyway, so in most cases the rule being listed twice is just duplication rather than having any effect.

I think this situation might just be an accidental leftover from the split to the airbnb-base package (see here) and then #637.

As such, to increase consistency I would like to propose:

  • Moving eslint-config-airbnb-base/rules/strict from eslint-config-airbnb's extends to eslint-config-airbnb-base's (this won't affect legacy).
  • Deleting the manual strict rule definition from eslint-config-airbnb-base's rules.
  • Probably bumping the eslint-config-airbnb-base major version in case there's anyone using it who sets sourceType: 'script' manually rather than using legacy, since they would see a difference in behaviour.

If this sounds acceptable, I'm happy to open a PR :-)

@edmorley edmorley changed the title Consolidating strict rule definition between eslint-config-airbnb and eslint-config-airbnb-base Consolidating strict rule definition between airbnb and airbnb-base Oct 9, 2017
@edmorley
Copy link
Contributor Author

If this sounds acceptable, I'm happy to open a PR :-)

Any thoughts before I open the PR? :-)

@ljharb
Copy link
Collaborator

ljharb commented Oct 27, 2017

I believe it is intentional as-is.

When using babel, every file is a module, and thus auto-strict - so you never should use a "use strict" directive.

When not using babel, you should have the directive everywhere. When using the base config, it's much more likely that someone might not be using babel (since they won't be using jsx).

(Also, eslint-config-airbnb-base is not "generic", it's "airbnb minus react")

@edmorley
Copy link
Contributor Author

When not using babel, you should have the directive everywhere. When using the base config, it's much more likely that someone might not be using babel (since they won't be using jsx).

True, but from the OP:

However both eslint-config-airbnb-base and eslint-config-airbnb set sourceType: 'module'

...so even people using base already have module mode enabled.

@ljharb
Copy link
Collaborator

ljharb commented Oct 28, 2017

That is true - hmm.

OK, so, here's the changes I think should be made:

  1. [base] the legacy entry point should enable strict with safe (semver-major)
  2. [base] the index entry point should import rules/strict. (semver-major)
  3. the main package no longer needs to import rules/strict (semver-patch)

A PR that does the base and main changes each in one commit (commit message convention: [eslint config] $message and [eslint config] [base] $message) would be great :-)

edmorley added a commit to edmorley/javascript that referenced this issue Nov 20, 2018
Since the file is now imported in base instead.

Fixes airbnb#1582.
@edmorley
Copy link
Contributor Author

A PR that does the base and main changes each in one commit (commit message convention: [eslint config] $message and [eslint config] [base] $message) would be great :-)

Sorry for the delay; have opened #1962 :-)

edmorley added a commit to edmorley/javascript that referenced this issue Nov 20, 2018
Since the file is now imported in base instead.

Fixes airbnb#1582.
edmorley added a commit to edmorley/javascript that referenced this issue Jun 23, 2019
Since the file is now imported in base instead.

Fixes airbnb#1582.
ljharb pushed a commit to edmorley/javascript that referenced this issue Aug 10, 2019
Since the file is now imported in base instead.

Fixes airbnb#1582.
@marcospgp
Copy link

@ljharb said

When not using babel, you should have the directive everywhere. When using the base config, it's much more likely that someone might not be using babel (since they won't be using jsx).

Which is true. I use the base config and was surprised to see "use strict"; was no longer allowed after updating to the latest major version.

But this made me realize that the airbnb style guide

[...] assumes you are using Babel, and requires that you use babel-preset-airbnb or the equivalent. It also assumes you are installing shims/polyfills in your app, with airbnb-browser-shims or the equivalent.

So I get the idea it shouldn't really be used for Node.js and am thus going to switch to something else for that.

Posting here so you guys are aware of this part of your user base 😄

vunb pushed a commit to hsdt/javascript that referenced this issue Nov 27, 2019
Since the file is now imported in base instead.

Fixes airbnb#1582.
eugene2candy pushed a commit to eugene2candy/javascript that referenced this issue Apr 10, 2021
Since the file is now imported in base instead.

Fixes airbnb#1582.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants