Skip to content

feat: Add new includeIgnoreFile() to config-helpers#430

Open
kirkwaiblinger wants to merge 35 commits intoeslint:mainfrom
kirkwaiblinger:include-gitignore-in-path
Open

feat: Add new includeIgnoreFile() to config-helpers#430
kirkwaiblinger wants to merge 35 commits intoeslint:mainfrom
kirkwaiblinger:include-gitignore-in-path

Conversation

@kirkwaiblinger
Copy link
Copy Markdown
Contributor

@kirkwaiblinger kirkwaiblinger commented Apr 8, 2026

Prerequisites checklist

AI acknowledgment

  • I did not use AI to generate this PR.
    • (for the most part; some AI use for the added documentation)
  • (If the above is not checked) I have reviewed the AI-generated content before submitting.

What is the purpose of this pull request?

fixes #329

What changes did you make? (Give an overview)

Deprecate includeIgnoreFile(),convertIgnorePatternToMinimatch() in @eslint/compat. Add and export new includeIgnoreFile() (documented),convertIgnorePatternToMinimatch() (undocumented) in @eslint/config-helpers.

The new convertIgnorePatternToMinimatch() is unaltered.
The new includeIgnoreFile():

  • adds a gitignoreResolution option which can be false (default; interprets patterns relative to config file) or true (interprets patterns relative to ignore file).
  • can accept an array of ignore file paths rather than only a single ignore file path.

Related Issues

#329

Is there anything you'd like reviewers to focus on?


There is a companion PR in eslint repo: eslint/eslint#20735

@github-project-automation github-project-automation Bot moved this to Needs Triage in Triage Apr 8, 2026
@kirkwaiblinger kirkwaiblinger marked this pull request as ready for review April 8, 2026 19:30
@kirkwaiblinger kirkwaiblinger changed the title feat: Add new includeIgnoreFIle() to config-helpers feat: Add new includeIgnoreFile() to config-helpers Apr 8, 2026
});

