Skip to content

Conversation

@LunarWatcher
Copy link

@LunarWatcher LunarWatcher commented Sep 26, 2025

Closes #40 - I wish I had seen this issue three months ago, but managed to miss it (thanks for notifying me about everything except the things I'm interested in, GitHub), so here I am three months late

The solution here is just to slap a negative search for paths at it rather than using a .*. I did include backslashes in the group, but noticed later that none of the other paths include backslashes. If the paths are indeed normalised to forward slashes, let me know and I'll drop those from the regex Dropped per review

Summary by CodeRabbit

  • Bug Fixes

    • Refined detection of vimrc files to match only the filename at the current directory level, avoiding false positives in nested paths. Icon for vimrc remains unchanged.
    • Ensures .vimrc and vimrc-* files are correctly recognized across platforms.
  • Tests

    • Added coverage for vimrc pattern matching on various Unix/Windows paths, including cases with vimrc-related directories and Vagrantfile.

@coderabbitai
Copy link

coderabbitai bot commented Sep 26, 2025

Walkthrough

Refined the vimrc regex in assets/json/pattern.json to match only filenames at the current directory level (excluding deeper path segments). Added test cases in test/nerdfont/path/pattern.vimspec covering .vimrc, vimrc-whatever, and a nested vimrc-modules/Vagrantfile case.

Changes

Cohort / File(s) Summary
Pattern map update
assets/json/pattern.json
Changed vimrc pattern from ".*vimrc.*" to ".*vimrc[^/]*$"; icon remains "".
Tests for vimrc and related paths
test/nerdfont/path/pattern.vimspec
Added three test cases: vimrc-modules/Vagrantfile (and Windows-style vimrc-modules\\Vagrantfile) should map to Vagrant icon, .vimrc and vimrc-whatever should map to vim icon. Existing tests retained.

Sequence Diagram(s)

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I nudged a regex, gentle hop—so sly,
Now vimrc stays where filenames lie.
Subfolders? Nah, I skip that trail,
Root files only — tidy and hale.
Tests munch carrots, all checks pass—hooray! 🥕

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title Check ✅ Passed The title “Tighten vimrc regex” succinctly captures the primary change of narrowing the vimrc matching pattern and is clear and specific without unnecessary detail.
Linked Issues Check ✅ Passed The pull request directly addresses issue #40 by replacing the overly broad .*vimrc.* with .*vimrc[^/]*$ in assets/json/pattern.json and adding tests to confirm unintended paths are excluded, thereby fulfilling the linked issue’s objective of refining the vimrc regex.
Out of Scope Changes Check ✅ Passed All modifications are confined to updating the vimrc regex in assets/json/pattern.json and adding corresponding tests, with no unrelated files or functionality affected, so the PR remains focused on its intended scope.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Owner

@lambdalisue lambdalisue left a comment

Choose a reason for hiding this comment

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

The solution here is just to slap a negative search for paths at it rather than using a .*. I did include backslashes in the group, but noticed later that none of the other paths include backslashes. If the paths are indeed normalised to forward slashes, let me know and I'll drop those from the regex

I’d forgotten, but it doesn’t make sense to support Windows paths only for .vimrc. Let’s remove them for now and open a separate issue for Windows support if needed.

".*mootools.*\\.js$": "",
".*require.*\\.js$": "",
".*vimrc.*": "",
".*vimrc[^/\\\\]*$": "",
Copy link
Owner

@lambdalisue lambdalisue Sep 28, 2025

Choose a reason for hiding this comment

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

It looks like this pattern would also match HELLOvimrc// or WORLDvimrc\\\\\. Is accepting trailing slashes or backslashes intentional? I suspect you might have meant something like: .*vimrc\\(/.*\\)\\?$

Copy link
Author

@LunarWatcher LunarWatcher Sep 28, 2025

Choose a reason for hiding this comment

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

It wouldn't. [^] denotes a negative character capture group, i.e. matching everything except those characters. See https://regex101.com/r/7htfk4/2

Copy link
Owner

@lambdalisue lambdalisue Sep 28, 2025

Choose a reason for hiding this comment

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

Oops. Sorry, I might drunk. But then, it hits with hellovimrcworld as well? Is that what you expect? I feel it doesn't make sense. For example, .*vimrc\..* make a little bit sense to me (well, actually, leading .* doesn't make sense to me though. I (or someone) might mean \.vimrc\..* but I don't remember the context)

Copy link
Author

Choose a reason for hiding this comment

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

Leading stuff does make some sense. .lvimrc (from a plugin) and .gvimrc should be covered for example. The proper tightening of it matching those forms would probably be (.*/)?[._].vimrc$, but that probably has collateral damage if someone uses the postfix form for whatever reason

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
test/nerdfont/path/pattern.vimspec (1)

19-20: Add Windows-style path coverage

The regex now guards against both / and \, so we should also assert that a Windows-style vimrc-modules\Vagrantfile still resolves to the Vagrant glyph. That safeguards us if upstream ever stops normalizing to forward slashes.

      let glyph = nerdfont#path#pattern#find('vimrc-modules/Vagrantfile')
      Assert Equals(glyph, '')
+     let glyph = nerdfont#path#pattern#find('vimrc-modules\Vagrantfile')
+     Assert Equals(glyph, '')
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 14c3805 and 3031d8c.

📒 Files selected for processing (2)
  • assets/json/pattern.json (1 hunks)
  • test/nerdfont/path/pattern.vimspec (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • assets/json/pattern.json

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pattern for vimrc is too aggressive

2 participants