忽略代码

配置文件中的 ignorePatterns

你可以告诉 ESLint 在你的配置文件中使用 ignorePatterns 忽略特定的文件和目录。ignorePatterns 模式遵循与 .eslintignore 相同的规则。请参阅 .eslintignore 文件文档 了解更多信息。

{
    "ignorePatterns": ["temp.js", "**/vendor/*.js"],
    "rules": {
        //...
    }
}
  • ignorePatterns 中的通配符模式与配置文件所在的目录相关。
  • 您不能在 overrides 属性下写入 ignorePatterns 属性。
  • .eslintignore 中定义的模式优先于配置文件的 ignorePatterns 属性。

如果 glob 模式以 / 开头,则该模式相对于配置文件的基本目录。例如,lib/.eslintrc.json 中的 /foo.js 匹配 lib/foo.js,但不匹配 lib/subdir/foo.js

如果通过 --config CLI 选项提供配置,则配置中以 / 开头的忽略模式相对于当前工作目录,而不是给定配置的基本目录。例如,如果 --config configs/.eslintrc.json 存在,则配置中的忽略模式是相对于 . 而不是 ./configs

.eslintignore 文件

你可以通过在项目的根目录中创建一个 .eslintignore 文件来告诉 ESLint 忽略特定的文件和目录。.eslintignore 文件是一个纯文本文件,其中每一行都是一个 glob 模式,指示应该从 linting 中省略哪些路径。例如,以下将省略所有 JavaScript 文件:

**/*.js

sT97F4/WfEoCtkI/S00Yl12xs4bwyiEPggoeVIs2w79jQoQQrKoC3jLYBU2KSswiaeklrLdmeunry2IWxSf9f6GEeiYUVDTP55yP8LfVsCmGjHGOTQrhfO4r8dObq07SZ/XBb+FPB1453YK1gXCo4wRGGviNOCkJ6bDIjXyUS5vKSgjWc8a724kbG1eZZa3WamcyoqE8h1HAJexhHVxBu1EKCixdiA0WPcNrTz60cQSHJptcVgfOnprd9F40VySCeIvG5DIvy2HxT2FGxOa4GA1vp0kHfF39qWE21fJikROZdL3ZhCFYTZ2jwaweoI29Nm5dAFcoqTPO3K6xteG5YjkDOax7RSbUJtNeO7PZ2hbTroBLORCe+GF4nvqM+n4x+D8meATUcUr2oqDVjKu1vJfMPUPk5RJTdJBNt1UoZXkH9OkHf3dgvLnEAPsYMRsVtgFFoenAkr10Nge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dykFTN9FQTLKFGJhalZ0hoVRFMKkNEbp7lmTikyzXd9uV1nFMrIdWTIcxc=

使用备用文件

dAEIqF3bnz3bQ1b07/tADeG8Ff+if5eLq53BLpP9jahIcmSZRyjBQSLkYUNSBzJ8xA6TxkkbKjbu/WfcqusMsO2qk2JTVG0HQJZnA/0/Rj4jPk/kEqhZgkvE4BrBQTOpsUy7ta9KNJg6sixQx1Eyafb6jQYhVD5UJtpCydFX4Jx3QXTRUegssyBuC0KVEFhK49HDBqntS5c1D7cnDgAL7UsSD2JP8tohkuafNrxxklgCkB/jkLjq6mBJ10ajDattCbAwpXihmH8dOCDBRm5lE874XNVLTqtTFMFOUQ3J6rlWEjIsRorGrk0GQk73+AFuLXrlcpQb0dkHlNHjpkNOEkf3AO6cVkbr522qxKWhc+s=

eslint --ignore-path .jshintignore file.js

FxbZQxSBpI43m4sK0yASPFOcsug3AFwDIQhBR5p7J/oY0aNXo+5F6ubcwgWfQU25GhCkJuDpcLyZIh7/Oy84uw==

eslint --ignore-path .gitignore file.js

bUcobk4B4eHSgKu+zvjmt2NpHfR54LrzXRnbLRKvNMU4s/083CQMuAZZ10uflKGTlkECq/b8kHPmKBE1qETKN7uF8GYsPQcvj2EnmI+B7AWGODAl0ZVWO5bKPqbF7aA6LIkbYqJ8YjuLvF4Yi/PK2bMVuH8gvJxYcJFKqm79JPMGBwdxa5AXqdwx11/2obxlOmkWQXu4Eb5pwKBL5hs7oJhxlyyumU6eXJTevTLuVRYWesiLZg9HINi914JbdwiOVJDWKeZpNhm6cUlf9Pwkmrj+XTbR8+kip4biGNrVms4O3M4dIpSt0zLxB0Qvx5cQCC3lQCWZp1Rk9K8bVL9Sc1W/9T682VFIOK3HWqacvIdhRRfWlm1CMIAYsxf6Qrcii2mmJSed4VBnqd/nO0JZTA==

在 package.json 中使用 eslintIgnore

ARP3PCuqDc2UoIq8yluLDBYLgHCduCw2vIX9K99Pm+3De0r2Fpz6COOd7NM1ssFX3WL5EDLJfOzDHMMyagUrPDOAGhM5Tr5SHBMpdgekcoiJQ/SxSLQcTZB8pXBcMt0XGgMm8qT/EoSSeMZunvRJm9GfqaPFXm1dlxATnHqEN+OlKiXXEsujCthTmlGrxcUlALrhVRX3O7qwTXLBeKGz6peHeeAIVy8CYde90aegQd0=

{
    "name": "mypackage",
    "version": "0.0.1",
    "eslintConfig": {
        "env": {
            "browser": true,
            "node": true
        }
    },
    "eslintIgnore": ["hello.js", "world.js"]
}

忽略的文件警告

/79KuB2K8sjS9qVOTFiePwO3lLAk4jeORNeD/xYNlzL/fWjCyFIyIn1SewANoRLOPyMJ2PrDRoWF9Ga4l6xFwrIz9OG+AWJDfD3T3w979G1PQ8GdchCRoJfNeZe0XH3nLa7rWZOF5stYnF8hq3vczcJHaNMo5BnWrlF0NPgtFLWFgt2fgLv5x8B7mI+NCUx+c2oL/3hQfLedZ0H7HY6y/s+F1/9L5RTuEn0jAwp/jXNdDeKMWx8XYP1pJxs/C8YzyjN6kAlUNiUeEryGSLQQ0W40UjtvMxXDXYbNidMKewGQVCTzqbHIpYhMELbF8HoD0Cb99eQDzsPeUXbx85Rjtg==

foo.js

Ao7NiKPCRctTjJD0kxHqha8qIBQGMXk6QBDFDCRPvBw=

eslint foo.js

jlFoeC5X/HBKaqJ3JqWw7Qz7sz6OxQK81dV3Z6sNLts=

foo.js
  0:0  warning  File ignored because of a matching ignore pattern. Use "--no-ignore" to override.

✖ 1 problem (0 errors, 1 warning)

t0RUptZELIv1AEVgkb4Zx0GHlT769O3gliLZHzzJ1QMMb4evMHzOjxAC/F9qFQRRWkNt2JbtzdVoj7QAPzGOikyYlM7KH7enR93pRCYGjnJstWy+FMqOmldbuMDeSKP0HHFMXmKFyukEEweqB8SOEQHGkW15SJ9RSW6NxjdO7yWttpS5ySMWkxMSUwWZW8Nr+bfvlwN4lhGfZ2mGGkf3GGya7Gn9Cg4V5nsXySkkaqU=

yDcVPrDw1KkiBJqUdkL2XtAI1ji1Q03CzaNUJLIzAziflJkhFBis+TJtvQ1MGIw5mvS2r6Al1ib5QtUCDuMvt+7N0lSKE9U6hjca66Ue8YorcPTgWb/v9lKQR+spaRoWpB0qNZ05yrpRDjGwGbM8fb0eF89bGjBhvpXIGeMYWMmLiQ4B8qSkUn9iIUAZdZlhgBsomm8mb1MwkSXoGRP2nUjaDiTkjn7DnSgi0+5dLWl1i6l1EFhnhl25szwYb/QQDPOhbl2WJfynWERbi5Ec1Q==

eslint .config/foo.js

jlFoeC5X/HBKaqJ3JqWw7Qz7sz6OxQK81dV3Z6sNLts=

.config/foo.js
  0:0  warning  File ignored by default.  Use a negated ignore pattern (like "--ignore-pattern '!<relative/path/to/filename>'") to override

✖ 1 problem (0 errors, 1 warning)

t0RUptZELIv1AEVgkb4Zx87WRnaiKmKBIP9LYntuxsxy5WY4oVPCmaoxekO3xJ+sQ7XSb9wjTs6TkJ8rx4BDjJViUcPSLRnJFBRQvG8McNa4Z9Mqg0zy7bn8ZAOEw4RqRK0CwoaJmfdTpZaDlCV3aVZ+iQvIsw+AREuneyc2O0juapQBlohRFEsjDzHaNYYShN6Wt1bEbXHzBEeOK+ulPcCMiWrYppQBEN0vB6vrXrLQ59FEzJG3O878S+qZuuL5yZbDEaB1c9iLhZebKRv3IS9rqG+xfRYUTo+UQguUT0XGa0zLAF5XIUgeK+AVgJEayq4NH7SehPQHNLAnHlHYYhqBeE7Qwbvm5T+eOg8GvP2fd+r6DY5LA8g41UN9I2Z4sxWbdGc0HOQwEubNTDYZQbKIQc9cvdmj6bwBwcAUrvM=