@mouse_484/eslint-config 3.0.0 → 3.1.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.
- package/package.json +4 -1
- package/src/index.js +61 -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.
|
|
4
|
+
"version": "3.1.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
|
-
|
|
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,60 @@ 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
|
-
|
|
27
|
+
export async function mouse(options, ...userConfigs) {
|
|
28
|
+
/** @type {TypedFlatConfigItem[]} */
|
|
29
|
+
const configs = []
|
|
30
|
+
|
|
31
|
+
configs.push({
|
|
32
|
+
name: 'mouse/source-files',
|
|
33
|
+
files: [GLOB_SRC],
|
|
34
|
+
rules: {
|
|
35
|
+
'style/max-len': ['error', {
|
|
36
|
+
code: 80,
|
|
37
|
+
tabWidth: 2,
|
|
38
|
+
comments: 120,
|
|
39
|
+
}],
|
|
40
|
+
},
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
if (options?.typescript) {
|
|
44
|
+
const pluginTs = await interopDefault(
|
|
45
|
+
import('@typescript-eslint/eslint-plugin'),
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @param {string} key
|
|
50
|
+
* @returns {import("eslint").Linter.RulesRecord}
|
|
51
|
+
* if tsconfigPath is defined, append '-type-checked' to the key
|
|
52
|
+
*/
|
|
53
|
+
const getRules = (key) => {
|
|
54
|
+
const typescriptOptions = resolveSubOptions(options, 'typescript')
|
|
55
|
+
const tsconfigPath = 'tsconfigPath' in typescriptOptions
|
|
56
|
+
? typescriptOptions.tsconfigPath
|
|
57
|
+
: undefined
|
|
58
|
+
|
|
59
|
+
return renameRules(
|
|
60
|
+
pluginTs.configs[
|
|
61
|
+
tsconfigPath ? `${key}-type-checked` : key
|
|
62
|
+
]?.rules ?? {},
|
|
63
|
+
{ '@typescript-eslint': 'ts' },
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
configs.push({
|
|
68
|
+
name: 'mouse/typescript',
|
|
69
|
+
files: [GLOB_TS, GLOB_TSX],
|
|
70
|
+
rules: {
|
|
71
|
+
...getRules('strict'),
|
|
72
|
+
...getRules('stylistic'),
|
|
73
|
+
},
|
|
74
|
+
})
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return antfu(options, ...configs, ...userConfigs)
|
|
23
78
|
}
|