Skip to content

Fix negated ignore patterns making jscodeshift ignore every file (#342) - #754

Open
Thanatos9404 wants to merge 1 commit into
meta:mainfrom
Thanatos9404:fix/ignore-negated-patterns
Open

Thanatos9404 wants to merge 1 commit into
meta:mainfrom
Thanatos9404:fix/ignore-negated-patterns

Conversation

@Thanatos9404

@Thanatos9404 Thanatos9404 commented Oct 19, 2026 •

Copy link
Copy Markdown

A line starting with ! in an ignore file, like !.jenkins/ in the .eslintignore from the issue, made jscodeshift skip every file. addIgnorePattern passed it to picomatch as is, and picomatch reads a leading ! as "anything except".

Each pattern now remembers whether it was negated, and shouldIgnore lets the last matching pattern decide, like .gitignore. So a lone negated pattern no longer ignores anything, !keep.js after *.js brings keep.js back, and ignore files without ! lines behave exactly as before. As in git, a negation can't bring back files inside a directory that is already ignored.

One case still differs from git: if an earlier directory pattern also covers the negated directory (.*/ then !.jenkins/), files inside it stay ignored. I can handle that here or in a follow-up.

Thanks to @rootkiller6788 for the earlier attempt in #736. This version keeps the patterns in order, so a later pattern can still override an earlier negation.

Tests: new cases in src/__tests__/ignoreFiles-test.js. Eight of them fail on main and all pass with this change. A patch changeset is included.

Fixes #342

A pattern that starts with `!`, such as `!.jenkins/` in a file passed to
--ignore-config, was handed to picomatch unchanged. picomatch reads a
leading `!` as "anything except", so the pattern matched almost every
path and jscodeshift skipped all files.

Keep each added pattern as an ordered rule that records whether it was
negated, and let the last rule that matches a path decide whether the
path is ignored, as .gitignore does. A negated pattern now re-includes
paths ignored by an earlier pattern and has no effect on its own. A
negated directory such as `!.jenkins/` re-includes only the directory,
so the paths inside it are still checked against the other patterns.
`\!foo` still matches a literal `!foo`, and `!!foo` re-includes it.

Fixes meta#342.
@changeset-bot

changeset-bot Bot commented Oct 19, 2026

Copy link
Copy Markdown

πŸ¦‹ Changeset detected

Latest commit: ccef579

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
jscodeshift Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@meta-cla meta-cla Bot added the CLA Signed label Oct 19, 2026
@vercel

vercel Bot commented Oct 19, 2026

Copy link
Copy Markdown

@Thanatos9404 is attempting to deploy a commit to the Meta Open Source Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"!.jenkins/" in the ".eslintignore" makes jscodeshift ignore all files

1 participant