Javascript JShint 中的 ES6 - .jshintrc 有 esversion,但仍然收到警告(使用 atom)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37247474/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 20:04:28  来源:igfitidea点击:

ES6 in JShint - .jshintrc has esversion, but still getting warning (using atom)

javascriptecmascript-6jshintatom-editor

提问by Ron I

I am using atom, and I've tried several different jshint packages and they all give a warning which says

我正在使用 atom,我已经尝试了几个不同的 jshint 包,它们都给出了一个警告,上面写着

"template literal syntax' is only available in ES6 (use 'esversion: 6')"

I created a top level .jshintrc file (at root), and added the following json:

我创建了一个顶级 .jshintrc 文件(在根目录下),并添加了以下 json:

{
  "esversion":6
}

However, it is still throwing the same error. Any ideas how to resolve. I've included the link to the JSHint optionspage. I'd like to start playing around with ES6 syntax, but would prefer not to have extra warnings.

但是,它仍然抛出相同的错误。任何想法如何解决。我已经包含了指向JSHint 选项页面的链接。我想开始使用 ES6 语法,但不想有额外的警告。

Thanks SO community!

感谢 SO 社区!

回答by Micheal Vu

The filename should be .jshintrc, and the content is

文件名应该是.jshintrc,内容是

{
  "esversion": 6
}

回答by Noam Manos

Instead of creating .jshintrcfile, you can simply add at the top of your js file:

您可以简单地在 js 文件的顶部添加,而不是创建.jshintrc文件:

/*jshint esversion: 6 */ 

回答by Tony

We have two choices.

我们有两个选择。

1. Using .jshintrcfile.

1. 使用.jshintrc文件。

Create .jshintrcfile in root directory and type as below. It applies to all codes

在根目录中创建.jshintrc文件并键入如下。它适用于所有代码

{
    "esversion": 6
}

If you're still getting warning, close and re-open your editor.

如果您仍然收到警告,请关闭并重新打开您的编辑器。



2. Using hint.

2. 使用提示。

Type as below at the top of the your code. It applies to just the code.

在您的代码顶部键入以下内容。它仅适用于代码。

/* jshint esversion: 6 */

回答by lvnam96

Remember to close then reopen your JS file / text editor.

请记住关闭然后重新打开您的 JS 文件/文本编辑器。

回答by Ron I

Using the atom packages linterand linter-jshint, I got it to work by uninstalling and then reinstalling the packages and then restarting atom. I did download ESLint and installed it per people's suggestions, looking forward to testing it out.

使用原子包短绒棉短绒-jshint,我通过卸载并重新安装包,然后重新启动原子它得到的工作。我确实下载了 ESLint 并根据人们的建议安装了它,期待对其进行测试。

回答by Timar Ivo Batis

Has to be the first entry of the jshintrc file. Doesn't make much sense but that's what fixed it for me.

必须是 jshintrc 文件的第一个条目。没有多大意义,但这就是为我解决的问题。

{
"esversion": 6,
"browser": true,
    ...
    ...
    ...
"globals": {... }
}

回答by Phan Van Linh

Create a file .jshintrcwith content

创建一个.jshintrc包含内容的文件

{
    "esversion": 6
}

Put this file to your projectroot directory. Reopen your js file (no need restart atom). It will work for your current project.

把这个文件放到你的项目根目录下。重新打开你的 js 文件(不需要重启 atom)。它将适用于您当前的项目。

Put this file to your homedirectory (eg: C, D, E, Desktop, Lirary,...). Reopen your js.file (no need restart atom). It will work for all project inside homedirectory

将此文件放入您的目录(例如:CDEDesktopLirary、...)。重新打开你的 js.file(不需要重启 atom)。它将适用于目录中的所有项目

回答by RRR

The config file in which you have enabled es6 should be enabled through your IDE; eg:for Intellij there's a clear option for adding config files.JSHint for Intellij

启用 es6 的配置文件应该通过 IDE 启用;例如:对于 Intellij,添加配置文件有一个明确的选项。Intellij 的 JSHint