Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eslint disable strict mode when using babel parser

I'm using eslint in order to check valid JavaScript in a React project. However, I encountered an issue when I use --rule 'strict: 0' and --parser=babel-eslint in the same time. By example:

Eslint without babel parser:

eslint --no-eslintrc file.js

Displays no output because it doesn't find error.

Eslint with babel-parser:

eslint --no-eslintrc --parser=babel-eslint file.js

Displays this error:

file.js
1:1  error  Parsing error: Octal literal in strict mode
> 39 |  language.french.value           = ' caract\350res';

I tried to disable strict mode with --rule 'strict: 0' but it fails. I get still the precedent error.

Do you know a way to disable strict mode by using babel-parser ?

like image 462
Samuel Dauzon Avatar asked Oct 30 '22 03:10

Samuel Dauzon


1 Answers

I've just run into the same issue, finally found an answer on github. You can turn off the global strict mode by changing the sourceType to script within your .eslintrc file:

{
  ...
  parser: 'babel-eslint',
  parserOptions: {
    sourceType: 'script'
  }
  ...
}

Or, if you want to set this through the cli then simply:

eslint --no-eslintrc --parser=babel-eslint --parser-options=sourceType:script file.js
like image 149
ikarasz Avatar answered Nov 09 '22 06:11

ikarasz