Skip to content

Commit 4d14fb7

Browse files
committed
feat(fmt): add define.fmt config registration
1 parent ed15b80 commit 4d14fb7

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

packages/rstack/src/config.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { RslibConfigDefinition } from '@rslib/core';
55
import type { RslintConfig } from '@rslint/core';
66
import type { UserConfig, UserConfigAsyncFn } from '@rspress/core';
77
import type { RstestConfigExport } from '@rstest/core';
8+
import type { FmtConfigDefinition } from './fmt/types.ts';
89
import type { StagedConfig } from './staged.ts';
910

1011
export type RslintConfigDefinition = RslintConfig | (() => Promise<RslintConfig>);
@@ -16,6 +17,7 @@ export type Configs = {
1617
doc?: RspressConfigDefinition;
1718
test?: RstestConfigExport;
1819
lint?: RslintConfigDefinition;
20+
fmt?: FmtConfigDefinition;
1921
staged?: StagedConfig;
2022
};
2123

@@ -106,6 +108,12 @@ type Define = {
106108
* This config is used by the `rs lint` command.
107109
*/
108110
lint: (config: RslintConfig | (() => Promise<RslintConfig>)) => void;
111+
/**
112+
* Defines the Prettier config for formatting.
113+
*
114+
* This config will be used by the `rs fmt` command.
115+
*/
116+
fmt: (config: FmtConfigDefinition) => void;
109117
/**
110118
* Defines the lint-staged config for staged files.
111119
*
@@ -133,6 +141,7 @@ export const define: Define = {
133141
doc: (config) => setConfig('doc', config),
134142
test: (config) => setConfig('test', config),
135143
lint: (config) => setConfig('lint', config),
144+
fmt: (config) => setConfig('fmt', config),
136145
staged: (config) => setConfig('staged', config),
137146
};
138147

packages/rstack/src/fmt/types.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import type { Config as PrettierConfig } from 'prettier';
2+
3+
interface FmtConfig extends PrettierConfig {
4+
/** Gitignore-compatible patterns relative to the Rstack config root. */
5+
ignorePatterns?: string[];
6+
}
7+
8+
type FmtConfigDefinition = FmtConfig | (() => FmtConfig | Promise<FmtConfig>);
9+
10+
export type { FmtConfig, FmtConfigDefinition };

0 commit comments

Comments
 (0)