@chanyuxi/eslint-waltz 0.0.0-alpha.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/dist/index.js ADDED
@@ -0,0 +1,535 @@
1
+ import globals from 'globals';
2
+
3
+ function importGitignoreSeek() {
4
+ return import('eslint-config-flat-gitignore').then(m => m.default);
5
+ }
6
+ function importTypeScriptPlugin() {
7
+ return import('typescript-eslint').then(m => m.default.plugin);
8
+ }
9
+ function importTypeScriptParser() {
10
+ return import('typescript-eslint').then(m => m.default.parser);
11
+ }
12
+ function importStylisticPlugin() {
13
+ return import('@stylistic/eslint-plugin').then(m => m.default);
14
+ }
15
+ function importJsoncPlugin() {
16
+ return import('eslint-plugin-jsonc').then(m => m.default);
17
+ }
18
+ function importJsoncParser() {
19
+ return (import('jsonc-eslint-parser'));
20
+ }
21
+ function importImportsPlugin() {
22
+ return import('eslint-plugin-import');
23
+ }
24
+
25
+ async function gitignore(enable) {
26
+ return (await importGitignoreSeek())({
27
+ name: 'waltz/gitignore/setup',
28
+ ...(enable === true
29
+ ? { strict: true }
30
+ : enable),
31
+ });
32
+ }
33
+
34
+ const JS_FILES = '**/*.?([cm])js?(x)';
35
+ const TS_FILES = '**/*.?([cm])ts?(x)';
36
+ const JSON_FILES = '**/*.{json,json5,jsonc}';
37
+
38
+ async function importsConfig() {
39
+ const importsPlugin = await importImportsPlugin();
40
+ return {
41
+ files: [JS_FILES, TS_FILES],
42
+ plugins: {
43
+ imports: importsPlugin,
44
+ },
45
+ rules: {
46
+ // 'imports/no-unresolved': 'error',
47
+ 'imports/named': 'error',
48
+ 'imports/namespace': 'error',
49
+ 'imports/default': 'error',
50
+ 'imports/export': 'error',
51
+ 'imports/no-named-as-default': 'warn',
52
+ 'imports/no-named-as-default-member': 'warn',
53
+ 'imports/no-duplicates': 'warn',
54
+ 'imports/order': ['error', {
55
+ 'groups': [
56
+ 'builtin',
57
+ 'external',
58
+ 'parent',
59
+ 'sibling',
60
+ 'index',
61
+ 'type',
62
+ ['object', 'unknown'],
63
+ ],
64
+ 'pathGroups': [
65
+ {
66
+ pattern: '@/**',
67
+ group: 'internal',
68
+ position: 'before',
69
+ },
70
+ {
71
+ pattern: '*.{css,scss,less}',
72
+ group: 'unknown',
73
+ patternOptions: { matchBase: true },
74
+ position: 'after',
75
+ },
76
+ {
77
+ pattern: '*.{svg,png,jpg,gif,webp}',
78
+ group: 'unknown',
79
+ patternOptions: { matchBase: true },
80
+ position: 'after',
81
+ },
82
+ ],
83
+ 'pathGroupsExcludedImportTypes': ['builtin'],
84
+ 'newlines-between': 'always',
85
+ 'alphabetize': {
86
+ order: 'asc',
87
+ caseInsensitive: true,
88
+ orderImportKind: 'asc',
89
+ },
90
+ 'named': true,
91
+ 'warnOnUnassignedImports': true,
92
+ 'distinctGroup': false,
93
+ }],
94
+ },
95
+ };
96
+ }
97
+
98
+ function jsConfig(config = {}) {
99
+ return {
100
+ name: 'waltz/js/rules',
101
+ files: config.files ?? [JS_FILES],
102
+ languageOptions: {
103
+ globals: {
104
+ ...(config.globals
105
+ ? config.globals.map(name => globals[name]).reduce((a, b) => ({ ...a, ...b }), {})
106
+ : {}),
107
+ },
108
+ },
109
+ rules: {
110
+ 'constructor-super': 'error',
111
+ 'for-direction': 'error',
112
+ 'getter-return': 'error',
113
+ 'no-async-promise-executor': 'error',
114
+ 'no-case-declarations': 'error',
115
+ 'no-class-assign': 'error',
116
+ 'no-compare-neg-zero': 'error',
117
+ 'no-cond-assign': 'error',
118
+ 'no-const-assign': 'error',
119
+ 'no-constant-binary-expression': 'error',
120
+ 'no-constant-condition': 'error',
121
+ 'no-control-regex': 'error',
122
+ 'no-debugger': 'error',
123
+ 'no-delete-var': 'error',
124
+ 'no-dupe-args': 'error',
125
+ 'no-dupe-class-members': 'error',
126
+ 'no-dupe-else-if': 'error',
127
+ 'no-dupe-keys': 'error',
128
+ 'no-duplicate-case': 'error',
129
+ 'no-empty': 'error',
130
+ 'no-empty-character-class': 'error',
131
+ 'no-empty-pattern': 'error',
132
+ 'no-empty-static-block': 'error',
133
+ 'no-ex-assign': 'error',
134
+ 'no-extra-boolean-cast': 'error',
135
+ 'no-fallthrough': 'error',
136
+ 'no-func-assign': 'error',
137
+ 'no-global-assign': 'error',
138
+ 'no-import-assign': 'error',
139
+ 'no-invalid-regexp': 'error',
140
+ 'no-irregular-whitespace': 'error',
141
+ 'no-loss-of-precision': 'error',
142
+ 'no-misleading-character-class': 'error',
143
+ 'no-new-native-nonconstructor': 'error',
144
+ 'no-nonoctal-decimal-escape': 'error',
145
+ 'no-obj-calls': 'error',
146
+ 'no-octal': 'error',
147
+ 'no-prototype-builtins': 'error',
148
+ 'no-redeclare': 'error',
149
+ 'no-regex-spaces': 'error',
150
+ 'no-self-assign': 'error',
151
+ 'no-setter-return': 'error',
152
+ 'no-shadow-restricted-names': 'error',
153
+ 'no-sparse-arrays': 'error',
154
+ 'no-this-before-super': 'error',
155
+ 'no-undef': 'error',
156
+ 'no-unexpected-multiline': 'error',
157
+ 'no-unreachable': 'error',
158
+ 'no-unsafe-finally': 'error',
159
+ 'no-unsafe-negation': 'error',
160
+ 'no-unsafe-optional-chaining': 'error',
161
+ 'no-unused-labels': 'error',
162
+ 'no-unused-private-class-members': 'error',
163
+ 'no-unused-vars': 'error',
164
+ 'no-useless-backreference': 'error',
165
+ 'no-useless-catch': 'error',
166
+ 'no-useless-escape': 'error',
167
+ 'no-with': 'error',
168
+ 'require-yield': 'error',
169
+ 'use-isnan': 'error',
170
+ 'valid-typeof': 'error',
171
+ ...config.overrides,
172
+ },
173
+ };
174
+ }
175
+
176
+ async function jsoncConfig() {
177
+ const [jsoncPlugin, jsoncParser,] = await Promise.all([
178
+ importJsoncPlugin(),
179
+ importJsoncParser(),
180
+ ]);
181
+ return [
182
+ {
183
+ name: 'waltz/jsonc/setup',
184
+ files: [JSON_FILES],
185
+ plugins: {
186
+ jsonc: jsoncPlugin,
187
+ },
188
+ languageOptions: {
189
+ parser: jsoncParser,
190
+ },
191
+ },
192
+ {
193
+ name: 'waltz/jsonc/rules',
194
+ files: [JSON_FILES],
195
+ rules: {
196
+ 'jsonc/comma-dangle': 'error',
197
+ 'jsonc/no-bigint-literals': 'error',
198
+ 'jsonc/no-binary-expression': 'error',
199
+ 'jsonc/no-binary-numeric-literals': 'error',
200
+ 'jsonc/no-comments': 'error',
201
+ 'jsonc/no-dupe-keys': 'error',
202
+ 'jsonc/no-escape-sequence-in-identifier': 'error',
203
+ 'jsonc/no-floating-decimal': 'error',
204
+ 'jsonc/no-hexadecimal-numeric-literals': 'error',
205
+ 'jsonc/no-infinity': 'error',
206
+ 'jsonc/no-multi-str': 'error',
207
+ 'jsonc/no-nan': 'error',
208
+ 'jsonc/no-number-props': 'error',
209
+ 'jsonc/no-numeric-separators': 'error',
210
+ 'jsonc/no-octal-numeric-literals': 'error',
211
+ 'jsonc/no-octal': 'error',
212
+ 'jsonc/no-parenthesized': 'error',
213
+ 'jsonc/no-plus-sign': 'error',
214
+ 'jsonc/no-regexp-literals': 'error',
215
+ 'jsonc/no-sparse-arrays': 'error',
216
+ 'jsonc/no-template-literals': 'error',
217
+ 'jsonc/no-undefined-value': 'error',
218
+ 'jsonc/no-unicode-codepoint-escapes': 'error',
219
+ 'jsonc/no-useless-escape': 'error',
220
+ 'jsonc/quote-props': 'error',
221
+ 'jsonc/quotes': 'error',
222
+ 'jsonc/space-unary-ops': 'error',
223
+ 'jsonc/valid-json-number': 'error',
224
+ 'jsonc/vue-custom-block/no-parsing-error': 'error',
225
+ 'jsonc/indent': ['error', 2],
226
+ },
227
+ },
228
+ {
229
+ files: ['**/package.json'],
230
+ name: 'antfu/sort/package-json',
231
+ rules: {
232
+ 'jsonc/sort-array-values': [
233
+ 'error',
234
+ {
235
+ order: { type: 'asc' },
236
+ pathPattern: '^files$',
237
+ },
238
+ ],
239
+ 'jsonc/sort-keys': [
240
+ 'error',
241
+ {
242
+ order: [
243
+ 'publisher',
244
+ 'name',
245
+ 'displayName',
246
+ 'type',
247
+ 'version',
248
+ 'private',
249
+ 'packageManager',
250
+ 'description',
251
+ 'author',
252
+ 'contributors',
253
+ 'license',
254
+ 'funding',
255
+ 'homepage',
256
+ 'repository',
257
+ 'bugs',
258
+ 'keywords',
259
+ 'categories',
260
+ 'sideEffects',
261
+ 'imports',
262
+ 'exports',
263
+ 'main',
264
+ 'module',
265
+ 'unpkg',
266
+ 'jsdelivr',
267
+ 'types',
268
+ 'typesVersions',
269
+ 'bin',
270
+ 'icon',
271
+ 'files',
272
+ 'engines',
273
+ 'activationEvents',
274
+ 'contributes',
275
+ 'scripts',
276
+ 'peerDependencies',
277
+ 'peerDependenciesMeta',
278
+ 'dependencies',
279
+ 'optionalDependencies',
280
+ 'devDependencies',
281
+ 'pnpm',
282
+ 'overrides',
283
+ 'resolutions',
284
+ 'husky',
285
+ 'simple-git-hooks',
286
+ 'lint-staged',
287
+ 'eslintConfig',
288
+ ],
289
+ pathPattern: '^$',
290
+ },
291
+ {
292
+ order: { type: 'asc' },
293
+ pathPattern: '^(?:dev|peer|optional|bundled)?[Dd]ependencies(Meta)?$',
294
+ },
295
+ {
296
+ order: { type: 'asc' },
297
+ pathPattern: '^(?:resolutions|overrides|pnpm.overrides)$',
298
+ },
299
+ {
300
+ order: [
301
+ 'types',
302
+ 'import',
303
+ 'require',
304
+ 'default',
305
+ ],
306
+ pathPattern: '^exports.*$',
307
+ },
308
+ {
309
+ order: [
310
+ // client hooks only
311
+ 'pre-commit',
312
+ 'prepare-commit-msg',
313
+ 'commit-msg',
314
+ 'post-commit',
315
+ 'pre-rebase',
316
+ 'post-rewrite',
317
+ 'post-checkout',
318
+ 'post-merge',
319
+ 'pre-push',
320
+ 'pre-auto-gc',
321
+ ],
322
+ pathPattern: '^(?:gitHooks|husky|simple-git-hooks)$',
323
+ },
324
+ ],
325
+ },
326
+ },
327
+ {
328
+ files: ['**/[jt]sconfig.json', '**/[jt]sconfig.*.json'],
329
+ name: 'antfu/sort/tsconfig-json',
330
+ rules: {
331
+ 'jsonc/sort-keys': [
332
+ 'error',
333
+ {
334
+ order: [
335
+ 'extends',
336
+ 'compilerOptions',
337
+ 'references',
338
+ 'files',
339
+ 'include',
340
+ 'exclude',
341
+ ],
342
+ pathPattern: '^$',
343
+ },
344
+ {
345
+ order: [
346
+ /* Projects */
347
+ 'incremental',
348
+ 'composite',
349
+ 'tsBuildInfoFile',
350
+ 'disableSourceOfProjectReferenceRedirect',
351
+ 'disableSolutionSearching',
352
+ 'disableReferencedProjectLoad',
353
+ /* Language and Environment */
354
+ 'target',
355
+ 'jsx',
356
+ 'jsxFactory',
357
+ 'jsxFragmentFactory',
358
+ 'jsxImportSource',
359
+ 'lib',
360
+ 'moduleDetection',
361
+ 'noLib',
362
+ 'reactNamespace',
363
+ 'useDefineForClassFields',
364
+ 'emitDecoratorMetadata',
365
+ 'experimentalDecorators',
366
+ 'libReplacement',
367
+ /* Modules */
368
+ 'baseUrl',
369
+ 'rootDir',
370
+ 'rootDirs',
371
+ 'customConditions',
372
+ 'module',
373
+ 'moduleResolution',
374
+ 'moduleSuffixes',
375
+ 'noResolve',
376
+ 'paths',
377
+ 'resolveJsonModule',
378
+ 'resolvePackageJsonExports',
379
+ 'resolvePackageJsonImports',
380
+ 'typeRoots',
381
+ 'types',
382
+ 'allowArbitraryExtensions',
383
+ 'allowImportingTsExtensions',
384
+ 'allowUmdGlobalAccess',
385
+ /* JavaScript Support */
386
+ 'allowJs',
387
+ 'checkJs',
388
+ 'maxNodeModuleJsDepth',
389
+ /* Type Checking */
390
+ 'strict',
391
+ 'strictBindCallApply',
392
+ 'strictFunctionTypes',
393
+ 'strictNullChecks',
394
+ 'strictPropertyInitialization',
395
+ 'allowUnreachableCode',
396
+ 'allowUnusedLabels',
397
+ 'alwaysStrict',
398
+ 'exactOptionalPropertyTypes',
399
+ 'noFallthroughCasesInSwitch',
400
+ 'noImplicitAny',
401
+ 'noImplicitOverride',
402
+ 'noImplicitReturns',
403
+ 'noImplicitThis',
404
+ 'noPropertyAccessFromIndexSignature',
405
+ 'noUncheckedIndexedAccess',
406
+ 'noUnusedLocals',
407
+ 'noUnusedParameters',
408
+ 'useUnknownInCatchVariables',
409
+ /* Emit */
410
+ 'declaration',
411
+ 'declarationDir',
412
+ 'declarationMap',
413
+ 'downlevelIteration',
414
+ 'emitBOM',
415
+ 'emitDeclarationOnly',
416
+ 'importHelpers',
417
+ 'importsNotUsedAsValues',
418
+ 'inlineSourceMap',
419
+ 'inlineSources',
420
+ 'mapRoot',
421
+ 'newLine',
422
+ 'noEmit',
423
+ 'noEmitHelpers',
424
+ 'noEmitOnError',
425
+ 'outDir',
426
+ 'outFile',
427
+ 'preserveConstEnums',
428
+ 'preserveValueImports',
429
+ 'removeComments',
430
+ 'sourceMap',
431
+ 'sourceRoot',
432
+ 'stripInternal',
433
+ /* Interop Constraints */
434
+ 'allowSyntheticDefaultImports',
435
+ 'esModuleInterop',
436
+ 'forceConsistentCasingInFileNames',
437
+ 'isolatedDeclarations',
438
+ 'isolatedModules',
439
+ 'preserveSymlinks',
440
+ 'verbatimModuleSyntax',
441
+ 'erasableSyntaxOnly',
442
+ /* Completeness */
443
+ 'skipDefaultLibCheck',
444
+ 'skipLibCheck',
445
+ ],
446
+ pathPattern: '^compilerOptions$',
447
+ },
448
+ ],
449
+ },
450
+ },
451
+ ];
452
+ }
453
+
454
+ async function stylisticConfig(options = {}) {
455
+ const eslintStylistic = await importStylisticPlugin();
456
+ const configs = eslintStylistic.configs.customize();
457
+ return {
458
+ name: 'waltz/stylistic/setup',
459
+ files: options.files ?? [JS_FILES, TS_FILES],
460
+ plugins: {
461
+ '@stylistic': eslintStylistic,
462
+ },
463
+ rules: {
464
+ ...configs.rules,
465
+ ...options.overrides,
466
+ },
467
+ };
468
+ }
469
+
470
+ async function tsConfig(options = {}) {
471
+ const [typeScriptPlugin, typeScriptParser,] = await Promise.all([
472
+ importTypeScriptPlugin(),
473
+ importTypeScriptParser(),
474
+ ]);
475
+ const resolvedConfig = typeof options === 'boolean' ? {} : options;
476
+ return [
477
+ {
478
+ name: 'waltz/ts/setup',
479
+ files: [TS_FILES],
480
+ plugins: {
481
+ '@typescript-eslint': typeScriptPlugin,
482
+ },
483
+ languageOptions: {
484
+ parser: typeScriptParser,
485
+ },
486
+ },
487
+ {
488
+ name: 'waltz/ts/rules',
489
+ files: resolvedConfig.files ?? [TS_FILES],
490
+ rules: {
491
+ '@typescript-eslint/ban-ts-comment': 'error',
492
+ 'no-array-constructor': 'off',
493
+ '@typescript-eslint/no-array-constructor': 'error',
494
+ '@typescript-eslint/no-duplicate-enum-values': 'error',
495
+ '@typescript-eslint/no-empty-object-type': 'error',
496
+ '@typescript-eslint/no-explicit-any': 'error',
497
+ '@typescript-eslint/no-extra-non-null-assertion': 'error',
498
+ '@typescript-eslint/no-misused-new': 'error',
499
+ '@typescript-eslint/no-namespace': 'error',
500
+ '@typescript-eslint/no-non-null-asserted-optional-chain': 'error',
501
+ '@typescript-eslint/no-require-imports': 'error',
502
+ '@typescript-eslint/no-this-alias': 'error',
503
+ '@typescript-eslint/no-unnecessary-type-constraint': 'error',
504
+ '@typescript-eslint/no-unsafe-declaration-merging': 'error',
505
+ '@typescript-eslint/no-unsafe-function-type': 'error',
506
+ 'no-unused-expressions': 'off',
507
+ '@typescript-eslint/no-unused-expressions': 'error',
508
+ 'no-unused-vars': 'off',
509
+ '@typescript-eslint/no-unused-vars': 'error',
510
+ '@typescript-eslint/no-wrapper-object-types': 'error',
511
+ '@typescript-eslint/prefer-as-const': 'error',
512
+ '@typescript-eslint/prefer-namespace-keyword': 'error',
513
+ '@typescript-eslint/triple-slash-reference': 'error',
514
+ ...resolvedConfig.overrides,
515
+ },
516
+ },
517
+ ];
518
+ }
519
+
520
+ async function waltz(options = {}, ...orders) {
521
+ const config = [];
522
+ if (options.gitignore) {
523
+ config.push(await gitignore(options.gitignore));
524
+ }
525
+ config.push(await stylisticConfig(options.stylistic), jsConfig(options.js), ...(await jsoncConfig()));
526
+ if (options.ts) {
527
+ config.push(...(await tsConfig(options.ts)));
528
+ }
529
+ if (options.imports) {
530
+ config.push(await importsConfig());
531
+ }
532
+ return [...config, ...orders];
533
+ }
534
+
535
+ export { waltz as default };
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "@chanyuxi/eslint-waltz",
3
+ "type": "module",
4
+ "version": "0.0.0-alpha.1",
5
+ "packageManager": "pnpm@10.4.1",
6
+ "description": "Great, all I can say is thank you @antfu/eslint-config",
7
+ "author": "chanyuxi <2438149743@qq.com> (https://github.com/chanyuxi)",
8
+ "publishConfig": {
9
+ "access": "public"
10
+ },
11
+ "license": "ISC",
12
+ "keywords": [
13
+ "chanyuxi",
14
+ "eslint",
15
+ "config"
16
+ ],
17
+ "exports": {
18
+ "types": "./dist/index.d.ts",
19
+ "import": "./dist/index.js",
20
+ "default": "./dist/index.js"
21
+ },
22
+ "files": [
23
+ "dist"
24
+ ],
25
+ "scripts": {
26
+ "build": "pnpm gen && rollup -c rollup.config.ts --configPlugin @rollup/plugin-typescript",
27
+ "gen": "tsx scripts/typegen.ts",
28
+ "lint": "eslint",
29
+ "lint:fix": "eslint --fix",
30
+ "typeCheck": "tsc"
31
+ },
32
+ "peerDependencies": {
33
+ "@stylistic/eslint-plugin": "^5.2.2",
34
+ "eslint": "^9.32.0",
35
+ "eslint-config-flat-gitignore": "^2.1.0",
36
+ "eslint-plugin-import": "^2.32.0",
37
+ "eslint-plugin-jsonc": "^2.20.1",
38
+ "globals": "^16.3.0",
39
+ "jsonc-eslint-parser": "^2.4.0",
40
+ "typescript-eslint": "^8.38.0"
41
+ },
42
+ "devDependencies": {
43
+ "@rollup/plugin-typescript": "^12.1.4",
44
+ "@stylistic/eslint-plugin": "^5.2.2",
45
+ "@types/node": "^24.1.0",
46
+ "eslint": "^9.32.0",
47
+ "eslint-config-flat-gitignore": "^2.1.0",
48
+ "eslint-plugin-import": "^2.32.0",
49
+ "eslint-plugin-jsonc": "^2.20.1",
50
+ "eslint-typegen": "^2.3.0",
51
+ "globals": "^16.3.0",
52
+ "jiti": "^2.5.1",
53
+ "jsonc-eslint-parser": "^2.4.0",
54
+ "rollup": "^4.46.2",
55
+ "rollup-plugin-delete": "^3.0.1",
56
+ "rollup-plugin-dts": "^6.2.1",
57
+ "ts-node": "^10.9.2",
58
+ "tslib": "^2.8.1",
59
+ "tsx": "^4.20.3",
60
+ "typescript": "^5.8.3",
61
+ "typescript-eslint": "^8.38.0"
62
+ }
63
+ }