Skip to content

fix(oxfmt): Use correct root dir with ignore and overrides for nested cwd#17244

Merged
graphite-app[bot] merged 1 commit intomainfrom
12-22-fix_oxfmt_use_correct_root_dir_with_ignore_and_overrides_for_nested_cwd
Dec 22, 2025
Merged

fix(oxfmt): Use correct root dir with ignore and overrides for nested cwd#17244
graphite-app[bot] merged 1 commit intomainfrom
12-22-fix_oxfmt_use_correct_root_dir_with_ignore_and_overrides_for_nested_cwd

Conversation

@leaysgur
Copy link
Member

@leaysgur leaysgur commented Dec 22, 2025

In the oxfmt-related settings, paths are specified in the following:

  • .editorconfig [src/*.json] part
  • .(prettier|git)ignore, --ignore-pathed file
  • .oxfmtrc .ignorePatterns
  • CLI positional paths

These paths are often written as relative paths, but path resolution is currently based on the cwd.

This is generally not a problem in most common use cases, as follows.

- project/   # root == cwd
  - .editorconfig
  - .prettierignore
  - .oxfmtrc.json

However, oxfmt can also find .oxfmtrc files by traversing upward from nested subdirectories toward the parent directory.

- project/   # root
  - .editorconfig
  - .prettierignore
  - .oxfmtrc.json
  - nested/  # cwd

At this case, relative path resolution should be based on each individual setting file.

Copilot AI review requested due to automatic review settings December 22, 2025 02:38
@github-actions github-actions bot added A-cli Area - CLI A-formatter Area - Formatter C-bug Category - Bug labels Dec 22, 2025
Copy link
Member Author

leaysgur commented Dec 22, 2025


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug where ignore patterns from .oxfmtrc.json and glob patterns from .editorconfig were incorrectly resolved relative to the current working directory instead of their respective config file locations. This caused issues when running oxfmt from nested subdirectories.

Key changes:

  • EditorConfig patterns now resolve relative to the .editorconfig file location
  • Ignore patterns from .oxfmtrc.json now resolve relative to the config file location
  • Multiple gitignore matchers are used to handle different pattern types with their appropriate root directories

Reviewed changes

Copilot reviewed 12 out of 14 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
apps/oxfmt/src/core/config.rs Updated to use the .editorconfig file's directory as the base for pattern resolution instead of cwd
apps/oxfmt/src/cli/walk.rs Refactored to use multiple gitignore matchers with correct root directories for each pattern type (ignore files, config patterns, exclude paths)
apps/oxfmt/src/cli/format.rs Passed oxfmtrc_path parameter to Walk::build to enable proper pattern resolution
apps/oxfmt/test/editorconfig.test.ts Added test case for nested cwd with editorconfig pattern matching
apps/oxfmt/test/config_ignore_patterns.test.ts Added test case for nested cwd with ignore patterns
apps/oxfmt/test/snapshots/editorconfig.test.ts.snap Added snapshot verifying correct editorconfig pattern resolution from nested directory
apps/oxfmt/test/snapshots/config_ignore_patterns.test.ts.snap Added snapshot verifying correct ignore pattern resolution from nested directory
apps/oxfmt/test/fixtures/editorconfig/nested_cwd/.editorconfig Test fixture defining per-directory indentation rules
apps/oxfmt/test/fixtures/editorconfig/nested_cwd/sub/test.ts Test fixture file with 8-space indentation
apps/oxfmt/test/fixtures/config_ignore_patterns_nested_cwd/.oxfmtrc.json Test fixture defining ignore patterns for subdirectory
apps/oxfmt/test/fixtures/config_ignore_patterns_nested_cwd/sub/src/test.js Test fixture file that should be formatted
apps/oxfmt/test/fixtures/config_ignore_patterns_nested_cwd/sub/generated/ignored.js Test fixture file that should be ignored
apps/oxfmt/test/fixtures/config_ignore_patterns_nested_cwd/src/test.js Test fixture file at root level
apps/oxfmt/test/fixtures/config_ignore_patterns_nested_cwd/generated/ignored.js Test fixture file at root level that should be ignored

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@leaysgur leaysgur force-pushed the 12-22-fix_oxfmt_use_correct_root_dir_with_ignore_and_overrides_for_nested_cwd branch from a491971 to fd8879c Compare December 22, 2025 02:59
@leaysgur leaysgur requested a review from Dunqing December 22, 2025 03:06
@leaysgur leaysgur force-pushed the 12-22-fix_oxfmt_use_correct_root_dir_with_ignore_and_overrides_for_nested_cwd branch from fd8879c to e00d403 Compare December 22, 2025 04:29
@leaysgur leaysgur force-pushed the 12-22-fix_oxfmt_use_correct_root_dir_with_ignore_and_overrides_for_nested_cwd branch from e00d403 to fde61bb Compare December 22, 2025 05:28
@graphite-app graphite-app bot added the 0-merge Merge with Graphite Merge Queue label Dec 22, 2025
@graphite-app
Copy link
Contributor

graphite-app bot commented Dec 22, 2025

Merge activity

… cwd (#17244)

In the `oxfmt`-related settings, paths are specified in the following:

- `.editorconfig` `[src/*.json]` part
- `.(prettier|git)ignore`, `--ignore-path`ed file
- `.oxfmtrc` `.ignorePatterns`
- CLI positional paths

These paths are often written as relative paths, but path resolution is currently based on the `cwd`.

This is generally not a problem in most common use cases, as follows.

```
- project/   # root == cwd
  - .editorconfig
  - .prettierignore
  - .oxfmtrc.json
```

However, `oxfmt` can also find `.oxfmtrc` files by traversing upward from nested subdirectories toward the parent directory.

```
- project/   # root
  - .editorconfig
  - .prettierignore
  - .oxfmtrc.json
  - nested/  # cwd
```

At this case, relative path resolution should be based on each individual setting file.
@graphite-app graphite-app bot force-pushed the 12-22-fix_oxfmt_use_correct_root_dir_with_ignore_and_overrides_for_nested_cwd branch from fde61bb to 7b810f4 Compare December 22, 2025 08:55
@graphite-app graphite-app bot merged commit 7b810f4 into main Dec 22, 2025
18 checks passed
@graphite-app graphite-app bot deleted the 12-22-fix_oxfmt_use_correct_root_dir_with_ignore_and_overrides_for_nested_cwd branch December 22, 2025 09:01
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Dec 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-cli Area - CLI A-formatter Area - Formatter C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants