Skip to content

Conversation

@alanprice-admiral
Copy link

@alanprice-admiral alanprice-admiral commented Dec 11, 2025

Summary

  • Fixes .jscpd.json does not ignore file(s) #496 - ignore patterns in .jscpd.json and package.json were not being applied
  • Root cause: ignore patterns were not resolved relative to config file location
  • Solution: Added resolveIgnorePattern() to properly handle relative, absolute, and **/ patterns

Changes

  • apps/jscpd/src/options.ts: Added resolveIgnorePattern() function and applied to ignore patterns in readConfigJson() and readPackageJsonConfig()
  • packages/finder/src/files.ts: Explicitly set cwd in fast-glob options for consistent path resolution

Testing

  • All existing tests pass (82 tests)
  • Manual testing with various ignore patterns confirmed fix works correctly

🤖 Generated with Claude Code


This change is Reviewable

Summary by CodeRabbit

  • Bug Fixes
    • Corrected resolution of configuration paths and ignore patterns so they resolve relative to the configuration location, preventing mismatches.
    • Made file glob matching use an explicit working-directory context and deterministic absolute flag for more consistent file discovery results.

✏️ Tip: You can customize this high-level summary in your review settings.

Fixed issue kucherenko#496 where ignore patterns specified in .jscpd.json or
package.json were not being applied correctly.

The root cause was that ignore patterns were not being resolved
relative to the configuration file location, causing fast-glob to
interpret them incorrectly. This change adds a resolveIgnorePattern()
function that:
- Preserves absolute paths unchanged
- Preserves **/ patterns (which match at any depth)
- Converts relative patterns to be relative to process.cwd()

Also explicitly set cwd in fast-glob options to ensure consistent
path resolution.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
@coderabbitai
Copy link

coderabbitai bot commented Dec 11, 2025

Walkthrough

Normalize jscpd ignore and path entries by resolving patterns relative to the configuration directory and add deterministic glob options (explicit cwd and boolean for absolute) for file discovery behavior.

Changes

Cohort / File(s) Summary
Ignore pattern normalization
apps/jscpd/src/options.ts
Adds isAbsolute/relative imports and implements resolveIgnorePattern(configDir, pattern) to normalize ignore patterns. Updates readConfigJson and readPackageJsonConfig to resolve path entries against configDir and to normalize ignore entries via the new helper.
Glob configuration adjustment
packages/finder/src/files.ts
Sets `absolute: options.absolute

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

  • Inspect resolveIgnorePattern behavior for: absolute patterns, patterns starting with **/, and relative patterns resolved to configDir.
  • Verify configDir is computed and applied consistently in readConfigJson and readPackageJsonConfig.
  • Confirm fast-glob option changes (absolute default and cwd) do not break existing matching in typical CI/workspace setups.

Poem

🐰
I hopped through folders, sniffed each line,
Resolved the paths where patterns twine.
From config burrow they now depart,
No stray ignores will roam the chart.
A tiny hop — the linter’s heart. ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: fixing ignore patterns in configuration files, which directly addresses the core issue being resolved.
Linked Issues check ✅ Passed The PR successfully addresses issue #496 by implementing proper resolution of ignore patterns relative to config file locations and applying the fix in both readConfigJson() and readPackageJsonConfig().
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing ignore pattern resolution; the explicit cwd setting in files.ts is a necessary supporting change for consistent path resolution.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 266cb95 and b5894a1.

📒 Files selected for processing (1)
  • apps/jscpd/src/options.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/jscpd/src/options.ts

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

@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: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e8381ad and 266cb95.

📒 Files selected for processing (2)
  • apps/jscpd/src/options.ts (3 hunks)
  • packages/finder/src/files.ts (1 hunks)
🔇 Additional comments (3)
packages/finder/src/files.ts (1)

101-103: LGTM! Improved determinism for glob resolution.

The explicit || false default for absolute and the explicit cwd setting make path resolution more predictable and align with the config-relative ignore pattern handling introduced in this PR.

apps/jscpd/src/options.ts (2)

94-100: Config path resolution looks correct.

The change from dirname(config) to dirname(configFile) is important—it ensures paths are resolved against the absolute config location rather than the potentially-relative input parameter. The ignore pattern transformation correctly delegates to resolveIgnorePattern, though that function needs the substring bug fix noted separately.


110-116: Package.json config resolution matches the .jscpd.json pattern.

Consistent application of the same path and ignore pattern resolution logic. Once resolveIgnorePattern is fixed, this will work correctly.

Fixed critical bug where absolutePattern.startsWith(cwd) could incorrectly
match sibling directories with similar prefixes (e.g., '/project' matching
'/projectdata').

Replaced string prefix check with path.relative() for proper path comparison.
Now correctly checks if a path is under cwd by verifying the relative path
doesn't start with '..'.

All existing tests pass (82 tests total).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
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.

.jscpd.json does not ignore file(s)

1 participant