忽略文件

您可以通过指定一个或多个 glob 模式将 ESLint 配置为在 linting 时忽略某些文件和目录。您可以通过以下方式忽略文件:

  • ignorePatterns 添加到配置文件。
  • 创建一个包含忽略模式的专用文件(默认为 .eslintignore)。

配置文件中的 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

zK1CypQsq2i3Yl4DIsJqUX6wnGAfgKKKRm4/BU9PINycm1yWDFGB5mAYEZX5rDhgRtpXSC+viphYh5riSmLJlSJKeYdAwLz1Bq1nE3cneSOtqkB9AzKpAieT9Gr5uoz50rbccCMaTk0re8lckD83+skVX89v/odqhI2Ef+msYH+cOCuLnE4ojqgnWPXmT3Sjb6P1ST1Vdj9E968gU8lwF0vdk7UNRBz+VjJVjBklRx2nrbF8Ud419wTREmEYUdsGg3JWNXwW3EH/vZTFjXsWgm6AaYpJ4QbafMAWYps+FPZGAJTIDohYw1YShTvAwseobTXtBgGkbH3QwV0cYREUB+VfgwFKk7oolIYMLO3fcDNiY2Xy9hMk/ynzk1KnrbxTr7L2hODnupKg61Y0py5e89UBwP55+qbUldxXn42D9B0Da48O9K+GeEyUQ7aVEcHXcrHxtBjurir1byk1mvZHOw==

.eslintignore 文件

H1CCKYllhWDy6PP6Ey01xCQbNR87iUL3miVZc8A5j/vlwfDw9fozy96JstAIG/BL1/ahYYijjzNnz6Lr8P7iYGE1WNa8ukWvZMSc52UTVzLehuGTaOIjPo2X7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Fa3irKexDRPecx+6rAdU+vHhALzuacpgrMfNaoiU5GRsq0waNborGk3sfImxElSb8HQxjN/nuu6epSTOrnbVjlOEUhbxVFWDmRXkbqfHS885lv9DgWKddinm/V9OAKwAjuirDGUN91Jd4WQdGv4rSe6GOhs60rId6wKrDkB1f47ccPxN+oyl6i3zs4g=

eslint --ignore-path .jshintignore file.js

K0e8gXspusxCuHPwhgvxSqrnNOTkyatjkUsYnjlupSm6i1ZB2lfL6f1zjYo81HUTzS2Gs8HhIccsWAypC58Dqw==

eslint --ignore-path .gitignore file.js

hWvPjo+rS7INv+PapHxYoSNHiMlRX9aa0m/OWRGdewjy132n18v0zQEPg4QhbKFcDMY/zba8xHtwEH8+0F5YfOzR42l+yWkDvW/mStIHgvlg/C+BI6hxYOW2EirN0USN2lXsbc1vympu+cs5GIic21nT41p7mx1R7C4A/SNkh2txT/FPXwBoOFnzdUK4U4pmN1R1tnjyoI7JWYUYY8cAGUETdeEgdqlIbverSGPb1A5Qg/fX9HkliognrONGYrRsqG6OgKoNzCqV+HvoJD1w+VVN1s7JhTBRph1nHHHWh3eI5KCSMhw2YnbfGJWolg2AOPG1wDQnDkOPRiRw4i10AHSLByMuQP/wpQj9GseZBqDU9ptQxA6KaaCbof8i9+Ai

在 package.json 中使用 eslintIgnore

e9IUGjne4YrIo5vnC0uTRcoZLuwI5WaROhU6cUs0aOxLPRotCLgdnHOWMEdgfsadvnw2Jd0CKyFhQQGMFmLajcgh5x6vIv9pBwKq+5YbI4o+y6xCKp9migNbhRSnGGUp1xIzMY7pTZDPx3MguNlwqlsnJGqkOGErDC+dSzJXs7Ii8DEIvb41IUHqG0PvnXzZgHAKKOrd4GhsBsxUkQ6egz92DpCIYCbv1+eJk3KKyOI/BGNaiNmIY408Wj6U0Yyc

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

忽略的文件警告

wCIMrb0jwkaE/xtiJqIiAvT3uX5ScqwVqch+MX/OLHhyRujlo/bMgxf4iigz5XKq4zHtX1mKt2RxuOSFjeUBDglMcqHKuvmTiBJIRlVrrhL7V3IqZ7qLzaombc7op6kPUiV/cRF/TYqk5CUJNk4HExeHCMbQClLaJZOa6LdD2S1t7r3KL+SnevkTg57Wg8jUBjMw+VCY9kCOvh7diJ3RZwj5I8Vh7s8oSm6CaKMNhuJ7/i2Da49tbf3nyJvd6xBsbENMqzTeLy36j9NdMdmcrFASC8z6Jzj6ws/wJnYbvA6Ht1DmzTWWlj2yNWA7zXHSIyDPw0yDWtJee4p0T7jFbloUJksDcSYfFC+6mRctsFM=

foo.js

KCQjRx7OPrr7yOEGcs1YqZI9bo8xwxRX6dzFBs820ec=

eslint foo.js

dmMZCnZsUum0F1dH+NCGn/jDHiDe9TsMGuUwopE1jlY=

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

✖ 1 problem (0 errors, 1 warning)

nEb8c7pDu6wJ1+3d4Uccil3MvsfAlD5Yx9JkRrUaq0fY3VoP4Z8BPSlhHPCFThkowUhbqFSL0oAdZgEXhsYyIBOd0ekLt94v6x+2CVQyBNzrwqXY2cABb/yXq3licjuz6eNTOabc3CGo4drJ/AoCsmwpP54JEeXRqqcKGGpVbDLBQPlwfcxtitlNhdag+BFNAqWYgIpPfTNR/dkG3T9s7QviceyQ/Xr3MiZMlLIUppQ=

Uc6t0BHRCtkbBmp+swW2n6wjZYD+TUbSqLZ8aM8zLbUO3imJqSnhE1v04QUki1IEGyMIGl2FrE+5nIhseQhlzbJyFBnFobEyQ/McKGH8ZAGZBj/FmHqK0zhBqR0u7SLuxGvZ2arU7OCg8LsvRSHk3RAsIu4SPDi+kwxycpUQaHv42YUJxidxd0tvEgCVDZAepUYv98xJ0x2NGgvvkf2FegWnTEysSi3qSlR83REcNNED0qyzVa8xt1qSha1nqVT1CfUfl/C7nFNkqGsVpVU9jQ==

eslint .config/foo.js

dmMZCnZsUum0F1dH+NCGn/jDHiDe9TsMGuUwopE1jlY=

.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)

nEb8c7pDu6wJ1+3d4Ucciu81kU0DsfbJzoRd+1l+HeXKs9zv3d5tz5hMm9jektnxR9U2og6Om7HEA6hdns7On0H1vMQBKID0kDAlKvGTKDSGc1TUgxb0fVYtDFdrfgBCz0lx2vcaRr6fbyT8QYu+Z/UTNPLO5bT7+AOx1fRKHwRdNX7uF/rk0ttdkfiXuSUe8EIhBSUsuWQX40NU5MRm8tZQbeW5J2LWnTHEhfZOjBtq0ylmuQ8454XlZq41q4Bx0jUJvMVWKoCbgr7RUIaHLsY0cvTGIrfhavxqyGrA8SJcgVXF8UDskVI28SzH08xLlKgn56MRRvaK//bAYfha8/4V2ay21h876BCBl4+a1Xnwgsw1BDbeQdRV1OgEQvBBNBahRq1mPkmuxP+TpmUzmg==