How to set jshint/jsxhint “esnext” option in Atom

雨燕双飞 提交于 2020-01-11 17:09:11

问题


I am using Atom's linter, react, and linter-jshint/linter-jsxhint. In my JSX files, I keep getting the warning

Warning: 'import' is only available in ES6 (use esnext option). (W119)

That's pretty straightforward. I did some searching, and found that this can be set under the jshintConfig option in package.json (when using NPM). My project uses NPM and I have a package.json. I added:

"jshintConfig": {
  "esnext": true
}

After that, I did a reload but the warnings persist. I also modified my linter-jshint/linter-jsxhint config in Atom (config.cson) with:

"linter-jshint":
  harmony: true
  esnext: true

"linter-jsxhint":
  harmony: true
  esnext: true

And did a reload but that didn't help it either.

So: when using linter-jshint/linter-jsxhint as Atom packages, how to I set the esnext option?


回答1:


First possibility, recommended : you can create a .jshintrc in you home directory and jshint will read it in case there is none in the project directory. You might need to restart Atom after.

Another possibility not recommended : you could also change the config of jshint in Atom and specify the location of your global .jshintrcif for some reason you don't want to put it in your home directory with the flag --config

'linter-jshint':
  'jshintExecutablePath': /path/to/jshint --config /path/to/.jshinrc

Run 'which jshint' to find the path. It is not recommended because every other .jshinrc file (in the project, etc.) will be ignore:

jshint will look for this configuration in a number of locations, stopping at the first positive match:

  • The location specified with the --config flag

  • A file named package.json located in the current directory or any parent of the current directory (the configuration should be declared as the jshintConfig attribute of that file's JSON value)

  • A file named .jshintrc located in the current directory or any parent of the current directory

  • A file named .jshintrc located in the current user's "home" directory (where defined)



回答2:


You can create a .jshintrc in your project folder, it will be read by the linter as a json source file.

To use esnext option,

{
    "esnext": true
}

You will probably need to reopen your JS file to be able to see the new changes.




回答3:


You can use the inline configuration adding this comment in your file .js:

/* jshint esversion: 6 */

http://jshint.com/docs/



来源:https://stackoverflow.com/questions/31080498/how-to-set-jshint-jsxhint-esnext-option-in-atom

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!