Skip to content

Commit ae1d6ff

Browse files
authored
feat: Make perfectionist configurable inside antfu() (#848)
* Make `perfectionist` configurable inside `antfu()` * Update snapshot * Add the `perfectionist` key in eslint config * Switch position to match test snapshot * Add perfectionist to`CONFIG_PRESET_FULL_ON` consistant * Adjust `full-off` snapshot to reflect result when `perfectionist: false`
1 parent 8d25a37 commit ae1d6ff

8 files changed

Lines changed: 30 additions & 19 deletions

File tree

eslint.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export default antfu(
1919
},
2020
},
2121
formatters: true,
22+
perfectionist: true,
2223
pnpm: true,
2324
type: 'lib',
2425
jsx: {

src/config-presets.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export const CONFIG_PRESET_FULL_ON: OptionsConfig = {
1515
markdown: true,
1616
nextjs: true,
1717
node: true,
18+
perfectionist: true,
1819
pnpm: true,
1920
react: true,
2021
regexp: true,
@@ -49,6 +50,7 @@ export const CONFIG_PRESET_FULL_OFF: OptionsConfig = {
4950
markdown: false,
5051
nextjs: false,
5152
node: false,
53+
perfectionist: false,
5254
pnpm: false,
5355
react: false,
5456
regexp: false,

src/configs/perfectionist.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { TypedFlatConfigItem } from '../types'
1+
import type { OptionsOverrides, TypedFlatConfigItem } from '../types'
22

33
import { pluginPerfectionist } from '../plugins'
44

@@ -7,7 +7,11 @@ import { pluginPerfectionist } from '../plugins'
77
*
88
* @see https://github.com/azat-io/eslint-plugin-perfectionist
99
*/
10-
export async function perfectionist(): Promise<TypedFlatConfigItem[]> {
10+
export async function perfectionist(options: OptionsOverrides): Promise<TypedFlatConfigItem[]> {
11+
const {
12+
overrides = {},
13+
} = options
14+
1115
return [
1216
{
1317
name: 'antfu/perfectionist/setup',
@@ -36,6 +40,8 @@ export async function perfectionist(): Promise<TypedFlatConfigItem[]> {
3640
}],
3741
'perfectionist/sort-named-exports': ['error', { order: 'asc', type: 'natural' }],
3842
'perfectionist/sort-named-imports': ['error', { order: 'asc', type: 'natural' }],
43+
44+
...overrides,
3945
},
4046
},
4147
]

src/factory.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ export function antfu(
103103
jsx: enableJsx = true,
104104
nextjs: enableNextjs = false,
105105
node: enableNode = true,
106+
perfectionist: enablePerfectionist = true,
106107
pnpm: enableCatalogs = !!findUpSync('pnpm-workspace.yaml'),
107108
react: enableReact = false,
108109
regexp: enableRegexp = true,
@@ -165,11 +166,16 @@ export function antfu(
165166
}),
166167
comments(),
167168
command(),
168-
169-
// Optional plugins (installed but not enabled by default)
170-
perfectionist(),
171169
)
172170

171+
if (enablePerfectionist) {
172+
configs.push(
173+
perfectionist({
174+
overrides: getOverrides(options, 'perfectionist'),
175+
}),
176+
)
177+
}
178+
173179
if (enableNode) {
174180
configs.push(
175181
node(),

src/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,13 @@ export interface OptionsConfig extends OptionsComponentExts, OptionsProjectType
425425
*/
426426
unicorn?: boolean | OptionsUnicorn
427427

428+
/**
429+
* Options for eslint-plugin-perfectionist.
430+
*
431+
* @default true
432+
*/
433+
perfectionist?: boolean | OptionsOverrides
434+
428435
/**
429436
* Options for eslint-plugin-import-lite.
430437
*

test/__snapshots__/api/index.snapshot.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export interface OptionsConfig extends OptionsComponentExts, OptionsProjectType
1515
jsx?: boolean | OptionsJSX;
1616
e18e?: boolean | OptionsE18e;
1717
unicorn?: boolean | OptionsUnicorn;
18+
perfectionist?: boolean | OptionsOverrides;
1819
imports?: boolean | OptionsOverrides;
1920
test?: boolean | OptionsOverrides;
2021
vue?: boolean | OptionsVue;
@@ -2006,7 +2007,7 @@ export declare function jsx(_?: OptionsJSX): Promise<TypedFlatConfigItem[]>;
20062007
export declare function markdown(_?: OptionsFiles & OptionsComponentExts & OptionsMarkdown): Promise<TypedFlatConfigItem[]>;
20072008
export declare function nextjs(_?: OptionsOverrides & OptionsFiles): Promise<TypedFlatConfigItem[]>;
20082009
export declare function node(): Promise<TypedFlatConfigItem[]>;
2009-
export declare function perfectionist(): Promise<TypedFlatConfigItem[]>;
2010+
export declare function perfectionist(_: OptionsOverrides): Promise<TypedFlatConfigItem[]>;
20102011
export declare function pnpm(_: OptionsPnpm): Promise<TypedFlatConfigItem[]>;
20112012
export declare function react(_?: OptionsTypeScriptParserOptions & OptionsTypeScriptWithTypes & OptionsReact & OptionsFiles): Promise<TypedFlatConfigItem[]>;
20122013
export declare function regexp(_?: OptionsRegExp & OptionsOverrides): Promise<TypedFlatConfigItem[]>;

test/__snapshots__/api/index.snapshot.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export async function markdown(_) {}
5959
export async function nextjs(_) {}
6060
export async function node() {}
6161
export var parserPlain /* const */
62-
export async function perfectionist() {}
62+
export async function perfectionist(_) {}
6363
export async function pnpm(_) {}
6464
export async function react(_) {}
6565
export async function regexp(_) {}

test/__snapshots__/factory/full-off.snap.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -139,18 +139,6 @@
139139
"command/command",
140140
],
141141
},
142-
{
143-
"name": "antfu/perfectionist/setup",
144-
"plugins": [
145-
"perfectionist",
146-
],
147-
"rules": [
148-
"perfectionist/sort-exports",
149-
"perfectionist/sort-imports",
150-
"perfectionist/sort-named-exports",
151-
"perfectionist/sort-named-imports",
152-
],
153-
},
154142
{
155143
"name": "antfu/e18e/rules",
156144
"plugins": [

0 commit comments

Comments
 (0)