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.
Warning This option has been deprecated and will be removed in the next major release of JSHint. JSHint is limiting its scope to issues of code correctness. If you would like to enforce rules relating to code style, check out the JSCS project.
In order to disable jshint for a workspace specify "jshint. enable" : false in the workspace settings. jshint is enabled by default.
The two foremost linting options for JavaScript codebases are ESLint and JSHint.
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.config": {}
(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.
cmd + ,
)jshint.options
into the search bar"esversion": 6
to the options object.2.
Or simply add this to your user settings:
"jshint.options": {
"esversion": 6
}
[UPDATE] new vscode settings
cmd + ,
)jshint
into search2.
I spent ages trying to fix this. Every solution talks about 'setting options'. I don't know what that means. Finally, I figured it out. You can just include a commented out line at the top of the file /*jshint esversion: 6 */
.
You can specify esversion:6 inside jshint options object. Please see the image. I am using grunt-contrib-jshint plugin.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With