Repository navigation
Conversation
|
Codex (GPT-6 family; exact serving variant not recorded) assisted with the patch and validation. I reviewed and approved all work before submission. The affected package passes all 733 tests, type checking, build, ESLint and formatting checks. The regression fails on unchanged upstream. |
There was a problem hiding this comment.
🔵 Needs a closer look
It changes core gitignore matching semantics in a widely-used library, where subtle ordering/edge-case effects across all consumers warrant human verification.
0 open findings
What changed in this PR
This PR fixes incorrect .gitignore handling in cspell-glob (issue #5104). Previously, GlobMatcher split rules into negative and positive groups and checked all negatives before any positives, so a later ignore rule could not override an earlier un-ignore (!) rule. The matcher now evaluates every rule in declared order and the last matching rule determines the outcome, matching Git's documented ordering semantics. A per-source-rule dedup preserves the previous behavior of reporting the first generated variant for a single source pattern.
Changes:
- Replaced the two-phase neg/pos matching with a single ordered pass in
buildMatcherFnwhere the last matching rule wins. - Tightened
GlobRule.pattern/buildMatcherFntypes toGlobPatternNormalizedand usedrawRoot/rawGlobto collapse consecutive variants from the same source rule. - Added
Rule orderingtests covering ordered ignore/un-ignore precedence and first-variant reporting.
| File | Description |
|---|---|
| packages/cspell-glob/src/GlobMatcher.ts | Rewrites testRules to iterate all rules in order (last match wins) and reports the first generated variant per source rule; updates related types. |
| packages/cspell-glob/src/GlobMatcher.test.ts | Adds Rule ordering tests validating ordered gitignore precedence and first-variant reporting. |
🧠 Review effort: Balanced
Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.
.gitignore and ignorePaths rules in order
Jason3S
left a comment
There was a problem hiding this comment.
Thank you for picking up #5104, @ScribleSean, and welcome to cspell! 🎉
Checking rules in one pass, with the last match winning, is exactly how .gitignore works, and it makes the code simpler as well. I ran the reproduction from the issue against your branch and all five cases now match what git does. I also compared a set of other patterns against git check-ignore, and none of them got worse.
I updated the PR title and description a little. Both go into the release notes as written, and the same matcher also handles the ignorePaths setting, so I mentioned that too. Nothing for you to do there.
More tests, please
The new tests cover the case from the issue. Could you add a few more, so that the "last rule wins" behavior stays fixed? These are all common real-world patterns, and I checked the expected values with git check-ignore:
| Patterns | File | Ignored |
|---|---|---|
!keep.txt, *.txt |
keep.txt |
true (a later rule overrides an earlier !) |
*.txt, !a.txt, a.txt |
a.txt |
true |
tmp/*, !tmp/.gitkeep |
tmp/.gitkeep |
false (the "keep an empty folder" pattern) |
tmp/*, !tmp/.gitkeep |
tmp/a.txt |
true |
The first three rows can go into the Rule ordering table you added in GlobMatcher.test.ts. It would also help to have a test in packages/cspell-gitignore that parses a small .gitignore with one of these orderings. That covers the path people actually use, the useGitignore setting.
Optional
- Reported line number: if the same pattern appears on two lines, for example
*.logon lines 1 and 3, the match reports line 1, butgit check-ignore -vreports line 3. This is because the check that groups the variants of one rule compares the pattern text. Tracking which original rule each variant came from would fix it. This was the same before your change, so feel free to leave it for another PR. - Leftover comments: a few commented-out lines just below the rules still mention the old negative and positive rule lists. You could remove them while you're here.
Thanks again! This is a long-standing issue, and it's great to see it fixed.
|
Thanks for checking the reproduction and improving the release-note text. I added all four cases to the rule-order table and added four cases that parse The affected packages pass all 737 matcher tests and 134 gitignore tests. The full repository build, test suite, lint and spelling checks also pass. The full test command needed I left the optional repeated-pattern line-number change for a separate PR. |
|
Thank you for this fix, @ScribleSean, and for the clear tests. Applying rules in order is how I updated the PR description. It is published as-is in the release notes, so we keep it accurate for people who use cspell. The change reaches a little further than ignore files and
We're happy with that: the same rule everywhere is easier to explain. So the description now lists these, and no longer says the command line is unaffected. The question of how separately declared include and exclude globs should combine is now #9463. One optional suggestion, if you'd like to take it on: the matcher used to stop at the first matching rule, but it now checks every rule for every file. If it walks the rules from the end instead, the first match it finds is the one that decides, and it can stop there. To keep reporting the first variant of that rule, as your new test expects, it can then step back over the earlier variants generated from the same rule. Happy to merge without it, too. |
Performance ReportDaily Performancexychart-beta
title Files Per Second by Day
y-axis Files per Second
x-axis Date [Sep-14, Sep-16, Sep-17, Sep-20, Sep-22, Sep-24, Sep-27, Sep-28, Sep-29, Sep-30, Oct-1, Oct-2, Oct-8, Oct-9, Oct-10, Oct-11, Oct-13, Oct-14]
bar [197.87, 189.83, 198.93, 223.14, 203.41, 191.85, 190.34, 190.33, 191.42, 191.65, 187.17, 187.29, 194.39, 192.05, 218.83, 197.10, 195.24, 196.98]
line [97.36, 113.44, 95.42, 93.37, 113.84, 158.94, 91.50, 106.48, 102.03, 106.46, 94.98, 113.77, 93.63, 125.18, 87.00, 104.77, 109.42, 97.82]
line [156.67, 149.67, 167.24, 171.44, 166.11, 165.94, 180.17, 169.69, 179.61, 173.13, 150.88, 153.50, 149.45, 170.98, 162.38, 193.61, 167.04, 182.48]
line [159.91, 274.11, 160.48, 154.49, 133.29, 206.55, 172.23, 156.59, 180.95, 179.76, 145.22, 129.53, 157.39, 199.58, 152.82, 170.97, 185.75, 187.43]
line [79.87, 74.03, 79.32, 76.57, 77.71, 78.68, 74.59, 96.62, 94.86, 81.46, 69.18, 73.06, 66.65, 96.25, 112.51, 78.91, 82.77, 95.93]
line [151.50, 140.12, 185.15, 139.87, 144.59, 151.47, 163.76, 164.48, 145.07, 153.00, 154.07, 155.61, 136.07, 148.26, 141.19, 185.69, 154.55, 167.46]
line [61.82, 49.92, 50.20, 50.36, 50.54, 47.43, 56.40, 49.96, 64.67, 50.46, 44.40, 48.96, 71.61, 56.00, 55.29, 59.99, 68.80, 63.78]
line [47.78, 46.42, 45.99, 42.51, 50.42, 46.36, 61.34, 51.99, 46.51, 53.11, 48.59, 73.40, 59.94, 62.62, 55.56, 54.77, 45.21, 57.26]
line [96.78, 160.57, 101.71, 98.32, 105.51, 103.82, 101.18, 119.72, 101.30, 101.24, 103.40, 125.70, 125.48, 99.76, 158.05, 114.31, 137.32, 143.13]
line [118.61, 125.51, 156.41, 126.36, 117.29, 122.97, 147.55, 130.31, 120.84, 131.56, 115.38, 110.82, 116.53, 214.42, 116.00, 118.77, 144.83, 135.56]
line [77.91, 142.49, 79.52, 110.64, 76.31, 85.79, 97.01, 82.92, 84.16, 84.72, 77.34, 87.34, 75.86, 81.29, 136.91, 94.03, 101.02, 106.18]
line [23.74, 22.20, 23.03, 24.38, 22.79, 25.90, 22.55, 24.52, 26.32, 24.36, 24.04, 25.09, 23.35, 22.45, 21.51, 25.71, 29.42, 24.60]
line [213.84, 211.89, 203.30, 203.26, 249.81, 370.77, 255.08, 280.21, 227.10, 239.56, 208.40, 216.14, 204.22, 251.15, 211.26, 222.05, 242.35, 195.61]
line [226.41, 183.84, 178.08, 240.62, 182.34, 183.11, 178.48, 227.71, 175.37, 193.07, 180.70, 197.68, 174.97, 189.16, 226.87, 200.18, 179.39, 170.89]
line [6.69, 7.98, 6.67, 6.83, 6.48, 7.18, 7.27, 6.94, 7.83, 6.98, 6.40, 6.43, 8.18, 6.76, 7.44, 7.30, 6.32, 5.81]
line [197.07, 148.01, 150.26, 150.22, 155.16, 146.16, 150.57, 146.25, 172.87, 161.95, 149.25, 258.77, 151.43, 150.43, 254.02, 168.57, 231.71, 173.54]
line [318.90, 363.44, 349.72, 406.48, 449.44, 342.12, 376.67, 347.31, 443.48, 368.45, 332.70, 302.48, 422.03, 338.21, 306.48, 376.46, 318.53, 415.95]
line [214.17, 355.08, 286.90, 193.09, 220.97, 216.09, 223.67, 208.59, 258.02, 244.00, 208.42, 273.15, 264.14, 216.71, 266.75, 228.80, 223.08, 242.80]
line [265.83, 272.53, 247.23, 246.03, 470.19, 256.56, 257.27, 291.74, 296.65, 268.66, 245.94, 244.92, 242.23, 245.65, 270.12, 330.98, 278.79, 272.38]
line [18.79, 24.79, 24.63, 19.73, 20.13, 19.16, 18.74, 19.48, 22.38, 21.10, 27.10, 18.00, 23.58, 17.31, 20.37, 21.44, 22.38, 20.67]
line [247.49, 246.97, 251.50, 236.84, 249.23, 243.91, 273.74, 252.33, 270.33, 282.14, 249.68, 432.83, 249.77, 263.65, 247.10, 235.41, 323.97, 237.06]
line [17.04, 25.59, 14.10, 13.68, 15.06, 15.07, 17.30, 20.40, 18.84, 16.01, 18.80, 15.62, 18.14, 15.49, 15.23, 15.94, 13.89, 14.95]
line [381.43, 392.33, 359.21, 375.60, 366.33, 321.23, 484.87, 422.08, 444.64, 410.96, 351.78, 368.84, 361.47, 370.09, 351.86, 414.54, 417.07, 450.45]
line [20.76, 21.20, 21.42, 29.89, 21.10, 33.29, 22.21, 22.99, 25.81, 22.79, 21.40, 20.78, 24.57, 21.27, 19.07, 21.50, 21.24, 21.05]
line [23.63, 25.87, 21.39, 25.97, 25.29, 24.28, 26.03, 27.14, 29.89, 26.22, 25.83, 25.33, 31.76, 42.94, 27.61, 25.97, 34.21, 26.38]
line [82.90, 86.51, 81.41, 84.89, 78.73, 86.02, 82.17, 86.87, 92.07, 92.00, 84.24, 92.67, 106.68, 84.76, 82.82, 101.29, 118.90, 106.77]
line [276.88, 185.15, 203.08, 216.06, 205.09, 247.61, 251.50, 220.80, 227.59, 212.73, 213.55, 197.04, 208.25, 194.51, 251.63, 210.60, 231.31, 195.70]
line [44.11, 74.38, 48.80, 46.22, 56.03, 61.86, 55.07, 50.38, 50.26, 50.11, 43.90, 42.10, 56.81, 48.66, 45.19, 43.33, 48.66, 49.29]
line [63.80, 67.85, 68.28, 64.95, 121.18, 70.33, 81.37, 68.55, 70.46, 78.07, 69.43, 66.84, 65.37, 64.09, 65.74, 75.83, 77.12, 85.06]
line [130.94, 82.16, 79.40, 98.84, 72.96, 83.85, 90.86, 105.55, 94.80, 87.05, 82.35, 80.71, 82.95, 74.90, 76.80, 94.05, 96.82, 90.40]
line [179.89, 238.35, 171.61, 172.61, 177.91, 241.32, 177.39, 178.05, 221.01, 182.74, 163.48, 169.32, 168.97, 278.92, 166.54, 166.53, 170.79, 182.99]
line [127.77, 210.87, 148.03, 126.65, 140.55, 188.49, 125.20, 157.87, 127.91, 135.21, 124.24, 125.20, 125.79, 225.70, 154.24, 126.07, 127.29, 154.67]
line [126.89, 119.89, 121.04, 127.46, 154.00, 162.49, 123.69, 144.71, 125.72, 134.25, 127.46, 121.17, 173.95, 124.58, 216.72, 133.97, 123.87, 179.60]
line [119.42, 176.53, 123.45, 123.33, 163.66, 174.86, 123.76, 140.60, 149.87, 128.75, 160.37, 148.80, 127.97, 206.50, 122.84, 138.06, 149.67, 127.82]
line [204.55, 207.72, 211.00, 215.66, 277.45, 216.60, 208.75, 228.82, 225.46, 221.92, 198.17, 351.24, 197.76, 198.13, 208.30, 202.68, 201.79, 286.37]
line [277.45, 226.45, 225.10, 268.40, 226.40, 290.41, 225.84, 287.60, 216.33, 247.70, 277.53, 288.63, 233.16, 374.71, 397.16, 261.34, 217.24, 216.25]
line [191.12, 144.91, 193.30, 142.56, 168.42, 145.10, 149.37, 134.63, 171.73, 154.69, 140.49, 131.94, 134.65, 137.28, 142.04, 172.94, 162.65, 138.06]
line [262.40, 339.51, 263.75, 234.66, 253.01, 268.39, 293.97, 280.40, 292.26, 260.88, 404.51, 328.53, 305.64, 243.36, 444.70, 255.37, 254.42, 269.53]
line [531.12, 384.37, 384.60, 745.85, 398.12, 385.90, 416.89, 405.74, 428.96, 399.50, 398.65, 384.43, 625.58, 373.38, 382.28, 469.75, 409.07, 459.09]
line [281.57, 222.43, 291.44, 219.17, 221.75, 221.55, 237.73, 242.39, 246.40, 245.33, 214.25, 212.38, 215.08, 238.25, 274.47, 219.66, 252.51, 201.93]
line [303.17, 236.15, 234.71, 233.17, 234.84, 298.34, 266.72, 232.18, 229.70, 240.06, 392.72, 229.48, 222.78, 224.66, 204.36, 254.42, 277.26, 263.36]
line [177.63, 183.43, 188.58, 244.43, 196.97, 192.51, 179.82, 187.80, 186.23, 183.20, 182.62, 177.99, 183.70, 179.89, 233.14, 207.50, 218.41, 233.63]
line [56.65, 66.08, 70.58, 54.86, 55.17, 51.26, 53.54, 77.09, 47.84, 59.17, 54.01, 70.63, 55.18, 49.90, 84.72, 57.64, 57.38, 58.19]
line [101.98, 98.46, 103.01, 98.38, 99.03, 101.47, 103.27, 100.93, 105.22, 117.10, 120.39, 97.23, 97.90, 123.96, 100.36, 115.55, 122.73, 121.00]
line [243.92, 325.88, 260.22, 243.99, 243.96, 239.11, 261.23, 266.19, 247.38, 252.69, 432.16, 234.56, 233.40, 238.56, 234.64, 256.33, 219.99, 268.01]
line [93.89, 113.70, 92.25, 94.28, 98.57, 98.01, 93.82, 94.62, 89.71, 106.79, 118.50, 123.61, 91.76, 95.32, 93.61, 112.00, 123.43, 126.07]
line [317.36, 187.32, 321.78, 198.42, 179.83, 171.82, 219.08, 181.95, 180.26, 215.27, 175.03, 168.70, 269.72, 161.18, 172.81, 172.65, 208.47, 189.05]
line [33.93, 34.79, 33.36, 33.83, 35.26, 55.80, 33.99, 34.03, 41.23, 40.49, 30.44, 33.53, 33.57, 32.29, 33.27, 34.79, 37.33, 39.48]
line [248.77, 196.63, 194.10, 246.18, 197.54, 195.96, 190.07, 228.82, 222.46, 205.73, 192.21, 184.58, 245.51, 246.82, 245.36, 219.50, 226.50, 196.89]
line [211.67, 318.15, 234.86, 348.02, 254.54, 210.42, 205.10, 287.53, 207.85, 231.21, 200.22, 207.10, 331.74, 203.63, 192.81, 213.97, 213.28, 214.30]
line [171.09, 160.76, 222.99, 297.37, 220.86, 165.88, 186.63, 165.05, 169.83, 183.91, 159.55, 166.58, 162.12, 169.35, 265.31, 194.05, 178.95, 177.70]
Time to Process Files
Note:
Files per Second over Time
Data Throughput
|
Summary
Glob patterns in a list are now applied in the order they are written, and the last pattern that matches a file decides. Before, a pattern that starts with
!always won, wherever it was in the list.For example, in a
.gitignorefile, a laternode_modules/rule now ignores files beneath an earlier!un-ignored/rule.This applies to:
.gitignorefiles.ignorePathsthat start with!, when files are checked through thecspell-libAPI. Thecspellcommand line still skips these patterns and shows a warning.overrides[].filename.--fileor--file-list.Part of #5104.