Skip to content

feat: add support for custom name parameter to includeIgnoreFile #211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 3, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/compat/src/ignore-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@ export function convertIgnorePatternToMinimatch(pattern) {
/**
* Reads an ignore file and returns an object with the ignore patterns.
* @param {string} ignoreFilePath The absolute path to the ignore file.
* @param {string} [name] The name of the ignore file config.
* @returns {FlatConfig} An object with an `ignores` property that is an array of ignore patterns.
* @throws {Error} If the ignore file path is not an absolute path.
*/
export function includeIgnoreFile(ignoreFilePath) {
export function includeIgnoreFile(ignoreFilePath, name) {
if (!path.isAbsolute(ignoreFilePath)) {
throw new Error("The ignore file location must be an absolute path.");
}
Expand All @@ -80,7 +81,7 @@ export function includeIgnoreFile(ignoreFilePath) {
const lines = ignoreFile.split(/\r?\n/u);

return {
name: "Imported .gitignore patterns",
name: name || "Imported .gitignore patterns",
ignores: lines
.map(line => line.trim())
.filter(line => line && !line.startsWith("#"))
Expand Down
23 changes: 23 additions & 0 deletions packages/compat/tests/ignore-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,28 @@ describe("@eslint/compat", () => {
],
});
});

it("should return an object with a custom name", () => {
const ignoreFilePath = fileURLToPath(
new URL(
"../tests/fixtures/ignore-files/gitignore1.txt",
import.meta.url,
),
);
const result = includeIgnoreFile(ignoreFilePath, "Custom Name");
assert.deepStrictEqual(result, {
name: "Custom Name",
ignores: [
"**/node_modules",
"!fixtures/node_modules",
"dist",
"**/*.log",
"**/.cache/",
".vuepress/dist",
"*/foo.js",
"dir/**/*",
],
});
});
});
});
1 change: 1 addition & 0 deletions packages/config-helpers/src/global-ignores.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ let globalIgnoreCount = 0;
* @param {string[]} ignorePatterns The ignore patterns.
* @param {string} [name] The name of the global ignores config.
* @returns {Config} The global ignores config.
* @throws {TypeError} If ignorePatterns is not an array or if it is empty.
*/
export function globalIgnores(ignorePatterns, name) {
if (!Array.isArray(ignorePatterns)) {
Expand Down