Given I have following js file
mondwan@Monds-MacBook-Air:~/Documents/codetest/eslint$ cat a.js
'use strict';
console.log('abc');
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"]
}
}
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)
However, it works with default parser.
mondwan@Monds-MacBook-Air:~/Documents/codetest/eslint$ cat .eslintrc.json
{
"rules": {
"strict": [2, "global"]
}
}
mondwan@Monds-MacBook-Air:~/Documents/codetest/eslint$ eslint a.js
mondwan@Monds-MacBook-Air:~/Documents/codetest/eslint$
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]
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.
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 ismodule, in contrast to the default eslint parser wherescriptis default)