@chanyuxi/eslint-waltz 1.1.0 → 1.1.1
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/README.md +2 -2
- package/dist/index.d.ts +11 -9
- package/dist/index.js +94 -62
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@ The following configuration modules are available:
|
|
|
19
19
|
- JSONC and imports are enabled by default and can be disabled with `json: false` and `imports: false`.
|
|
20
20
|
- TypeScript, React, Tailwind CSS, and gitignore support are opt-in.
|
|
21
21
|
|
|
22
|
-
The `stylistic` configuration is always enabled. Perfectionist is enabled by default with
|
|
22
|
+
The `stylistic` configuration is always enabled. Perfectionist is enabled by default with the `recommended-alphabetical` preset.
|
|
23
23
|
|
|
24
24
|
# Usage
|
|
25
25
|
|
|
@@ -33,7 +33,7 @@ pnpm add -D @chanyuxi/eslint-waltz eslint @eslint/js @stylistic/eslint-plugin es
|
|
|
33
33
|
|
|
34
34
|
Install the peer packages for any optional modules you enable, such as `typescript-eslint`, `eslint-plugin-tailwindcss`, `tailwindcss`, or the React ESLint plugins.
|
|
35
35
|
|
|
36
|
-
Perfectionist
|
|
36
|
+
Perfectionist uses the `recommended-alphabetical` preset by default. Use `perfectionist: { preset: 'recommended-custom' }`, `recommended-line-length`, or `recommended-natural` to select another recommended preset. ESLint 10 and the current integrations require Node.js `>=20.19.0`.
|
|
37
37
|
|
|
38
38
|
Tailwind CSS support targets `eslint-plugin-tailwindcss` 4.x and Tailwind CSS 4.x. Node.js `>=20.19.0` is required when the Tailwind CSS module is enabled.
|
|
39
39
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import globals from 'globals';
|
|
2
1
|
import { Linter } from 'eslint';
|
|
3
2
|
import { FlatGitignoreOptions } from 'eslint-config-flat-gitignore';
|
|
4
3
|
import { PluginSettings } from 'eslint-plugin-tailwindcss';
|
|
4
|
+
import globals from 'globals';
|
|
5
5
|
|
|
6
6
|
/* eslint-disable */
|
|
7
7
|
/* prettier-ignore */
|
|
@@ -9886,8 +9886,8 @@ interface PerfectionistOptions extends SharedOptions {
|
|
|
9886
9886
|
/**
|
|
9887
9887
|
* Select one of Perfectionist's full recommended presets.
|
|
9888
9888
|
*
|
|
9889
|
-
* Without a preset,
|
|
9890
|
-
* default. A preset
|
|
9889
|
+
* Without a preset, the `recommended-alphabetical` preset is enabled by
|
|
9890
|
+
* default. A preset selects one of the plugin's recommended presets.
|
|
9891
9891
|
*/
|
|
9892
9892
|
preset?: PerfectionistPreset;
|
|
9893
9893
|
/**
|
|
@@ -9942,7 +9942,8 @@ interface WaltzOptions {
|
|
|
9942
9942
|
*/
|
|
9943
9943
|
gitignore?: boolean | FlatGitignoreOptions;
|
|
9944
9944
|
/**
|
|
9945
|
-
* Enable rules for validating
|
|
9945
|
+
* Enable rules for validating imports and exports. Import ordering is
|
|
9946
|
+
* provided by Perfectionist when enabled, and by `imports/order` otherwise.
|
|
9946
9947
|
*
|
|
9947
9948
|
* This configuration is enabled by default. JavaScript files are included
|
|
9948
9949
|
* by default, and the scope also includes TypeScript files when `ts` is
|
|
@@ -9968,8 +9969,9 @@ interface WaltzOptions {
|
|
|
9968
9969
|
* Enable linting for JSON, JSON5, and JSONC files.
|
|
9969
9970
|
*
|
|
9970
9971
|
* The default configuration also sorts keys in `package.json` and
|
|
9971
|
-
* TypeScript configuration files.
|
|
9972
|
-
*
|
|
9972
|
+
* TypeScript configuration files. Passing `files` changes the scope of the
|
|
9973
|
+
* general JSON rules; the specialized file sorting remains targeted to
|
|
9974
|
+
* those file names.
|
|
9973
9975
|
*
|
|
9974
9976
|
* @default true
|
|
9975
9977
|
* @see https://github.com/ota-meshi/eslint-plugin-jsonc
|
|
@@ -9978,9 +9980,9 @@ interface WaltzOptions {
|
|
|
9978
9980
|
/**
|
|
9979
9981
|
* Configure Perfectionist sorting rules.
|
|
9980
9982
|
*
|
|
9981
|
-
* This configuration is enabled by default with
|
|
9982
|
-
* `
|
|
9983
|
-
* a `preset` to
|
|
9983
|
+
* This configuration is enabled by default with the
|
|
9984
|
+
* `recommended-alphabetical` preset. Set it to `false` to disable it, or
|
|
9985
|
+
* pass a `preset` to select one of the recommended configurations.
|
|
9984
9986
|
*
|
|
9985
9987
|
* @default true
|
|
9986
9988
|
* @see https://perfectionist.dev/configs
|
package/dist/index.js
CHANGED
|
@@ -72,10 +72,56 @@ const TS_FILES = '**/*.?([cm])ts?(x)';
|
|
|
72
72
|
const JSON_FILES = '**/*.{json,json5,jsonc}';
|
|
73
73
|
const ALL_SCRIPTS_FILES = [JS_FILES, TS_FILES];
|
|
74
74
|
|
|
75
|
-
async function importsConfig(isEnableTypeScript = false, options = {}) {
|
|
75
|
+
async function importsConfig(isEnableTypeScript = false, options = {}, relative = {}) {
|
|
76
76
|
const importsPlugin = await importImportXPlugin();
|
|
77
77
|
const scriptFiles = isEnableTypeScript ? ALL_SCRIPTS_FILES : [JS_FILES];
|
|
78
78
|
const files = options.files ?? scriptFiles;
|
|
79
|
+
const { 'imports/order': orderOverride, ...overrides } = options.overrides ?? {};
|
|
80
|
+
const orderRules = {
|
|
81
|
+
'imports/order': orderOverride ?? [
|
|
82
|
+
'error',
|
|
83
|
+
{
|
|
84
|
+
'alphabetize': {
|
|
85
|
+
caseInsensitive: true,
|
|
86
|
+
order: 'asc',
|
|
87
|
+
orderImportKind: 'asc',
|
|
88
|
+
},
|
|
89
|
+
'distinctGroup': false,
|
|
90
|
+
'groups': [
|
|
91
|
+
'builtin',
|
|
92
|
+
'external',
|
|
93
|
+
'parent',
|
|
94
|
+
'sibling',
|
|
95
|
+
'index',
|
|
96
|
+
'type',
|
|
97
|
+
['object', 'unknown'],
|
|
98
|
+
],
|
|
99
|
+
'named': true,
|
|
100
|
+
'newlines-between': 'always',
|
|
101
|
+
'pathGroups': [
|
|
102
|
+
{
|
|
103
|
+
group: 'internal',
|
|
104
|
+
pattern: '@/**',
|
|
105
|
+
position: 'before',
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
group: 'unknown',
|
|
109
|
+
pattern: '*.{css,scss,less}',
|
|
110
|
+
patternOptions: { matchBase: true },
|
|
111
|
+
position: 'after',
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
group: 'unknown',
|
|
115
|
+
pattern: '*.{svg,png,jpg,gif,webp}',
|
|
116
|
+
patternOptions: { matchBase: true },
|
|
117
|
+
position: 'after',
|
|
118
|
+
},
|
|
119
|
+
],
|
|
120
|
+
'pathGroupsExcludedImportTypes': ['builtin'],
|
|
121
|
+
'warnOnUnassignedImports': true,
|
|
122
|
+
},
|
|
123
|
+
],
|
|
124
|
+
};
|
|
79
125
|
return [
|
|
80
126
|
{
|
|
81
127
|
files,
|
|
@@ -95,52 +141,17 @@ async function importsConfig(isEnableTypeScript = false, options = {}) {
|
|
|
95
141
|
'imports/no-duplicates': 'warn',
|
|
96
142
|
'imports/no-named-as-default': 'warn',
|
|
97
143
|
'imports/no-named-as-default-member': 'warn',
|
|
98
|
-
|
|
99
|
-
'error',
|
|
100
|
-
{
|
|
101
|
-
'groups': [
|
|
102
|
-
'builtin',
|
|
103
|
-
'external',
|
|
104
|
-
'parent',
|
|
105
|
-
'sibling',
|
|
106
|
-
'index',
|
|
107
|
-
'type',
|
|
108
|
-
['object', 'unknown'],
|
|
109
|
-
],
|
|
110
|
-
'pathGroups': [
|
|
111
|
-
{
|
|
112
|
-
pattern: '@/**',
|
|
113
|
-
group: 'internal',
|
|
114
|
-
position: 'before',
|
|
115
|
-
},
|
|
116
|
-
{
|
|
117
|
-
pattern: '*.{css,scss,less}',
|
|
118
|
-
group: 'unknown',
|
|
119
|
-
patternOptions: { matchBase: true },
|
|
120
|
-
position: 'after',
|
|
121
|
-
},
|
|
122
|
-
{
|
|
123
|
-
pattern: '*.{svg,png,jpg,gif,webp}',
|
|
124
|
-
group: 'unknown',
|
|
125
|
-
patternOptions: { matchBase: true },
|
|
126
|
-
position: 'after',
|
|
127
|
-
},
|
|
128
|
-
],
|
|
129
|
-
'pathGroupsExcludedImportTypes': ['builtin'],
|
|
130
|
-
'newlines-between': 'always',
|
|
131
|
-
'alphabetize': {
|
|
132
|
-
order: 'asc',
|
|
133
|
-
caseInsensitive: true,
|
|
134
|
-
orderImportKind: 'asc',
|
|
135
|
-
},
|
|
136
|
-
'named': true,
|
|
137
|
-
'warnOnUnassignedImports': true,
|
|
138
|
-
'distinctGroup': false,
|
|
139
|
-
},
|
|
140
|
-
],
|
|
141
|
-
...options.overrides,
|
|
144
|
+
...overrides,
|
|
142
145
|
},
|
|
143
146
|
},
|
|
147
|
+
{
|
|
148
|
+
files,
|
|
149
|
+
...(relative.perfectionistFiles
|
|
150
|
+
? { ignores: relative.perfectionistFiles }
|
|
151
|
+
: {}),
|
|
152
|
+
name: 'waltz/imports/order',
|
|
153
|
+
rules: orderRules,
|
|
154
|
+
},
|
|
144
155
|
];
|
|
145
156
|
}
|
|
146
157
|
|
|
@@ -175,14 +186,17 @@ async function jsoncConfig(options = {}) {
|
|
|
175
186
|
importJsoncParser(),
|
|
176
187
|
]);
|
|
177
188
|
const files = options.files ?? [JSON_FILES];
|
|
178
|
-
const packageJsonFiles =
|
|
179
|
-
const tsconfigFiles =
|
|
189
|
+
const packageJsonFiles = ['**/package.json'];
|
|
190
|
+
const tsconfigFiles = [
|
|
180
191
|
'**/[jt]sconfig.json',
|
|
181
192
|
'**/[jt]sconfig.*.json',
|
|
182
193
|
];
|
|
194
|
+
const setupFiles = options.files
|
|
195
|
+
? [...options.files, ...packageJsonFiles, ...tsconfigFiles]
|
|
196
|
+
: files;
|
|
183
197
|
return [
|
|
184
198
|
{
|
|
185
|
-
files,
|
|
199
|
+
files: setupFiles,
|
|
186
200
|
languageOptions: {
|
|
187
201
|
parser: jsoncParser,
|
|
188
202
|
},
|
|
@@ -460,21 +474,19 @@ async function perfectionistConfig(options = {}, relative) {
|
|
|
460
474
|
const scriptFiles = relative.isEnableTypeScript
|
|
461
475
|
? ALL_SCRIPTS_FILES
|
|
462
476
|
: [JS_FILES];
|
|
463
|
-
const
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
'perfectionist/sort-jsx-props': 'error',
|
|
467
|
-
};
|
|
477
|
+
const ruleFiles = options.files ?? scriptFiles;
|
|
478
|
+
const preset = options.preset ?? 'recommended-alphabetical';
|
|
479
|
+
const recommendedRules = perfectionist.configs[preset].rules ?? {};
|
|
468
480
|
return [
|
|
469
481
|
{
|
|
470
|
-
files:
|
|
482
|
+
files: ruleFiles,
|
|
471
483
|
name: 'waltz/perfectionist/setup',
|
|
472
484
|
plugins: {
|
|
473
485
|
perfectionist,
|
|
474
486
|
},
|
|
475
487
|
},
|
|
476
488
|
{
|
|
477
|
-
files:
|
|
489
|
+
files: ruleFiles,
|
|
478
490
|
name: 'waltz/perfectionist/rules',
|
|
479
491
|
...(options.settings ? { settings: options.settings } : {}),
|
|
480
492
|
rules: {
|
|
@@ -499,10 +511,15 @@ async function reactConfig(options = {}, relative) {
|
|
|
499
511
|
? ALL_SCRIPTS_FILES
|
|
500
512
|
: [JS_FILES];
|
|
501
513
|
const ruleFiles = resolvedConfig.files ?? scriptFiles;
|
|
514
|
+
const setupFiles = relative.isEnableTypeScript && resolvedConfig.files
|
|
515
|
+
? [...resolvedConfig.files, TS_FILES]
|
|
516
|
+
: relative.isEnableTypeScript
|
|
517
|
+
? scriptFiles
|
|
518
|
+
: ruleFiles;
|
|
502
519
|
const typeScriptRules = relative.isEnableTypeScript
|
|
503
520
|
? [
|
|
504
521
|
{
|
|
505
|
-
files:
|
|
522
|
+
files: [TS_FILES],
|
|
506
523
|
name: 'waltz/react/typescript-rules',
|
|
507
524
|
rules: {
|
|
508
525
|
'@eslint-react/dom/no-unknown-property': 'off',
|
|
@@ -513,7 +530,7 @@ async function reactConfig(options = {}, relative) {
|
|
|
513
530
|
: [];
|
|
514
531
|
return [
|
|
515
532
|
{
|
|
516
|
-
files:
|
|
533
|
+
files: setupFiles,
|
|
517
534
|
name: 'waltz/react/setup',
|
|
518
535
|
plugins: {
|
|
519
536
|
'@eslint-react': reactPlugin,
|
|
@@ -606,6 +623,7 @@ async function stylisticConfig(options = {}, relative) {
|
|
|
606
623
|
const scriptFiles = relative.isEnableTypeScript
|
|
607
624
|
? ALL_SCRIPTS_FILES
|
|
608
625
|
: [JS_FILES];
|
|
626
|
+
const ruleFiles = options.files ?? scriptFiles;
|
|
609
627
|
// Directly use the generated recommendation rules
|
|
610
628
|
const configs = eslintStylistic.configs.customize();
|
|
611
629
|
// This will enable the following rules.
|
|
@@ -676,14 +694,14 @@ async function stylisticConfig(options = {}, relative) {
|
|
|
676
694
|
// '@stylistic/jsx-wrap-multilines'
|
|
677
695
|
return [
|
|
678
696
|
{
|
|
679
|
-
files:
|
|
697
|
+
files: ruleFiles,
|
|
680
698
|
name: 'waltz/stylistic/setup',
|
|
681
699
|
plugins: {
|
|
682
700
|
'@stylistic': eslintStylistic,
|
|
683
701
|
},
|
|
684
702
|
},
|
|
685
703
|
{
|
|
686
|
-
files:
|
|
704
|
+
files: ruleFiles,
|
|
687
705
|
name: 'waltz/stylistic/rules',
|
|
688
706
|
rules: {
|
|
689
707
|
...configs.rules,
|
|
@@ -731,9 +749,10 @@ async function tsConfig(options = {}) {
|
|
|
731
749
|
importTypeScriptRecommendedRules(),
|
|
732
750
|
]);
|
|
733
751
|
const resolvedConfig = typeof options === 'boolean' ? {} : options;
|
|
752
|
+
const ruleFiles = resolvedConfig.files ?? [TS_FILES];
|
|
734
753
|
return [
|
|
735
754
|
{
|
|
736
|
-
files:
|
|
755
|
+
files: ruleFiles,
|
|
737
756
|
languageOptions: {
|
|
738
757
|
parser: typeScriptParser,
|
|
739
758
|
},
|
|
@@ -743,7 +762,7 @@ async function tsConfig(options = {}) {
|
|
|
743
762
|
},
|
|
744
763
|
},
|
|
745
764
|
{
|
|
746
|
-
files:
|
|
765
|
+
files: ruleFiles,
|
|
747
766
|
name: 'waltz/ts/rules',
|
|
748
767
|
rules: {
|
|
749
768
|
...recommendedRules,
|
|
@@ -756,6 +775,17 @@ async function tsConfig(options = {}) {
|
|
|
756
775
|
async function waltz(options = {}, ...orders) {
|
|
757
776
|
const isEnableTypeScript = !!options.ts;
|
|
758
777
|
const isEnableReact = !!options.react;
|
|
778
|
+
const isEnablePerfectionist = options.perfectionist !== false;
|
|
779
|
+
const scriptFiles = isEnableTypeScript ? ALL_SCRIPTS_FILES : [JS_FILES];
|
|
780
|
+
const configuredPerfectionistFiles = typeof options.perfectionist === 'object'
|
|
781
|
+
? options.perfectionist.files
|
|
782
|
+
: undefined;
|
|
783
|
+
const hasSimplePerfectionistFiles = configuredPerfectionistFiles?.every(file => typeof file === 'string');
|
|
784
|
+
const perfectionistFiles = isEnablePerfectionist
|
|
785
|
+
? hasSimplePerfectionistFiles
|
|
786
|
+
? configuredPerfectionistFiles
|
|
787
|
+
: scriptFiles
|
|
788
|
+
: undefined;
|
|
759
789
|
const configs = [];
|
|
760
790
|
if (options.gitignore) {
|
|
761
791
|
configs.push(gitignore(options.gitignore));
|
|
@@ -775,7 +805,9 @@ async function waltz(options = {}, ...orders) {
|
|
|
775
805
|
if (options.imports !== false) {
|
|
776
806
|
configs.push(importsConfig(isEnableTypeScript, options.imports === true || options.imports === undefined
|
|
777
807
|
? {}
|
|
778
|
-
: options.imports
|
|
808
|
+
: options.imports, {
|
|
809
|
+
perfectionistFiles,
|
|
810
|
+
}));
|
|
779
811
|
}
|
|
780
812
|
if (isEnableReact) {
|
|
781
813
|
configs.push(reactConfig(options.react, {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chanyuxi/eslint-waltz",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.1",
|
|
5
5
|
"packageManager": "pnpm@10.4.1",
|
|
6
6
|
"description": "A composable ESLint flat config for JavaScript, TypeScript, JSONC, imports, React, Tailwind CSS, and Perfectionist.",
|
|
7
7
|
"author": "chanyuxi <2438149743@qq.com> (https://github.com/chanyuxi)",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"test": "node --import tsx test/index.ts",
|
|
49
49
|
"check": "pnpm run typeCheck && pnpm run lint && pnpm run test",
|
|
50
50
|
"changeset": "changeset",
|
|
51
|
-
"version": "changeset version && pnpm install --lockfile-only",
|
|
51
|
+
"version": "changeset version && pnpm install --lockfile-only",
|
|
52
52
|
"release": "pnpm build && changeset publish",
|
|
53
53
|
"prepack": "pnpm build",
|
|
54
54
|
"prepare": "husky"
|