-
-
Notifications
You must be signed in to change notification settings - Fork 711
refactor(formatter): Export unified way to get_parse_options #15027
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(formatter): Export unified way to get_parse_options #15027
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors the formatter codebase by centralizing parse options configuration. A new get_parse_options() function is introduced in oxc_formatter to provide a unified way to configure parser options for formatting operations, eliminating duplicated configuration blocks across multiple files.
Key changes:
- Introduced
get_parse_options()function incrates/oxc_formatter/src/service/parse_utils.rsthat returns standardizedParseOptionsfor formatting - Replaced 11 instances of inline
ParseOptionsconfiguration with calls to the new helper function - Moved
oxc_parserfrom dev-dependencies to regular dependencies inoxc_formatter/Cargo.toml
Reviewed Changes
Copilot reviewed 13 out of 14 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/oxc_formatter/src/service/parse_utils.rs | Defines new get_parse_options() function with standard parser configuration for formatting |
| crates/oxc_formatter/src/service/mod.rs | Updates module exports to include parse_utils |
| crates/oxc_formatter/src/lib.rs | Exports the new get_parse_options() function publicly |
| crates/oxc_formatter/Cargo.toml | Moves oxc_parser from dev-dependencies to dependencies |
| tasks/prettier_conformance/src/lib.rs | Replaces inline ParseOptions with get_parse_options() call |
| tasks/benchmark/benches/formatter.rs | Replaces inline ParseOptions with get_parse_options() call |
| napi/playground/src/lib.rs | Replaces inline ParseOptions with get_parse_options() call |
| crates/oxc_language_server/src/formatter/server_formatter.rs | Replaces inline ParseOptions with get_parse_options() call |
| crates/oxc_formatter/tests/ir_transform/mod.rs | Replaces inline ParseOptions with get_parse_options() call |
| crates/oxc_formatter/tests/fixtures/mod.rs | Replaces inline ParseOptions with get_parse_options() call |
| crates/oxc_formatter/examples/sort_imports.rs | Replaces inline ParseOptions with get_parse_options() call |
| crates/oxc_formatter/examples/formatter.rs | Replaces inline ParseOptions with get_parse_options() call |
| apps/oxfmt/src/service.rs | Replaces inline ParseOptions with get_parse_options() call |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
CodSpeed Performance ReportMerging #15027 will not alter performanceComparing Summary
Footnotes |
Merge activity
|
Export `oxc_formatter::get_parse_options` to get this options everywhere.
```rs
ParseOpitons {
parse_regular_expression: false,
// Enable all syntax features
allow_v8_intrinsics: true,
allow_return_outside_function: true,
// `oxc_formatter` expects this to be false
preserve_parens: false,
}
```
cd0ef1d to
5de99c2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! We probably need to export a parse method because we also need to align the SourceType everywhere as well.
Ah~, make sense! I'll do it tomorrow. |
But it will bundle the parser, not sure if this should be done. 🥲 |
|
Now I just remembered that I had noticed that too and given up on doing that! 😅 Let's leave it for now. |
## [1.25.0] - 2025-10-30 ### 💥 BREAKING CHANGES - 659fd37 linter: [**BREAKING**] `tsgolint`: request fixes when necessary (#15048) (camchenry) ### 🚀 Features - ed24d60 linter: Expose tsgolint program diagnostics (#15080) (camc314) - 23660c9 linter: `tsgolint`: handle omitted fixes and suggestions (#15047) (camchenry) - f7bef73 linter/plugins: Scope manager API (#14890) (Arsh) - 3e15cdd linter/strict-boolean-expression: Add rule (#14930) (camc314) - bd74603 linter: Add support for vitest/valid-title rule (#12085) (Tyler Earls) ### 🐛 Bug Fixes - e41dee5 linter/consistent-type-definition: Skip comments when looking for token (#14909) (camc314) - 806f9ba linter: Search system PATH for tsgolint executable (#14861) (magic-akari) - ee68089 linter: Normalize JS plugin names (#15010) (Peter Wagenet) - 597340e ast-tools: Use oxfmt to format generated code (#15064) (camc314) - 5eaaa8e linter: Prevent underflow in count_comment_lines for JSX files (#15026) (ityuany) - 88577a8 import/no-namespace: Remove dot special case (#15032) (Arsh) - 55ee962 linter/vars-on-top: False positive with typescript declare block (#14952) (Hamir Mahal) - 2de9f39 linter/plugins: Fall back to package name if meta.name is missing (#14938) (Peter Wagenet) - 5ace84b linter/no-empty-object-type: Parse `"allowWithName"` as regular expressions (#14943) (Arsh) - 5a2832d editor: Stop client when delete .oxlintrc.json with `oxc.requireConfig` (#14897) (Liang Mi) - 3e29d23 linter: Use aliases when parsing cli rules (#14912) (Arsh) - b94b6aa linter/explicit-module-boundary-types: False negative with export default function (#14905) (camc314) - 7060863 linter/no-standaline-expect: False positive with expect in callback (#14902) (camc314) - dc5a71b linter/no-accumulating-spread: False positive in nested callbacks within reduce (#14898) (camc314) ### 🚜 Refactor - 8d8d508 editor: Flatten `flags` options (#15006) (Sysix) - b1e1531 language_server: Extract library interface from main.rs (#15036) (Boshen) - 5de99c2 formatter: Export unified way to get_parse_options (#15027) (leaysgur) - b55df7f language_server: Move sub option for `flags` to the root + deprecate flags (#14933) (Sysix) ### 📚 Documentation - e15c91c linter: Add configuration option docs for eslint/init-declarations rule. (#15085) (Connor Shea) - f4505bc linter: Add configuration option docs for eslint/id-length rule. (#15083) (Connor Shea) - dd4c9d2 linter: Add configuration option docs for eslint/getter-return rule. (#15081) (Connor Shea) - 008e67a linter: Add configuration option docs for jest/no-large-snapshots rule. (#15079) (Connor Shea) - 31daf79 linter: Add configuration option docs for import/no-commonjs rule. (#15077) (Connor Shea) - 9bf8ebe linter: Add configuration option docs for jsdoc/check-tag-names rule. (#15076) (Connor Shea) - 491ab5e linter: Add configuration option docs for jsdoc/no-defaults rule. (#15074) (Connor Shea) - 2602d7e linter: Add configuration option docs for jsdoc/empty-tags rule. (#15072) (Connor Shea) - c3a92e0 linter: Add configuration option docs for oxc/no-rest-spread-properties rule. (#15070) (Connor Shea) - c7c9213 linter: Add configuration option docs for oxc/no-optional-chaining rule. (#15071) (Connor Shea) - 47a616f linter: Add configuration option docs for typescript/no-empty-object-type rule. (#14968) (Connor Shea) - fcc1e25 linter: Add configuration option docs for typescript/no-explicit-any rule. (#15051) (Connor Shea) - 1b88934 linter: Add configuration option docs for eslint/no-multi-assign rule. (#15052) (Connor Shea) - 909d4b9 linter: Add configuration option docs for eslint/no-unsafe-negation rule. (#15053) (Connor Shea) - f60763b linter: Add configuration option docs for eslint/no-useless-computed-key rule. (#15054) (Connor Shea) - c8911d4 linter: Add configuration option docs for eslint/no-unneeded-ternary rule. (#15056) (Connor Shea) - 9fc6374 linter: Add configuration option docs for eslint/no-misleading-character-class rule. (#15058) (Connor Shea) - 7656e2b linter: Add configuration option docs for eslint/sort-imports rule. (#15013) (Connor Shea) - bb06039 linter: Add configuration option docs for unicorn/no-instanceof-builtins rule. (#14999) (Connor Shea) - a4af5ff linter: Add configuration option docs for unicorn/no-typeof-undefined rule. (#15001) (Connor Shea) - ac2ed39 linter: Add configuration option docs for unicorn/numeric-separators-style rule. (#15002) (Connor Shea) - 5ce3e33 linter: Add configuration option docs for unicorn/prefer-object-from-entries rule. (#15003) (Connor Shea) - 07aea72 linter: Add configuration option docs for eslint/sort-keys rule. (#15014) (Connor Shea) - 35b36e0 linter: Add configuration option docs for eslint/no-eval rule. (#15015) (Connor Shea) - d222b85 linter: Add configuration option docs for eslint/no-empty rule. (#15017) (Connor Shea) - 83bbc37 linter: Add configuration option docs for eslint/no-extend-native rule. (#15018) (Connor Shea) - aade2fe linter: Add configuration option docs for eslint/no-extra-boolean-cast rule. (#15019) (Connor Shea) - bae0c09 linter: Add configuration option docs for jsdoc/require-yields rule. (#15024) (Connor Shea) - 06c77b6 linter: Add configuration option docs for unicorn/prefer-at rule. (#15023) (Connor Shea) - 54b2cb4 linter: Add configuration option docs for eslint/max-classes-per-file rule. (#15022) (Connor Shea) - b5acda7 linter: Add configuration option docs for typescript/explicit-module-boundary-types rule. (#15021) (Connor Shea) - a0c6162 linter: Add configuration option docs for vue/max-props rule. (#14966) (Connor Shea) - 3ec59c0 linter: Add configuration option docs for no-async-endpoint-handlers rule. (#14965) (Connor Shea) - 7a275fd linter: Add configuration option docs for no-map-spread rule. (#14964) (Connor Shea) - 0002b7c linter: Add configuration option docs for no-barrel-file rule. (#14963) (Connor Shea) - fd4b7ab linter: Add configuration option docs for unicorn/consistent-function-scoping rule. (#14969) (Connor Shea) - aa339b3 linter: Add configuration option docs for eslint/no-void rule. (#14970) (Connor Shea) - af8bdae linter: Add configuration option docs for import/no-anonymous-default-export rule. (#14971) (Connor Shea) - 5a81953 linter: Add configuration option docs for jest/require-hook rule. (#14972) (Connor Shea) - 1be268d linter: Add configuration option docs for jest/require-top-level-describe rule. (#14973) (Connor Shea) - 860a58c linter: Add configuration option docs for jest/no-hooks rule. (#14974) (Connor Shea) - b69b586 linter: Add configuration option docs for jest/max-expects rule. (#14975) (Connor Shea) - 2e02fe0 linter: Add configuration option docs for jest/no-deprecated-functions rule (#14976) (Connor Shea) - cdc6c4f linter: Add configuration option docs for unicorn/no-array-sort rule. (#14977) (Connor Shea) - 40eb394 linter/no-unassigned-import-config: Add auto generated config docs (#14918) (camc314) ### ⚡ Performance - a9f68b2 linter: Move up rule retainment into initial collection to reduce allocation size (#14822) (camchenry) - b27c5b9 linter: Add codegen support for regex nodes (#14874) (camchenry) ### 🧪 Testing - bf898e5 linter: Increase stability of tsgolint test cases (#15063) (camc314) - 49da411 linter/no-standalone-expect: Fix tests (#14901) (camc314) Co-authored-by: camc314 <18101008+camc314@users.noreply.github.com>
## [0.9.0] - 2025-10-30 ### 🚀 Features - 8fe7e85 formatter: Support printing Formatter IR (#14855) (Dunqing) ### 🐛 Bug Fixes - a6b6ef8 formatter: Correct calculating layout for `TSNonNullExpression` in `StaticMemberExpression` (#15065) (Dunqing) - 99bd995 formatter: Print parenthesis for sequence expression in `ReturnStatement` and `ExpressionStatement` (#15062) (Dunqing) - f3fb998 formatter: Correct printing comments for `TSAsExpression` (#15061) (Dunqing) - 1e4a018 formatter: Correct checking of the short argument for `CallArguments` (#15055) (Dunqing) - c0dfd9b formatter: Print comments before fat arrow as-is for `ArrowFunctionExpression` (#15050) (Dunqing) - 206b519 formatter: Should hug parameter with `TSMappedType` type annotation (#15049) (Dunqing) - e48c604 formatter: Incorrect formatting of a function with `this` parameter (#15031) (Dunqing) - a9f0c45 formatter: Decorators and class method on the same line shouldn't be broken by a leading comment of the method (#15029) (Dunqing) - 43d74e4 formatter: Handle `<CRLF>` for `SourceText` (#15016) (leaysgur) - 34fab40 formatter: Correct calculating layout for `ChainExpression` in `StaticMemberExpression` (#14986) (Dunqing) - 68dc101 formatter: Should not break when the parent of root of `StaticMemberExpression` is used as the `Argument` of `NewExpression` (#14985) (Dunqing) - 071b739 formatter: Align the short argument handling for UnaryExpression with Prettier (#14984) (Dunqing) - 3940f3a formatter: `BestFitting` doesn't exactly matches the `conditinalGroup` behavior in Prettier (#14983) (Dunqing) - 4a84e44 formatter: Align the logic of printing type parameters, parameters, and return type for functions with Prettier (#14942) (Dunqing) - 68c1f2a formatter: Non-nested static member expressions will never break (#14929) (Dunqing) - 42adc47 formatter: Check whether a type alias is complex when its right hand side never break (#14928) (Dunqing) - e501f13 formatter: Should not add a trailing comma for long curried calls when `trailingComma` is es5 (#14913) (Dunqing) ### 🚜 Refactor - 7d64291 formatter: Simplify printing ClassElement with a semicolon (#15030) (Dunqing) - 5de99c2 formatter: Export unified way to get_parse_options (#15027) (leaysgur) - f6f22e2 formatter: Clean up unneeded implementations for printing comments (#14935) (Dunqing) - 7a2b9d1 formatter: Improve printing trailing comments (#14934) (Dunqing) - ba10caa formatter: Align printing trailing comments with Prettier (#14927) (Dunqing) - 597c9e8 formatter: Remove redundunt public API (#14915) (leaysgur) ### ⚡ Performance - 467b3a1 formatter: Optimize grouping logic for call arguments (#15033) (Dunqing) Co-authored-by: leaysgur <6259812+leaysgur@users.noreply.github.com>
## [0.9.0] - 2025-10-30 ### 🚀 Features - 8fe7e85 formatter: Support printing Formatter IR (#14855) (Dunqing) ### 🐛 Bug Fixes - a6b6ef8 formatter: Correct calculating layout for `TSNonNullExpression` in `StaticMemberExpression` (#15065) (Dunqing) - 99bd995 formatter: Print parenthesis for sequence expression in `ReturnStatement` and `ExpressionStatement` (#15062) (Dunqing) - f3fb998 formatter: Correct printing comments for `TSAsExpression` (#15061) (Dunqing) - 1e4a018 formatter: Correct checking of the short argument for `CallArguments` (#15055) (Dunqing) - c0dfd9b formatter: Print comments before fat arrow as-is for `ArrowFunctionExpression` (#15050) (Dunqing) - 206b519 formatter: Should hug parameter with `TSMappedType` type annotation (#15049) (Dunqing) - e48c604 formatter: Incorrect formatting of a function with `this` parameter (#15031) (Dunqing) - a9f0c45 formatter: Decorators and class method on the same line shouldn't be broken by a leading comment of the method (#15029) (Dunqing) - 43d74e4 formatter: Handle `<CRLF>` for `SourceText` (#15016) (leaysgur) - 34fab40 formatter: Correct calculating layout for `ChainExpression` in `StaticMemberExpression` (#14986) (Dunqing) - 68dc101 formatter: Should not break when the parent of root of `StaticMemberExpression` is used as the `Argument` of `NewExpression` (#14985) (Dunqing) - 071b739 formatter: Align the short argument handling for UnaryExpression with Prettier (#14984) (Dunqing) - 3940f3a formatter: `BestFitting` doesn't exactly matches the `conditinalGroup` behavior in Prettier (#14983) (Dunqing) - 4a84e44 formatter: Align the logic of printing type parameters, parameters, and return type for functions with Prettier (#14942) (Dunqing) - 68c1f2a formatter: Non-nested static member expressions will never break (#14929) (Dunqing) - 42adc47 formatter: Check whether a type alias is complex when its right hand side never break (#14928) (Dunqing) - e501f13 formatter: Should not add a trailing comma for long curried calls when `trailingComma` is es5 (#14913) (Dunqing) ### 🚜 Refactor - 7d64291 formatter: Simplify printing ClassElement with a semicolon (#15030) (Dunqing) - 5de99c2 formatter: Export unified way to get_parse_options (#15027) (leaysgur) - f6f22e2 formatter: Clean up unneeded implementations for printing comments (#14935) (Dunqing) - 7a2b9d1 formatter: Improve printing trailing comments (#14934) (Dunqing) - ba10caa formatter: Align printing trailing comments with Prettier (#14927) (Dunqing) - 597c9e8 formatter: Remove redundunt public API (#14915) (leaysgur) ### ⚡ Performance - 467b3a1 formatter: Optimize grouping logic for call arguments (#15033) (Dunqing) ### 💼 Other - aceff66 oxfmt: V0.9.0 (#15088) (Boshen)
## [0.9.0] - 2025-10-30 ### 🚀 Features - 8fe7e85 formatter: Support printing Formatter IR (#14855) (Dunqing) ### 🐛 Bug Fixes - a6b6ef8 formatter: Correct calculating layout for `TSNonNullExpression` in `StaticMemberExpression` (#15065) (Dunqing) - 99bd995 formatter: Print parenthesis for sequence expression in `ReturnStatement` and `ExpressionStatement` (#15062) (Dunqing) - f3fb998 formatter: Correct printing comments for `TSAsExpression` (#15061) (Dunqing) - 1e4a018 formatter: Correct checking of the short argument for `CallArguments` (#15055) (Dunqing) - c0dfd9b formatter: Print comments before fat arrow as-is for `ArrowFunctionExpression` (#15050) (Dunqing) - 206b519 formatter: Should hug parameter with `TSMappedType` type annotation (#15049) (Dunqing) - e48c604 formatter: Incorrect formatting of a function with `this` parameter (#15031) (Dunqing) - a9f0c45 formatter: Decorators and class method on the same line shouldn't be broken by a leading comment of the method (#15029) (Dunqing) - 43d74e4 formatter: Handle `<CRLF>` for `SourceText` (#15016) (leaysgur) - 34fab40 formatter: Correct calculating layout for `ChainExpression` in `StaticMemberExpression` (#14986) (Dunqing) - 68dc101 formatter: Should not break when the parent of root of `StaticMemberExpression` is used as the `Argument` of `NewExpression` (#14985) (Dunqing) - 071b739 formatter: Align the short argument handling for UnaryExpression with Prettier (#14984) (Dunqing) - 3940f3a formatter: `BestFitting` doesn't exactly matches the `conditinalGroup` behavior in Prettier (#14983) (Dunqing) - 4a84e44 formatter: Align the logic of printing type parameters, parameters, and return type for functions with Prettier (#14942) (Dunqing) - 68c1f2a formatter: Non-nested static member expressions will never break (#14929) (Dunqing) - 42adc47 formatter: Check whether a type alias is complex when its right hand side never break (#14928) (Dunqing) - e501f13 formatter: Should not add a trailing comma for long curried calls when `trailingComma` is es5 (#14913) (Dunqing) ### 🚜 Refactor - 7d64291 formatter: Simplify printing ClassElement with a semicolon (#15030) (Dunqing) - 5de99c2 formatter: Export unified way to get_parse_options (#15027) (leaysgur) - f6f22e2 formatter: Clean up unneeded implementations for printing comments (#14935) (Dunqing) - 7a2b9d1 formatter: Improve printing trailing comments (#14934) (Dunqing) - ba10caa formatter: Align printing trailing comments with Prettier (#14927) (Dunqing) - 597c9e8 formatter: Remove redundunt public API (#14915) (leaysgur) ### ⚡ Performance - 467b3a1 formatter: Optimize grouping logic for call arguments (#15033) (Dunqing) ### 💼 Other - 6368793 oxfmt: V0.9.0 (#15091) (Boshen) - aceff66 oxfmt: V0.9.0 (#15088) (Boshen)

Export
oxc_formatter::get_parse_optionsto get this options everywhere.