@bfra.me/eslint-config 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.d.ts +68 -2
- package/lib/index.js +104 -57
- package/package.json +13 -4
- package/src/config.d.ts +2 -1
- package/src/configs/index.ts +1 -0
- package/src/configs/perfectionist.ts +56 -30
- package/src/configs/prettier.ts +38 -0
- package/src/define-config.ts +22 -1
- package/src/options.ts +37 -0
- package/src/plugins.ts +1 -1
- package/src/rules.d.ts +16 -0
package/lib/index.d.ts
CHANGED
|
@@ -2687,6 +2687,10 @@ interface Rules {
|
|
|
2687
2687
|
* @see https://eslint.org/docs/latest/rules/prefer-template
|
|
2688
2688
|
*/
|
|
2689
2689
|
'prefer-template'?: Linter.RuleEntry<[]>
|
|
2690
|
+
/**
|
|
2691
|
+
* @see https://github.com/prettier/eslint-plugin-prettier#options
|
|
2692
|
+
*/
|
|
2693
|
+
'prettier/prettier'?: Linter.RuleEntry<PrettierPrettier>
|
|
2690
2694
|
/**
|
|
2691
2695
|
* Require quotes around object literal property names
|
|
2692
2696
|
* @see https://eslint.org/docs/latest/rules/quote-props
|
|
@@ -6882,6 +6886,18 @@ type PreferReflect = []|[{
|
|
|
6882
6886
|
type PreferRegexLiterals = []|[{
|
|
6883
6887
|
disallowRedundantWrapping?: boolean
|
|
6884
6888
|
}]
|
|
6889
|
+
// ----- prettier/prettier -----
|
|
6890
|
+
type PrettierPrettier = []|[{
|
|
6891
|
+
[k: string]: unknown | undefined
|
|
6892
|
+
}]|[{
|
|
6893
|
+
[k: string]: unknown | undefined
|
|
6894
|
+
}, {
|
|
6895
|
+
usePrettierrc?: boolean
|
|
6896
|
+
fileInfoOptions?: {
|
|
6897
|
+
[k: string]: unknown | undefined
|
|
6898
|
+
}
|
|
6899
|
+
[k: string]: unknown | undefined
|
|
6900
|
+
}]
|
|
6885
6901
|
// ----- quote-props -----
|
|
6886
6902
|
type QuoteProps = ([]|[("always" | "as-needed" | "consistent" | "consistent-as-needed")] | []|[("always" | "as-needed" | "consistent" | "consistent-as-needed")]|[("always" | "as-needed" | "consistent" | "consistent-as-needed"), {
|
|
6887
6903
|
keywords?: boolean
|
|
@@ -7199,6 +7215,7 @@ type ConfigNames =
|
|
|
7199
7215
|
| '@bfra.me/jsdoc'
|
|
7200
7216
|
| '@bfra.me/imports'
|
|
7201
7217
|
| '@bfra.me/command'
|
|
7218
|
+
| '@bfra.me/prettier'
|
|
7202
7219
|
| '@bfra.me/perfectionist'
|
|
7203
7220
|
| '@bfra.me/typescript/plugins'
|
|
7204
7221
|
| '@bfra.me/typescript/parser'
|
|
@@ -7270,6 +7287,32 @@ interface OptionsOverrides {
|
|
|
7270
7287
|
*/
|
|
7271
7288
|
overrides?: Config['rules'];
|
|
7272
7289
|
}
|
|
7290
|
+
/**
|
|
7291
|
+
* Options for configuring the Perfectionist sorting behavior.
|
|
7292
|
+
*/
|
|
7293
|
+
interface OptionsPerfectionist {
|
|
7294
|
+
/**
|
|
7295
|
+
* Whether to sort named exports.
|
|
7296
|
+
*
|
|
7297
|
+
* @default true
|
|
7298
|
+
*/
|
|
7299
|
+
sortNamedExports?: boolean;
|
|
7300
|
+
/**
|
|
7301
|
+
* Whether to sort named imports.
|
|
7302
|
+
* @default true
|
|
7303
|
+
*/
|
|
7304
|
+
sortNamedImports?: boolean;
|
|
7305
|
+
/**
|
|
7306
|
+
* Whether to sort exports.
|
|
7307
|
+
* @default true
|
|
7308
|
+
*/
|
|
7309
|
+
sortExports?: boolean;
|
|
7310
|
+
/**
|
|
7311
|
+
* Whether to sort imports.
|
|
7312
|
+
* @default true
|
|
7313
|
+
*/
|
|
7314
|
+
sortImports?: boolean;
|
|
7315
|
+
}
|
|
7273
7316
|
/**
|
|
7274
7317
|
* Provides options to configure the TypeScript parser and type-aware linting rules.
|
|
7275
7318
|
*
|
|
@@ -7355,6 +7398,14 @@ type Options = Flatten<{
|
|
|
7355
7398
|
* Options to override the behavior of JavaScript-related rules.
|
|
7356
7399
|
*/
|
|
7357
7400
|
javascript?: OptionsOverrides;
|
|
7401
|
+
/**
|
|
7402
|
+
* Options to override the behavior of Perfectionist sorting rules.
|
|
7403
|
+
*/
|
|
7404
|
+
perfectionist?: boolean | OptionsPerfectionist;
|
|
7405
|
+
/**
|
|
7406
|
+
* Options to override the behavior of the Prettier code formatter.
|
|
7407
|
+
*/
|
|
7408
|
+
prettier?: boolean | OptionsOverrides;
|
|
7358
7409
|
/**
|
|
7359
7410
|
* Enable TypeScript support.
|
|
7360
7411
|
*
|
|
@@ -7388,12 +7439,27 @@ declare function javascript(options?: JavaScriptOptions): Promise<Config[]>;
|
|
|
7388
7439
|
|
|
7389
7440
|
declare function jsdoc(): Promise<Config[]>;
|
|
7390
7441
|
|
|
7442
|
+
/**
|
|
7443
|
+
* Represents the combined options for the Perfectionist ESLint plugin, including options for editor integration, overrides, and the Perfectionist plugin itself.
|
|
7444
|
+
*/
|
|
7445
|
+
type PerfectionistOptions = Flatten<OptionsIsInEditor & OptionsOverrides & OptionsPerfectionist>;
|
|
7391
7446
|
/**
|
|
7392
7447
|
* Perfectionist plugin for sorting items and properties.
|
|
7393
7448
|
*
|
|
7394
7449
|
* @see https://github.com/azat-io/eslint-plugin-perfectionist
|
|
7395
7450
|
*/
|
|
7396
|
-
declare function perfectionist(): Promise<Config[]>;
|
|
7451
|
+
declare function perfectionist(options?: PerfectionistOptions): Promise<Config[]>;
|
|
7452
|
+
|
|
7453
|
+
/**
|
|
7454
|
+
* Represents the options for the ESLint Prettier configuration.
|
|
7455
|
+
*/
|
|
7456
|
+
type PrettierOptions = Flatten<OptionsIsInEditor & OptionsOverrides>;
|
|
7457
|
+
/**
|
|
7458
|
+
* Generates an ESLint configuration for Prettier.
|
|
7459
|
+
* @param options - The options for the Prettier configuration.
|
|
7460
|
+
* @returns An array of ESLint configurations.
|
|
7461
|
+
*/
|
|
7462
|
+
declare function prettier(options?: PrettierOptions): Promise<Config[]>;
|
|
7397
7463
|
|
|
7398
7464
|
/**
|
|
7399
7465
|
* Represents the options for configuring the TypeScript ESLint configuration.
|
|
@@ -7477,4 +7543,4 @@ declare const GLOB_TESTS: string[];
|
|
|
7477
7543
|
|
|
7478
7544
|
declare const config: ConfigComposer;
|
|
7479
7545
|
|
|
7480
|
-
export { type AwaitableFlatConfig, type Config, type ConfigComposer, type ConfigNames, type Flatten, GLOB_EXCLUDE, GLOB_SRC, GLOB_SRC_EXT, GLOB_TESTS, GLOB_TS, GLOB_TSX, type JavaScriptOptions, type Options, type OptionsFiles, type OptionsIsInEditor, type OptionsOverrides, type OptionsTypeScript, type OptionsTypeScriptParserOptions, type OptionsTypeScriptWithTypes, type Rules, type TypeScriptOptions, type VitestOptions, command, composeConfig, config, config as default, defineConfig, epilogue, eslintComments, ignores, imports, isInEditor, isInGitLifecycle, javascript, jsdoc, perfectionist, typescript, vitest };
|
|
7546
|
+
export { type AwaitableFlatConfig, type Config, type ConfigComposer, type ConfigNames, type Flatten, GLOB_EXCLUDE, GLOB_SRC, GLOB_SRC_EXT, GLOB_TESTS, GLOB_TS, GLOB_TSX, type JavaScriptOptions, type Options, type OptionsFiles, type OptionsIsInEditor, type OptionsOverrides, type OptionsPerfectionist, type OptionsTypeScript, type OptionsTypeScriptParserOptions, type OptionsTypeScriptWithTypes, type PerfectionistOptions, type PrettierOptions, type Rules, type TypeScriptOptions, type VitestOptions, command, composeConfig, config, config as default, defineConfig, epilogue, eslintComments, ignores, imports, isInEditor, isInGitLifecycle, javascript, jsdoc, perfectionist, prettier, typescript, vitest };
|
package/lib/index.js
CHANGED
|
@@ -139,7 +139,7 @@ import { default as default6 } from "eslint-plugin-unused-imports";
|
|
|
139
139
|
// @__NO_SIDE_EFFECTS__
|
|
140
140
|
async function interopDefault(m) {
|
|
141
141
|
const resolved = await m;
|
|
142
|
-
return resolved.default
|
|
142
|
+
return "default" in resolved ? /* @__PURE__ */ interopDefault(resolved.default) : resolved;
|
|
143
143
|
}
|
|
144
144
|
__name(interopDefault, "interopDefault");
|
|
145
145
|
|
|
@@ -289,7 +289,8 @@ async function jsdoc() {
|
|
|
289
289
|
__name(jsdoc, "jsdoc");
|
|
290
290
|
|
|
291
291
|
// src/configs/perfectionist.ts
|
|
292
|
-
async function perfectionist() {
|
|
292
|
+
async function perfectionist(options = {}) {
|
|
293
|
+
const { isInEditor: isInEditor2 = false, overrides = {}, sortExports = true, sortImports = true, sortNamedExports = true, sortNamedImports = true } = options;
|
|
293
294
|
return [
|
|
294
295
|
{
|
|
295
296
|
name: "@bfra.me/perfectionist",
|
|
@@ -297,67 +298,99 @@ async function perfectionist() {
|
|
|
297
298
|
perfectionist: default5
|
|
298
299
|
},
|
|
299
300
|
rules: {
|
|
300
|
-
|
|
301
|
-
"
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
301
|
+
...sortNamedExports && {
|
|
302
|
+
"perfectionist/sort-named-exports": [
|
|
303
|
+
isInEditor2 ? "warn" : "error",
|
|
304
|
+
{
|
|
305
|
+
groupKind: "values-first",
|
|
306
|
+
type: "natural"
|
|
307
|
+
}
|
|
308
|
+
]
|
|
309
|
+
},
|
|
310
|
+
...sortNamedImports && {
|
|
311
|
+
"perfectionist/sort-named-imports": [
|
|
312
|
+
isInEditor2 ? "warn" : "error",
|
|
313
|
+
{
|
|
314
|
+
groupKind: "values-first",
|
|
315
|
+
type: "natural"
|
|
316
|
+
}
|
|
317
|
+
]
|
|
318
|
+
},
|
|
319
|
+
...sortExports && {
|
|
320
|
+
"perfectionist/sort-exports": [
|
|
321
|
+
isInEditor2 ? "warn" : "error",
|
|
322
|
+
{
|
|
323
|
+
type: "natural"
|
|
324
|
+
}
|
|
325
|
+
]
|
|
326
|
+
},
|
|
327
|
+
...sortImports && {
|
|
328
|
+
"perfectionist/sort-imports": [
|
|
329
|
+
isInEditor2 ? "warn" : "error",
|
|
330
|
+
{
|
|
331
|
+
groups: [
|
|
332
|
+
"type",
|
|
333
|
+
[
|
|
334
|
+
"parent-type",
|
|
335
|
+
"sibling-type",
|
|
336
|
+
"index-type"
|
|
337
|
+
],
|
|
338
|
+
"builtin",
|
|
339
|
+
"external",
|
|
340
|
+
[
|
|
341
|
+
"internal",
|
|
342
|
+
"internal-type"
|
|
343
|
+
],
|
|
344
|
+
[
|
|
345
|
+
"parent",
|
|
346
|
+
"sibling",
|
|
347
|
+
"index"
|
|
348
|
+
],
|
|
349
|
+
"object",
|
|
350
|
+
"side-effect",
|
|
351
|
+
"side-effect-style"
|
|
337
352
|
],
|
|
338
|
-
[
|
|
339
|
-
"
|
|
340
|
-
"sibling",
|
|
341
|
-
"index"
|
|
353
|
+
internalPattern: [
|
|
354
|
+
"^[~#]/.*"
|
|
342
355
|
],
|
|
343
|
-
"
|
|
344
|
-
"
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
],
|
|
350
|
-
newlinesBetween: "ignore",
|
|
351
|
-
order: "asc",
|
|
352
|
-
type: "natural"
|
|
353
|
-
}
|
|
354
|
-
]
|
|
356
|
+
newlinesBetween: "ignore",
|
|
357
|
+
type: "natural"
|
|
358
|
+
}
|
|
359
|
+
]
|
|
360
|
+
},
|
|
361
|
+
...overrides
|
|
355
362
|
}
|
|
356
363
|
}
|
|
357
364
|
];
|
|
358
365
|
}
|
|
359
366
|
__name(perfectionist, "perfectionist");
|
|
360
367
|
|
|
368
|
+
// src/configs/prettier.ts
|
|
369
|
+
async function prettier(options = {}) {
|
|
370
|
+
const { isInEditor: isInEditor2, overrides } = options;
|
|
371
|
+
const [configPrettier, pluginPrettier] = await Promise.all([
|
|
372
|
+
interopDefault(import("eslint-config-prettier")),
|
|
373
|
+
interopDefault(import("eslint-plugin-prettier"))
|
|
374
|
+
]);
|
|
375
|
+
return [
|
|
376
|
+
{
|
|
377
|
+
name: "@bfra.me/prettier",
|
|
378
|
+
plugins: {
|
|
379
|
+
prettier: pluginPrettier
|
|
380
|
+
},
|
|
381
|
+
rules: {
|
|
382
|
+
...configPrettier.rules,
|
|
383
|
+
...(pluginPrettier.configs?.recommended).rules,
|
|
384
|
+
...isInEditor2 ? {} : {
|
|
385
|
+
"prettier/prettier": "error"
|
|
386
|
+
},
|
|
387
|
+
...overrides
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
];
|
|
391
|
+
}
|
|
392
|
+
__name(prettier, "prettier");
|
|
393
|
+
|
|
361
394
|
// src/configs/typescript.ts
|
|
362
395
|
import process from "node:process";
|
|
363
396
|
var TypeAwareRules = {
|
|
@@ -558,7 +591,7 @@ var AllowedConfigPropertiesForOptions = [
|
|
|
558
591
|
"settings"
|
|
559
592
|
];
|
|
560
593
|
async function defineConfig(options = {}, ...userConfigs) {
|
|
561
|
-
const { gitignore: enableGitignore = true, typescript: enableTypeScript = isPackageExists("typescript") } = options;
|
|
594
|
+
const { gitignore: enableGitignore = true, perfectionist: enablePerfectionist = true, prettier: enablePrettier = isPackageExists("prettier"), typescript: enableTypeScript = isPackageExists("typescript") } = options;
|
|
562
595
|
const isInEditor2 = options.isInEditor ?? isInEditor;
|
|
563
596
|
if (isInEditor2) console.log("[@bfra.me/eslint-config] Editor specific config is enabled. Some rules may be disabled.");
|
|
564
597
|
const configs = [];
|
|
@@ -576,7 +609,20 @@ async function defineConfig(options = {}, ...userConfigs) {
|
|
|
576
609
|
configs.push(ignores(options.ignores), javascript({
|
|
577
610
|
isInEditor: isInEditor2,
|
|
578
611
|
overrides: getOverrides(options, "javascript")
|
|
579
|
-
}), eslintComments(), jsdoc(), imports(), command()
|
|
612
|
+
}), eslintComments(), jsdoc(), imports(), command());
|
|
613
|
+
if (enablePrettier) {
|
|
614
|
+
configs.push(prettier({
|
|
615
|
+
isInEditor: isInEditor2,
|
|
616
|
+
overrides: getOverrides(options, "prettier")
|
|
617
|
+
}));
|
|
618
|
+
}
|
|
619
|
+
if (enablePerfectionist) {
|
|
620
|
+
configs.push(perfectionist({
|
|
621
|
+
isInEditor: isInEditor2,
|
|
622
|
+
overrides: getOverrides(options, "perfectionist"),
|
|
623
|
+
...resolveSubOptions(options, "perfectionist")
|
|
624
|
+
}));
|
|
625
|
+
}
|
|
580
626
|
const typescriptOptions = resolveSubOptions(options, "typescript");
|
|
581
627
|
if (enableTypeScript) {
|
|
582
628
|
configs.push(typescript({
|
|
@@ -638,6 +684,7 @@ export {
|
|
|
638
684
|
javascript,
|
|
639
685
|
jsdoc,
|
|
640
686
|
perfectionist,
|
|
687
|
+
prettier,
|
|
641
688
|
typescript,
|
|
642
689
|
vitest
|
|
643
690
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bfra.me/eslint-config",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Shared ESLint configuration for bfra.me",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bfra.me",
|
|
@@ -53,12 +53,15 @@
|
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@eslint/config-inspector": "0.5.6",
|
|
55
55
|
"@eslint/js": "9.15.0",
|
|
56
|
+
"@types/eslint-config-prettier": "6.11.3",
|
|
56
57
|
"@types/fs-extra": "11.0.4",
|
|
57
58
|
"@types/node": "22.10.0",
|
|
58
59
|
"@typescript-eslint/types": "8.16.0",
|
|
59
60
|
"@vitest/eslint-plugin": "1.1.11",
|
|
60
61
|
"eslint": "9.15.0",
|
|
62
|
+
"eslint-config-prettier": "9.1.0",
|
|
61
63
|
"eslint-plugin-no-only-tests": "3.3.0",
|
|
64
|
+
"eslint-plugin-prettier": "5.2.1",
|
|
62
65
|
"eslint-typegen": "0.3.2",
|
|
63
66
|
"execa": "9.5.1",
|
|
64
67
|
"fast-glob": "3.3.2",
|
|
@@ -68,9 +71,9 @@
|
|
|
68
71
|
"tsup": "8.3.5",
|
|
69
72
|
"tsx": "4.19.2",
|
|
70
73
|
"vitest": "2.1.6",
|
|
71
|
-
"@bfra.me/eslint-config": "0.
|
|
72
|
-
"@bfra.me/
|
|
73
|
-
"@bfra.me/
|
|
74
|
+
"@bfra.me/eslint-config": "0.7.0",
|
|
75
|
+
"@bfra.me/prettier-config": "0.13.2",
|
|
76
|
+
"@bfra.me/tsconfig": "0.9.3"
|
|
74
77
|
},
|
|
75
78
|
"peerDependencies": {
|
|
76
79
|
"@vitest/eslint-plugin": "^1.1.4",
|
|
@@ -81,8 +84,14 @@
|
|
|
81
84
|
"@vitest/eslint-plugin": {
|
|
82
85
|
"optional": true
|
|
83
86
|
},
|
|
87
|
+
"eslint-config-prettier": {
|
|
88
|
+
"optional": true
|
|
89
|
+
},
|
|
84
90
|
"eslint-plugin-no-only-tests": {
|
|
85
91
|
"optional": true
|
|
92
|
+
},
|
|
93
|
+
"eslint-plugin-prettier": {
|
|
94
|
+
"optional": true
|
|
86
95
|
}
|
|
87
96
|
},
|
|
88
97
|
"publishConfig": {
|
package/src/config.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type {Linter} from 'eslint'
|
|
|
5
5
|
import type {FlatConfigComposer, ResolvableFlatConfig} from 'eslint-flat-config-utils'
|
|
6
6
|
import type {Rules} from './rules'
|
|
7
7
|
|
|
8
|
-
export type {FlatConfigComposer, ResolvableFlatConfig
|
|
8
|
+
export type {FlatConfigComposer, ResolvableFlatConfig}
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Represents a value that resolves to one or more ESLint flat configurations.
|
|
@@ -39,6 +39,7 @@ export type ConfigNames =
|
|
|
39
39
|
| '@bfra.me/jsdoc'
|
|
40
40
|
| '@bfra.me/imports'
|
|
41
41
|
| '@bfra.me/command'
|
|
42
|
+
| '@bfra.me/prettier'
|
|
42
43
|
| '@bfra.me/perfectionist'
|
|
43
44
|
| '@bfra.me/typescript/plugins'
|
|
44
45
|
| '@bfra.me/typescript/parser'
|
package/src/configs/index.ts
CHANGED
|
@@ -1,12 +1,28 @@
|
|
|
1
1
|
import type {Config} from '../config'
|
|
2
|
+
import type {Flatten, OptionsIsInEditor, OptionsOverrides, OptionsPerfectionist} from '../options'
|
|
2
3
|
import {perfectionist as pluginPerfectionist} from '../plugins'
|
|
3
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Represents the combined options for the Perfectionist ESLint plugin, including options for editor integration, overrides, and the Perfectionist plugin itself.
|
|
7
|
+
*/
|
|
8
|
+
export type PerfectionistOptions = Flatten<
|
|
9
|
+
OptionsIsInEditor & OptionsOverrides & OptionsPerfectionist
|
|
10
|
+
>
|
|
11
|
+
|
|
4
12
|
/**
|
|
5
13
|
* Perfectionist plugin for sorting items and properties.
|
|
6
14
|
*
|
|
7
15
|
* @see https://github.com/azat-io/eslint-plugin-perfectionist
|
|
8
16
|
*/
|
|
9
|
-
export async function perfectionist(): Promise<Config[]> {
|
|
17
|
+
export async function perfectionist(options: PerfectionistOptions = {}): Promise<Config[]> {
|
|
18
|
+
const {
|
|
19
|
+
isInEditor = false,
|
|
20
|
+
overrides = {},
|
|
21
|
+
sortExports = true,
|
|
22
|
+
sortImports = true,
|
|
23
|
+
sortNamedExports = true,
|
|
24
|
+
sortNamedImports = true,
|
|
25
|
+
} = options
|
|
10
26
|
return [
|
|
11
27
|
{
|
|
12
28
|
name: '@bfra.me/perfectionist',
|
|
@@ -14,37 +30,47 @@ export async function perfectionist(): Promise<Config[]> {
|
|
|
14
30
|
perfectionist: pluginPerfectionist as any,
|
|
15
31
|
},
|
|
16
32
|
rules: {
|
|
17
|
-
|
|
18
|
-
'
|
|
19
|
-
|
|
20
|
-
|
|
33
|
+
...(sortNamedExports && {
|
|
34
|
+
'perfectionist/sort-named-exports': [
|
|
35
|
+
isInEditor ? 'warn' : 'error',
|
|
36
|
+
{groupKind: 'values-first', type: 'natural'},
|
|
37
|
+
],
|
|
38
|
+
}),
|
|
39
|
+
|
|
40
|
+
...(sortNamedImports && {
|
|
41
|
+
'perfectionist/sort-named-imports': [
|
|
42
|
+
isInEditor ? 'warn' : 'error',
|
|
43
|
+
{groupKind: 'values-first', type: 'natural'},
|
|
44
|
+
],
|
|
45
|
+
}),
|
|
46
|
+
|
|
47
|
+
...(sortExports && {
|
|
48
|
+
'perfectionist/sort-exports': [isInEditor ? 'warn' : 'error', {type: 'natural'}],
|
|
49
|
+
}),
|
|
21
50
|
|
|
22
|
-
|
|
23
|
-
'
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
51
|
+
...(sortImports && {
|
|
52
|
+
'perfectionist/sort-imports': [
|
|
53
|
+
isInEditor ? 'warn' : 'error',
|
|
54
|
+
{
|
|
55
|
+
groups: [
|
|
56
|
+
'type',
|
|
57
|
+
['parent-type', 'sibling-type', 'index-type'],
|
|
58
|
+
'builtin',
|
|
59
|
+
'external',
|
|
60
|
+
['internal', 'internal-type'],
|
|
61
|
+
['parent', 'sibling', 'index'],
|
|
62
|
+
'object',
|
|
63
|
+
'side-effect',
|
|
64
|
+
'side-effect-style',
|
|
65
|
+
],
|
|
66
|
+
internalPattern: ['^[~#]/.*'],
|
|
67
|
+
newlinesBetween: 'ignore',
|
|
68
|
+
type: 'natural',
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
}),
|
|
27
72
|
|
|
28
|
-
|
|
29
|
-
'error',
|
|
30
|
-
{
|
|
31
|
-
groups: [
|
|
32
|
-
'type',
|
|
33
|
-
['parent-type', 'sibling-type', 'index-type'],
|
|
34
|
-
'builtin',
|
|
35
|
-
'external',
|
|
36
|
-
['internal', 'internal-type'],
|
|
37
|
-
['parent', 'sibling', 'index'],
|
|
38
|
-
'object',
|
|
39
|
-
'side-effect',
|
|
40
|
-
'side-effect-style',
|
|
41
|
-
],
|
|
42
|
-
internalPattern: ['^[~#]/.*'],
|
|
43
|
-
newlinesBetween: 'ignore',
|
|
44
|
-
order: 'asc',
|
|
45
|
-
type: 'natural',
|
|
46
|
-
},
|
|
47
|
-
],
|
|
73
|
+
...overrides,
|
|
48
74
|
},
|
|
49
75
|
},
|
|
50
76
|
]
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type {Config} from '../config'
|
|
2
|
+
import type {Flatten, OptionsIsInEditor, OptionsOverrides} from '../options'
|
|
3
|
+
import {interopDefault} from '../plugins'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Represents the options for the ESLint Prettier configuration.
|
|
7
|
+
*/
|
|
8
|
+
export type PrettierOptions = Flatten<OptionsIsInEditor & OptionsOverrides>
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Generates an ESLint configuration for Prettier.
|
|
12
|
+
* @param options - The options for the Prettier configuration.
|
|
13
|
+
* @returns An array of ESLint configurations.
|
|
14
|
+
*/
|
|
15
|
+
export async function prettier(options: PrettierOptions = {}): Promise<Config[]> {
|
|
16
|
+
const {isInEditor, overrides} = options
|
|
17
|
+
const [configPrettier, pluginPrettier] = await Promise.all([
|
|
18
|
+
interopDefault(import('eslint-config-prettier')),
|
|
19
|
+
interopDefault(import('eslint-plugin-prettier')),
|
|
20
|
+
])
|
|
21
|
+
|
|
22
|
+
return [
|
|
23
|
+
{
|
|
24
|
+
name: '@bfra.me/prettier',
|
|
25
|
+
plugins: {
|
|
26
|
+
prettier: pluginPrettier,
|
|
27
|
+
},
|
|
28
|
+
rules: {
|
|
29
|
+
...configPrettier.rules,
|
|
30
|
+
...(pluginPrettier.configs?.recommended as Config).rules,
|
|
31
|
+
|
|
32
|
+
...(isInEditor ? {} : {'prettier/prettier': 'error'}),
|
|
33
|
+
|
|
34
|
+
...overrides,
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
]
|
|
38
|
+
}
|
package/src/define-config.ts
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
javascript,
|
|
13
13
|
jsdoc,
|
|
14
14
|
perfectionist,
|
|
15
|
+
prettier,
|
|
15
16
|
typescript,
|
|
16
17
|
vitest,
|
|
17
18
|
} from './configs'
|
|
@@ -48,6 +49,8 @@ export async function defineConfig(
|
|
|
48
49
|
): ConfigComposer {
|
|
49
50
|
const {
|
|
50
51
|
gitignore: enableGitignore = true,
|
|
52
|
+
perfectionist: enablePerfectionist = true,
|
|
53
|
+
prettier: enablePrettier = isPackageExists('prettier'),
|
|
51
54
|
typescript: enableTypeScript = isPackageExists('typescript'),
|
|
52
55
|
} = options
|
|
53
56
|
|
|
@@ -80,9 +83,27 @@ export async function defineConfig(
|
|
|
80
83
|
jsdoc(),
|
|
81
84
|
imports(),
|
|
82
85
|
command(),
|
|
83
|
-
perfectionist(),
|
|
84
86
|
)
|
|
85
87
|
|
|
88
|
+
if (enablePrettier) {
|
|
89
|
+
configs.push(
|
|
90
|
+
prettier({
|
|
91
|
+
isInEditor,
|
|
92
|
+
overrides: getOverrides(options, 'prettier'),
|
|
93
|
+
}),
|
|
94
|
+
)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (enablePerfectionist) {
|
|
98
|
+
configs.push(
|
|
99
|
+
perfectionist({
|
|
100
|
+
isInEditor,
|
|
101
|
+
overrides: getOverrides(options, 'perfectionist'),
|
|
102
|
+
...resolveSubOptions(options, 'perfectionist'),
|
|
103
|
+
}),
|
|
104
|
+
)
|
|
105
|
+
}
|
|
106
|
+
|
|
86
107
|
const typescriptOptions = resolveSubOptions(options, 'typescript')
|
|
87
108
|
// const tsconfigPath ='tsconfigPath' in typescriptOptions ? typescriptOptions.tsconfigPath : undefined
|
|
88
109
|
|
package/src/options.ts
CHANGED
|
@@ -42,6 +42,33 @@ export interface OptionsOverrides {
|
|
|
42
42
|
overrides?: Config['rules']
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
/**
|
|
46
|
+
* Options for configuring the Perfectionist sorting behavior.
|
|
47
|
+
*/
|
|
48
|
+
export interface OptionsPerfectionist {
|
|
49
|
+
/**
|
|
50
|
+
* Whether to sort named exports.
|
|
51
|
+
*
|
|
52
|
+
* @default true
|
|
53
|
+
*/
|
|
54
|
+
sortNamedExports?: boolean
|
|
55
|
+
/**
|
|
56
|
+
* Whether to sort named imports.
|
|
57
|
+
* @default true
|
|
58
|
+
*/
|
|
59
|
+
sortNamedImports?: boolean
|
|
60
|
+
/**
|
|
61
|
+
* Whether to sort exports.
|
|
62
|
+
* @default true
|
|
63
|
+
*/
|
|
64
|
+
sortExports?: boolean
|
|
65
|
+
/**
|
|
66
|
+
* Whether to sort imports.
|
|
67
|
+
* @default true
|
|
68
|
+
*/
|
|
69
|
+
sortImports?: boolean
|
|
70
|
+
}
|
|
71
|
+
|
|
45
72
|
/**
|
|
46
73
|
* Provides options to configure the TypeScript parser and type-aware linting rules.
|
|
47
74
|
*
|
|
@@ -140,6 +167,16 @@ export type Options = Flatten<
|
|
|
140
167
|
*/
|
|
141
168
|
javascript?: OptionsOverrides
|
|
142
169
|
|
|
170
|
+
/**
|
|
171
|
+
* Options to override the behavior of Perfectionist sorting rules.
|
|
172
|
+
*/
|
|
173
|
+
perfectionist?: boolean | OptionsPerfectionist
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Options to override the behavior of the Prettier code formatter.
|
|
177
|
+
*/
|
|
178
|
+
prettier?: boolean | OptionsOverrides
|
|
179
|
+
|
|
143
180
|
/**
|
|
144
181
|
* Enable TypeScript support.
|
|
145
182
|
*
|
package/src/plugins.ts
CHANGED
|
@@ -5,7 +5,7 @@ export async function interopDefault<T>(
|
|
|
5
5
|
m: Awaitable<T>,
|
|
6
6
|
): Promise<T extends {default: infer U} ? U : T> {
|
|
7
7
|
const resolved = await m
|
|
8
|
-
return
|
|
8
|
+
return 'default' in resolved ? interopDefault(resolved.default) : resolved
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
// @ts-expect-error - No types
|
package/src/rules.d.ts
CHANGED
|
@@ -2681,6 +2681,10 @@ export interface Rules {
|
|
|
2681
2681
|
* @see https://eslint.org/docs/latest/rules/prefer-template
|
|
2682
2682
|
*/
|
|
2683
2683
|
'prefer-template'?: Linter.RuleEntry<[]>
|
|
2684
|
+
/**
|
|
2685
|
+
* @see https://github.com/prettier/eslint-plugin-prettier#options
|
|
2686
|
+
*/
|
|
2687
|
+
'prettier/prettier'?: Linter.RuleEntry<PrettierPrettier>
|
|
2684
2688
|
/**
|
|
2685
2689
|
* Require quotes around object literal property names
|
|
2686
2690
|
* @see https://eslint.org/docs/latest/rules/quote-props
|
|
@@ -6876,6 +6880,18 @@ type PreferReflect = []|[{
|
|
|
6876
6880
|
type PreferRegexLiterals = []|[{
|
|
6877
6881
|
disallowRedundantWrapping?: boolean
|
|
6878
6882
|
}]
|
|
6883
|
+
// ----- prettier/prettier -----
|
|
6884
|
+
type PrettierPrettier = []|[{
|
|
6885
|
+
[k: string]: unknown | undefined
|
|
6886
|
+
}]|[{
|
|
6887
|
+
[k: string]: unknown | undefined
|
|
6888
|
+
}, {
|
|
6889
|
+
usePrettierrc?: boolean
|
|
6890
|
+
fileInfoOptions?: {
|
|
6891
|
+
[k: string]: unknown | undefined
|
|
6892
|
+
}
|
|
6893
|
+
[k: string]: unknown | undefined
|
|
6894
|
+
}]
|
|
6879
6895
|
// ----- quote-props -----
|
|
6880
6896
|
type QuoteProps = ([]|[("always" | "as-needed" | "consistent" | "consistent-as-needed")] | []|[("always" | "as-needed" | "consistent" | "consistent-as-needed")]|[("always" | "as-needed" | "consistent" | "consistent-as-needed"), {
|
|
6881
6897
|
keywords?: boolean
|