Commit Graph

381 Commits

Author SHA1 Message Date
leaysgur 876fbe30f1 fix(oxfmt): expand Fill parts in tsx-in-vue (#26427)
Fixes #26398, closes #26399.

---

Our Rust printer knows how to expand `Fill` with `Interned`, but Prettier printer does not.
2026-09-08 01:29:38 +00:00
Sysix a5a4ac8811 refactor(lsp): ToolTrait consume TextDocument & CodeActionParams (#26339)
Refactors the `oxc_language_server::Tool` trait and associated LSP plumbing to pass `TextDocument` and `CodeActionParams` by value, aligning tool APIs with “consume” semantics and simplifying call sites that previously had to keep borrowed values alive.
2026-09-05 18:33:58 +00:00
Yuji Sugiura 1cad286676 perf(oxfmt): match editorconfig once per file (#26239) 2026-09-02 12:58:48 +09:00
leaysgur 260c5eb312 perf(oxfmt): match overrides once per file (#26238) 2026-09-02 03:33:02 +00:00
leaysgur 61565bc7b2 perf(oxfmt): share resolved FormatConfig via Arc instead of cloning per file (#26237)
Also refactoring as aligning to `Arc`, no `Box` anymore.
2026-09-02 02:40:14 +00:00
leaysgur 5ff57f83c0 fix(formatter/sort-imports): handle custom side effect groups (#26217)
Fixes #26165

- `side_effect` is predefined selector, it cannot be used as custom group name
- respect custom group which uses `side_effect` as side-effect-import correctly
- fix metadata detection bug
2026-09-01 03:56:36 +00:00
Boshen ac4785a139 perf(diagnostics): use fixed ANSI styles (#26130)
Replace dynamic diagnostic styles with fixed ANSI prefixes, reducing `oxfmt` and `oxlint` release text size.

AI assistance: Codex was used. The contributor remains responsible for this change.
2026-08-27 05:19:35 +00:00
Sysix 7e2f193dc2 refactor(lsp): allow tools to send multiple ClientMessages (#25961)
> ## Pull request overview
>
> Refactors the language-server tool initialization/restart plumbing to support emitting multiple `ClientMessage`s (instead of a single optional message), so tools can surface more than one warning/error to the client during startup and config changes.
>
2026-08-22 10:17:51 +00:00
renovate[bot] 2d2b3be43d chore(deps): update rust crate sort-package-json to v1 (#25741)
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
|
[sort-package-json](https://redirect.github.com/oxc-project/sort-package-json)
| workspace.dependencies | major | `0.0.15` → `1.0.0` |

---

### Release Notes

<details>
<summary>oxc-project/sort-package-json (sort-package-json)</summary>

###
[`v1.0.0`](https://redirect.github.com/oxc-project/sort-package-json/blob/HEAD/CHANGELOG.md#100---2026-08-16)

[Compare
Source](https://redirect.github.com/oxc-project/sort-package-json/compare/v0.0.15...v1.0.0)

##### Changed

- **Breaking:** Stabilize the public `SortOptions` API and refresh crate
metadata and documentation
([#&#8203;158](https://redirect.github.com/oxc-project/sort-package-json/pull/158))

</details>

---

### Configuration

📅 **Schedule**: (in timezone Asia/Shanghai)

- Branch creation
  - At any time (no schedule defined)
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR was generated by [Mend Renovate](https://mend.io/renovate/).
View the [repository job
log](https://developer.mend.io/github/oxc-project/oxc).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC4yOS41IiwidXBkYXRlZEluVmVyIjoiNDQuMjkuNSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Boshen <boshenc@gmail.com>
2026-08-16 13:58:43 +00:00
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 c07fe7c217 feat(oxfmt): support experimentalOperatorPosition (#25643)
Fixes #16366

---

Option name requires `experimental` prefix for now.

Values are:

- `"start"`
- `"end"`(default)

This is also available on playground.
2026-08-14 08:12:16 +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 40f7f9ba68 chore(oxfmt): do not wrap debug fn with cfg(debug_assertions) (#25575)
Fixes https://github.com/oxc-project/oxc/actions/runs/31665337633/job/94338562978

TIL: `debug_assert_eq!` is compiled as a "constantly false if" even when assertions are off.
2026-08-13 05:32:23 +00:00
leaysgur 1a83a8ddb2 fix(oxfmt): mirror printer line suppression and restore dedent-to-root (#25573)
Fixes #25568, #25569
2026-08-13 03:50:19 +00:00
leaysgur fed6681eda docs(oxfmt): skip expanding overrides options (#25572)
Follow up on #25544.

Oxlint also omits `overrides[].rules`.
2026-08-13 02:35:53 +00:00
Boshen 030857b509 refactor(diagnostics): update oxc-miette to v4 (#25395)
Remove the miette `Report` wrapper and update oxc-miette to v4's narrowed diagnostic and source protocol.

AI-assisted by OpenAI Codex.
2026-08-10 07:48:02 +00:00
leaysgur 033ddf6d38 refactor(oxfmt,formatter): simplify js-in-html-in-js handling (#25464)
Prettier uses the `conditionalGroup` IR for JS and YAML.

When this appeared in JS(containing `conditionalGroup`)-in-HTML(`script` tags)-in-JS (`oxc_formatter`), we previously bypassed the `Doc` to IR conversion.

This PR adds support for this conversion and removes the string format fallback path.
2026-08-10 06:02:17 +00:00
leaysgur 95dc917441 fix(oxfmt): drop IR Space at line start for js-in-xxx (#25460)
Closes #25042
2026-08-10 04:24:03 +00:00
leaysgur b37b9f05b6 refactor(formatter_core): rename DispatchXxx (#25436)
Pure renaming.

- `DispatchOutcome` -> `DispatchResponse` (counter part of `DispatchRequest`)
- `DispatchResult` -> `DispatchPayload` (lives in `DispatchResponse`)
2026-08-09 15:07:42 +00:00
leaysgur 00f490d7f7 refactor(oxfmt,formatter): split sortImports validation and use type enum (#25432)
Reduce runtime validation.

Also, by using type `enum`, IDE and TS types are also covered.
2026-08-09 15:07:41 +00:00
leaysgur 13c5374ac1 refactor(oxfmt): rename "external_formatter" to "prettier" (#25430)
Use explicit wording.
2026-08-09 15:07:40 +00:00
leaysgur a26f856402 refactor(oxfmt): rename external_formatter to external_services (#25429)
`ExternalFormatter` is merely a transport that calls the JS side via napi; it is not referred to as a formatter.
2026-08-09 15:07:40 +00:00
leaysgur 36d5e13fc2 refactor(formatter_core,formatter,oxfmt): rename embedded meta to child_context (#25428)
`parent_context` <-> `child_context` is more intuitive.
2026-08-09 14:59:36 +00:00
leaysgur 1a2c64a356 fix(formatter,oxfmt): apply effective print width for JSDoc fence (#25413)
As JSDoc is always contained within the ` * ` fenced comments, the `printWidth` option should not have been used as is.

The dedicated `jsdocPrintWidth` option has not yet been implemented. #24633
2026-08-09 14:49:14 +00:00
leaysgur ce29325cfe refactor(oxfmt): consolidate embedded routing and service profiles (#25396)
Consolidated the criteria for determining which languages are handled by?

- natively by Rust
- passed to Prettier

when formatting embedded code, as these were previously scattered across various places.
2026-08-09 14:32:11 +00:00
leaysgur 8213e72f37 refactor(formatter,oxfmt): flatten embedded dispatch contract (#25391)
Due to historical reasons, the IR was passed as `[Doc, (Doc, ...Doc)]` only when processing `gql-in-js`, whilst for other cases such as `css-in-js` and `html-in-js`, it was always `[Doc]`.

Now, every result is single `Doc`.
2026-08-09 14:32:11 +00:00
leaysgur 465b723d04 refactor(formatter,oxfmt): unify host services as SessionServices on FormatSession (#25388)
- dispatcher
- string_embedder
- tailwind_sorter

Group these 3 together as `SessionServices`, make them available to `FormatSession`, and pass them around.
2026-08-09 14:32:10 +00:00
leaysgur aa1334f1c8 refactor(oxfmt): use dispatcher for non-napi xxx-in-js (#25387)
Although everything was ready in #25331, it was still behind the `napi` gate, so removed it.
2026-08-09 14:32:10 +00:00
leaysgur fd02a8956e feat(oxfmt): dispatch yaml-in-css(frontmatter) to oxc_formatter_yaml (#25336)
Using the `Dispatcher` set up so far, detect the YAML front matter and process it using `oxc_formatter_yaml`.
2026-08-09 14:15:05 +00:00
leaysgur 567089f3c5 refactor(oxfmt): route JSDoc fence through the dispatcher (#25334)
Markdown code fences can also be written in JSDoc, and other languages can be formatted as inline code within them.
2026-08-09 13:54:12 +00:00
leaysgur b3ad060cfd refactor(formatter): migrate embedded entries to FormatSession (#25332)
Apply `FormatSession` everywhere introduced in #25329.
2026-08-09 13:06:35 +00:00
leaysgur fb8affe04c refactor(oxfmt): make native dispatch registry available without napi (#25331)
Previously, as Prettier was required for embedded formatting, so embedding was only supported in `napi` builds.

However, as the number of rewritten Rust components has increased recently, we have enabled embedded formatting in `pure` builds as well, thereby reducing the scope of the `napi` gate.
2026-08-09 13:06:35 +00:00
leaysgur 11e0645dc9 refactor(oxfmt,formatter_core): add DispatchOutcome with recursion limit (#25330)
In the embedding format, issuing a `DispatchRequest` returns a `DispatchOutcome`.

Additionally, by managing the nesting depth, made it possible to limit the number of recursion.
2026-08-09 13:06:34 +00:00
leaysgur 8e779c946b refactor(formatter_core): finalize documents once at print time (#25328)
Call `propagate_expand()` inside `Formatted`, here is the only place to finalize IRs.
2026-08-09 12:33:39 +00:00
Alexander S. c7583238a0 refactor(lsp): add ToolBuildResult struct for optional client message (#25386)
Added a new `ToolBuildResult` struct, so an optional `ClientMessage` can
be passed to `Backend` (in a later PR).
This allows us later to send the custom message to the clients interface
when some config errors happened on the (re)creation.

There is no message sent yet, this will be integrated in another PR too.
This PR is just the base for the `ToolInterface`.
2026-08-08 17:02:23 +00:00
leaysgur ab12665f34 feat(formatter_core): add hardlineWithoutBreakParent equivalent IR (#25273)
builder: `hard_line_break().without_expand_parent()`
2026-08-04 04:31:56 +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 ee47f21ce4 refactor(oxfmt): move Doc-to-IR postprocess() under prettier_compat (#25141)
Just relocated.
2026-07-31 08:20:38 +00:00
leaysgur acfbf46767 refactor(formatter_core): add CoreFormatOptions and FormatOptions::apply_core (#25138)
These common, core format options:

- LineEnding
- LineWidth
- IndentWidth
- IndentStyle

should be defined in core, and to be shared.
2026-07-31 08:11:23 +00:00
leaysgur a9e76e9e1f fix(oxfmt): rework tsx-in-vue support (#25106)
Follow-up to #25063.

tsx-in-vue was supported in #25063 with a parse-retry (ts fails → retry as tsx), chosen to keep the common ts path single-parse.

However, this leaves a hole: a `lang="tsx"` block without JSX parses fine as plain ts, so the retry never fires and the lone generic comma is removed:

```vue
<script setup lang="tsx">
const identity = <T,>(x: T) => x; // → <T>(x: T) => x, breaks as TS17008
</script>
```

Since parse failure fundamentally cannot detect this, the only fix is to scan the `lang` declaration itself.

The JS host now scans the SFC once per file and passes `_oxfmtVueScriptLang: "tsx"` down to `textToDoc()`. This makes the retry obsolete, so it is removed.

This PR also settles the comma policy: keep it only where it is load-bearing.

- JSX grammar (`<T>` would be a JSX opener)
- and `.mts/.cts` (TS7060, #18928)

and remove it everywhere else, keyed on the grammar, regardless of context.

Deliberate divergence: Prettier keys on filepath and keeps the comma in ts-in-vue/svelte (while its own ts-in-md embed uses `dummy.ts` as `filepath` and removes it). Plain-TS sources now behave identically wherever they live.
2026-07-30 05:27:07 +00:00
leaysgur 1b57f783fb feat(oxfmt): support tsx-in-vue (#25063)
Part of #16608, closes #25046.

---

Even with a simple regexp, I don't want to impact the performance of the vast majority of ts-in-vue paths.

With this approach, only tsx-in-vue use cases will be affected, and even that will be kept to a minimum since it can be handled entirely on the Rust side. (JS <-> Rust roundtrip is also slow)
2026-07-29 07:27:43 +00:00
leaysgur be7f6da49a feat(oxfmt): colorize diff file list in check mode (#25061)
Fixes #25018
2026-07-29 06:00:25 +00:00
leaysgur 0c16cb5aba feat(oxfmt)!: Format parser:yaml files by oxc_formatter_yaml (#24890)
Format `.yaml`, `.yml` and others by `oxc_formatter_yaml`.

Also handle maybe-json-or-yaml files like `.prettierrc`.
2026-07-28 06:16:26 +00:00
leaysgur e6e584b9be fix(oxfmt): type jsdoc. enum options (#25008)
Fixes #24999
2026-07-28 01:22:23 +00:00
leaysgur eabfe016cf feat(oxfmt/lsp): support oxc.fmt.disableNestedConfig (#24965)
Refs: voidzero-dev/vite-plus#2245

(I had assumed Oxlint didn't have an option for LSP either, but that wasn't the case.)
2026-07-27 01:32:09 +00:00
leaysgur 9bf5c71ac7 refactor(formatter_core): introduce exact_line_breaks builder (#24865)
Introduce `exact_line_breaks(count)` IR builder.

This produces a line element that prints exactly `count` line breaks, exempt from the printer's hardline collapsing / empty-line capping.

Blank runs inside verbatim values (YAML block/flow scalars, GraphQL block strings) are the value itself and must not be normalized.
Previously this was emulated by emitting raw `\n` text followed by a re-arming `hard_line_break()`..., hack.

Also removed the printer behavior that trims end of line whitespaces.
2026-07-24 04:05:12 +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
camc314 66e1a25c0e chore(all): fix clippy::manual_assert_eq (#24351) 2026-07-10 09:57:05 +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