Skip to content

refactor(copilot-rule): reuse toPosixPath and switch sameRelativePath to object params#1644

Open
Chen17-sq wants to merge 1 commit into
dyoshikawa:mainfrom
Chen17-sq:refactor/1603-reuse-toposixpath-in-copilot-rule
Open

refactor(copilot-rule): reuse toPosixPath and switch sameRelativePath to object params#1644
Chen17-sq wants to merge 1 commit into
dyoshikawa:mainfrom
Chen17-sq:refactor/1603-reuse-toposixpath-in-copilot-rule

Conversation

@Chen17-sq
Copy link
Copy Markdown

Summary

Addresses the refactor checklist in #1603 for src/features/rules/copilot-rule.ts:

  • DRY — Replace the local path.replace(/\\/g, "/") with the shared toPosixPath utility from src/utils/file.ts, in line with the coding guideline that points to toPosixPath for non-filesystem path normalization.
  • Keep the slash collapse, but justify it — The follow-up replace(/\/+/g, "/") is still needed: on POSIX, node:path.join(".github\\", "x.md") keeps the trailing backslash literal, so after toPosixPath runs we get .github//x.md. A short comment now spells this out so future readers don't think the collapse is dead code.
  • Avoid the path parameter name — Rename pathp so it no longer shadows the node:path import in the same file.
  • Object-based sameRelativePath — Switch the four positional strings to {dir, file} objects per the project's coding guidelines, and update both call sites (fromFile, forDeletion).

Test plan

  • pnpm cicheck (fmt + oxlint + eslint + tsgo + vitest 5552 tests + cspell + secretlint) passes locally on Node 22.
  • New forDeletion tests:
    • Root deletion target is detected when relativeDirPath is ".github\\".
    • Non-root paths with a mid-path backslash (".github\\instructions") stay non-root.
  • Existing root-detection test for .github\\ continues to pass — behavior is preserved, only the helper implementation changes.

Refs #1603.

… to object params

Addresses the review findings tracked in dyoshikawa#1603:

- Replace the local backslash regex with the shared toPosixPath utility, keeping the consecutive-slash collapse and explaining the WSL edge case it covers

- Rename the parameter from path to p to avoid shadowing the node:path import

- Move sameRelativePath from four positional strings to {dir, file} objects per the coding guidelines and update both call sites

- Add forDeletion tests that pin down root detection with a trailing backslash separator and confirm non-root paths with mid-path backslashes stay non-root

Refs dyoshikawa#1603.
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.

1 participant