eslint uploader.js
时,什么也没有发生——换行后提示符返回。没有任何输出。我已经在同一目录下的JSON文件上运行它,并使用Grunt任务在整个项目的JS文件上运行它。这些会返回一些错误,但跟我的预期相差甚远。
当我在命令行上运行
eslint
时,它表现如预期——返回参数和选项文档。我尝试重新启动实例、重新安装ESLint,甚至有意将错误引入到uploader.js
中,但什么也没发生,更不用说教程中显示的输出了。能有人提供帮助吗?eslint uploader.js
时,什么也没有发生——换行后提示符返回。没有任何输出。eslint
时,它表现如预期——返回参数和选项文档。我尝试重新启动实例、重新安装ESLint,甚至有意将错误引入到uploader.js
中,但什么也没发生,更不用说教程中显示的输出了。能有人提供帮助吗?从 ESLint 1.0.0 版本开始,默认关闭所有的代码检测规则。
该教程是在此版本之前编写的,因此可能会出现一些错误而没有配置文件。官方网站提供了一个 迁移指南。在您的情况下,您可能希望在整个教程中使用 "eslint:recommended" 扩展您的 ".eslintrc" 文件(或仅手动包含预期规则)。根据指南,以下内容是最接近旧版本的:
{
"extends": "eslint:recommended",
"rules": {
"no-alert": 2,
"no-array-constructor": 2,
"no-caller": 2,
"no-catch-shadow": 2,
"no-empty-label": 2,
"no-eval": 2,
"no-extend-native": 2,
"no-extra-bind": 2,
"no-implied-eval": 2,
"no-iterator": 2,
"no-label-var": 2,
"no-labels": 2,
"no-lone-blocks": 2,
"no-loop-func": 2,
"no-multi-spaces": 2,
"no-multi-str": 2,
"no-native-reassign": 2,
"no-new": 2,
"no-new-func": 2,
"no-new-object": 2,
"no-new-wrappers": 2,
"no-octal-escape": 2,
"no-process-exit": 2,
"no-proto": 2,
"no-return-assign": 2,
"no-script-url": 2,
"no-sequences": 2,
"no-shadow": 2,
"no-shadow-restricted-names": 2,
"no-spaced-func": 2,
"no-trailing-spaces": 2,
"no-undef-init": 2,
"no-underscore-dangle": 2,
"no-unused-expressions": 2,
"no-use-before-define": 2,
"no-with": 2,
"camelcase": 2,
"comma-spacing": 2,
"consistent-return": 2,
"curly": [2, "all"],
"dot-notation": [2, { "allowKeywords": true }],
"eol-last": 2,
"no-extra-parens": [2, "functions"],
"eqeqeq": 2,
"key-spacing": [2, { "beforeColon": false, "afterColon": true }],
"new-cap": 2,
"new-parens": 2,
"quotes": [2, "double"],
"semi": 2,
"semi-spacing": [2, {"before": false, "after": true}],
"space-infix-ops": 2,
"space-return-throw-case": 2,
"space-unary-ops": [2, { "words": true, "nonwords": false }],
"strict": [2, "function"],
"yoda": [2, "never"]
}
}
我也遇到了同样的问题(顺便说一下,是在2023年)。我安装了eslint,但当我输入npx eslint app.js
时,它返回的结果是空的,只有一个新的空行。
所以,对我来说解决方案是:
I checked globally installed eslint npm list -g
Eslint was installed globally, and I didn't want that, so I deleted it npm uninstall -g eslint
Then I checked that package.json was on place (If you don't have package.json, then create it npm init
and hit enter several times)
I reinstalled eslint npm init eslint@/config
And the most important part: in .eslintrc.json (which will be created after installing eslint) you have to set rules (I took this solution from an answer E_net4). For example:
{
"extends": "eslint:recommended",
"rules": {
"no-alert": 2,
"no-array-constructor": 2,
"no-caller": 2,
"no-catch-shadow": 2,
"no-empty-label": 2,
"no-eval": 2,
"no-extend-native": 2,
"no-extra-bind": 2,
"no-implied-eval": 2,
"no-iterator": 2,
"no-label-var": 2,
"no-labels": 2,
"no-lone-blocks": 2,
"no-loop-func": 2,
"no-multi-spaces": 2,
"no-multi-str": 2,
"no-native-reassign": 2,
"no-new": 2,
"no-new-func": 2,
"no-new-object": 2,
"no-new-wrappers": 2,
"no-octal-escape": 2,
"no-process-exit": 2,
"no-proto": 2,
"no-return-assign": 2,
"no-script-url": 2,
"no-sequences": 2,
"no-shadow": 2,
"no-shadow-restricted-names": 2,
"no-spaced-func": 2,
"no-trailing-spaces": 2,
"no-undef-init": 2,
"no-underscore-dangle": 2,
"no-unused-expressions": 2,
"no-use-before-define": 2,
"no-with": 2,
"camelcase": 2,
"comma-spacing": 2,
"consistent-return": 2,
"curly": [2, "all"],
"dot-notation": [2, { "allowKeywords": true }],
"eol-last": 2,
"no-extra-parens": [2, "functions"],
"eqeqeq": 2,
"key-spacing": [2, { "beforeColon": false, "afterColon": true }],
"new-cap": 2,
"new-parens": 2,
"quotes": [2, "double"],
"semi": 2,
"semi-spacing": [2, {"before": false, "after": true}],
"space-infix-ops": 2,
"space-return-throw-case": 2,
"space-unary-ops": [2, { "words": true, "nonwords": false }],
"strict": [2, "function"],
"yoda": [2, "never"]
}
}
And npx eslint app.js
returned a bunch of errors in my code (as it suppose to work). But I decided to change rules to some "standardized rules" and installed airbnb rules (instructions here https://www.npmjs.com/package/eslint-config-airbnb)
eslint
只是一个检查工具。 - E net4