Commit Graph

45 Commits

Author SHA1 Message Date
leaysgur f94b22296c test(formatter,formatter_css,formatter_json,formatter_yaml): restore coverage lost in fixture consolidation (#26129)
- Restore wrongly consolidated fixtures
- State new fixtures policy and apply
- Check `endOfLine` option and output at test harness level
2026-08-27 06:12:52 +00:00
leaysgur 181953b92d docs(oxfmt,formatter_core,formatter,formatter_yaml,formatter_css,formatter_graphql): extract DIVERGENCES.md out from AGENTS.md (#26121)
- Extract "known divergences" section from `AGENTS.md` to explicit `DIVERGENCES.md` with code example
- Update all anchors
- Add missing pinned fixtures
2026-08-27 05:33:58 +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 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 8f758d3cf5 refactor(formatter_core): group src/ modules by domain (#25527)
Also removed dead code and comments.
2026-08-12 06:43:55 +00:00
leaysgur b297fb1cb8 refactor(formatter,formatter_tests): fix up (#25478)
Cleaning up after the series of migrations.

- Docs clean up
- More strict `jsdoc` option handling in fixture tests
2026-08-12 00:48:33 +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 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 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 6eae5c9803 docs(formatter,oxfmt): record embed-layer decisions in place (#25422)
Just notes.
2026-08-09 14:49:15 +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 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 eaa7c692d2 docs(formatter_core): extract FORMATTER_POLICY (#25233) 2026-08-03 05:56:42 +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 dbf27196fc chore(formatter_css): use oxc-css-parser (#23920) 2026-06-29 04:15:34 +00:00
leaysgur 2dc451ca8b chore(formatter_graphql): use oxc-graphql-parser (#23919) 2026-06-29 04:15:34 +00:00
leaysgur b4d0dc9e30 docs(oxfmt,formatter,formatter_css,formatter_core): update AGENTS.md (#23814) 2026-06-29 04:15:33 +00:00
leaysgur 6fe3e45c8f refactor(oxfmt): fix up code and comments (#23770)
There's still room for refactoring, but this will serve as a starting point for now.
2026-06-29 03:15:28 +00:00
leaysgur 48e2d7855b fix(formatter_css): improve major prettier diffs (#23327)
Fixed many formatting diffs by checking real world repo.
2026-06-29 03:15:26 +00:00
leaysgur 259e0cdf60 feat(oxfmt,formatter_graphql)!: support draft syntax with removing prettier fallback (#23326)
- Fork `apollo-rs` to be compatible with Prettier(`latest` for now)
  - https://github.com/leaysgur/apollo-rs
- By doing this, Prettier fallback is no longer needed
- And now all prettier_conformance are passed, no parse error skip

> [!WARNING]
> TODO: Move fork under `oxc-project` org and replace refs
2026-06-29 03:15:25 +00:00
leaysgur 721667ec8e refactor(oxfmt)!: remove prettier fallback for css-in-js failure (#23324)
- Removed last remaining Prettier fallback path for css-in-js failure case
- In our Rust formatter host paths, Prettier is not used for CSS/LESS/SCSS anymore
2026-06-29 03:15:25 +00:00
leaysgur 43aa5fe1ef refactor(formatter_css): update oxc_formatter_css to support sortTailwindcss option (#23323)
- Before this PR: If `sortTailwindcss` option is enabled for CSS/LESS/SCSS, it was formatted by Prettier
- After this PR: `oxc_formatter_css` also handles `sortTailwindcss` as like `oxc_formatter` does
2026-06-29 03:15:24 +00:00
leaysgur 9d2a9579c1 refactor(oxfmt): use Rust formatters for jsdoc code fence (#23322)
In addition to basic embedded (e.g. css-in-js), JSDoc also contain code fence as markdown.

This PR makes JSDoc code fence also formatted by `oxc_formatter_(css|graphql)` if specified.
2026-06-29 03:15:24 +00:00
leaysgur accbc49def feat(oxfmt)!: format parser:css,less,scss files + css-in-js by oxc_formatter_css (#23321)
- Use `oxc_formatter_css` from Oxfmt to handle CSS/LESS/SCSS files
- css-in-js is also handled by `oxc_formatter_css`
  - But it will fallback to Prettier if formatting failed
  - No fallback for no-embedded path
- At the point of this PR, it will fallback to Prettier when tailwind is required to format

NOTE: Both fallback will be removed in later PR.

In that sense, as a result of this series of PRs, Oxfmt's CSS support will no longer be 100% compatible compared to Prettier.

Since the parsers used are also different, it will no longer be possible to support certain postcss-plugin-specific syntax, invalid syntax or legacy syntax.

> [!WARNING]
> TODO: Move fork under `oxc-project` org and replace refs
2026-06-29 03:15:24 +00:00
leaysgur a7fd35e7df refactor(oxfmt): handle gql-in-js by oxc_formatter_graphql (#23319)
- To use `oxc_formatter_graphql` in gql-in-js context, ground level refactoring was needed
- Extracted common logic for handling embeddings into `oxc_formatter_core`
- Updated other `xxx-in-js` callers to reflect these changes
- Added a `format_to_ir()` method to each formatter in addition to the existing `format()` method
2026-06-29 02:55:31 +00:00
leaysgur 01de9ece8b feat(oxfmt): format parser:graphql files by oxc_formatter_graphql (#23318)
- Use `oxc_formatter_graphql` from Oxfmt to handle `.gql` and `.graphql` files
- At point of this PR, gql-in-js is still handled by Prettier

As described in #23317, Prettier supports more syntax than ours, so for now fallback to Prettier when `oxc_formatter_graphql` failed to format.

NOTE: This fallback will be removed in later PR.
2026-06-29 02:55:30 +00:00
leaysgur 845f393362 docs(oxfmt,formatter,formatter_json,formatter_core): add/update AGENTS.md (#22873)
- Update: apps/oxfmt
- Add: crates/oxc_formatter_core,oxc_formatter,oxc_formatter_json
2026-06-01 08:18:15 +00:00
leaysgur f87b33464d test(oxfmt): Refactor test fixtures usage (#21494)
- Normalized tests that were ambiguous as to whether they were fixtures or scenarios based
- Specified this rule in AGENTS.md
- Made the test name report in the CLI clearer
2026-04-16 09:40:58 +00:00
leaysgur 5900d23f76 test(oxfmt): Misc refactors (#21484)
- Simplify sort_imports test
- Add note comment to stdin_pipe test
- Update AGENTS.md
2026-04-15 22:50:00 +00:00
leaysgur ff8422ab18 chore(oxfmt): Update AGENTS.md (#20637) 2026-03-23 01:36:27 +00:00
leaysgur ff2f28a622 chore(oxfmt): Update AGENTS.md (#20169) 2026-03-10 02:02:57 +00:00
leaysgur ec91dce7b3 refactor(oxfmt): Generate TS types from schema (#19901)
Like oxlint does.

No public definition change.
It also prepares for dynamic configuration files.
2026-03-02 23:51:22 +00:00
leaysgur 92a18f4ddc chore(oxfmt): Update AGENTS.md (#18911) 2026-02-04 01:49:37 +00:00
leaysgur 6262fcfd99 chore(oxfmt): Update AGENTS.md and comments related to path handling (#18613)
Additional notes on handling paths in cross-platform environments.

Comments have also been added to relevant sections in the code.
2026-01-27 01:52:30 +00:00
leaysgur 5e2daaa92a chore(oxfmt): Update AGENTS.md (#18383) 2026-01-22 05:33:44 +00:00
leaysgur 1aea211424 refactor(oxfmt): Move Oxfmtrc to apps/oxfmt (#17824)
Before this PR, `Oxfmtrc` was defined in `oxc_formatter` to avoid the circular reference `oxc_language_server` > `oxfmt` > `oxc_language_server`....

But now, `oxc_language_server` does not depend on `Oxfmtrc` since LSP implementation has moved to `apps/oxfmt`.

Therefore, by this PR, `Oxfmtrc` is moved to its proper location, in `apps/oxfmt`.

- Moved `Oxfmtrc` from `oxc_formatter` to `apps/oxfmt`
- Re-exposed from `apps/oxfmt`
- Now only `tasks/website_formatter` depends on it
- Also aligned JSON schema generation with `oxlint` by `just formatter-schema-json`

NOTE: In `oxc_formatter`, there are 2 places (`ir_transform` and `fixtures` tests) where we manually convert options from JSON. I'd like to fix this too in the future.
2026-01-09 15:11:36 +00:00
leaysgur 1a02f6ee8c test(oxfmt): Arrange test files and directries (#17822)
Sorry for the large diff! 🙇🏻

But it's mostly just file relocations (and path updates).
Details on the changes are also documented in [`AGENTS.md`](https://github.com/oxc-project/oxc/pull/17822/changes#diff-b9a8ddc83e0b93133df7274e37b5fcdaec808090721eec2194782fe968819e69), so please refer to that file.

TL;DR: I wanted to colocate test cases and fixtures in the same directory.
2026-01-09 15:11:35 +00:00
leaysgur 67b36c5381 chore(oxfmt): Arrange AGENTS.md (#17777)
Misc updates, will merge after CI.
2026-01-08 02:32:24 +00:00
leaysgur 36c285329d chore(oxfmt): Add AGENTS.md for apps/oxfmt (#17034)
While it was possible to load it with `@` in the root's `AGENTS.md`, but it's fine to do only when necessary.

Will merge after CI.
2025-12-18 01:44:20 +00:00