Why does JSHint throw a warning if I am using const?

后端 未结 17 2965
眼角桃花
眼角桃花 2020-12-12 08:18

This is the error I get when using const:



        
相关标签:
17条回答
  • 2020-12-12 09:01

    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.

    1. User Settings

    2. JSHint config

    3. "jshint.config": {} (Edit)

    4. 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

    0 讨论(0)
  • 2020-12-12 09:02

    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.
    0 讨论(0)
  • 2020-12-12 09:02

    For SublimeText 3 on Mac:

    1. Create a .jshintrc file in your root directory (or wherever you prefer) and specify the esversion:
        # .jshintrc
        {
          "esversion": 6
        }
    
    1. Reference the pwd of the file you just created in SublimeLinter user settings (Sublime Text > Preference > Package Settings > SublimeLinter > Settings)
        // SublimeLinter Settings - User
        {
          "linters": {
            "jshint": {
              "args": ["--config", "/Users/[your_username]/.jshintrc"]
            }
          }
        }
    
    1. Quit and relaunch SublimeText
    0 讨论(0)
  • 2020-12-12 09:05

    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.

    0 讨论(0)
  • 2020-12-12 09:05

    If you are using Grunt configuration, You need to do the following steps

    Warning message in Jshint:

    Solution:

    1. Set the jshint options and map the .jshintrc.js file

    1. Create the .jshintrc.js file in that file add the following code
    {  
      "esversion": 6  
    } 
    

    After configured this, Run again It will skip the warning,

    0 讨论(0)
  • 2020-12-12 09:06

    Create .jshintrc file in the root dir and add there the latest js version: "esversion": 9 and asi version: "asi": true (it will help you to avoid using semicolons)

    {
        "esversion": 9,
        "asi": true
    }
    
    0 讨论(0)
提交回复
热议问题