diff --git a/packages/rstack/src/config.ts b/packages/rstack/src/config.ts index 1dfbb9f..3411ffa 100644 --- a/packages/rstack/src/config.ts +++ b/packages/rstack/src/config.ts @@ -5,6 +5,7 @@ import type { RslibConfigDefinition } from '@rslib/core'; import type { RslintConfig } from '@rslint/core'; import type { UserConfig, UserConfigAsyncFn } from '@rspress/core'; import type { RstestConfigExport } from '@rstest/core'; +import type { FmtConfigDefinition } from './fmt/types.ts'; import type { StagedConfig } from './staged.ts'; export type RslintConfigDefinition = RslintConfig | (() => Promise); @@ -16,6 +17,7 @@ export type Configs = { doc?: RspressConfigDefinition; test?: RstestConfigExport; lint?: RslintConfigDefinition; + fmt?: FmtConfigDefinition; staged?: StagedConfig; }; @@ -106,6 +108,12 @@ type Define = { * This config is used by the `rs lint` command. */ lint: (config: RslintConfig | (() => Promise)) => void; + /** + * Defines the Prettier config for formatting. + * + * This config will be used by the `rs fmt` command. + */ + fmt: (config: FmtConfigDefinition) => void; /** * Defines the lint-staged config for staged files. * @@ -133,6 +141,7 @@ export const define: Define = { doc: (config) => setConfig('doc', config), test: (config) => setConfig('test', config), lint: (config) => setConfig('lint', config), + fmt: (config) => setConfig('fmt', config), staged: (config) => setConfig('staged', config), }; diff --git a/packages/rstack/src/fmt/types.ts b/packages/rstack/src/fmt/types.ts new file mode 100644 index 0000000..1aca60d --- /dev/null +++ b/packages/rstack/src/fmt/types.ts @@ -0,0 +1,10 @@ +import type { Config as PrettierConfig } from 'prettier'; + +interface FmtConfig extends PrettierConfig { + /** Gitignore-compatible patterns relative to the Rstack config root. */ + ignorePatterns?: string[]; +} + +type FmtConfigDefinition = FmtConfig | (() => FmtConfig | Promise); + +export type { FmtConfig, FmtConfigDefinition };