Commit Graph

66 Commits

Author SHA1 Message Date
leaysgur 3d00a7635b fix(formatter_css): keep comment inside important and simple-vars colon (#26370)
Follow up on #26337

Also, normalize `important` token with/without comments.
2026-09-07 01:33:14 +00:00
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 0f4af5d7df test(formatter_tests): assert fingerprint survives formatting (#26322)
Historically, only JS formatter has had the `detect_code_removal` feature, which uses CI to check for missing nodes or comments.

While this would be useful in other languages (especially CSS), but setting up the mechanism is difficult. For now, just start with something simple that just guarantees the number of comments.

That said, even with a mechanism in place, it can't detect anything unless the cases are fully covered by fixtures, so this only tells us that the current state is problem-free.
2026-09-04 07:14:53 +00:00
leaysgur 172ddb67dc fix(formatter_css): keep a same-line line comment on its line (#26321)
Consistent output with other language formatters.
2026-09-04 07:14:53 +00:00
leaysgur cafaf32de1 fix(formatter_css): never drop comments inside an at-rule prelude (#26320)
Fix missing comment bug.
2026-09-04 07:14:52 +00:00
leaysgur 534a0fe838 fix(formatter_css): keep a line comment on its comma's line (#26319)
e.g.

```scss
$my-map: (
  "foo": 1, // Comment
  "bar": 2, // Comment
);
```

should not be formatted:

```scss
$my-map: (
  "foo": 1,
  // Comment
  "bar": 2, // Comment
);
```
2026-09-04 07:14:52 +00:00
leaysgur 99cfd7556e fix(formatter_css): hide raw comment printing API, use strcut instead (#26316)
#26313 for CSS formatter. This also fixes some bugs.
2026-09-04 07:14:52 +00:00
leaysgur 2028896ab9 fix(formatter_css): preserve comments around SCSS/Less variable values (#26276)
```less
// input
@a: /* c */ 1;

// before
@a: 1;

// after
@a: /* c */ 1;
```

Comment should be preserved.

```scss
// input
$x: // c
  1;

// before
$x:
  // c1;

// after
$x: // c
  1;
```

Content should be preserved.
2026-09-03 08:17:36 +00:00
leaysgur 6752abc1a2 fix(formatter_css): keep leading comments before (#26272)
Apply comment printing policy.
2026-09-03 08:17:36 +00:00
leaysgur b3c287a47d fix(formatter_css): fix SCSS bracket list printing (#26270)
`$basic: [1, 2];` and `$basic: (1, 2);` should be formatted in the same way.
2026-09-03 08:17:35 +00:00
leaysgur bac770adaa fix(formatter_css): preserve comment in SCSS paren comma list (#26269)
Keep comment position for consistency.
2026-09-03 08:17:35 +00:00
leaysgur c7b57efc38 fix(formatter_css): print SCSS map consisntent with and without comment (#26268)
```scss
$no-comment: (
  a: 1,
);
$with-block: (
  /* c */ a: 1,
);
```

These should be formatted in the same way.
2026-09-03 08:17:34 +00:00
leaysgur 063e2b6249 fix(formatter_css): preserve trailing comma in single-item scss lists (#26245)
Keep these as-is.

```scss
foo: ("a",);

$x: "a",;
```

Even if they consist of a single element, these are still lists, and if the commas are removed, their type changes.

And also fixed inconsistent comment printing.
2026-09-03 08:17:33 +00:00
leaysgur 1fb37b6e47 feat(formatter/css): format declaration-shaped raw-prelude rules (postcss nested config blocks) (#26194)
Fixes #26158

---

> Otherwise, [restore a mark](https://drafts.csswg.org/css-syntax-3/#token-stream-restore-a-mark) from input, then [consume a qualified rule](https://drafts.csswg.org/css-syntax-3/#consume-a-qualified-rule) from input, with nested set to true, and [<semicolon-token>](https://drafts.csswg.org/css-syntax-3/#typedef-semicolon-token) as the stop token.
> https://drafts.csswg.org/css-syntax-3/#consume-block-contents

When fallback happens: format block, keep prelude verbatim.
2026-08-31 04:42:06 +00:00
leaysgur 57e8e22483 fix(formatter_css): space a folded sign after a call in Less operations (#26134)
Follow up on #26132.

By that change, Less is also possible to format binary operation like SCSS.
2026-08-27 07:49:30 +00:00
leaysgur 0e734cc7ae test(formatter_css): pin signed-value parser fixes from oxc-css-parser 0.0.12 (#26132)
Bump parser and pin fixed by https://github.com/oxc-project/oxc-css-parser/pull/158
2026-08-27 07:49:30 +00:00
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 3e5adf9e87 test(formatter_css): consolidate redundant fixtures (#26124)
Remove redundant fixtures.
2026-08-27 05:33:59 +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 5c0a5ff7bf fix(formatter_css): fill own-line block comments inside space-separated values (#25578)
Fixed idempotency issue.

Block comment is a normal fill item in values.
2026-08-13 07:45:25 +00:00
leaysgur 53debfa10e fix(formatter_css): keep trailing comma and indent after comment-preceded last map value (#25577)
Fixed idempotency issue.

```scss
$with-comment_n_comma: (
  a: (
    x: 1,
  ),
  /* This comment should not affect trailing comma, indent depth */
  b: (
    x: 2,
  ),
);
```
2026-08-13 07:45:25 +00:00
leaysgur 40d38a0813 fix(formatter_css): keep multi value function args intact after leading comment (#25518)
Fixes #25480
2026-08-12 05:36:15 +00:00
leaysgur 4544183058 test(formatter_tests,formatter,formatter_css): always track idempotency violations in snapshots (#25512)
Trackable easier than before.
2026-08-12 02:25:55 +00:00
leaysgur b63e88a0b4 test(formatter_css): pin more known divergence (#25479)
Found cases that had been discarded due to runner bugs before.
2026-08-12 00:48:33 +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 e4437275de refactor(formatter_css,formatter_json,formatter_graphql,formatter_tests): move out prettier CSS,JSON,GraphQL conformance from tasks/ (#25472)
Migration from tasks/prettier_conformance to each crate test using oxc_formatter_tests, for CSS, JSON, and GraphQL.
2026-08-12 00:48:32 +00:00
leaysgur 6e1b4ddceb refactor(formatter_core,formatter_tests): extract oxc_formatter_tests crate from oxc_formatter_core (#25465)
- Extract `test_harness` feature as crate `oxc_formatter_tests`
- This crate will also provide infra for `tasks/prettier_conformance` later
2026-08-12 00:40:59 +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 52b146f025 refactor(formatter_core): share split_bom helper (#25333)
In order to standardise the handling of front matter, it was also necessary to standardise the handling of the BOM, which may appear before the FM.
2026-08-09 13:06:35 +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 e23dccf338 fix(formatter_css): bump oxc-css-parser to accept unknown at-rule with interpolated (#25277)
Fixes #25272
2026-08-04 06:39:46 +00:00
leaysgur 8c2ed1a04f test(formatter_css): add grid arg re-wrap fixture (#25229)
Follow up #25226
2026-08-03 02:49:01 +00:00
leaysgur 68146bd3b9 fix(formatter_css): preserve glued plugin words in grid values (#25225)
Fixes #25223
2026-08-03 02:00:00 +00:00
leaysgur 96a9744198 refactor(formatter_core): export apply_core_options for tests (#25139)
The same as #25138, for fixture tests.
2026-07-31 08:11:23 +00:00
leaysgur dd28596d0a fix(formatter_css): bump oxc-css-parser for substituted at-rule preludes (#25104)
Fixes #25075
2026-07-30 03:28:44 +00:00
leaysgur f56009a676 fix(oxfmt): correct prose about comment width in fits measurement (#25054)
Audited every formatter crate against the trailing-comment width discipline.

- same-line trailing line comments ride `line_suffix` and are excluded from the fits measurement
- while trailing block comments print inline and count

Corrected the prose that misstated it.
2026-07-29 02:57:17 +00:00
leaysgur 761a882a49 fix(formatter_css): keep leading + in An+B to enable idempotency check (#24973)
Keep `:nth-child(+3n + 1)` as-is, NOT `:nth(+ 3n + 1)` which is not allowed.
2026-07-27 09:07:31 +00:00
leaysgur ae1a39b71c fix(formatter_css): align wrapped selector-arg indent (#24971)
Fixes #24843

---

Tracing back to the root cause, this is also related to what had diverged because of Prettier's inconsistent behavior.
Since I cannot determine for sure how it should be output in more complex cases (like that issue) at this point, decided to revert to being Prettier-compatible.
2026-07-27 06:47:19 +00:00
leaysgur fb34196ec7 fix(formatter_css): keep non-ASCII strings with quotes (#24870)
Fixes #24841
2026-07-24 02:13:21 +00:00
leaysgur cb9655da3e test(formatter_core): assert fixture idempotency in test harness (#24819)
Automatically test idempotency with fixture tests.

Currently, JS and CSS formatter have the issue, will fix later to enable.
2026-07-23 04:51:26 +00:00
leaysgur 31783e997c fix(formatter_css): print nested SCSS map with consistent indent (#24789)
Fixes #24773
2026-07-22 01:58:53 +00:00
leaysgur fd7cf5b500 fix(formatter_css): update oxc-css-parser to 0.0.9 (#24745)
Fixes #24726
2026-07-21 04:52:30 +00:00
leaysgur c399367877 fix(formatter_css): update oxc-css-parser to 0.0.8 (#24725)
This also fixes #24723
2026-07-20 13:37:52 +00:00
leaysgur 33e32d8e51 fix(formatter_css): use line_suffix for EOL line comment (#24580)
The same motivation as #24579
2026-07-16 01:37:31 +00:00
leaysgur 95262b9d94 fix(formatter_css): keep more value comments before comma (#24487)
Follow up on #24484.

Apply the same rule for all call sites.
2026-07-14 06:28:50 +00:00
leaysgur cd53d98460 fix(formatter_css): keep value comments before comma (#24484)
Fixes #24469

This keeps comments before/after `,` stay the same position.
2026-07-14 06:28:49 +00:00
leaysgur 0173cd37a3 feat(formatter_css): format Less :extend and merge props (#24358)
Follows:

- https://github.com/prettier/prettier/pull/19550
- https://github.com/prettier/prettier/pull/19517
2026-07-13 00:13:32 +00:00
leaysgur fcc28dfc9c fix(formatter_css): Keep glued-braket-value tight (#24352)
Fixes #24334
2026-07-13 00:08:30 +00:00
leaysgur eeabc4a55f fix(formatter_css): bail on EOF-recovered parse errors (#24282)
Also updated the code to reflect the changes in `oxc-css-parser` 0.0.6.
2026-07-08 02:17:08 +00:00