ESLint - 显示问题尝试 Lint 但 Lint 文件
ESLint - Shows Issue Trying to Lint but Lints File
我在 Angular 项目中使用 ESLint。
我将 cypress 文件夹中的 js 文件(我的 e2e 测试)设置为具有不同的规则,方法是在 .eslintrc.js 文件中设置覆盖,如下所示:
module.exports = {
env: {
browser: true,
es6: true,
node: true
},
extends: ["prettier", "prettier/@typescript-eslint", "plugin:prettier/recommended"],
parser: "@typescript-eslint/parser",
parserOptions: {
project: "tsconfig.json",
sourceType: "module"
},
plugins: [
"eslint-plugin-import",
"eslint-plugin-jsdoc",
"@angular-eslint/eslint-plugin",
"@typescript-eslint",
"@typescript-eslint/tslint",
"eslint-plugin-html"
],
rules: {
"prefer-const": "error",
"@angular-eslint/component-class-suffix": "error",
"@angular-eslint/directive-class-suffix": "error",
"@angular-eslint/no-host-metadata-property": "error",
"@angular-eslint/no-input-rename": "error",
"@angular-eslint/no-inputs-metadata-property": "error",
"@angular-eslint/no-output-on-prefix": "error",
"@angular-eslint/no-output-rename": "error",
"@angular-eslint/no-outputs-metadata-property": "error",
"@angular-eslint/use-lifecycle-interface": "error",
"@angular-eslint/use-pipe-transform-interface": "error",
"@typescript-eslint/consistent-type-definitions": "error",
"@typescript-eslint/dot-notation": "off",
"@typescript-eslint/explicit-member-accessibility": [
"off",
{
accessibility: "explicit"
}
],
"@typescript-eslint/indent": ["off"],
"@typescript-eslint/member-delimiter-style": [
"error",
{
multiline: {
delimiter: "semi",
requireLast: true
},
singleline: {
delimiter: "semi",
requireLast: false
}
}
],
"@typescript-eslint/member-ordering": "off",
"@typescript-eslint/naming-convention": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-empty-interface": "error",
"@typescript-eslint/no-inferrable-types": [
"error",
{
ignoreParameters: true
}
],
"@typescript-eslint/no-misused-new": "error",
"@typescript-eslint/no-non-null-assertion": "error",
"@typescript-eslint/prefer-function-type": "error",
"@typescript-eslint/quotes": "off",
"@typescript-eslint/semi": ["error", "always"],
"@typescript-eslint/type-annotation-spacing": "error",
"@typescript-eslint/unified-signatures": "error",
"arrow-body-style": ["off"],
"arrow-parens": ["off", "always"],
"brace-style": ["error", "1tbs"],
"comma-dangle": "off",
"constructor-super": "error",
curly: "error",
"eol-last": "error",
eqeqeq: ["error", "smart"],
"guard-for-in": "error",
"id-blacklist": "off",
"id-match": "off",
"import/no-deprecated": "warn",
"jsdoc/no-types": "error",
"linebreak-style": "off",
"max-len": [
"error",
{
code: 140
}
],
"new-parens": "off",
"newline-per-chained-call": "off",
"no-bitwise": "error",
"no-caller": "error",
"no-console": [
"error",
{
allow: [
"log",
"dirxml",
"warn",
"error",
"dir",
"timeLog",
"assert",
"clear",
"count",
"countReset",
"group",
"groupCollapsed",
"groupEnd",
"table",
"Console",
"markTimeline",
"profile",
"profileEnd",
"timeline",
"timelineEnd",
"timeStamp",
"context"
]
}
],
"no-debugger": "error",
"no-empty": "off",
"no-eval": "error",
"no-extra-semi": "off",
"no-fallthrough": "error",
"no-irregular-whitespace": "off",
"no-multiple-empty-lines": "off",
"no-new-wrappers": "error",
"no-restricted-imports": ["error", "rxjs/Rx"],
"no-shadow": [
"off",
{
hoist: "all"
}
],
"@typescript-eslint/no-shadow": ["error"],
"no-throw-literal": "error",
"no-trailing-spaces": "error",
"no-undef-init": "error",
"no-underscore-dangle": "off",
"no-unused-labels": "error",
"no-var": "error",
"prefer-const": "error",
"quote-props": "off",
radix: "error",
"react/jsx-curly-spacing": "off",
"react/jsx-equals-spacing": "off",
"react/jsx-wrap-multilines": "off",
"space-before-function-paren": "off",
"space-before-blocks": "error",
"space-in-parens": ["off", "never"],
"spaced-comment": [
"error",
"always",
{
markers: ["/"]
}
],
"@typescript-eslint/tslint/config": [
"error",
{
rules: {
"import-spacing": true,
whitespace: [true, "check-branch", "check-decl", "check-operator", "check-separator", "check-type"],
}
}
]
},
overrides: [
{
files: ["cypress/**/*.js"],
rules: {
"space-before-blocks": "error",
"no-var": "off",
"no-bitwise": "off",
"eqeqeq": "off",
"prefer-const": "off"
}
}
]
};
我解决了这些文件夹中的所有 lint 问题,然后,当我 运行 lint 时,它显示一条消息说“已尝试对 {file-name} 进行 lint,但没有发现有效的启用规则已解析配置中的文件类型和文件路径。
我不明白,文件正在被检查,但消息说没有。
这是一个屏幕截图,我故意造成了 lint 错误。您会看到上面的消息“已尝试 lint...但未发现有效...”,然后在其下方显示该文件实际上已被 lint(因为它显示了 lint 错误)。
为什么会这样?我想这并没有阻止我对代码进行 linting,但它很烦人。
我看到您在 eslintrc 文件中添加了 @typescript-eslint/tslint
插件。
看来您的项目中包含 tslint.json
文件,您需要向 tslint.json
添加规则
问题:https://github.com/palantir/tslint/issues/3735#issuecomment-368520472
"jsRules": {
"no-empty": true
}
我能够通过为忽略规则的 js 文件添加覆盖部分来解决此问题,如下所示:
overrides: [
{
files: ["**/*.js"],
rules: {
"@typescript-eslint/tslint/config": ["off"] //this is the rule that was causing the message, but you can add other rules here
}
}
]
我在主要规则部分之外添加了这部分。
我在 Angular 项目中使用 ESLint。
我将 cypress 文件夹中的 js 文件(我的 e2e 测试)设置为具有不同的规则,方法是在 .eslintrc.js 文件中设置覆盖,如下所示:
module.exports = {
env: {
browser: true,
es6: true,
node: true
},
extends: ["prettier", "prettier/@typescript-eslint", "plugin:prettier/recommended"],
parser: "@typescript-eslint/parser",
parserOptions: {
project: "tsconfig.json",
sourceType: "module"
},
plugins: [
"eslint-plugin-import",
"eslint-plugin-jsdoc",
"@angular-eslint/eslint-plugin",
"@typescript-eslint",
"@typescript-eslint/tslint",
"eslint-plugin-html"
],
rules: {
"prefer-const": "error",
"@angular-eslint/component-class-suffix": "error",
"@angular-eslint/directive-class-suffix": "error",
"@angular-eslint/no-host-metadata-property": "error",
"@angular-eslint/no-input-rename": "error",
"@angular-eslint/no-inputs-metadata-property": "error",
"@angular-eslint/no-output-on-prefix": "error",
"@angular-eslint/no-output-rename": "error",
"@angular-eslint/no-outputs-metadata-property": "error",
"@angular-eslint/use-lifecycle-interface": "error",
"@angular-eslint/use-pipe-transform-interface": "error",
"@typescript-eslint/consistent-type-definitions": "error",
"@typescript-eslint/dot-notation": "off",
"@typescript-eslint/explicit-member-accessibility": [
"off",
{
accessibility: "explicit"
}
],
"@typescript-eslint/indent": ["off"],
"@typescript-eslint/member-delimiter-style": [
"error",
{
multiline: {
delimiter: "semi",
requireLast: true
},
singleline: {
delimiter: "semi",
requireLast: false
}
}
],
"@typescript-eslint/member-ordering": "off",
"@typescript-eslint/naming-convention": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-empty-interface": "error",
"@typescript-eslint/no-inferrable-types": [
"error",
{
ignoreParameters: true
}
],
"@typescript-eslint/no-misused-new": "error",
"@typescript-eslint/no-non-null-assertion": "error",
"@typescript-eslint/prefer-function-type": "error",
"@typescript-eslint/quotes": "off",
"@typescript-eslint/semi": ["error", "always"],
"@typescript-eslint/type-annotation-spacing": "error",
"@typescript-eslint/unified-signatures": "error",
"arrow-body-style": ["off"],
"arrow-parens": ["off", "always"],
"brace-style": ["error", "1tbs"],
"comma-dangle": "off",
"constructor-super": "error",
curly: "error",
"eol-last": "error",
eqeqeq: ["error", "smart"],
"guard-for-in": "error",
"id-blacklist": "off",
"id-match": "off",
"import/no-deprecated": "warn",
"jsdoc/no-types": "error",
"linebreak-style": "off",
"max-len": [
"error",
{
code: 140
}
],
"new-parens": "off",
"newline-per-chained-call": "off",
"no-bitwise": "error",
"no-caller": "error",
"no-console": [
"error",
{
allow: [
"log",
"dirxml",
"warn",
"error",
"dir",
"timeLog",
"assert",
"clear",
"count",
"countReset",
"group",
"groupCollapsed",
"groupEnd",
"table",
"Console",
"markTimeline",
"profile",
"profileEnd",
"timeline",
"timelineEnd",
"timeStamp",
"context"
]
}
],
"no-debugger": "error",
"no-empty": "off",
"no-eval": "error",
"no-extra-semi": "off",
"no-fallthrough": "error",
"no-irregular-whitespace": "off",
"no-multiple-empty-lines": "off",
"no-new-wrappers": "error",
"no-restricted-imports": ["error", "rxjs/Rx"],
"no-shadow": [
"off",
{
hoist: "all"
}
],
"@typescript-eslint/no-shadow": ["error"],
"no-throw-literal": "error",
"no-trailing-spaces": "error",
"no-undef-init": "error",
"no-underscore-dangle": "off",
"no-unused-labels": "error",
"no-var": "error",
"prefer-const": "error",
"quote-props": "off",
radix: "error",
"react/jsx-curly-spacing": "off",
"react/jsx-equals-spacing": "off",
"react/jsx-wrap-multilines": "off",
"space-before-function-paren": "off",
"space-before-blocks": "error",
"space-in-parens": ["off", "never"],
"spaced-comment": [
"error",
"always",
{
markers: ["/"]
}
],
"@typescript-eslint/tslint/config": [
"error",
{
rules: {
"import-spacing": true,
whitespace: [true, "check-branch", "check-decl", "check-operator", "check-separator", "check-type"],
}
}
]
},
overrides: [
{
files: ["cypress/**/*.js"],
rules: {
"space-before-blocks": "error",
"no-var": "off",
"no-bitwise": "off",
"eqeqeq": "off",
"prefer-const": "off"
}
}
]
};
我解决了这些文件夹中的所有 lint 问题,然后,当我 运行 lint 时,它显示一条消息说“已尝试对 {file-name} 进行 lint,但没有发现有效的启用规则已解析配置中的文件类型和文件路径。
我不明白,文件正在被检查,但消息说没有。 这是一个屏幕截图,我故意造成了 lint 错误。您会看到上面的消息“已尝试 lint...但未发现有效...”,然后在其下方显示该文件实际上已被 lint(因为它显示了 lint 错误)。
为什么会这样?我想这并没有阻止我对代码进行 linting,但它很烦人。
我看到您在 eslintrc 文件中添加了 @typescript-eslint/tslint
插件。
看来您的项目中包含 tslint.json
文件,您需要向 tslint.json
问题:https://github.com/palantir/tslint/issues/3735#issuecomment-368520472
"jsRules": {
"no-empty": true
}
我能够通过为忽略规则的 js 文件添加覆盖部分来解决此问题,如下所示:
overrides: [
{
files: ["**/*.js"],
rules: {
"@typescript-eslint/tslint/config": ["off"] //this is the rule that was causing the message, but you can add other rules here
}
}
]
我在主要规则部分之外添加了这部分。