Adding Formatter Options
Formatter options cross crate and application boundaries. Changing only core ConfigConfig can leave the CLI, WASM bindings, embedded package, playground, or docs with stale values.
- Add the field to
crates/typstyle-core/src/config.rscrates/typstyle-core/src/config.rs, set itsConfig::default()Config::default()value, and add a builder method when useful to library callers. - Update every formatter path that reads it; search for the field and related builder methods.
❗Important
Adding, removing, or changing a public
ConfigConfig field changes the Rust API. Decide whether the release may be breaking and migrate every in-workspace consumer together.- Add the argument/value enum in
crates/typstyle/src/cli.rscrates/typstyle/src/cli.rsand map it to coreConfigConfigincrates/typstyle/src/fmt.rscrates/typstyle/src/fmt.rs. - Preserve existing invocations when extending a boolean flag into an optional value. Require
==for values so paths are not consumed:--wrap-text=sentence--wrap-text=sentence, while--wrap-text file.typ--wrap-text file.typremains valid. - Test positional paths and invalid values in
crates/typstyle/tests/test_style_args.rscrates/typstyle/tests/test_style_args.rs. - Run
just generate-cli-helpjust generate-cli-helpand update copied help text inREADME.mdREADME.md.
- Update direct
ConfigConfigliterals incrates/crates/andtests/tests/; updatetests/src/common/directive.rstests/src/common/directive.rsif fixtures need to select the option. - Add focused semantic tests and representative fixture snapshots. Keep convergence and consistency checks enabled unless disabling them is understood and documented.
Before considering migration complete, search the repository and check the workspace:
rg 'old_field|OldVariant' --glob '!target/**'cargo check --workspace
rg 'old_field|OldVariant' --glob '!target/**'cargo check --workspace
ConfigConfig is deserialized by typstyle-wasmtypstyle-wasm and typstyle-typlugintypstyle-typlugin. For serialized options:
- Test serde serialization and deserialization in
typstyle-coretypstyle-core. - Ensure
crates/typstyle-wasm/build.rscrates/typstyle-wasm/build.rstranslates the field type into the generated TypeScriptConfigConfiginterface and honors serde names instead of Rust variant names. - Update defaults in
contrib/typstyle-embedded/src/lib.typcontrib/typstyle-embedded/src/lib.typand its README. - Update
docs/pages/docs/pages/render directives: examples use embedded-plugin configuration, not CLI argument names. Runjust build-pluginjust build-pluginbefore building docs.
- Update
FormatOptionsFormatOptions, defaults, andformatOptionsToConfigformatOptionsToConfiginplayground/src/utils/formatter.tsplayground/src/utils/formatter.ts, plus the control inplayground/src/components/forms/SettingsPanel.tsxplayground/src/components/forms/SettingsPanel.tsx. - Update URL-state expectations if the option name or type changed, and add a WASM binding test for its serialized value.
-
Rebuild generated bindings before TypeScript validation:
cd playgroundpnpm build:wasmpnpm buildpnpm test:runcd playgroundpnpm build:wasmpnpm buildpnpm test:run
Run checks appropriate to every touched boundary:
cargo fmt --checkcargo check --workspacecargo clippy --workspace --all-targets --all-featurescargo nextest run --workspace --no-fail-fastjust build-docs
cargo fmt --checkcargo check --workspacecargo clippy --workspace --all-targets --all-featurescargo nextest run --workspace --no-fail-fastjust build-docs
For behavior changes, review snapshots and test narrow widths, inline markup, comments, line-sensitive markup markers, and repeated formatting for convergence.