Commit Graph

82 Commits

Author SHA1 Message Date
leaysgur 95943aa6f2 feat(oxfmt): Support vite.config.* .fmt field (#20197)
NOTE: I'll do a self-review and add the test tomorrow.

<details>
<summary>Prompt</summary>

```
# Support `vite.config.*` as a Configuration File

## Target Files

- `vite.config.ts`
- `vite.config.mts`
- `vite.config.cts`
- `vite.config.js`
- `vite.config.mjs`
- `vite.config.cjs`

## Auto-Discovery Priority

When searching for a config file from `cwd` upwards, the following priority applies within the same directory:

1. Tool-specific JSON/JSONC config files (e.g. `.oxfmtrc.json`, `.oxlintrc.json`)
2. Tool-specific JS/TS config files (e.g. `oxfmt.config.ts`, `oxlint.config.ts`)
3. `vite.config.*`

## Extracting Configuration

The default export of `vite.config.*` is expected to contain tool-specific configuration under a dedicated field:

- oxfmt: `.fmt`
- oxlint: `.lint`

If the field does not exist, an error is returned (e.g. `Expected a 'fmt' field in the default export.`).

## Explicit `--config` Flag

When `--config vite.config.ts` is explicitly specified, the same behavior applies. The file name is used to determine whether to extract a nested field.

## LSP

`vite.config.*` files are added to the file watch patterns so that configuration changes trigger a reload.
```

</details>
2026-03-11 04:34:48 +00:00
leaysgur 172fc072f3 feat(oxfmt): .js/.ts config file support (#20135)
Fixes #19711, also resolves some of the demands for nested configs.
2026-03-11 04:34:48 +00:00
leaysgur 92f44900ee fix(oxfmt): Apply is_ignored_dir for glob paths too (#20056)
Fixes #20036
2026-03-06 04:18:28 +00:00
leaysgur 935c340dd2 test(oxfmt): Add css-in-js conformance (#20020)
Add tests for updated css-in-js.
2026-03-06 04:00:19 +00:00
leaysgur ca1169fbb1 chore(oxfmt): Add comments for test/cli/utils (#19805) 2026-02-27 04:52:19 +00:00
leaysgur e7572aaf8a test(oxfmt): Add snapshot for invalid file error reports (#19802)
Just adding tests for sure.

..., but to do so, we need to force dumb theme for `miette`.
2026-02-27 04:40:12 +00:00
leaysgur 14a0181548 feat(oxfmt): Support graphql() variant for gql-in-js (#19703)
Part of #15180

Now we can support all gql-in-js variants. ✌🏻
2026-02-26 15:24:02 +00:00
leaysgur 035933c443 feat(formatter,oxfmt): Support js-in-vue (partially) (#19514)
### Overview

Part of #16608

This PR applies `oxc_formatter` to the js-in-vue section.

However, it is not complete and is only applied to the following parts within js-in-vue:

- `script` block
  - and `generic="..."`
- `v-for` LHS
- `v-slot`

In the `script` block, `external_callback` is used like a regular JS file, but it isn't for others.

TL;DR: Now you can use sort-imports for Vue files.

### Review points

The points I'd like to ask your review are the following:

- Addition of `format_node()` to `oxc_formatter`
  - Made it possible to process any type that implements `Format`, not just `Program`
- The implementation of `js-in-vue` fragment was separated as much as possible to avoid impacting existing code
- `oxc_formatter` IR to prettier `Doc`

### TODOs

- [x] Planning
- [x] Implementation
- [x] Check benchmark
- [x] Check coverage
- [x] Understand & refactor
  - [x] oxfmt: JS side
  - [x] oxfmt: Rust side
  - [x] oxfmt: to_doc.rs
  - [x] oxc_formatter: fragment_format
- [x] Check benchmark again
- [x] Check coverage again
- [x] Check ecosystem-ci
- [x] Tests 👉🏻 #19563
2026-02-24 10:17:35 +00:00
leaysgur 984dc07f4f feat(oxfmt): Strip "experimental"SortXxx prefix (#19567)
- `experimentalSortImports` 👉🏻 `sortImports`
- `experimentalSortPackageJson` 👉🏻 `sortPackageJson`
- `experimentalTailwindcss` 👉🏻 `sortTailwindcss`

To avoid breaking changes, the old name is retained as an alias.
2026-02-20 08:56:22 +00:00
leaysgur d1c2fb628a feat(formatter/sort_imports): Support customGroups attributes(selector and modifiers) (#19356)
Fixes #19264

The original issue only mentioned `modifiers`, but I've implemented `selector` as well.
While the original implementation also supports more attributes, I believe this is sufficient for now.
2026-02-13 05:15:00 +00:00
leaysgur 856a01ff40 feat(formatter/sort_imports)!: Replace prefix match with glob pattern in customGroups.elementNamePattern (#19066)
Fixes #18726

Support glob matching instead of prefix matching.

The original used regex, but there was no necessity for it, and this approach offers better performance.

In any case, it will be a braking change.

```js
// before: Matches react, reactify, react-router, etc
"elementNamePattern": ["react"]
// after: Matches react only

// before: Matches loot-core, loot-core/foo, etc
"elementNamePattern": ["loot-core"]
// after: Matches only loot-core, should update to
"elementNamePattern": ["loot-core/*"]
```
2026-02-10 02:14:10 +00:00
leaysgur 5ea5bda86c fix(oxfmt): Handle isSingleJsxExpressionStatementInMarkdown() check for js-in-md (#19042) 2026-02-09 08:59:37 +00:00
leaysgur 8536dce989 feat(oxfmt): Support glob for CLI paths (#18976)
Fixes #13705

- Support glob patterns like `*.js`, `**/*.ts`, and `{a,b}.js` in CLI paths
- Globs are pre-expanded to make `ignore` crate respects `.gitignore`
  - Existing cases that don't use glob will NOT be affected in terms of performance

This also fixes bug that `oxfmt a.js a.js` formats the same file 2 times 🙈
2026-02-06 07:59:55 +00:00
leaysgur 7d2b8c3ec2 test(oxfmt): Add tests for js-in-xxx plugin (#18913)
Added API tests and CLI tests for js-in-(markdown|mdx) plugin.

For now, Vue tests are useless, but will be useful if we support it.
2026-02-06 05:50:05 +00:00
leaysgur e754b18dca fix(oxfmt/migrate-prettier): Set experimentalSortPackagejson: false by default (#18831)
Fixes #18741
2026-02-02 01:52:22 +00:00
leaysgur c3d05c1b3c fix(formatter,oxfmt): Handle CRLF with embedded formatting (#18686)
Fixes #18663 , but not related to Angular.

Actually, before this fix, when performing embedded formatting with `endOfLine: crlf` specified, it seemed to panic in debug builds.

https://github.com/oxc-project/oxc/blob/e440b78fd4a925c06547815406d45eb02e0aa370/crates/oxc_formatter/src/formatter/builders.rs#L342

`Text` can not contain `\r`.

Since this check is disabled in release builds, it simply resulted in extra line breaks.
2026-01-29 08:32:23 +00:00
Luca Fischer ee30de98cf feat(oxfmt): add config migration from biome (#18638)
Added Biome-to-oxfmt configuration migration, based on the Prettier
implementation.

I wasn't sure if I should exclude settings that match oxfmt's defaults
from the generated config, but I'm happy to do so if you’d like
2026-01-28 21:09:13 +09:00
leaysgur ac1ff4edcd fix(oxfmt): Use empty_line IR for empty xxx-in-js line (#18623)
Fixes #18040
2026-01-27 08:50:16 +00:00
leaysgur 8f76900978 fix(oxfmt): Dedent xxx-in-js templates before calling prettier (#18622)
Fixes #18522
2026-01-27 08:50:15 +00:00
leaysgur 6b726efd80 fix(oxfmt): Trim whitespace only xxx-in-js templates (#18621)
Fixes #18523
2026-01-27 08:50:15 +00:00
leaysgur 224140cbc6 fix(oxfmt): Canonicalize .. component in config path (#18570)
Fixes `ignorePatterns` not working when `--config` is specified with a `..` path (e.g., `--config ../../.oxfmtrc.json`)

Canonicalize the joined path via `fs::canonicalize()` in `normalize_relative_path()`.
2026-01-26 07:56:25 +00:00
leaysgur 52b5003bd1 feat(formatter,oxfmt): Support Angular @Component({ template, styles }) (#18324)
Part of #15180
2026-01-21 16:50:14 +00:00
leaysgur 864b4ab247 fix(oxfmt): Use format_config for external_options override (#18252)
Fixes #18246
2026-01-19 15:42:23 +00:00
leaysgur 90ce4b747f fix(oxfmt): Restore customGroups handling lost (#18243)
Fix for the issue where the code passing settings from `oxfmt` to `oxc_formatter` was missing.

- Also added tests
- Also fixed the TS type that was missing
2026-01-19 14:07:49 +00:00
leaysgur 73fedb965f fix(oxfmt): Apply .editorconfig root section with oxfmtrc.overrides (#18210)
Fixed a bug found through self-review.
2026-01-19 09:17:55 +00:00
leaysgur 63df94b6d2 test(oxfmt): Test oxfmtrc.overrides (#18208)
Follow up on #18068
2026-01-19 07:39:44 +00:00
Yuji Sugiura 58baabfac4 test(oxfmt): Split embedded_languages tests by lang (#18069)
Pure refactoring;

Snapshots are a bit easier to review now.
2026-01-19 09:43:39 +09:00
magic-akari fd2c792d9a feat(formatter): support css prop, styled jsx, and member/computed styled.tags (#17990)
This PR adds support for embedded language formatting in
styled-components and styled-jsx patterns:

## Changes

- [x] **Support ``styled.div`...` `` tagged templates**: Allow
formatting of tagged templates with member expressions like
`styled.div`, enabling better support for styled-components
- [x] **Support ``styled["computed"]`...` ``**: Handle static computed
member expressions in styled tags
- [x] **Support ``styled(Component)`...` ``**: Handle styled calls with
component arguments for styled-components
- [x] **Support ``<div css={`...`} />``**: Format CSS content in JSX
`css` prop
- [x] **Support ``<style jsx>{`...`}</style>``**: Format Styled JSX
content in JSX elements

## Related Issues
- Part of #15180

## Known Limitations

- **Template substitution is not supported**: Expressions inside
template literals like `` css`color: ${THIS_VAR};` `` are not yet
supported

---------

Co-authored-by: Dunqing <dengqing0821@gmail.com>
2026-01-16 17:11:39 +09:00
leaysgur efacb138be fix(oxfmt): Do not wrap with block_indent() if format_embedded fails (#17975)
Fixes #17948 and may fix `next.js` repo diffs. => Confirmed all xxx-in-js diffs are resolved ✨

---

When Prettier fails to format embedded code (e.g., valid `css` tag but with invalid content), the previous implementation returned the original code as a successful result.

This caused issues because `block_indent` is always added (assuming Prettier has normalized root indentation).

As a result, indentation/newlines grow infinitely on each format run.
2026-01-14 05:10:28 +00:00
leaysgur 9d0f551878 fix(oxfmt): Do not panic with subdirectry and config (#17955)
Fixes #17954
2026-01-13 08:19:12 +00:00
leaysgur 9d96cc6f7a fix(oxfmt): Use std(out/err)._handle.setBlocking(true) to handle WouldBlock error in Rust (#17950)
Fixes #17939, closes #17943 and #17946.
2026-01-13 05:40:13 +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