feat(oxfmt): .js/.ts config file support#20135
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
37d2b76 to
f7f8894
Compare
f7f8894 to
dcf7c16
Compare
dcf7c16 to
ebafbbf
Compare
There was a problem hiding this comment.
Pull request overview
Adds dynamic JS/TS configuration file support to oxfmt (similar to oxlint), enabling oxfmt.config.{ts,mts,cts,js,mjs,cjs} to be discovered/loaded (via Node/NAPI) across CLI, stdin, and LSP flows.
Changes:
- Add config discovery support for
oxfmt.config.*and pass a JS config loader callback through NAPI into Rust config resolution. - Add
defineConfig()to the JS API for typed config authoring, plus CLI/LSP/API tests and fixtures. - Update LSP watch patterns and CLI config tests/snapshots to account for new config file types.
Reviewed changes
Copilot reviewed 37 out of 38 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| apps/oxfmt/test/lsp/init/init.test.ts | Updates LSP config watch patterns to include JS/TS config filenames. |
| apps/oxfmt/test/lsp/format/format.test.ts | Adds fixtures/tests for applying JS/TS configs and explicit fmt.configPath with TS config. |
| apps/oxfmt/test/lsp/format/fixtures/custom_config_path_js/semicolons-as-needed.ts | Fixture for explicit TS config path formatting behavior. |
| apps/oxfmt/test/lsp/format/fixtures/custom_config_path_js/format.config.ts | Fixture TS config used via fmt.configPath. |
| apps/oxfmt/test/lsp/format/fixtures/config-js-semi/test.ts | Fixture verifying oxfmt.config.ts is picked up. |
| apps/oxfmt/test/lsp/format/fixtures/config-js-semi/oxfmt.config.ts | Fixture TS config for LSP formatting tests. |
| apps/oxfmt/test/lsp/format/snapshots/format.test.ts.snap | Snapshot updates for new LSP config behaviors. |
| apps/oxfmt/test/cli/js_config/js_config.test.ts | New CLI integration tests for JS/TS config loading and error cases. |
| apps/oxfmt/test/cli/js_config/fixtures/priority/test.ts | Fixture for precedence behavior (JSON vs JS/TS config). |
| apps/oxfmt/test/cli/js_config/fixtures/priority/oxfmt.config.ts | Fixture TS config (lower priority than JSON). |
| apps/oxfmt/test/cli/js_config/fixtures/priority/.oxfmtrc.json | Fixture JSON config (higher priority). |
| apps/oxfmt/test/cli/js_config/fixtures/error_not_object/test.ts | Fixture for “default export not object” error. |
| apps/oxfmt/test/cli/js_config/fixtures/error_not_object/oxfmt.config.ts | Fixture TS config exporting non-object. |
| apps/oxfmt/test/cli/js_config/fixtures/error_no_default/test.ts | Fixture for “no default export” error. |
| apps/oxfmt/test/cli/js_config/fixtures/error_no_default/oxfmt.config.ts | Fixture TS config without default export. |
| apps/oxfmt/test/cli/js_config/fixtures/basic/test.ts | Basic fixture for loading TS config. |
| apps/oxfmt/test/cli/js_config/fixtures/basic/oxfmt.config.ts | Basic TS config fixture. |
| apps/oxfmt/test/cli/js_config/snapshots/js_config.test.ts.snap | Snapshots for CLI JS/TS config cases. |
| apps/oxfmt/test/cli/config_file/fixtures/fmt.config.ts | Adds TS config fixture for --config path. |
| apps/oxfmt/test/cli/config_file/config_file.test.ts | Updates config-file tests to include TS config and to exclude .ts from check globs. |
| apps/oxfmt/test/cli/config_file/snapshots/config_file.test.ts.snap | Snapshot updates for config-file tests. |
| apps/oxfmt/test/api/basic.test.ts | Adds defineConfig() API coverage in the JS API tests. |
| apps/oxfmt/src/stdin/mod.rs | Plumbs JS config loader into stdin formatting config resolution. |
| apps/oxfmt/src/main_napi.rs | Extends NAPI run_cli to accept a JS config loader callback and propagate it to all modes. |
| apps/oxfmt/src/lsp/server_formatter.rs | Adds JS/TS config files to LSP watch patterns; uses unified config resolver that supports JS/TS configs. |
| apps/oxfmt/src/lsp/mod.rs | Updates LSP entrypoint to accept/pass JS config loader. |
| apps/oxfmt/src/core/mod.rs | Exposes JS config loader types and config filename lists under the napi feature. |
| apps/oxfmt/src/core/js_config.rs | Adds NAPI-based JS/TS config loader wrapper for Rust codepaths. |
| apps/oxfmt/src/core/config.rs | Adds discovery of oxfmt.config.* and unified ConfigResolver::from_config supporting JS/TS configs (NAPI) and JSON/JSONC. |
| apps/oxfmt/src/cli/format.rs | Plumbs optional JS config loader into CLI config resolution (NAPI build). |
| apps/oxfmt/src/cli/command.rs | Updates CLI help text to document supported config extensions. |
| apps/oxfmt/src-js/index.ts | Adds defineConfig() helper with type inference for configs. |
| apps/oxfmt/src-js/cli/js_config.ts | Implements Node-side loader using dynamic import() with cache-busting. |
| apps/oxfmt/src-js/cli.ts | Passes JS config loader callback into NAPI runCli. |
| apps/oxfmt/src-js/bindings.js | Updates generated bindings exports/destructuring to match native exports. |
| apps/oxfmt/src-js/bindings.d.ts | Updates generated typings for changed runCli signature. |
You can also share your feedback on Copilot code review. Take the survey.
ee283ec to
b0ff1a0
Compare
|
If it's just about the part that calls js to resolve config, I feel that standardizing it would probably increase maintenance costs? We might need to look at it from a broader scope, but our CLI differ the supported features (such as .editorconfig, how walk through dirs, etc) and the behavior isn't strictly consistent, I'm not sure how exactly we should compromise. 😓 |
I didn't really look at the code, but it sounds like you've also added nested config support? I think we should share this + implement a trait for oxfmt/oxlint for the parts that need specialisation |
|
Ah, no, that's not yet. (Personally, I'm not sure if it should be supported or not. And if it becomes necessary, as you said, I will definitely start by standardizing the implementation…) It meant that user can now refer to common/shared settings without nesting. 👌🏻 |
7f1696f to
6a74e82
Compare
6a74e82 to
49e7843
Compare
Merge activity
|
Fixes #19711, also resolves some of the demands for nested configs.
49e7843 to
172fc07
Compare
# Oxlint ### 🚀 Features - 04a5ce0 oxlint: Support `vite.config.ts` `.lint` field (#20214) (leaysgur) - 1735215 linter: Implement `react/no-clone-element` rule. (#20129) (connorshea) - 68e6f6f linter: Implement `react/no-react-children` rule. (#20104) (connorshea) - fe3b32e linter/plugins: Add `oxlint-plugin-eslint` package (#20009) (overlookmotel) ### 🐛 Bug Fixes - 05f6a09 linter/no-inline-comments: Deserialize rule options with serde (#20207) (camc314) - c7eb09d linter/default-case: Deserialize rule options with serde (#20206) (camc314) - f85e16c linter/plugins: Fix types for visitor compilation (#20203) (overlookmotel) - 44e24e0 linter/exhaustive-deps: Ignore type-only typeof deps (#20201) (camc314) - 0b04998 linter/no-fallthrough: Deserialize rule options with serde (#20192) (camc314) - a1031cb linter/new-cap: Deserialize rule options with serde (#20161) (camc314) - ad27fd6 linter: Add help messages to import plugin diagnostics (#20158) (John Costa) - 1340307 linter/plugins: Ensure `after` hooks always run (#20167) (overlookmotel) - c4812ec linter/plugins: Reset visitor compilation state if error during compilation (#20166) (overlookmotel) - 887eecc linter/plugins: Add license notice to `oxlint-plugin-eslint` package (#20164) (overlookmotel) - e1713a4 linter/plugins: Include common chunks in `oxlint-plugin-eslint` package (#20163) (overlookmotel) - a9acb2b linter: Check `globals` entry for `no-undef`, only check es2026 globals for `no-extend-native` and `no-constant-binary-expression` (#20089) (Sysix) - 5559f0d linter/no-unused-vars: `reportUsedIgnorePattern` should not report used rest siblings (#20108) (Don Isaac) - de7c0e2 linter/plugins: Correct error message for `markVariableAsUsed` (#20152) (overlookmotel) ### ⚡ Performance - 3a86427 linter/plugins: Pre-populate cache of `EnterExit` objects at startup (#20194) (overlookmotel) - d243391 linter/plugins: Replace arrays with `Uint8Array`s (#20190) (overlookmotel) - 8742f8b linter/plugins: Pre-populate cache of `VisitProp` objects (#20189) (overlookmotel) - 3061acb linter/plugins: Pre-populate cache of `EnterExit` objects (#20187) (overlookmotel) - c73912b linter/plugins: Free visit functions earlier (#20186) (overlookmotel) - d9f8ff4 linter/plugins: Faster reset of visitor state (#20185) (overlookmotel) - 42aff15 oxlint/lsp: Avoid computing diagnostics for non invoked code actions requests (#20080) (Sysix) ### 📚 Documentation - a080650 linter/plugins: Fix documentation of visitor compilation (#20202) (overlookmotel) - 542a04a linter: Add a link to the cyclomatic complexity Wikipedia article in `eslint/complexity` (#20174) (connorshea) # Oxfmt ### 🚀 Features - 95943aa oxfmt: Support `vite.config.*` `.fmt` field (#20197) (leaysgur) - 172fc07 oxfmt: .js/.ts config file support (#20135) (leaysgur) ### 🐛 Bug Fixes - e483569 oxfmt: Avoid double-escaping in css-in-js (#20211) (leaysgur) Co-authored-by: leaysgur <6259812+leaysgur@users.noreply.github.com>

Fixes #19711, also resolves some of the demands for nested configs.