This is the error I get when using const:
<error line="2" column="1" severity="warning" message="'const' is available in ES6 (use esnext option) or Mozilla JS extensions (use moz)." source="jshint.W104" />
My code looks like this:
const Suites = {
Spade: 1,
Heart: 2,
Diamond: 3,
Club: 4
};
The code works fine only JSHint is warning me every time.
When relying upon ECMAScript 6 features such as const
, you should set this option so JSHint doesn't raise unnecessary warnings.
/*jshint esnext: true */ (Edit 2015.12.29: updated syntax to reflect @Olga's comments)
/*jshint esversion: 6 */
const Suites = {
Spade: 1,
Heart: 2,
Diamond: 3,
Club: 4
};
This option, as the name suggests, tells JSHint that your code uses ECMAScript 6 specific syntax. http://jshint.com/docs/options/#esversion
Edit 2017.06.11: added another option based on this answer.
While inline configuration works well for an individual file, you can also enable this setting for the entire project by creating a .jshintrc
file in your project's root and adding it there.
{
"esversion": 6
}
You can add a file named .jshintrc in your app's root with the following content to apply this setting for the whole solution:
{
"esversion": 6
}
James' answer suggests that you can add a comment /*jshint esversion: 6 */
for each file, but it is more work than necessary if you need to control many files.
I got this same warning when using an export statement. I'm using VS Code and used a similar approach to Wenlong Jiang's solution.
- User Settings
- JSHint config
"jshint.options": {}
(Edit)Use double quotes when specifying
"esversion"
Or copy this snippet into User Settings:
"jshint.options": { "esversion": 6, }
Creating a .jshintrc
file isn't necessary if you want to configure the global jshint settings for your editor
If you're using VSCode:
1.
- Go to preferences -> settings (
cmd + ,
) - Type
jshint.options
into the search bar - Hover over it and click on the pencil icon
- Its now appended on the right side.
- Add
"esversion": 6
to the options object.
2.
Or simply add this to your user settings:
"jshint.options": {
"esversion": 6
}
[UPDATE] new vscode settings
- Go to preferences -> settings (
cmd + ,
) - type
jshint
into search
- continue with step
2.
When you start using ECMAScript 6 this error thrown by your IDE.
There are two options available:
if you have only one file and want to use the es6 then simply add below line at the top of the file.
/*jshint esversion: 6 */
Or if you have number of js file or you are using any framework(like nodejs express)you can create a new file named .jshintrc
in your root directory and add code below in the file:
{
"esversion": 6
}
If you want to use the es6 version onward for each project you can configure your IDE.
If you are using Webstorm and if you don't have your own config file, then just enable EcmaScript.next
in Relaxing options in in
Settings | Languages & Frameworks | JavaScript | Code Quality Tools | JSHint
See this question How-do-I-resolve-these-JSHint-ES6-errors
If you are using Grunt configuration, You need to do the following steps
Warning message in Jshint:
Solution:
- Set the jshint options and map the .jshintrc.js file
- Create the .jshintrc.js file in that file add the following code
{ "esversion": 6 }
After configured this, Run again It will skip the warning,
Create a file called, say jshint_opts with this content: { "esversion": 6 }
Then invoke jshint with something like this command line:
jshint --config jshint_opts lib/*.js
If using Sublime Text 3:
- Go to Preferences -> Settings
- Under Preferences.sublime-settings—User add "esversion": 6
来源:https://stackoverflow.com/questions/27441803/why-does-jshint-throw-a-warning-if-i-am-using-const