Commit Graph

14 Commits

Author SHA1 Message Date
leaysgur 673dc6db69 docs(oxfmt): move some docs from AGENTS.md to code comment (#25649)
Follow up on https://github.com/oxc-project/oxc/pull/25531#discussion_r3773878394
2026-08-14 09:48:31 +00:00
leaysgur a38f7b3d57 fix(oxlint,oxfmt): apply .gitignore only to walk targets, not explicitly named files (#25531)
Possibly fixes #25259, and partial revert of #25133.

---

- `.gitignore` applies only to discovery (walking directory targets, cwd, globs)
- An explicitly named file target is linted / formatted even when gitignored
  - = Restoring the pre-[#25133]() behavior for files, while fully keeping the [#25107]() fix for walk roots

| Target | Current | This PR |
| --- | --- | --- |
| Explicit file (`oxlint dist/a.js`) | skipped | linted |
| Explicit directory (`oxlint dist`) | skipped | skipped |
| cwd inside ignored tree | skipped | skipped |

The underlying principle:

> `.gitignore` is a message addressed to git, not to tools.
> Borrowing it to scope discovery is a useful heuristic, and a heuristic may narrow what the walk finds, but never refuse what the user names.
> Only tool's own ignore config can refuse. (which remain hard for the husky staged-file case).

This also re-aligns the CLI with stdin and LSP, which deliberately do not consult `.gitignore` (#19206).
👉🏻 This is the main motivation.

### Why not full revert

A directory target names where to search, not what to process.
The files under it are still discovered by the walk, so discovery rules apply.
Reverting that would bring back [#25107](), whose old behavior was not even a statable spec: whether running inside an ignored tree processed anything depended on the ignore pattern's form (bare `generated` did, `generated/**` didn't), an artifact of walker pruning, not a design.

### Regarding to `--no-ignore`

This flag remains orthogonal as a walk-level opt-out (`--no-ignore=vcs dist`) and for filling gap between existing tools.

However, with explicit files working again, I'm inclined to close those PRs and revisit if demand shows up.

For [#25259]()'s use case: name the files, e.g. `oxlint dist/foo.js` (or shell-expanded glob).
2026-08-14 03:35:34 +00:00
leaysgur 20f68e74a3 fix(oxlint,oxfmt): respect .gitignore for walk targets and explicit paths (#25133)
Fixes #25107.

The `ignore` crate walker enforces gitignore's "everything under an ignored directory is ignored" rule only by pruning ignored directories during traversal.

And it never filters its walk roots.
So when a walk target (based on cwd or an explicit CLI target path) is already inside a gitignored tree, pruning never happens and a bare directory pattern like `generated` matches nothing file-level. (even though `git check-ignore` says they are ignored)

See also BurntSushi/ripgrep#2595

### Changes

- oxc_config: added `GitignoreChecker`
  - a pre-walk check that replays git's resolution order over the ancestor chain
  - Matchers and `.git`/`.jj` probes are cached per directory
- oxlint / oxfmt: filter all CLI targets through this check before walking

### Behavior changes

- Explicitly passed gitignored files are now skipped (previously always linted/formatted)
- `oxlint --no-ignore` no longer force-lints gitignored targets
  - The same behavior as `--no-ignore` does not disable during walk `.gitignore`

<details>
<summary>FYI: Current our ignore model overview</summary>

Two independent families, AND-ed (a path excluded by any layer is skipped):

| Layer                                        | Source                                                 | oxlint                                                                                         | oxfmt                                                |
| -------------------------------------------- | ------------------------------------------------------ | ---------------------------------------------------------------------------------------------- | ---------------------------------------------------- |
| git-derived (always on, not user-disablable) | nested `.gitignore`, `.git/info/exclude` (during walk) | walker via shared `configure_walk_builder`                                                     | same (shared)                                        |
|                                              | walk roots / explicit CLI targets                      | `GitignoreChecker` (this PR)                                                                   | `GitignoreChecker` (this PR)                         |
| tool-owned                                   | ignore file                                            | `.eslintignore` / `--ignore-path`; disabled by `--no-ignore`                                   | `.prettierignore` / `--ignore-path`; no disable flag |
|                                              | CLI patterns                                           | `--ignore-pattern`; disabled by `--no-ignore`                                                  | `!pattern` path args                                 |
|                                              | config `ignorePatterns`                                | `LintIgnoreMatcher` (already containment-correct via `matched_path_or_any_parents`); always on | scope-local `is_path_ignored` (same); always on      |

NOTE: `ignorePatterns` never had this bug, only the walker-backed gitignore layer did; this PR brings it to the same level.
A `!` negation in `ignorePatterns` cannot re-include gitignored paths (unchanged; the layers are independent).

</details>
2026-08-02 13:11:06 +00:00
leaysgur e81b2ff6c5 fix(oxlint,oxfmt): report error for invalid glob patterns (#24744)
Fixes #24612

- Update `fast-glob` to `1.1.0` which exposes `validate()` api
- Use it in `oxc_config`, apps will be validated through `deserialize`
- Oxfmt supports globs for CLI paths, also validated
2026-07-21 04:43:49 +00:00
camc314 92f154a07c feat(oxlint,oxfmt): auto-discover .mts config files (#24357)
## Summary

- auto-discover `oxfmt.config.mts` and `oxlint.config.mts`
- watch `.mts` configs in the language server and reject `.ts`/`.mts` conflicts
- add focused CLI and LSP coverage
2026-07-10 11:38:35 +00:00
leaysgur 83378351e4 fix(linter): error on ignorePatterns that cannot match files aoutside the config directory (#24341)
Follow up on #24339

- Added the same guard as Oxfmt
- Since they are identical, I moved them into `oxc_config` so they can be shared
2026-07-10 09:05:48 +00:00
leaysgur ddb6eed17e refactor(oxlint): Use oxc_config::find_unique_config_by_readdir (#22447)
Also removed unused functions from `oxc_config`.

As a bonus of sharing the code, the number of syscalls should decrease, resulting in a slight improvement in perf.
2026-05-15 08:36:45 +00:00
leaysgur d3ced13095 refactor(config): Add find_unique_config_by_readdir from Oxfmt (#22445)
As of this PR, there are no changes to the behavior.

The duplicate function is defined solely for the purpose of standardization in a subsequent PR.
2026-05-15 08:17:51 +00:00
leaysgur 78e6b63019 refactor(oxlint): Extract walk+vcs helper to oxc_config (#22209)
Suggested in https://github.com/oxc-project/oxc/pull/22033#issuecomment-4359887587 w/ small refactoring.

Is it about time to rename it to `oxc_cli`? 👀
2026-05-07 16:28:02 +09:00
leaysgur 330fe31f82 refactor(config): Update doc comment for GlobSet (#22197)
Follow up on #22147.
2026-05-07 02:13:27 +00:00
camc314 fb3067ca2b refactor(oxfmt): use shared GlobSet for overrides (#22147)
uses oxlint's `GlobSet` for overrides over `Vec<String>`.

This helpe move out some shared normalization code from oxlint and oxfmt to the shared config crate.

Hopefully this change is ok for you @leaysgur  - I was originally hoping to share somethign else, but it seems trickier than I expected, so I just moved this out instead, which feels to me a good change
2026-05-06 16:14:04 +00:00
camc314 4614455ad9 refactor(config): move GlobSet to oxc_config (#22146)
Moves `GlobSet` from `oxc_linter` to `oxc_config` to enable sharing between oxlint/oxfmt
2026-05-06 12:16:23 +00:00
camc314 04dde0ff17 refactor(config): split discovery module (#22145)
Splits out the config discovery from the main `lib.rs` file.

`lib.rs` will now just re-export items.

See upstack PRs for more context.
2026-05-06 12:16:23 +00:00
camc314 cb2af99bed refactor(oxc_config_discovery): rename to oxc_config (#22144)
I'm adding `GlobSet` to this crate, so the `oxc_config_discovery` name no longer fits
2026-05-06 12:16:22 +00:00