@agilebot/eslint-config 0.2.0 → 0.2.2

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 CHANGED
@@ -1,17 +1,16 @@
1
- # @agilebot/eslint-config
2
-
3
- ### Usage
4
-
5
- ```bash
6
- npm install --save-dev eslint \
7
- @agilebot/eslint-config \
8
- @agilebot/eslint-plugin \
9
- @agilebot/eslint-utils
10
- ```
11
-
12
- ```js
13
- // .eslintrc.js
14
- const { agilebot } = require('@agilebot/eslint-utils');
15
-
16
- module.exports = agilebot(__dirname);
17
- ```
1
+ # @agilebot/eslint-config
2
+
3
+ ### Usage
4
+
5
+ ```bash
6
+ npm install --save-dev eslint \
7
+ @agilebot/eslint-config \
8
+ @agilebot/eslint-plugin
9
+ ```
10
+
11
+ ```js
12
+ // .eslintrc.js
13
+ const { agilebot } = require('@agilebot/eslint-config');
14
+
15
+ module.exports = agilebot(__dirname);
16
+ ```
package/dist/index.d.ts CHANGED
@@ -5,6 +5,8 @@ interface FactoryOptions {
5
5
  cspellWords?: string[];
6
6
  config?: Linter.Config;
7
7
  react?: boolean;
8
+ vue?: number;
9
+ module?: boolean;
8
10
  godaddy?: boolean;
9
11
  }
10
12
  declare function factory(root: string, options?: FactoryOptions): Linter.BaseConfig;
package/dist/index.js CHANGED
@@ -180,11 +180,14 @@ function promise() {
180
180
  // src/configs/import.ts
181
181
  var import_node_path = __toESM(require("path"));
182
182
  var import_node_fs = __toESM(require("fs"));
183
- var import_find_root = require("@manypkg/find-root");
184
183
  var import_eslint_utils = require("@agilebot/eslint-utils");
185
- function eslintImport(packageDir, devDependencies) {
186
- const { rootDir } = (0, import_find_root.findRootSync)(__dirname);
187
- const pkg = require(import_node_path.default.join(packageDir, "package.json"));
184
+ function eslintImport(opts) {
185
+ const rootDir = (0, import_eslint_utils.findRootDir)(__dirname);
186
+ const pkgPath = import_node_path.default.join(opts.packageDir, "package.json");
187
+ if (!import_node_fs.default.existsSync(pkgPath)) {
188
+ throw new Error(`package.json not found in ${opts.packageDir}`);
189
+ }
190
+ const pkg = JSON.parse(import_node_fs.default.readFileSync(pkgPath, "utf8"));
188
191
  const tmpPkg = {
189
192
  name: `${pkg.name}/tmp`,
190
193
  dependencies: {
@@ -192,7 +195,7 @@ function eslintImport(packageDir, devDependencies) {
192
195
  }
193
196
  };
194
197
  const tmpPkgSafeName = tmpPkg.name.replaceAll("/", "__");
195
- const cacheDir = (0, import_eslint_utils.getCacheDir)(rootDir);
198
+ const cacheDir = (0, import_eslint_utils.findCacheDir)(rootDir);
196
199
  const tmpPkgDir = import_node_path.default.join(cacheDir, "tmp-pkg", tmpPkgSafeName);
197
200
  if (!import_node_fs.default.existsSync(tmpPkgDir)) {
198
201
  import_node_fs.default.mkdirSync(tmpPkgDir, { recursive: true });
@@ -226,7 +229,7 @@ function eslintImport(packageDir, devDependencies) {
226
229
  "import/no-extraneous-dependencies": [
227
230
  "error",
228
231
  {
229
- packageDir: [packageDir, tmpPkgDir, rootDir],
232
+ packageDir: [opts.packageDir, tmpPkgDir, rootDir],
230
233
  devDependencies: [
231
234
  "test/**/*",
232
235
  "tests/**/*",
@@ -236,7 +239,7 @@ function eslintImport(packageDir, devDependencies) {
236
239
  "**/.storybook/**",
237
240
  "**/*.stories.{ts,tsx}",
238
241
  "**/scripts/*.{ts,mts}",
239
- ...devDependencies ?? []
242
+ ...opts.devDependencies ?? []
240
243
  ],
241
244
  includeInternal: true
242
245
  }
@@ -283,21 +286,20 @@ function eslintImport(packageDir, devDependencies) {
283
286
  }
284
287
 
285
288
  // src/configs/unicorn.ts
286
- function unicorn() {
289
+ function unicorn(opts) {
287
290
  return {
288
291
  plugins: ["unicorn"],
289
292
  extends: ["plugin:unicorn/recommended"],
290
293
  rules: {
291
- // unicorn默认规则太严格,屏蔽以下
294
+ "unicorn/prefer-module": opts.module ? "error" : "off",
295
+ "unicorn/prefer-top-level-await": opts.module ? "error" : "off",
292
296
  "unicorn/filename-case": "off",
293
297
  "unicorn/import-style": "off",
294
298
  "unicorn/prefer-at": "off",
295
299
  "unicorn/prevent-abbreviations": "off",
296
300
  "unicorn/prefer-date-now": "off",
297
301
  "unicorn/no-process-exit": "off",
298
- "unicorn/prefer-module": "off",
299
302
  "unicorn/no-null": "off",
300
- "unicorn/prefer-top-level-await": "off",
301
303
  "unicorn/consistent-function-scoping": "off",
302
304
  "unicorn/numeric-separators-style": "off",
303
305
  "unicorn/prefer-optional-catch-binding": "off",
@@ -385,6 +387,15 @@ function react() {
385
387
  };
386
388
  }
387
389
 
390
+ // src/configs/vue.ts
391
+ function vue(opts) {
392
+ return {
393
+ extends: [
394
+ opts.version === 3 ? "plugin:vue/vue3-recommended" : "plugin:vue/recommended"
395
+ ]
396
+ };
397
+ }
398
+
388
399
  // src/configs/jsdoc.ts
389
400
  function jsdoc() {
390
401
  return {
@@ -449,7 +460,7 @@ function deprecation() {
449
460
  }
450
461
 
451
462
  // src/configs/cspell.ts
452
- function cspell(words) {
463
+ function cspell(opts) {
453
464
  return {
454
465
  plugins: ["@cspell"],
455
466
  rules: {
@@ -459,7 +470,7 @@ function cspell(words) {
459
470
  checkComments: false,
460
471
  autoFix: false,
461
472
  cspell: {
462
- words
473
+ words: opts.words
463
474
  }
464
475
  }
465
476
  ]
@@ -470,7 +481,30 @@ function cspell(words) {
470
481
  // src/configs/agilebot.ts
471
482
  function agilebot() {
472
483
  return {
473
- extends: ["plugin:@agilebot/recommended"]
484
+ extends: ["plugin:@agilebot/recommended"],
485
+ plugins: ["react-hooks"],
486
+ rules: {
487
+ "react-hooks/exhaustive-deps": "off",
488
+ "@agilebot/react/better-exhaustive-deps": [
489
+ "warn",
490
+ {
491
+ checkMemoizedVariableIsStatic: true,
492
+ staticHooks: {
493
+ "useIpc.*": {
494
+ value: true,
495
+ regexp: true
496
+ },
497
+ useDialog: true,
498
+ useSnackbar: true,
499
+ useForm: true,
500
+ "use.*Store": {
501
+ value: true,
502
+ regexp: true
503
+ }
504
+ }
505
+ }
506
+ ]
507
+ }
474
508
  };
475
509
  }
476
510
 
@@ -515,13 +549,21 @@ function godaddy() {
515
549
  // src/factory.ts
516
550
  function factory(root, options) {
517
551
  import_node_assert.default.ok(root, "root option is required");
552
+ const commonConfigs = [
553
+ unicorn({
554
+ module: options?.module ?? false
555
+ }),
556
+ eslint(),
557
+ eslintImport({
558
+ packageDir: root,
559
+ devDependencies: options?.devDependencies
560
+ }),
561
+ prettier()
562
+ ];
518
563
  if (options?.godaddy) {
519
564
  return (0, import_eslint_utils3.mergeESLintConfig)(
520
565
  godaddy(),
521
- prettier(),
522
- unicorn(),
523
- eslint(),
524
- eslintImport(root, options?.devDependencies),
566
+ ...commonConfigs,
525
567
  options?.config ?? {}
526
568
  );
527
569
  }
@@ -536,10 +578,12 @@ function factory(root, options) {
536
578
  "*.js",
537
579
  "*.jsx",
538
580
  "*.cjs",
539
- "*.mjs"
581
+ "*.mjs",
582
+ "*.vue"
540
583
  ],
541
- parser: "@typescript-eslint/parser",
584
+ parser: !options?.vue ? "@typescript-eslint/parser" : "vue-eslint-parser",
542
585
  parserOptions: {
586
+ parser: "@typescript-eslint/parser",
543
587
  tsconfigRootDir: root
544
588
  },
545
589
  ...(0, import_eslint_utils3.mergeESLintConfig)(
@@ -547,16 +591,18 @@ function factory(root, options) {
547
591
  standard(),
548
592
  ts(),
549
593
  promise(),
550
- eslintImport(root, options?.devDependencies),
551
- unicorn(),
552
594
  options?.react ? react() : {},
595
+ options?.vue ? vue({
596
+ version: options.vue
597
+ }) : {},
553
598
  jsdoc(),
554
599
  lodash(),
555
- eslint(),
556
600
  deprecation(),
557
- cspell(options?.cspellWords ?? []),
601
+ cspell({
602
+ words: options?.cspellWords ?? []
603
+ }),
604
+ ...commonConfigs,
558
605
  agilebot(),
559
- prettier(),
560
606
  options?.config ?? {}
561
607
  )
562
608
  },
@@ -567,7 +613,7 @@ function factory(root, options) {
567
613
  }
568
614
  },
569
615
  {
570
- files: ["*.d.ts"],
616
+ files: ["*.d.ts", "*.cts", "*.mts"],
571
617
  rules: {
572
618
  // .d.ts中支持导入ts文件中的类型
573
619
  "@typescript-eslint/consistent-type-imports": "off",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agilebot/eslint-config",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Agilebot's ESLint config",
5
5
  "main": "dist",
6
6
  "types": "dist/index.d.ts",
@@ -16,7 +16,6 @@
16
16
  "homepage": "https://github.com/sh-agilebot/frontend-toolkit/tree/master/packages/eslint-config#readme",
17
17
  "dependencies": {
18
18
  "@cspell/eslint-plugin": "^8.7.0",
19
- "@manypkg/find-root": "^2.2.1",
20
19
  "@stylistic/eslint-plugin": "^1.7.0",
21
20
  "@typescript-eslint/eslint-plugin": "^7.6.0",
22
21
  "@typescript-eslint/parser": "^7.6.0",
@@ -38,9 +37,10 @@
38
37
  "eslint-plugin-react-hooks": "^4.6.0",
39
38
  "eslint-plugin-react-prefer-function-component": "^3.3.0",
40
39
  "eslint-plugin-unicorn": "^52.0.0",
40
+ "eslint-plugin-vue": "^9.25.0",
41
41
  "eslint-plugin-you-dont-need-lodash-underscore": "^6.13.0",
42
42
  "fast-glob": "^3.3.2",
43
- "@agilebot/eslint-utils": "0.2.0"
43
+ "@agilebot/eslint-utils": "0.2.2"
44
44
  },
45
45
  "peerDependencies": {
46
46
  "@agilebot/eslint-plugin": "*",