Commit Graph

15 Commits

Author SHA1 Message Date
leaysgur 68e12abe2c feat(formatter_css): follow the oxc-css-parser's acceptance line (#26337)
Fixes #26290, #26291.
Also, many changes to follow refined parser acceptance line.

---

CI will fail until parser version bumped, needs oxc-project/oxc-css-parser/pull/166
2026-09-07 01:33:14 +00:00
leaysgur d9749a747d refactor(formatter_core,formatter): enforce finalize-once behind the print (#25425)
Follow the rule, #25328.
2026-08-09 14:59:36 +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 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 3b7fb916ee docs(formatter_css): update AGENTS.md and examples (#24488)
Use `printWidth: 80` for examples.
2026-07-14 06:28:50 +00:00
leaysgur e0b35a1a5b feat(formatter_css): update oxc-css-parser@0.0.3 (#23974)
Fixes #23969, closes #23983.

Notably `oxc-css-parser@0.0.3` contains:

- partial `postcss-simple-vars` support
- fix glued css-in-js placeholder (`${C}:hover &`)

As `oxc_allocator` has also been added as a dependency in `oxc-css-parser`, this has caused a conflict with the latest local (workspace) instance, so a `patch.crates-io` section has also been added. Apparently, this is a technique also used in [Tokio](https://github.com/tokio-rs/tokio/blob/master/Cargo.toml#L18-L23).
2026-07-01 02:16:59 +00:00
leaysgur dd5d39ec2e refactor(formatter_css): use try_parsing_value_in_custom_property option (#23968)
Drop the manual custom-property reparse helper. Use the parser's `try_parsing_value_in_custom_property` option instead.

One new SCSS conformance failure (`scss/variables/apply-rule.scss`):
The new AST gives `SassNestingDeclaration` instead of token-soup, so the swallow case formats structurally instead of verbatim.

```scss
--p: { /* ... */ } /* <- nosemi */
--q: red;
```

CSS and Less are unaffected.
2026-06-30 02:31:53 +00:00
leaysgur dbf27196fc chore(formatter_css): use oxc-css-parser (#23920) 2026-06-29 04:15:34 +00:00
leaysgur 692c73aae5 refactor(oxfmt,formatter_css): rework css-in-js with substituion (#23787)
As we have forked the CSS parser, we can control how JS substitutions `${}` inside css-in-js are represented and how they interact.

We are no longer bound by Prettier’s conventions, allowing us to implement the code more efficiently.
2026-06-29 03:54:45 +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 72a5d0887a refactor(oxfmt): use unified embedded ir results (#23325)
- Add `EmbeddedIr` struct in `oxc_formatter_core`
- Each `format_to_ir` implementation returns this as unified result
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 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 dffa4b329f feat(formatter_css): implement oxc_formatter_css (#23320)
- Implement `oxc_formatter_css` crate
- Use `raffia` crate
  - https://github.com/g-plane/raffia
  - Supports CSS, LESS and SCSS
- Prettier uses `postcss` for parser
  - https://github.com/prettier/prettier/blob/1c6ba5539141552e0e8e22d401ea620d8fdff468/package.json#L100-L105

Since design of `postcss`, this parser is very lenient with syntax.
Because of this, the AST is also less detailed, so formatting processes often rely on text-based.

On the other hand, `raffia` is relatively strict, so it cannot parse some postcss plugin syntax.

While this part clearly creates a difference from Prettier, we have judged that it is not an issue since it still supports major plugins syntax and aligns with current trends.
2026-06-29 03:15:23 +00:00