@mouse_484/eslint-config 4.0.3 → 4.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/bin/cli.js +17 -17
- package/jsconfig.json +8 -0
- package/package.json +1 -1
- package/src/const/cases.js +6 -0
- package/src/const/glob.js +11 -0
- package/src/index.js +8 -17
- package/src/index.d.ts +0 -10
package/bin/cli.js
CHANGED
|
@@ -60,13 +60,13 @@ function runCommand(command, args = []) {
|
|
|
60
60
|
/**
|
|
61
61
|
* Update JSON file with transform function
|
|
62
62
|
* @param {string} filePath - JSON file path
|
|
63
|
-
* @param {(data: any) => any}
|
|
63
|
+
* @param {(data: any) => any} updateFunction - Transform function
|
|
64
64
|
*/
|
|
65
|
-
async function updateJSONFile(filePath,
|
|
66
|
-
const content = await fs.readFile(filePath, '
|
|
65
|
+
async function updateJSONFile(filePath, updateFunction) {
|
|
66
|
+
const content = await fs.readFile(filePath, 'utf8')
|
|
67
67
|
const data = JSON.parse(content)
|
|
68
|
-
const updated =
|
|
69
|
-
await fs.writeFile(filePath, JSON.stringify(updated,
|
|
68
|
+
const updated = updateFunction(data)
|
|
69
|
+
await fs.writeFile(filePath, JSON.stringify(updated, undefined, 2))
|
|
70
70
|
return updated
|
|
71
71
|
}
|
|
72
72
|
|
|
@@ -103,9 +103,9 @@ async function main() {
|
|
|
103
103
|
const cwd = process.cwd()
|
|
104
104
|
const packageJSONPath = path.join(cwd, PACKAGE_JSON_FILE)
|
|
105
105
|
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
delete
|
|
106
|
+
const package_ = await updateJSONFile(packageJSONPath, (packageData) => {
|
|
107
|
+
packageData.devDependencies = packageData.devDependencies || {}
|
|
108
|
+
delete packageData.devDependencies[SOURCE.name]
|
|
109
109
|
|
|
110
110
|
let targetVersion
|
|
111
111
|
try {
|
|
@@ -119,28 +119,28 @@ async function main() {
|
|
|
119
119
|
targetVersion = 'latest'
|
|
120
120
|
}
|
|
121
121
|
TARGET.version = targetVersion
|
|
122
|
-
|
|
122
|
+
packageData.devDependencies[TARGET.name] = targetVersion
|
|
123
123
|
|
|
124
|
-
|
|
125
|
-
...
|
|
124
|
+
packageData.scripts = {
|
|
125
|
+
...packageData.scripts,
|
|
126
126
|
'lint': 'eslint .',
|
|
127
127
|
'lint:fix': 'eslint --fix .',
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
-
return
|
|
130
|
+
return packageData
|
|
131
131
|
})
|
|
132
132
|
|
|
133
|
-
const
|
|
134
|
-
const eslintConfigFile =
|
|
133
|
+
const configExtension = package_.type === 'module' ? 'js' : 'mjs'
|
|
134
|
+
const eslintConfigFile = configExtension === 'js' ? ESLINT_CONFIG_JS_FILE : ESLINT_CONFIG_MJS_FILE
|
|
135
135
|
const configPath = path.join(cwd, eslintConfigFile)
|
|
136
136
|
|
|
137
|
-
let configContent = await fs.readFile(configPath, '
|
|
137
|
+
let configContent = await fs.readFile(configPath, 'utf8')
|
|
138
138
|
configContent = configContent
|
|
139
139
|
.replace(
|
|
140
140
|
`import ${SOURCE.import} from '${SOURCE.name}'`,
|
|
141
141
|
`import ${TARGET.import} from '${TARGET.name}'`,
|
|
142
142
|
)
|
|
143
|
-
.
|
|
143
|
+
.replaceAll(new RegExp(`(?<!['"])${SOURCE.import}(?!['"])`, 'g'), TARGET.import)
|
|
144
144
|
await fs.writeFile(configPath, configContent)
|
|
145
145
|
|
|
146
146
|
const finalInstallCmd = resolveCommand(pm.agent, 'install', [])
|
|
@@ -149,4 +149,4 @@ async function main() {
|
|
|
149
149
|
console.info(`Successfully replaced the config from ${SOURCE.name} to ${TARGET.name}`)
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
-
main()
|
|
152
|
+
await main()
|
package/jsconfig.json
ADDED
package/package.json
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { GLOB_SVELTE as GLOB_SVELTE_COMPONENTS } from '@antfu/eslint-config'
|
|
2
|
+
|
|
3
|
+
export const GLOB_SVELTE_ROUTES = '**/src/routes/**/\+*.svelte'
|
|
4
|
+
|
|
5
|
+
export const GLOB_README = '**/README.md'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Code block in markdown
|
|
9
|
+
* @see https://github.com/eslint/markdown/blob/32d8cbd8b6d2d121225b5291c2f9a0ea6c2ccd00/docs/processors/markdown.md?plain=1#L96
|
|
10
|
+
*/
|
|
11
|
+
export const GLOB_MARKDOWN_CODE_BLOCK = '**/*.md/**'
|
package/src/index.js
CHANGED
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
// @ts-check
|
|
2
1
|
import antfu, {
|
|
3
2
|
GLOB_ASTRO,
|
|
4
3
|
GLOB_SVELTE,
|
|
5
4
|
} from '@antfu/eslint-config'
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const CASES = {
|
|
9
|
-
'camelCase': 'camelCase',
|
|
10
|
-
'PascalCase': 'pascalCase',
|
|
11
|
-
'snake_case': 'snakeCase',
|
|
12
|
-
'kebab-case': 'kebabCase',
|
|
13
|
-
}
|
|
5
|
+
import { CASES } from './const/cases.js'
|
|
6
|
+
import { GLOB_MARKDOWN_CODE_BLOCK, GLOB_README, GLOB_SVELTE_ROUTES } from './const/glob.js'
|
|
14
7
|
|
|
15
8
|
/** @type {import('@antfu/eslint-config')["antfu"]} */
|
|
16
9
|
async function mouse(options, ...userConfigs) {
|
|
@@ -73,14 +66,14 @@ async function mouse(options, ...userConfigs) {
|
|
|
73
66
|
'unicorn/filename-case': [
|
|
74
67
|
'error',
|
|
75
68
|
{
|
|
76
|
-
case: CASES.
|
|
69
|
+
case: CASES.camelCase,
|
|
77
70
|
},
|
|
78
71
|
],
|
|
79
72
|
},
|
|
80
73
|
},
|
|
81
74
|
{
|
|
82
75
|
name: 'mouse/svelte/kit-routes',
|
|
83
|
-
files: [
|
|
76
|
+
files: [GLOB_SVELTE_ROUTES],
|
|
84
77
|
rules: {
|
|
85
78
|
'unicorn/filename-case': 'off',
|
|
86
79
|
},
|
|
@@ -97,6 +90,7 @@ async function mouse(options, ...userConfigs) {
|
|
|
97
90
|
{
|
|
98
91
|
allowList: {
|
|
99
92
|
Props: true,
|
|
93
|
+
args: true,
|
|
100
94
|
},
|
|
101
95
|
},
|
|
102
96
|
],
|
|
@@ -104,12 +98,8 @@ async function mouse(options, ...userConfigs) {
|
|
|
104
98
|
}, {
|
|
105
99
|
name: 'mouse/unicorn/filename-case',
|
|
106
100
|
files: [
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
* Code block in markdown
|
|
110
|
-
* @see https://github.com/eslint/markdown/blob/32d8cbd8b6d2d121225b5291c2f9a0ea6c2ccd00/docs/processors/markdown.md?plain=1#L96
|
|
111
|
-
*/
|
|
112
|
-
'**/*.md/**',
|
|
101
|
+
GLOB_README,
|
|
102
|
+
GLOB_MARKDOWN_CODE_BLOCK,
|
|
113
103
|
],
|
|
114
104
|
rules: {
|
|
115
105
|
'unicorn/filename-case': 'off',
|
|
@@ -122,4 +112,5 @@ async function mouse(options, ...userConfigs) {
|
|
|
122
112
|
|
|
123
113
|
export default mouse
|
|
124
114
|
export { mouse }
|
|
115
|
+
export * from './const/glob.js'
|
|
125
116
|
export * from '@antfu/eslint-config'
|
package/src/index.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { Awaitable, OptionsConfig, TypedFlatConfigItem } from '@antfu/eslint-config'
|
|
2
|
-
|
|
3
|
-
declare function mouse(
|
|
4
|
-
options: OptionsConfig & TypedFlatConfigItem,
|
|
5
|
-
...userConfigs: Awaitable<TypedFlatConfigItem | TypedFlatConfigItem[]>[]
|
|
6
|
-
): Promise<TypedFlatConfigItem>
|
|
7
|
-
|
|
8
|
-
export default mouse
|
|
9
|
-
export { mouse }
|
|
10
|
-
export * from '@antfu/eslint-config'
|