Babel-eslint: Bug report: babel-eslint `strict mode` always return false

Created on 28 Feb 2016  Â·  7Comments  Â·  Source: babel/babel-eslint

a.js

Given I have following js file

mondwan@Monds-MacBook-Air:~/Documents/codetest/eslint$ cat a.js
'use strict';

console.log('abc');

eslintrc I tried

Below is eslintrc I have tried.

mondwan@Monds-MacBook-Air:~/Documents/codetest/eslint$ cat .eslintrc.json
{
    "parser": "babel-eslint",
    "rules": {
        "strict": [2, "global"]
    }
}

mondwan@Monds-MacBook-Air:~/Documents/codetest/eslint$ cat .eslintrc.json
{
    "parser": "babel-eslint",
    "parserOption": {
        "ecmaVersion": 5,
        "ecmaFeatures": {
            "modules": false
        }
    },
    "rules": {
        "strict": [2, "global"]
    }
}

Result

None of the eslintrc gives correct result.

mondwan@Monds-MacBook-Air:~/Documents/codetest/eslint$ eslint a.js

/Users/mondwan/Documents/codetest/eslint/a.js
  1:1  error  'use strict' is unnecessary inside of modules  strict

✖ 1 problem (1 error, 0 warnings)

Default parser

However, it works with default parser.

mondwan@Monds-MacBook-Air:~/Documents/codetest/eslint$ cat .eslintrc.json
{
    "rules": {
        "strict": [2, "global"]
    }
}

Result

mondwan@Monds-MacBook-Air:~/Documents/codetest/eslint$ eslint a.js
mondwan@Monds-MacBook-Air:~/Documents/codetest/eslint$

Version

mondwan@Monds-MacBook-Air:~/Documents/codetest/eslint$ eslint --version
v2.2.0
mondwan@Monds-MacBook-Air:~/Documents/codetest/eslint$ npm -g list | grep babel
├─┬ [email protected]
bug

Most helpful comment

If you try the v6-beta of babel-eslint, this should be working again. The only thing you have to ensure when using this kind of files is setting the sourceType to script. (The default is module, in contrast to the default eslint parser where script is default)

{
    "parser": "babel-eslint",
    "parserOption": {
        "sourceType": "script",
    },
    "rules": {
        "strict": [2, "global"]
    }
}

All 7 comments

Maybe another bug source from #228 ?

Yeah, maybe due to eslint 2

Yes. You are right. Just tried with eslint v1.10.3. No such problem.

mondwan@mondwan-All-Series:~/Documents/codeTest/babelEslint$ npm list | grep babel-eslint
├─┬ [email protected]
mondwan@mondwan-All-Series:~/Documents/codeTest/babelEslint$ cat a.js 
'use strict';

console.log('a.js');
mondwan@mondwan-All-Series:~/Documents/codeTest/babelEslint$ cat .eslintrc.json 
{
    "parser": "babel-eslint",
    "rules": {
        "strict": [2, "global"]
    }
}
mondwan@mondwan-All-Series:~/Documents/codeTest/babelEslint$ node_modules/.bin/eslint --version
v1.10.3
mondwan@mondwan-All-Series:~/Documents/codeTest/babelEslint$ node_modules/.bin/eslint a.js 
mondwan@mondwan-All-Series:~/Documents/codeTest/babelEslint$ eslint --version
v2.2.0
mondwan@mondwan-All-Series:~/Documents/codeTest/babelEslint$ eslint a.js 

/home/mondwan/Documents/codeTest/babelEslint/a.js
  1:1  error  'use strict' is unnecessary inside of modules  strict

✖ 1 problem (1 error, 0 warnings)

I guess this means that it won't be fixed at this moment :'( ?

If you try the v6-beta of babel-eslint, this should be working again. The only thing you have to ensure when using this kind of files is setting the sourceType to script. (The default is module, in contrast to the default eslint parser where script is default)

{
    "parser": "babel-eslint",
    "parserOption": {
        "sourceType": "script",
    },
    "rules": {
        "strict": [2, "global"]
    }
}

Yes @danez . Just tried it works again on 6.0.0-beta-5.

mondwan@mondwan-All-Series:~/Documents/codeTest/babelEslint$ eslint a.js --print-config
{
  "globals": {},
  "env": {},
  "rules": {
    "strict": [
      2,
      "global"
    ]
  },
  "parserOptions": {
    "sourceType": "script"
  },
  "parser": "/usr/lib/node_modules/babel-eslint/index.js"
}
mondwan@mondwan-All-Series:~/Documents/codeTest/babelEslint$ eslint a.js 
mondwan@mondwan-All-Series:~/Documents/codeTest/babelEslint$ npm list | grep babel-eslint
├─┬ [email protected]
mondwan@mondwan-All-Series:~/Documents/codeTest/babelEslint$ eslint --version
v2.2.0

By the way how to force parser in eslint get the one in my local directory instead of /usr/lib? I cannot search this configuratioan from official eslint documentation?

to use babel-eslint from your local install just use:

{
  "parser": "babel-eslint"
}

mondwan is correct that the key is "parserOptions" with the "s" at the end, not "parserOption" as @danez stated above.

Was this page helpful?
0 / 5 - 0 ratings