如何使用 ESLint

How to use ESLint

基本上我已经从这里安装了 ESLint

http://eslint.org/docs/user-guide/getting-started

.eslintrs.json 看起来像这样

    {
    "extends": ["eslint:recommended",
                "angular",
                "plugin:jasmine/recommended"],
    "installedESLint": true,
    "plugins": [
        "standard",
        "promise",
        "jasmine"
    ],
    "rules": {
        "strict": 0,
        "indent": [2, 4],
        "quotes": [2, "single"],
        "no-unused-vars": 1,
        "no-underscore-dangle": 1
    },
    "env": {
        "jasmine": true
    },
    "globals": {
        "navigator": true
    }
}

基本上我需要检查的文件很少.js,但有多余的空格和不必要的行。也是

eslint myfile.js

这就是我得到的 自动配置失败。无法解析任何文件。

如何使用ESLint去除js文件不必要的空格和行?

配置文件应该是.eslintrc.*,或者只是.eslintrc

http://eslint.org/docs/user-guide/configuring

Configuration Files - use a JavaScript, JSON or YAML file to specify configuration information for an entire directory and all of its subdirectories. This can be in the form of an .eslintrc.* file or an eslintConfig field in a package.json file, both of which ESLint will look for and read automatically, or you can specify a configuration file on the command line.

编辑:

您可以附加 --fix 以请求 ESLint 自动修复发现的问题。

例如

eslint myfile.js mydir --fix

这意味着您没有配置 ESLINT 将检查您的代码的路径。

转到 your_project\node_modules.bin 文件夹,运行 eslint --init 然后你需要回答这些问题:

  • ?您希望如何配置 ESLint?
  • ?应检查哪些文件、路径或 glob?
  • ?您希望配置文件采用什么格式?
  • ?您在使用 ECMAScript 6 功能吗?
  • ?你在使用 ES6 模块吗?
  • ?你的代码运行会在哪里?浏览器、节点
  • ?你使用 CommonJS 吗?
  • ?你使用 JSX 吗?

注意第二题不要出现"No files were able to be parsed"错误