@agilebot/eslint-config 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
package/LICENSE CHANGED
@@ -1,9 +1,9 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2024 Agilebot, Inc.
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
-
7
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
-
9
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Agilebot, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/dist/index.d.ts CHANGED
@@ -6,6 +6,7 @@ interface FactoryOptions {
6
6
  config?: Linter.Config;
7
7
  react?: boolean;
8
8
  vue?: number;
9
+ module?: boolean;
9
10
  godaddy?: boolean;
10
11
  }
11
12
  declare function factory(root: string, options?: FactoryOptions): Linter.BaseConfig;
package/dist/index.js CHANGED
@@ -181,9 +181,13 @@ function promise() {
181
181
  var import_node_path = __toESM(require("path"));
182
182
  var import_node_fs = __toESM(require("fs"));
183
183
  var import_eslint_utils = require("@agilebot/eslint-utils");
184
- function eslintImport(packageDir, devDependencies) {
184
+ function eslintImport(opts) {
185
185
  const rootDir = (0, import_eslint_utils.findRootDir)(__dirname);
186
- const pkg = require(import_node_path.default.join(packageDir, "package.json"));
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"));
187
191
  const tmpPkg = {
188
192
  name: `${pkg.name}/tmp`,
189
193
  dependencies: {
@@ -225,7 +229,7 @@ function eslintImport(packageDir, devDependencies) {
225
229
  "import/no-extraneous-dependencies": [
226
230
  "error",
227
231
  {
228
- packageDir: [packageDir, tmpPkgDir, rootDir],
232
+ packageDir: [opts.packageDir, tmpPkgDir, rootDir],
229
233
  devDependencies: [
230
234
  "test/**/*",
231
235
  "tests/**/*",
@@ -235,7 +239,7 @@ function eslintImport(packageDir, devDependencies) {
235
239
  "**/.storybook/**",
236
240
  "**/*.stories.{ts,tsx}",
237
241
  "**/scripts/*.{ts,mts}",
238
- ...devDependencies ?? []
242
+ ...opts.devDependencies ?? []
239
243
  ],
240
244
  includeInternal: true
241
245
  }
@@ -282,21 +286,20 @@ function eslintImport(packageDir, devDependencies) {
282
286
  }
283
287
 
284
288
  // src/configs/unicorn.ts
285
- function unicorn() {
289
+ function unicorn(opts) {
286
290
  return {
287
291
  plugins: ["unicorn"],
288
292
  extends: ["plugin:unicorn/recommended"],
289
293
  rules: {
290
- // unicorn默认规则太严格,屏蔽以下
294
+ "unicorn/prefer-module": opts.module ? "error" : "off",
295
+ "unicorn/prefer-top-level-await": opts.module ? "error" : "off",
291
296
  "unicorn/filename-case": "off",
292
297
  "unicorn/import-style": "off",
293
298
  "unicorn/prefer-at": "off",
294
299
  "unicorn/prevent-abbreviations": "off",
295
300
  "unicorn/prefer-date-now": "off",
296
301
  "unicorn/no-process-exit": "off",
297
- "unicorn/prefer-module": "off",
298
302
  "unicorn/no-null": "off",
299
- "unicorn/prefer-top-level-await": "off",
300
303
  "unicorn/consistent-function-scoping": "off",
301
304
  "unicorn/numeric-separators-style": "off",
302
305
  "unicorn/prefer-optional-catch-binding": "off",
@@ -385,10 +388,10 @@ function react() {
385
388
  }
386
389
 
387
390
  // src/configs/vue.ts
388
- function vue(version) {
391
+ function vue(opts) {
389
392
  return {
390
393
  extends: [
391
- version === 3 ? "plugin:vue/vue3-recommended" : "plugin:vue/recommended"
394
+ opts.version === 3 ? "plugin:vue/vue3-recommended" : "plugin:vue/recommended"
392
395
  ]
393
396
  };
394
397
  }
@@ -457,7 +460,7 @@ function deprecation() {
457
460
  }
458
461
 
459
462
  // src/configs/cspell.ts
460
- function cspell(words) {
463
+ function cspell(opts) {
461
464
  return {
462
465
  plugins: ["@cspell"],
463
466
  rules: {
@@ -467,7 +470,7 @@ function cspell(words) {
467
470
  checkComments: false,
468
471
  autoFix: false,
469
472
  cspell: {
470
- words
473
+ words: opts.words
471
474
  }
472
475
  }
473
476
  ]
@@ -546,13 +549,21 @@ function godaddy() {
546
549
  // src/factory.ts
547
550
  function factory(root, options) {
548
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
+ ];
549
563
  if (options?.godaddy) {
550
564
  return (0, import_eslint_utils3.mergeESLintConfig)(
551
565
  godaddy(),
552
- prettier(),
553
- unicorn(),
554
- eslint(),
555
- eslintImport(root, options?.devDependencies),
566
+ ...commonConfigs,
556
567
  options?.config ?? {}
557
568
  );
558
569
  }
@@ -580,17 +591,18 @@ function factory(root, options) {
580
591
  standard(),
581
592
  ts(),
582
593
  promise(),
583
- eslintImport(root, options?.devDependencies),
584
- unicorn(),
585
594
  options?.react ? react() : {},
586
- options?.vue ? vue(options.vue) : {},
595
+ options?.vue ? vue({
596
+ version: options.vue
597
+ }) : {},
587
598
  jsdoc(),
588
599
  lodash(),
589
- eslint(),
590
600
  deprecation(),
591
- cspell(options?.cspellWords ?? []),
601
+ cspell({
602
+ words: options?.cspellWords ?? []
603
+ }),
604
+ ...commonConfigs,
592
605
  agilebot(),
593
- prettier(),
594
606
  options?.config ?? {}
595
607
  )
596
608
  },
@@ -601,7 +613,7 @@ function factory(root, options) {
601
613
  }
602
614
  },
603
615
  {
604
- files: ["*.d.ts"],
616
+ files: ["*.d.ts", "*.cts", "*.mts"],
605
617
  rules: {
606
618
  // .d.ts中支持导入ts文件中的类型
607
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.1",
3
+ "version": "0.2.2",
4
4
  "description": "Agilebot's ESLint config",
5
5
  "main": "dist",
6
6
  "types": "dist/index.d.ts",
@@ -40,7 +40,7 @@
40
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.1"
43
+ "@agilebot/eslint-utils": "0.2.2"
44
44
  },
45
45
  "peerDependencies": {
46
46
  "@agilebot/eslint-plugin": "*",