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

Can't overwrite "strict" rule #727

Closed
vitorbaptista opened this issue Feb 12, 2016 · 7 comments
Closed

Can't overwrite "strict" rule #727

vitorbaptista opened this issue Feb 12, 2016 · 7 comments

Comments

@vitorbaptista
Copy link

I have the following files:

// foo.js
function foo() {
  return 42;
}

foo();
---
extends: airbnb/base
rules:
  strict: [2, "global"]

Running eslint foo.js returns successfully, even though foo.js has no "use strict"; directive. If I change to extends: eslint:recommended, it complains because of the lack of "use strict"; (as expected).

I tried to overwrite another rule, so I changed the files to:

// foo.js
function foo() {
  return 42;
}

// Remove the call to foo();
// foo();
---
extends: airbnb/base
rules:
  no-unused-vars: 0

And it worked. I was able to overwrite no-unused-vars.

I'm running eslint@1.10.3 and eslint-config-airbnb@5.0.0 with Node v5.5.0 and npm v3.6.0.

@vitorbaptista vitorbaptista changed the title Can't change "strict" behaviour Can't overwrite "strict" rule Feb 12, 2016
vitorbaptista added a commit to opentrials/api that referenced this issue Feb 12, 2016
Unfortunately, there seems to be a bug on eslint-config-airbnb that ignores
rewriting the "strict" rules, so we can't check that we're always using strict.

I opened an issue on their repository about it:
airbnb/javascript#727
@ljharb
Copy link
Collaborator

ljharb commented Feb 12, 2016

If you're extending airbnb/base, that doesn't include any strict definition at all. Only the main airbnb includes the strict rule.

I'm not really sure why you wouldn't be able to enable that warning - if you try [2, "function"] does it complain?

@vitorbaptista
Copy link
Author

That's odd. I tried changing to [2, "function"] as well, but it kept succeeding. It only complained when I tried some invalid value (i.e. [2, "foo"]).

@ljharb
Copy link
Collaborator

ljharb commented Apr 20, 2016

You can now use the https://npmjs.com/eslint-config-airbnb-base package directly. Please reopen this if you're still having trouble.

@ljharb ljharb closed this as completed Apr 20, 2016
@Starefossen
Copy link

I can not get this to work correctly even after switching to eslint-config-airbnb-base.

@ljharb airbnb-base includes this strict definition, is it interfering?

@ljharb
Copy link
Collaborator

ljharb commented Apr 24, 2016

@Starefossen the separate base package includes that file but it's not included in the main export - however, it's turned on here. What problem are you having?

@Starefossen
Copy link

Sorry for this way to late reply :(

The problem I had was to force the use of "use strict"; using the "strict": [2, "global"] rule. This did not have any effect and ESLint said that "use strict"; was not necessary when using ES6 modules.

However this was in a Node.js project and my models are not ES6 modules and I wanted them all to have strict mode enabled and I was able to force it by setting "sourceType": "script" in parserOptions like this:

{                                                                    
    "extends": "airbnb-base",                                        
    "env": {                                                         
      "node": true                                                   
    },                                                               
    "parserOptions": {                                               
      "ecmaVersion": 6,                                              
      "sourceType": "script",                                        
      "ecmaFeatures": {                                              
        "modules": false                                             
      }                                                              
    },                                                               
    "rules": {                                                       
      "strict": [2, "global"]
    }                                                                
}                                                                    

@blakedietz
Copy link

@Starefossen you're solution works. I had the exact same use case for linting an AWS Lambda project. Thanks!

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

No branches or pull requests

4 participants