@mouse_484/eslint-config 3.0.0 → 3.2.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.
Files changed (2) hide show
  1. package/package.json +4 -1
  2. package/src/index.js +69 -6
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mouse_484/eslint-config",
3
3
  "type": "module",
4
- "version": "3.0.0",
4
+ "version": "3.2.0",
5
5
  "author": "mouse_484",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/mouse484/config/tree/main/packages/eslint",
@@ -18,5 +18,8 @@
18
18
  "main": "src/index.js",
19
19
  "dependencies": {
20
20
  "@antfu/eslint-config": "^2.21.1"
21
+ },
22
+ "devDependencies": {
23
+ "@typescript-eslint/eslint-plugin": "^7.13.1"
21
24
  }
22
25
  }
package/src/index.js CHANGED
@@ -1,10 +1,16 @@
1
- import antfu from '@antfu/eslint-config'
1
+ // @ts-check
2
+ import antfu, {
3
+ GLOB_SRC,
4
+ GLOB_TS,
5
+ GLOB_TSX,
6
+ interopDefault,
7
+ renameRules,
8
+ resolveSubOptions,
9
+ } from '@antfu/eslint-config'
2
10
 
3
11
  /**
4
12
  * @typedef {import('@antfu/eslint-config').OptionsConfig} OptionsConfig
5
13
  * @typedef {import('@antfu/eslint-config').TypedFlatConfigItem} TypedFlatConfigItem
6
- * @typedef {import('@antfu/eslint-config').Awaitable} Awaitable
7
- * @typedef {import('@antfu/eslint-config').TypedFlatConfigItem} TypedFlatConfigItem
8
14
  */
9
15
 
10
16
  /**
@@ -13,11 +19,68 @@ import antfu from '@antfu/eslint-config'
13
19
  *
14
20
  * @param {OptionsConfig & TypedFlatConfigItem} options
15
21
  * The options for generating the ESLint configurations.
16
- * @param {Awaitable<TypedFlatConfigItem | TypedFlatConfigItem[]>[]} userConfigs
22
+ * @param {import('@antfu/eslint-config').Awaitable<TypedFlatConfigItem | TypedFlatConfigItem[]>[]} userConfigs
17
23
  * The user configurations to be merged with the generated configurations.
18
24
  * @returns {Promise<TypedFlatConfigItem[]>}
19
25
  * The merged ESLint configurations.
20
26
  */
21
- export function mouse(options, ...userConfigs) {
22
- return antfu(options, ...userConfigs)
27
+ export async function mouse(options, ...userConfigs) {
28
+ options = {
29
+ lessOpinionated: true,
30
+ ...options,
31
+ }
32
+
33
+ /** @type {TypedFlatConfigItem[]} */
34
+ const configs = []
35
+
36
+ configs.push({
37
+ name: 'mouse/source-files',
38
+ files: [GLOB_SRC],
39
+ rules: {
40
+ 'style/max-len': [
41
+ 'error',
42
+ {
43
+ code: 80,
44
+ tabWidth: 2,
45
+ comments: 120,
46
+ },
47
+ ],
48
+ },
49
+ })
50
+
51
+ if (options?.typescript) {
52
+ const pluginTs = await interopDefault(
53
+ import('@typescript-eslint/eslint-plugin'),
54
+ )
55
+
56
+ /**
57
+ * @param {string} key
58
+ * @returns {import("eslint").Linter.RulesRecord}
59
+ * if tsconfigPath is defined, append '-type-checked' to the key
60
+ */
61
+ const getRules = (key) => {
62
+ const typescriptOptions = resolveSubOptions(options, 'typescript')
63
+ const tsconfigPath
64
+ = 'tsconfigPath' in typescriptOptions
65
+ ? typescriptOptions.tsconfigPath
66
+ : undefined
67
+
68
+ return renameRules(
69
+ pluginTs.configs[tsconfigPath ? `${key}-type-checked` : key]?.rules
70
+ ?? {},
71
+ { '@typescript-eslint': 'ts' },
72
+ )
73
+ }
74
+
75
+ configs.push({
76
+ name: 'mouse/typescript',
77
+ files: [GLOB_TS, GLOB_TSX],
78
+ rules: {
79
+ ...getRules('strict'),
80
+ ...getRules('stylistic'),
81
+ },
82
+ })
83
+ }
84
+
85
+ return antfu(options, ...configs, ...userConfigs)
23
86
  }