Skip to content

Commit 3aac6af

Browse files
committed
fix: resolve type errors in formatters, jsonc, and yaml configs
Make mergePrettierOptions generic to preserve parser type from overrides. Normalize StylisticConfig indent to handle array form of IndentRuleOptions.
1 parent dc7eccf commit 3aac6af

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

src/configs/formatters.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import { GLOB_CSS, GLOB_LESS, GLOB_MARKDOWN, GLOB_POSTCSS, GLOB_SCSS, GLOB_XML }
44
import { ensurePackages, interopDefault, isPackageInScope, parserPlain } from '../utils';
55
import { StylisticConfigDefaults } from './stylistic';
66

7-
function mergePrettierOptions(
7+
function mergePrettierOptions<T extends VendoredPrettierRuleOptions>(
88
options: VendoredPrettierOptions,
9-
overrides: VendoredPrettierRuleOptions = {},
10-
): VendoredPrettierRuleOptions {
9+
overrides: T,
10+
): VendoredPrettierOptions & T {
1111
return {
1212
...options,
1313
...overrides,
@@ -37,14 +37,16 @@ export async function formatters(
3737
]);
3838

3939
const {
40-
indent,
40+
indent: rawIndent,
4141
quotes,
4242
semi,
4343
} = {
4444
...StylisticConfigDefaults,
4545
...stylistic,
4646
};
4747

48+
const indent = Array.isArray(rawIndent) ? rawIndent[0] : rawIndent;
49+
4850
const prettierOptions: VendoredPrettierOptions = Object.assign(
4951
{
5052
endOfLine: 'auto',

src/configs/jsonc.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ export async function jsonc(
1212
} = options;
1313

1414
const {
15-
indent = 2,
15+
indent: rawIndent = 2,
1616
} = typeof stylistic === 'boolean' ? {} : stylistic;
1717

18+
const indent = Array.isArray(rawIndent) ? rawIndent[0] : rawIndent;
19+
1820
const [
1921
pluginJsonc,
2022
parserJsonc,

src/configs/yaml.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ export async function yaml(
1212
} = options;
1313

1414
const {
15-
indent = 2,
15+
indent: rawIndent = 2,
1616
quotes = 'single',
1717
} = typeof stylistic === 'boolean' ? {} : stylistic;
1818

19+
const indent = Array.isArray(rawIndent) ? rawIndent[0] : rawIndent;
20+
1921
const [
2022
pluginYaml,
2123
parserYaml,

0 commit comments

Comments
 (0)