Skip to content

Conversation

@hyperz111
Copy link

Prerequisites checklist

What is the purpose of this pull request?

Fix comment removal removal in includeIgnoreFile(). Following .gitignore documentation.

What changes did you make? (Give an overview)

In .map, I use regex for removing the valid comment.

Related Issues

N/A

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

N/A

@github-project-automation github-project-automation bot moved this to Needs Triage in Triage Nov 28, 2025
@eslint-github-bot
Copy link

Hi @hyperz111!, thanks for the Pull Request

The pull request title isn't properly formatted. We ask that you update the pull request title to match this format, as we use it to generate changelogs and automate releases.

  • The commit message tag wasn't recognized. Did you mean "docs", "fix", or "feat"?
  • There should be a space following the initial tag and colon, for example 'feat: Message'.

To Fix: You can fix this problem by clicking 'Edit' next to the pull request title at the top of this page.

Read more about contributing to ESLint here

@hyperz111 hyperz111 changed the title fix(compat): fix comments removal in includeIgnoreFile() fix: fix comments removal in includeIgnoreFile() Nov 28, 2025
@eslint-github-bot eslint-github-bot bot added the bug Something isn't working label Nov 28, 2025
@mdjermanovic
Copy link
Member

Hi @hyperz111, thanks for the PR!

Can you please update the original post with details about the bug this PR aims to fix, and an example where the bug is reproducible?

@hyperz111
Copy link
Author

Can you please update the original post with details about the bug this PR aims to fix, and an example where the bug is reproducible?

You can run this code to check:

const example = `
# Node.js
node_modules
!/fixtures/node_modules
/dist

# Logs
*.log # End with .log

# Gatsby files
.cache/

# vuepress build output
.vuepress/dist

# other
*/foo.js
dir/**
`.trim();

// Same function
function getIgnoresBefore(content) {
	return content
		.split(/\r?\n/g)
		.map(line => line.trim()) 
		.filter(line => line && !line.startsWith("#"));
}

console.log(getIgnoresBefore(example));

// Same function (in PR)
function getIgnoresAfter(content) {
	return content
		.split(/\r?\n/g)
		.map(line =>
				line
					.trim()
					.replace(/\s?[^\\]?#.*/gu, "")
					.trim(),
			)
			.filter(Boolean);
}

console.log(getIgnoresAfter(example));

@DMartens
Copy link

DMartens commented Nov 28, 2025

I think he wants to support lines with a comment after a pattern:

lib/* # handle this also as a comment

Currently we only support comments at the start of the line which is also what the specification says.
But the git CLI supports comments after patterns (by trying locally). Do we want to support this?

@hyperz111
Copy link
Author

I think he wants to support lines with a comment after a pattern:

lib/* # handle this also as a comment

Currently we only support comments at the start of the line which is also what the specification says.
But the git CLI supports comments after patterns (by trying locally). Do we want to support this?

Yes

@mdjermanovic
Copy link
Member

I think he wants to support lines with a comment after a pattern:

lib/* # handle this also as a comment

Currently we only support comments at the start of the line which is also what the specification says. But the git CLI supports comments after patterns (by trying locally). Do we want to support this?

I can't reproduce this behavior with my Git (git version 2.42.0.windows.2), and it isn't in the spec. Is it maybe some recent addition?

@mdjermanovic
Copy link
Member

Google search (AI overview) for gitignore comments says:

Trailing Comments: While the official documentation primarily refers to comments at the beginning of a line, some Git clients or environments might tolerate comments placed after an ignore pattern on the same line, though this is not universally guaranteed behavior. It is best practice to keep comments on their own lines for clarity and compatibility.

@DMartens
Copy link

DMartens commented Dec 1, 2025

I tried it on version 2.52.0 on linux. I could not find any further information about its introduction, so I would be -1 for this change but maybe add a documentation notice.

@mdjermanovic
Copy link
Member

I'm also -1 for this change as this seems to be a non-standard feature, and I'm fine with adding a note in the docs that this isn't supported.

Just to doublecheck in case we missed it. @hyperz111, since you linked the gitignore documentation, can you share the part of the documentation where this is described as allowed?

@nzakas
Copy link
Member

nzakas commented Dec 3, 2025

@mdjermanovic @DMartens just a reminder -- please move items on the Triage board when you're triaging.

@nzakas nzakas moved this from Needs Triage to Triaging in Triage Dec 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

Status: Triaging

Development

Successfully merging this pull request may close these issues.

4 participants