javascript - 如何使用 ESLint

标签 javascript visual-studio formatting 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

关于javascript - 如何使用 ESLint,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44793688/

相关文章:

javascript - Ruby 1.9 和 Javascript 正则表达式之间的区别

javascript - 使用 Java Selenium 的 Angular 4 等待条件

javascript - 删除 jquery/zepto 对 backbone.router 和 View 的依赖

visual-studio - 如何让 Visual Studio 在每个文件的顶部添加开源许可证

javascript - this.content 未使用模板中的值进行更新

android - 您上传了一个在 Debug模式下签名的 APK。您需要在 Release模式下签署您的 APK

c# - 使用 jenkins 构建 C# 项目

java - 正则表达式:格式化/多种格式

java - 如何从一行整数中删除前导/尾随空格?

swift - 在 Swift 中使用 %@ 格式化字符串