it("should return an object with an `ignores` property", () => {
const ignoreFilePath = fileURLToPath(
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should simplify this and in other spots by using import.meta.resolve (requires Node v18+)

Suggested change
const ignoreFilePath = fileURLToPath(
const ignoreFilePath = import.meta.resolve("../tests/fixtures/ignore-files/gitignore1.txt")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh... I never knew about import.meta.resolve. But in any case it looks like that still gets us a URL, which would need to be converted to a path with fileURLToPath(). So I'm not sure that that gains us anything? Unless I'm misunderstanding.

At the end of the day, this is really just the workaround for not having access to import.meta.dirname, which the linter complains about (due to supporting older versions of node)

// functionality of the `includeIgnoreFile` in `@eslint/compat`. The only
// discrepancy is the default name has been changed to reflect that it is
// really eslintignore mode by default.
describe("`includeIgnoreFile` compat with @eslint/compat", () => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests for the object form options ({ mode: string, name: string }) seem to be missing?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section of tests was copied verbatim from the @eslint/compat repo (with the one noted change). That version of includeIgnoreFile only supports a string for its second argument.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see, though, it looks like I haven't added a test with that combination in the preceding section. I'll go ahead and add one 👍

Comment thread packages/config-helpers/src/ignore-file.js Outdated
@kirkwaiblinger kirkwaiblinger requested a review from DMartens April 8, 2026 23:41
@mdjermanovic mdjermanovic moved this from Needs Triage to Implementing in Triage Apr 9, 2026
Comment thread packages/compat/README.md Outdated
Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
Comment thread packages/compat/tests/ignore-file.test.js Outdated
Comment thread packages/compat/README.md Outdated
Comment thread packages/config-helpers/README.md Outdated
Comment thread packages/migrate-config/package.json
mdjermanovic
mdjermanovic previously approved these changes Apr 14, 2026
Copy link
Copy Markdown
Member

@mdjermanovic mdjermanovic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks! Leaving open for others to verify.

Comment thread packages/compat/src/ignore-file.js Outdated
Comment thread packages/config-helpers/src/ignore-file.js Outdated
Comment thread packages/config-helpers/src/ignore-file.js Outdated
@kirkwaiblinger kirkwaiblinger requested a review from fasttime April 15, 2026 17:06
Copy link
Copy Markdown
Member

@fasttime fasttime left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some minor typos.

Comment thread packages/config-helpers/tests/types/types.test.ts Outdated
Comment thread packages/config-helpers/src/ignore-file.js Outdated
Comment thread packages/config-helpers/src/ignore-file.js Outdated
Comment thread packages/config-helpers/src/ignore-file.js Outdated
kirkwaiblinger and others added 2 commits April 18, 2026 15:30
Co-authored-by: Francesco Trotta <github@fasttime.org>
Co-authored-by: Francesco Trotta <github@fasttime.org>
Comment thread packages/compat/README.md
Comment thread packages/config-helpers/README.md
Comment thread packages/config-helpers/tests/types/types.test.ts
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR moves ignore-file utilities into @eslint/config-helpers by adding includeIgnoreFile() (with gitignore-relative support and multi-file support) and re-exporting convertIgnorePatternToMinimatch(), while deprecating the equivalents in @eslint/compat and updating @eslint/migrate-config to consume the new export.

Changes:

  • Add includeIgnoreFile() + convertIgnorePatternToMinimatch() implementation, docs, fixtures, and unit tests to @eslint/config-helpers.
  • Update @eslint/migrate-config to import convertIgnorePatternToMinimatch from @eslint/config-helpers and adjust dependencies.
  • Deprecate @eslint/compat ignore-file helpers and document the deprecation.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
packages/migrate-config/src/migrate-config.js Switches convertIgnorePatternToMinimatch import to @eslint/config-helpers.
packages/migrate-config/package.json Replaces @eslint/compat dependency with @eslint/config-helpers; removes eslint devDependency.
packages/config-helpers/tests/types/types.test.ts Adds TS type-surface checks for includeIgnoreFile() overload/return types.
packages/config-helpers/tests/ignore-file.test.js Adds unit tests for includeIgnoreFile() and convertIgnorePatternToMinimatch().
packages/config-helpers/tests/fixtures/ignore-files/gitignore1.txt Adds fixture ignore file used by new unit tests.
packages/config-helpers/src/index.js Re-exports new ignore-file utilities from the package entrypoint.
packages/config-helpers/src/ignore-file.js Implements includeIgnoreFile() (multi-file + basePath option) and convertIgnorePatternToMinimatch().
packages/config-helpers/README.md Documents includeIgnoreFile() usage, options, and multi-file behavior.
packages/compat/tests/ignore-file.test.js Updates file header comment (test behavior unchanged).
packages/compat/src/ignore-file.js Marks compat helpers as deprecated in JSDoc.
packages/compat/README.md Adds deprecation notice for compat includeIgnoreFile() documentation section.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/config-helpers/src/ignore-file.js
Comment thread packages/config-helpers/src/ignore-file.js
Comment thread packages/config-helpers/tests/types/types.test.ts
Comment thread packages/config-helpers/src/index.js
mdjermanovic
mdjermanovic previously approved these changes Apr 25, 2026
Copy link
Copy Markdown
Member

@mdjermanovic mdjermanovic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks! Leaving open for others to verify their review comments.

@lumirlumir lumirlumir moved this from Implementing to Second Review Needed in Triage Apr 26, 2026
Comment on lines +115 to +129
throw new Error(
"The options argument to `includeIgnoreFile()` should be an object or a string.",
);
}

const gitignoreResolution = optionsObject.gitignoreResolution ?? false;
if (typeof gitignoreResolution !== "boolean") {
throw new Error(
"The `gitignoreResolution` option must be specified a boolean or omitted",
);
}

const name = optionsObject.name ?? `Imported .gitignore patterns`;
if (typeof name !== "string") {
throw new Error(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
throw new Error(
"The options argument to `includeIgnoreFile()` should be an object or a string.",
);
}
const gitignoreResolution = optionsObject.gitignoreResolution ?? false;
if (typeof gitignoreResolution !== "boolean") {
throw new Error(
"The `gitignoreResolution` option must be specified a boolean or omitted",
);
}
const name = optionsObject.name ?? `Imported .gitignore patterns`;
if (typeof name !== "string") {
throw new Error(
throw new TypeError(
"The options argument to `includeIgnoreFile()` should be an object or a string.",
);
}
const gitignoreResolution = optionsObject.gitignoreResolution ?? false;
if (typeof gitignoreResolution !== "boolean") {
throw new TypeError(
"The `gitignoreResolution` option must be specified a boolean or omitted",
);
}
const name = optionsObject.name ?? `Imported .gitignore patterns`;
if (typeof name !== "string") {
throw new TypeError(

Maybe TypeError would be more specific here? When checking an argument’s type, TypeError seems more precise, and it looks like other places follow the TypeError approach for argument validation as well.

if (!Array.isArray(ignorePatterns)) {
throw new TypeError("ignorePatterns must be an array");
}
if (ignorePatterns.length === 0) {
throw new TypeError("ignorePatterns must contain at least one pattern");
}


It’s an optional suggestion, but I think adding a TypeError check to the tests would be a nice-to-have here.

assert.throws(
	() => includeIgnoreFile(123),
	{
		name: "TypeError",
		message: /error message/,
	},
);

Comment on lines +181 to +186
throw new Error(
"The first argument to `includeIgnoreFile()` should be a string or array of strings",
);
}
if (!path.isAbsolute(ignorePath)) {
throw new Error(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
throw new Error(
"The first argument to `includeIgnoreFile()` should be a string or array of strings",
);
}
if (!path.isAbsolute(ignorePath)) {
throw new Error(
throw new TypeError(
"The first argument to `includeIgnoreFile()` should be a string or array of strings",
);
}
if (!path.isAbsolute(ignorePath)) {
throw new TypeError(

Same here :)

Comment on lines +103 to +108
const ignoreFilePath = fileURLToPath(
new URL(
"../tests/fixtures/ignore-files/gitignore1.txt",
import.meta.url,
),
);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to extract ignoreFilePath into a top-level helper variable here?

It looks like ignoreFilePath is used six times across the tests, so I think moving it could make the code a bit more concise.

import.meta.url,
),
);
const basePath = fileURLToPath(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving basePath to the top level could also be a nice option, since it’s used twice (though I’m not strongly opinionated about it).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Second Review Needed

Development

Successfully merging this pull request may close these issues.

Change Request: includeIgnoreFile should respect the path to the directory containing the .gitignore

6 participants