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.

Consolidating `strict` rule definition between airbnb and airbnb-base

See original GitHub issue

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 😃

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
edmorleycommented, Nov 20, 2018

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 airbnb/javascript#1962 😃

0reactions
marcospgpcommented, Oct 14, 2019

@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 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

airbnb react/function-component-definition
I'm trying to use eslint . I get the above error ⬆️ and it states that: Value ["function-declaration","function-expression"] should be equal to one...
Read more >
Terms of Service - Airbnb Help Center
It is your responsibility to read and understand these rules, standards, policies, and requirements prior to booking a Listing.Be aware that some Hosts...
Read more >
How to use the eslint-config-airbnb-base/rules/style. ...
To help you get started, we've selected a few eslint-config-airbnb-base examples, ... Ensure the replacement rules use the options set by airbnb rather...
Read more >
Adopt airbnb javascript style guide v14.1 as new baseline ...
Their rules are more strict than ours, it's a good move for our ... The patch adopts the standards wholesale, which means no...
Read more >
Linting
You can write your own rules to ensure code consistency across your team or ... eslint-plugin-import is a peer dependency of eslint-config-airbnb-base, ...
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