Skip to content

Commit 6964cb1

Browse files
authored
feat: remove support for ignore files in FlatESLint (#16355)
* do not use `gitignoreToMinimatch` on `--ignore-pattern` * remove .eslintignore lookup * remove flat-eslint tests that assume .eslintignore lookup * remove --ignore-path CLI option * remove ignorePath contructor option * update docs and jsdoc * do not use gitIgnoreToMinimatch on ignorePatterns constructor option
1 parent 49bd1e5 commit 6964cb1

15 files changed

Lines changed: 145 additions & 291 deletions

Makefile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -518,11 +518,11 @@ target.lint = function([fix = false] = []) {
518518
* when analyzing `require()` calls from CJS modules in the `docs` directory. Since our release process does not run `npm install`
519519
* in the `docs` directory, linting would fail and break the release. Also, working on the main `eslint` package does not require
520520
* installing dependencies declared in `docs/package.json`, so most contributors will not have `docs/node_modules` locally.
521-
* Therefore, we add `--ignore-pattern docs` to exclude linting the `docs` directory from this command.
521+
* Therefore, we add `--ignore-pattern "docs/**"` to exclude linting the `docs` directory from this command.
522522
* There is a separate command `target.lintDocsJS` for linting JavaScript files in the `docs` directory.
523523
*/
524524
echo("Validating JavaScript files");
525-
lastReturn = exec(`${ESLINT}${fix ? "--fix" : ""} . --ignore-pattern docs`);
525+
lastReturn = exec(`${ESLINT}${fix ? "--fix" : ""} . --ignore-pattern "docs/**"`);
526526
if (lastReturn.code !== 0) {
527527
errors++;
528528
}

docs/src/user-guide/configuring/configuration-files-new.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ This configuration object applies to all files except those ending with `.config
132132

133133
#### Globally ignoring files with `ignores`
134134

135-
If `ignores` is used without any other keys in the configuration object, then the patterns act as additional global ignores, similar to those found in `.eslintignore`. Here's an example:
135+
If `ignores` is used without any other keys in the configuration object, then the patterns act as global ignores. Here's an example:
136136

137137
```js
138138
export default [
@@ -142,7 +142,7 @@ export default [
142142
];
143143
```
144144

145-
This configuration specifies that all of the files in the `.config` directory should be ignored. This pattern is added after the patterns found in `.eslintignore`.
145+
This configuration specifies that all of the files in the `.config` directory should be ignored. This pattern is added after the default patterns, which are `["**/node_modules/**", ".git/**"]`.
146146

147147
#### Cascading configuration objects
148148

eslint.config.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,23 @@ function createInternalFilesPatterns(pattern = null) {
7878

7979
module.exports = [
8080
...compat.extends("eslint"),
81+
{
82+
ignores: [
83+
"build/**",
84+
"coverage/**",
85+
"docs/**",
86+
"!docs/.eleventy.js",
87+
"jsdoc/**",
88+
"templates/**",
89+
"tests/bench/**",
90+
"tests/fixtures/**",
91+
"tests/performance/**",
92+
"tmp/**",
93+
"tools/internal-rules/node_modules/**",
94+
"**/test.js",
95+
"!**/.eslintrc.js"
96+
]
97+
},
8198
{
8299
plugins: {
83100
"internal-rules": internalPlugin,

lib/cli.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ const fs = require("fs"),
2525
RuntimeInfo = require("./shared/runtime-info");
2626
const { Legacy: { naming } } = require("@eslint/eslintrc");
2727
const { findFlatConfigFile } = require("./eslint/flat-eslint");
28-
const { gitignoreToMinimatch } = require("@humanwhocodes/gitignore-to-minimatch");
2928
const { ModuleImporter } = require("@humanwhocodes/module-importer");
3029

3130
const debug = require("debug")("eslint:cli");
@@ -145,7 +144,7 @@ async function translateOptions({
145144

146145
if (ignorePattern) {
147146
overrideConfig.push({
148-
ignores: ignorePattern.map(gitignoreToMinimatch)
147+
ignores: ignorePattern
149148
});
150149
}
151150

@@ -182,7 +181,6 @@ async function translateOptions({
182181
fix: (fix || fixDryRun) && (quiet ? quietFixPredicate : true),
183182
fixTypes: fixType,
184183
ignore,
185-
ignorePath,
186184
overrideConfig,
187185
overrideConfigFile,
188186
reportUnusedDisableDirectives: reportUnusedDisableDirectives ? "error" : void 0
@@ -193,6 +191,7 @@ async function translateOptions({
193191
options.rulePaths = rulesdir;
194192
options.useEslintrc = eslintrc;
195193
options.extensions = ext;
194+
options.ignorePath = ignorePath;
196195
}
197196

198197
return options;

lib/eslint/eslint-helpers.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,6 @@ function processOptions({
410410
fixTypes = null, // ← should be null by default because if it's an array then it suppresses rules that don't have the `meta.type` property.
411411
globInputPaths = true,
412412
ignore = true,
413-
ignorePath = null, // ← should be null by default because if it's a string then it may throw ENOENT.
414413
ignorePatterns = null,
415414
overrideConfig = null,
416415
overrideConfigFile = null,
@@ -441,6 +440,9 @@ function processOptions({
441440
if (unknownOptionKeys.includes("globals")) {
442441
errors.push("'globals' has been removed. Please use the 'overrideConfig.languageOptions.globals' option instead.");
443442
}
443+
if (unknownOptionKeys.includes("ignorePath")) {
444+
errors.push("'ignorePath' has been removed.");
445+
}
444446
if (unknownOptionKeys.includes("ignorePattern")) {
445447
errors.push("'ignorePattern' has been removed. Please use the 'overrideConfig.ignorePatterns' option instead.");
446448
}
@@ -493,9 +495,6 @@ function processOptions({
493495
if (typeof ignore !== "boolean") {
494496
errors.push("'ignore' must be a boolean.");
495497
}
496-
if (!isNonEmptyString(ignorePath) && ignorePath !== null) {
497-
errors.push("'ignorePath' must be a non-empty string or null.");
498-
}
499498
if (typeof overrideConfig !== "object") {
500499
errors.push("'overrideConfig' must be an object or null.");
501500
}
@@ -538,7 +537,6 @@ function processOptions({
538537
fixTypes,
539538
globInputPaths,
540539
ignore,
541-
ignorePath,
542540
ignorePatterns,
543541
reportUnusedDisableDirectives
544542
};

lib/eslint/flat-eslint.js

Lines changed: 3 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ const findUp = require("find-up");
1616
const { version } = require("../../package.json");
1717
const { Linter } = require("../linter");
1818
const { getRuleFromConfig } = require("../config/flat-config-helpers");
19-
const { gitignoreToMinimatch } = require("@humanwhocodes/gitignore-to-minimatch");
2019
const {
2120
Legacy: {
2221
ConfigOps: {
@@ -28,7 +27,6 @@ const {
2827
} = require("@eslint/eslintrc");
2928

3029
const {
31-
fileExists,
3230
findFiles,
3331
getCacheFile,
3432

@@ -76,9 +74,8 @@ const LintResultCache = require("../cli-engine/lint-result-cache");
7674
* @property {boolean|Function} [fix] Execute in autofix mode. If a function, should return a boolean.
7775
* @property {string[]} [fixTypes] Array of rule types to apply fixes for.
7876
* @property {boolean} [globInputPaths] Set to false to skip glob resolution of input file paths to lint (default: true). If false, each input file paths is assumed to be a non-glob path to an existing file.
79-
* @property {boolean} [ignore] False disables use of .eslintignore.
80-
* @property {string} [ignorePath] The ignore file to use instead of .eslintignore.
81-
* @property {string[]} [ignorePatterns] Ignore file patterns to use in addition to .eslintignore.
77+
* @property {boolean} [ignore] False disables all ignore patterns except for the default ones.
78+
* @property {string[]} [ignorePatterns] Ignore file patterns to use in addition to config ignores.
8279
* @property {ConfigData} [overrideConfig] Override config object, overrides all configs used with this instance
8380
* @property {boolean|string} [overrideConfigFile] Searches for default config file when falsy;
8481
* doesn't do any config file lookup when `true`; considered to be a config filename
@@ -151,30 +148,6 @@ function calculateStatsPerRun(results) {
151148
});
152149
}
153150

154-
/**
155-
* Loads global ignore patterns from an ignore file (usually .eslintignore).
156-
* @param {string} filePath The filename to load.
157-
* @returns {ignore} A function encapsulating the ignore patterns.
158-
* @throws {Error} If the file cannot be read.
159-
* @private
160-
*/
161-
async function loadIgnoreFilePatterns(filePath) {
162-
debug(`Loading ignore file: ${filePath}`);
163-
164-
try {
165-
const ignoreFileText = await fs.readFile(filePath, { encoding: "utf8" });
166-
167-
return ignoreFileText
168-
.split(/\r?\n/gu)
169-
.filter(line => line.trim() !== "" && !line.startsWith("#"));
170-
171-
} catch (e) {
172-
debug(`Error reading ignore file: ${filePath}`);
173-
e.message = `Cannot read ignore file: ${filePath}\nError: ${e.message}`;
174-
throw e;
175-
}
176-
}
177-
178151
/**
179152
* Create rulesMeta object.
180153
* @param {Map<string,Rule>} rules a map of rules from which to generate the object.
@@ -319,7 +292,6 @@ async function calculateConfigArray(eslint, {
319292
overrideConfig,
320293
configFile,
321294
ignore: shouldIgnore,
322-
ignorePath,
323295
ignorePatterns
324296
}) {
325297

@@ -364,22 +336,6 @@ async function calculateConfigArray(eslint, {
364336
configs.push(...slots.defaultConfigs);
365337

366338
let allIgnorePatterns = [];
367-
let ignoreFilePath;
368-
369-
// load ignore file if necessary
370-
if (shouldIgnore) {
371-
if (ignorePath) {
372-
ignoreFilePath = path.resolve(cwd, ignorePath);
373-
allIgnorePatterns = await loadIgnoreFilePatterns(ignoreFilePath);
374-
} else {
375-
ignoreFilePath = path.resolve(cwd, ".eslintignore");
376-
377-
// no error if .eslintignore doesn't exist`
378-
if (fileExists(ignoreFilePath)) {
379-
allIgnorePatterns = await loadIgnoreFilePatterns(ignoreFilePath);
380-
}
381-
}
382-
}
383339

384340
// append command line ignore patterns
385341
if (ignorePatterns) {
@@ -428,7 +384,7 @@ async function calculateConfigArray(eslint, {
428384
* so they can override default ignores.
429385
*/
430386
configs.push({
431-
ignores: allIgnorePatterns.map(gitignoreToMinimatch)
387+
ignores: allIgnorePatterns
432388
});
433389
}
434390

lib/options.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,16 @@ module.exports = function(usingFlatConfig) {
129129
};
130130
}
131131

132+
let ignorePathFlag;
133+
134+
if (!usingFlatConfig) {
135+
ignorePathFlag = {
136+
option: "ignore-path",
137+
type: "path::String",
138+
description: "Specify path of ignore file"
139+
};
140+
}
141+
132142
return optionator({
133143
prepend: "eslint [options] file.js [file.js] [dir]",
134144
defaults: {
@@ -203,11 +213,7 @@ module.exports = function(usingFlatConfig) {
203213
{
204214
heading: "Ignoring files"
205215
},
206-
{
207-
option: "ignore-path",
208-
type: "path::String",
209-
description: "Specify path of ignore file"
210-
},
216+
ignorePathFlag,
211217
{
212218
option: "ignore",
213219
type: "Boolean",

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
"dependencies": {
5858
"@eslint/eslintrc": "^1.3.2",
5959
"@humanwhocodes/config-array": "^0.10.5",
60-
"@humanwhocodes/gitignore-to-minimatch": "^1.0.2",
6160
"@humanwhocodes/module-importer": "^1.0.1",
6261
"ajv": "^6.10.0",
6362
"chalk": "^4.0.0",

tests/fixtures/.eslintignore_empty

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = [{
2+
ignores: ["**/fixtures/**"]
3+
}];

0 commit comments

Comments
 (0)