@kitql/eslint-config 0.5.5-next.0 → 0.5.5
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/.prettierrc.mjs +37 -26
- package/README.md +1 -1
- package/cmd.js +275 -275
- package/eslint.config.js +94 -87
- package/helper/findFileOrUp.js +16 -16
- package/package.json +9 -8
package/.prettierrc.mjs
CHANGED
|
@@ -1,30 +1,41 @@
|
|
|
1
1
|
import prettierConfig from '@theguild/prettier-config'
|
|
2
2
|
|
|
3
3
|
export default {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
4
|
+
...prettierConfig,
|
|
5
|
+
tabWidth: 1,
|
|
6
|
+
useTabs: true,
|
|
7
|
+
singleQuote: true,
|
|
8
|
+
semi: false,
|
|
9
|
+
arrowParens: 'always',
|
|
10
|
+
plugins: [
|
|
11
|
+
...prettierConfig.plugins,
|
|
12
|
+
'prettier-plugin-svelte',
|
|
13
|
+
'prettier-plugin-tailwindcss', // MUST come last
|
|
14
|
+
],
|
|
15
|
+
importOrderParserPlugins: ['typescript', 'decorators-legacy'],
|
|
16
|
+
importOrder: [
|
|
17
|
+
'<THIRD_PARTY_MODULES>',
|
|
18
|
+
'',
|
|
19
|
+
'^(\\$houdini)(.*)$', // special
|
|
20
|
+
'^(remult)(.*)$', // special
|
|
21
|
+
'^(firstly)(.*)$', // special
|
|
22
|
+
'^(@kitql)(.*)$', // special
|
|
23
|
+
'',
|
|
24
|
+
'^(\\$env)(.*)$', // special sveltekit
|
|
25
|
+
'^(\\$app)(.*)$', // special sveltekit
|
|
26
|
+
'',
|
|
27
|
+
'^(@app/common)(.*)$', // Aliases
|
|
28
|
+
'^(\\$)(.*)$', // Aliases
|
|
29
|
+
'',
|
|
30
|
+
'^[./]', // inside
|
|
31
|
+
],
|
|
32
|
+
overrides: [
|
|
33
|
+
{
|
|
34
|
+
files: ['README.md', 'packages/**/README.md'],
|
|
35
|
+
options: {
|
|
36
|
+
useTabs: false,
|
|
37
|
+
tabWidth: 2,
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
],
|
|
30
41
|
}
|
package/README.md
CHANGED
package/cmd.js
CHANGED
|
@@ -11,9 +11,9 @@ import { findFileOrUp } from './helper/findFileOrUp.js'
|
|
|
11
11
|
|
|
12
12
|
// df
|
|
13
13
|
const spinner = ora({
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
// hideCursor: true,
|
|
15
|
+
prefixText: bgBlueBright(` kitql-lint `),
|
|
16
|
+
text: 'check config',
|
|
17
17
|
})
|
|
18
18
|
spinner.start()
|
|
19
19
|
|
|
@@ -23,17 +23,17 @@ program.addOption(new Option('--eslint-only', 'only run eslint', false))
|
|
|
23
23
|
program.addOption(new Option('--prettier-only', 'only run prettier', false))
|
|
24
24
|
program.addOption(new Option('--verbose', 'add more logs', false))
|
|
25
25
|
program.addOption(
|
|
26
|
-
|
|
26
|
+
new Option('-d, --diff-only', 'only check files changed against base branch', false),
|
|
27
27
|
)
|
|
28
28
|
program.addOption(
|
|
29
|
-
|
|
29
|
+
new Option('--base-branch <type>', 'base branch to compare against (default: main)', 'main'),
|
|
30
30
|
)
|
|
31
31
|
program.addOption(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
new Option(
|
|
33
|
+
'-p, --prefix <type>',
|
|
34
|
+
'prefix by with "pnpm" or "npm" or "none" ("none" by default)',
|
|
35
|
+
'none',
|
|
36
|
+
),
|
|
37
37
|
)
|
|
38
38
|
|
|
39
39
|
program.parse(process.argv)
|
|
@@ -53,308 +53,308 @@ const baseBranch = options_cli.baseBranch ?? 'main'
|
|
|
53
53
|
|
|
54
54
|
let preToUse = ''
|
|
55
55
|
if (pre === 'npm') {
|
|
56
|
-
|
|
56
|
+
preToUse = 'npm exec '
|
|
57
57
|
} else if (pre === 'pnpm') {
|
|
58
|
-
|
|
58
|
+
preToUse = 'pnpm '
|
|
59
59
|
} else {
|
|
60
|
-
|
|
60
|
+
preToUse = ''
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
async function customSpawn(cmd) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
64
|
+
const child = spawn(cmd, {
|
|
65
|
+
shell: true,
|
|
66
|
+
cwd: process.cwd(),
|
|
67
|
+
stdio: 'inherit',
|
|
68
|
+
})
|
|
69
|
+
// console.log(`child`, child)
|
|
70
|
+
|
|
71
|
+
let data = ''
|
|
72
|
+
// for await (const chunk of child?.stdout) {
|
|
73
|
+
// console.log('stdout chunk: ' + chunk)
|
|
74
|
+
// data += chunk
|
|
75
|
+
// }
|
|
76
|
+
let error = ''
|
|
77
|
+
// for await (const chunk of child?.stderr) {
|
|
78
|
+
// console.error('stderr chunk: ' + chunk)
|
|
79
|
+
// error += chunk
|
|
80
|
+
// }
|
|
81
|
+
const exitCode = await new Promise((resolve, reject) => {
|
|
82
|
+
child.on('close', resolve)
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
if (exitCode) {
|
|
86
|
+
// throw new Error(`subprocess error exit ${exitCode}, ${error}`)
|
|
87
|
+
return { status: exitCode, error }
|
|
88
|
+
}
|
|
89
|
+
return data
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
let filesLength = -1
|
|
93
93
|
async function getDiffFiles() {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
94
|
+
spinner.text = verbose
|
|
95
|
+
? 'git diff ' + gray(`(getting changed files against ${baseBranch})`)
|
|
96
|
+
: 'git diff'
|
|
97
|
+
|
|
98
|
+
// First, get the git repository root
|
|
99
|
+
let gitRootPath = ''
|
|
100
|
+
try {
|
|
101
|
+
const gitRootCmd = 'git rev-parse --show-toplevel'
|
|
102
|
+
const gitRootChild = spawn(gitRootCmd, {
|
|
103
|
+
shell: true,
|
|
104
|
+
cwd: process.cwd(),
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
let rootData = ''
|
|
108
|
+
for await (const chunk of gitRootChild.stdout) {
|
|
109
|
+
rootData += chunk
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const gitRootExitCode = await new Promise((resolve) => {
|
|
113
|
+
gitRootChild.on('close', resolve)
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
if (gitRootExitCode === 0) {
|
|
117
|
+
gitRootPath = rootData.trim()
|
|
118
|
+
} else {
|
|
119
|
+
spinner.warn('Could not determine git repository root')
|
|
120
|
+
return null
|
|
121
|
+
}
|
|
122
|
+
} catch (error) {
|
|
123
|
+
spinner.warn(`Error getting git root: ${error.message}`)
|
|
124
|
+
return null
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Try to find the best base branch to compare against
|
|
128
|
+
const possibleBranches = [baseBranch, 'main', 'HEAD~1']
|
|
129
|
+
let validBranch = null
|
|
130
|
+
|
|
131
|
+
for (const branch of possibleBranches) {
|
|
132
|
+
try {
|
|
133
|
+
// Check if the branch exists
|
|
134
|
+
const checkBranchCmd = `git rev-parse --verify ${branch}`
|
|
135
|
+
const checkBranchChild = spawn(checkBranchCmd, {
|
|
136
|
+
shell: true,
|
|
137
|
+
cwd: process.cwd(),
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
const branchExitCode = await new Promise((resolve) => {
|
|
141
|
+
checkBranchChild.on('close', resolve)
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
if (branchExitCode === 0) {
|
|
145
|
+
validBranch = branch
|
|
146
|
+
if (verbose && branch !== baseBranch) {
|
|
147
|
+
spinner.info(`Using '${branch}' as base branch instead of '${baseBranch}'`)
|
|
148
|
+
}
|
|
149
|
+
break
|
|
150
|
+
}
|
|
151
|
+
} catch (error) {
|
|
152
|
+
// Continue to next branch
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (!validBranch) {
|
|
157
|
+
// If in CI, try to use a different approach
|
|
158
|
+
if (process.env.CI) {
|
|
159
|
+
try {
|
|
160
|
+
// In CI, we can try to get all staged and unstaged changes
|
|
161
|
+
validBranch = 'HEAD'
|
|
162
|
+
if (verbose) {
|
|
163
|
+
spinner.info('In CI environment, checking all changes')
|
|
164
|
+
}
|
|
165
|
+
} catch (error) {
|
|
166
|
+
spinner.warn(`Could not find a valid base branch to compare against`)
|
|
167
|
+
return null
|
|
168
|
+
}
|
|
169
|
+
} else {
|
|
170
|
+
spinner.warn(`Could not find a valid base branch to compare against`)
|
|
171
|
+
return null
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Now get the changed files
|
|
176
|
+
const cmd = `git diff --name-only --diff-filter=ACMR ${validBranch}`
|
|
177
|
+
|
|
178
|
+
try {
|
|
179
|
+
const child = spawn(cmd, {
|
|
180
|
+
shell: true,
|
|
181
|
+
cwd: process.cwd(),
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
let data = ''
|
|
185
|
+
for await (const chunk of child.stdout) {
|
|
186
|
+
data += chunk
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
let error = ''
|
|
190
|
+
for await (const chunk of child.stderr) {
|
|
191
|
+
error += chunk
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const exitCode = await new Promise((resolve) => {
|
|
195
|
+
child.on('close', resolve)
|
|
196
|
+
})
|
|
197
|
+
|
|
198
|
+
if (exitCode) {
|
|
199
|
+
// If the diff command failed, try a fallback approach for CI environments
|
|
200
|
+
if (process.env.CI) {
|
|
201
|
+
try {
|
|
202
|
+
// In CI, we can try to get all tracked files that have changes
|
|
203
|
+
const fallbackCmd = 'git ls-files --modified --others --exclude-standard'
|
|
204
|
+
const fallbackChild = spawn(fallbackCmd, {
|
|
205
|
+
shell: true,
|
|
206
|
+
cwd: process.cwd(),
|
|
207
|
+
})
|
|
208
|
+
|
|
209
|
+
let fallbackData = ''
|
|
210
|
+
for await (const chunk of fallbackChild.stdout) {
|
|
211
|
+
fallbackData += chunk
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const fallbackExitCode = await new Promise((resolve) => {
|
|
215
|
+
fallbackChild.on('close', resolve)
|
|
216
|
+
})
|
|
217
|
+
|
|
218
|
+
if (fallbackExitCode === 0 && fallbackData.trim()) {
|
|
219
|
+
data = fallbackData
|
|
220
|
+
if (verbose) {
|
|
221
|
+
spinner.info('Using fallback method to get changed files in CI')
|
|
222
|
+
}
|
|
223
|
+
} else {
|
|
224
|
+
spinner.warn(`Could not get changed files: ${error}`)
|
|
225
|
+
return null
|
|
226
|
+
}
|
|
227
|
+
} catch (fallbackError) {
|
|
228
|
+
spinner.warn(`Could not get changed files: ${error}`)
|
|
229
|
+
return null
|
|
230
|
+
}
|
|
231
|
+
} else {
|
|
232
|
+
spinner.warn(`Could not get changed files: ${error}`)
|
|
233
|
+
return null
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// Get the current working directory
|
|
238
|
+
const cwd = process.cwd()
|
|
239
|
+
|
|
240
|
+
// Process the files to make them relative to the current working directory
|
|
241
|
+
const files = data
|
|
242
|
+
.trim()
|
|
243
|
+
.split('\n')
|
|
244
|
+
.filter(Boolean)
|
|
245
|
+
.map((file) => {
|
|
246
|
+
// Convert the git path (relative to git root) to an absolute path
|
|
247
|
+
const absolutePath = path.join(gitRootPath, file)
|
|
248
|
+
|
|
249
|
+
// Convert the absolute path to a path relative to the current working directory
|
|
250
|
+
const relativePath = path.relative(cwd, absolutePath)
|
|
251
|
+
|
|
252
|
+
// Check if the file exists and is at or below the current directory
|
|
253
|
+
if (fs.existsSync(relativePath) && !relativePath.startsWith('..')) {
|
|
254
|
+
return relativePath
|
|
255
|
+
}
|
|
256
|
+
return null
|
|
257
|
+
})
|
|
258
|
+
.filter(Boolean) // Remove null entries (files not at or below current directory)
|
|
259
|
+
|
|
260
|
+
filesLength = files.length
|
|
261
|
+
if (verbose) {
|
|
262
|
+
spinner.info(`Found ${filesLength} changed files at or below current directory`)
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// Format the files for the command line, wrapping each in quotes and joining with spaces
|
|
266
|
+
return files.length > 0 ? files.map((f) => `'${f}'`).join(' ') : null
|
|
267
|
+
} catch (error) {
|
|
268
|
+
spinner.warn(`Error getting changed files: ${error.message}`)
|
|
269
|
+
return null
|
|
270
|
+
}
|
|
271
271
|
}
|
|
272
272
|
|
|
273
273
|
async function eslintRun() {
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
274
|
+
const cmdEsLint =
|
|
275
|
+
preToUse +
|
|
276
|
+
`eslint --no-warn-ignored` +
|
|
277
|
+
// format or not
|
|
278
|
+
`${format ? ' --fix' : ''}` +
|
|
279
|
+
// exec
|
|
280
|
+
` ${glob}`
|
|
281
281
|
|
|
282
|
-
|
|
282
|
+
spinner.text = verbose ? 'eslint ' + gray(`(${cmdEsLint})`) : 'eslint'
|
|
283
283
|
|
|
284
|
-
|
|
284
|
+
const result_eslint = await customSpawn(cmdEsLint)
|
|
285
285
|
|
|
286
|
-
|
|
286
|
+
return result_eslint
|
|
287
287
|
}
|
|
288
288
|
|
|
289
289
|
async function prettierRun() {
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
290
|
+
const cmdPrettier =
|
|
291
|
+
preToUse +
|
|
292
|
+
`prettier` +
|
|
293
|
+
` --list-different` +
|
|
294
|
+
// ignore?
|
|
295
|
+
` --ignore-path ${pathPrettierIgnore}` +
|
|
296
|
+
// config
|
|
297
|
+
` --config ${pathPrettierMjs}` +
|
|
298
|
+
// format or not
|
|
299
|
+
`${format ? ' --write' : ''}` +
|
|
300
|
+
// exec
|
|
301
|
+
` ${glob}`
|
|
302
|
+
|
|
303
|
+
spinner.text = verbose ? 'prettier ' + gray(`(${cmdPrettier})`) : 'prettier'
|
|
304
|
+
|
|
305
|
+
const result_prettier = await customSpawn(cmdPrettier)
|
|
306
|
+
|
|
307
|
+
return result_prettier
|
|
308
308
|
}
|
|
309
309
|
|
|
310
310
|
const took = []
|
|
311
311
|
|
|
312
312
|
const display = (text, time) => {
|
|
313
|
-
|
|
313
|
+
return `${gray(text)} ${green((time / 1000).toFixed(3))}${gray('s')}`
|
|
314
314
|
}
|
|
315
315
|
|
|
316
316
|
// If changed-only flag is set, get the list of changed files
|
|
317
317
|
if (diffOnly) {
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
318
|
+
spinner.text = 'Checking for changed files'
|
|
319
|
+
const changedFilesStart = performance.now()
|
|
320
|
+
const changedFiles = await getDiffFiles()
|
|
321
|
+
const changedFilesTook = performance.now() - changedFilesStart
|
|
322
|
+
took.push(display('diff', changedFilesTook))
|
|
323
|
+
|
|
324
|
+
if (changedFiles) {
|
|
325
|
+
glob = changedFiles
|
|
326
|
+
} else {
|
|
327
|
+
glob = ''
|
|
328
|
+
}
|
|
329
329
|
}
|
|
330
330
|
|
|
331
331
|
if (!prettierOnly && glob) {
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
332
|
+
const esLintStart = performance.now()
|
|
333
|
+
const eslintCode = await eslintRun()
|
|
334
|
+
const esLintTook = performance.now() - esLintStart
|
|
335
|
+
took.push(display('eslint', esLintTook))
|
|
336
|
+
if (eslintCode.status) {
|
|
337
|
+
spinner.prefixText = bgRedBright(` kitql-lint `)
|
|
338
|
+
spinner.fail(red(`eslint failed, check logs above.`))
|
|
339
|
+
process.exit(eslintCode.status)
|
|
340
|
+
}
|
|
341
341
|
}
|
|
342
342
|
|
|
343
343
|
if (!eslintOnly && glob) {
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
344
|
+
const prettierStart = performance.now()
|
|
345
|
+
const prettierCode = await prettierRun()
|
|
346
|
+
const prettierTook = performance.now() - prettierStart
|
|
347
|
+
took.push(display('prettier', prettierTook))
|
|
348
|
+
if (prettierCode.status) {
|
|
349
|
+
spinner.prefixText = bgRedBright(` kitql-lint `)
|
|
350
|
+
spinner.fail(red(`prettier failed, check logs above.`))
|
|
351
|
+
process.exit(prettierCode.status)
|
|
352
|
+
}
|
|
353
353
|
}
|
|
354
354
|
|
|
355
355
|
spinner.prefixText = bgGreen(` kitql-lint `)
|
|
356
356
|
spinner.succeed(
|
|
357
|
-
|
|
357
|
+
`All good, ${glob === '' ? 'nothing to do!' : filesLength !== -1 ? `your ${filesLength} files looks great!` : 'your files looks great!'} ${gray('(')}${took.join(gray(', '))}${gray(')')}`,
|
|
358
358
|
)
|
|
359
359
|
spinner.stop()
|
|
360
360
|
process.exit(0)
|
package/eslint.config.js
CHANGED
|
@@ -4,6 +4,7 @@ import pnpmCatalogs from 'eslint-plugin-pnpm-catalogs'
|
|
|
4
4
|
import svelte from 'eslint-plugin-svelte'
|
|
5
5
|
import unusedImports from 'eslint-plugin-unused-imports'
|
|
6
6
|
import globals from 'globals'
|
|
7
|
+
import * as jsoncParser from 'jsonc-eslint-parser'
|
|
7
8
|
import ts from 'typescript-eslint'
|
|
8
9
|
|
|
9
10
|
import { findFileOrUp } from './helper/findFileOrUp.js'
|
|
@@ -12,98 +13,104 @@ const pathPrettierIgnore = findFileOrUp('.prettierignore', { absolute: true })
|
|
|
12
13
|
|
|
13
14
|
/** @type {import('eslint').Linter.Config[]} */
|
|
14
15
|
export const config = [
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
16
|
+
{
|
|
17
|
+
name: '@kitql:prettier:ignores',
|
|
18
|
+
ignores: pathPrettierIgnore
|
|
19
|
+
? includeIgnoreFile(pathPrettierIgnore).ignores.filter((c) => !c.includes('package.json'))
|
|
20
|
+
: [],
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
name: 'eslint/defaults/recommended',
|
|
24
|
+
...js.configs.recommended, // TODO, would be nice to have a name by default?
|
|
25
|
+
},
|
|
26
|
+
...ts.configs.recommended,
|
|
27
|
+
...svelte.configs['flat/recommended'],
|
|
28
|
+
{
|
|
29
|
+
name: '@kitql:languages',
|
|
30
|
+
languageOptions: {
|
|
31
|
+
globals: {
|
|
32
|
+
...globals.browser,
|
|
33
|
+
...globals.node,
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: '@kitql:svelte:languages',
|
|
39
|
+
files: ['**/*.svelte'],
|
|
40
|
+
languageOptions: {
|
|
41
|
+
parserOptions: {
|
|
42
|
+
parser: ts.parser,
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: '@kitql:ignores',
|
|
48
|
+
ignores: ['build/', '.svelte-kit/', 'dist/', '**/build/', '**/.svelte-kit/', '**/dist/'],
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: '@kitql:unused-imports',
|
|
52
|
+
plugins: {
|
|
53
|
+
'unused-imports': unusedImports,
|
|
54
|
+
},
|
|
55
|
+
rules: {
|
|
56
|
+
'no-unused-vars': 'off',
|
|
57
|
+
'@typescript-eslint/no-unused-vars': 'off',
|
|
55
58
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
59
|
+
'unused-imports/no-unused-imports': 'error',
|
|
60
|
+
'unused-imports/no-unused-vars': 'off',
|
|
61
|
+
// 'unused-imports/no-unused-vars': [
|
|
62
|
+
// 'warn',
|
|
63
|
+
// {
|
|
64
|
+
// vars: 'all',
|
|
65
|
+
// varsIgnorePattern: '^_',
|
|
66
|
+
// args: 'after-used',
|
|
67
|
+
// argsIgnorePattern: '^_',
|
|
68
|
+
// },
|
|
69
|
+
// ],
|
|
70
|
+
'no-empty': ['error', { allowEmptyCatch: true }],
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
name: 'pnpm-catalogs:package.json',
|
|
75
|
+
files: ['package.json'],
|
|
76
|
+
languageOptions: {
|
|
77
|
+
parser: jsoncParser,
|
|
78
|
+
},
|
|
79
|
+
plugins: {
|
|
80
|
+
'pnpm-catalogs': pnpmCatalogs,
|
|
81
|
+
},
|
|
82
|
+
rules: {
|
|
83
|
+
'pnpm-catalogs/enforce-catalog': 'error',
|
|
84
|
+
'pnpm-catalogs/valid-catalog': 'error',
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
name: '@kitql:rules',
|
|
89
|
+
rules: {
|
|
90
|
+
'no-console': [
|
|
91
|
+
'error',
|
|
92
|
+
{
|
|
93
|
+
allow: ['info', 'warn', 'error', 'time', 'timeEnd', 'dir'],
|
|
94
|
+
},
|
|
95
|
+
],
|
|
89
96
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
+
'@typescript-eslint/no-require-imports': 'off',
|
|
98
|
+
'@typescript-eslint/ban-ts-ignore': 'off',
|
|
99
|
+
'@typescript-eslint/ban-ts-comment': 'off',
|
|
100
|
+
'@typescript-eslint/no-explicit-any': 'off',
|
|
101
|
+
'@typescript-eslint/no-non-null-assertion': 'off',
|
|
102
|
+
'@typescript-eslint/no-unused-expressions': 'off',
|
|
103
|
+
'@typescript-eslint/no-empty-object-type': 'off',
|
|
97
104
|
|
|
98
|
-
|
|
99
|
-
|
|
105
|
+
'no-undef': 'off',
|
|
106
|
+
'no-inner-declarations': 'off',
|
|
100
107
|
|
|
101
|
-
|
|
102
|
-
|
|
108
|
+
'svelte/no-at-html-tags': 'off',
|
|
109
|
+
'svelte/no-inner-declarations': 'off',
|
|
103
110
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
111
|
+
'svelte/require-each-key': 'warn',
|
|
112
|
+
},
|
|
113
|
+
},
|
|
107
114
|
]
|
|
108
115
|
|
|
109
116
|
export default config
|
package/helper/findFileOrUp.js
CHANGED
|
@@ -2,21 +2,21 @@ import { statSync } from 'node:fs'
|
|
|
2
2
|
import { resolve } from 'node:path'
|
|
3
3
|
|
|
4
4
|
export const findFileOrUp = (fileName, options) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
5
|
+
// Find file recursively 4 levels max up
|
|
6
|
+
for (let i = 0; i < 4; i++) {
|
|
7
|
+
try {
|
|
8
|
+
const pathFound = '../'.repeat(i) + fileName
|
|
9
|
+
if (statSync(pathFound)) {
|
|
10
|
+
if (options?.absolute) {
|
|
11
|
+
return resolve(pathFound)
|
|
12
|
+
}
|
|
13
|
+
return pathFound
|
|
14
|
+
}
|
|
15
|
+
} catch (error) {
|
|
16
|
+
// nothing to do
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
console.error(`"${fileName}" not found`)
|
|
21
|
+
return null
|
|
22
22
|
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kitql/eslint-config",
|
|
3
|
-
"version": "0.5.5
|
|
3
|
+
"version": "0.5.5",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"funding": "https://github.com/sponsors/jycouet",
|
|
6
|
-
"homepage": "https://www.kitql.dev/",
|
|
7
5
|
"description": "opinionated linting and formatting for projects",
|
|
8
6
|
"repository": {
|
|
9
7
|
"type": "git",
|
|
@@ -11,6 +9,8 @@
|
|
|
11
9
|
"directory": "packages/eslint-config",
|
|
12
10
|
"homepage": "https://github.com/jycouet/kitql/tree/main/packages/eslint-config"
|
|
13
11
|
},
|
|
12
|
+
"homepage": "https://www.kitql.dev/",
|
|
13
|
+
"funding": "https://github.com/sponsors/jycouet",
|
|
14
14
|
"license": "MIT",
|
|
15
15
|
"bin": {
|
|
16
16
|
"kitql-lint": "./cmd.js"
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
".prettierrc.mjs",
|
|
21
21
|
"cmd.js",
|
|
22
22
|
"cmd.sh",
|
|
23
|
-
"eslint.config.js",
|
|
24
23
|
"eslint.config.d.ts",
|
|
24
|
+
"eslint.config.js",
|
|
25
25
|
"helper/findFileOrUp.js"
|
|
26
26
|
],
|
|
27
27
|
"keywords": [
|
|
@@ -30,18 +30,19 @@
|
|
|
30
30
|
"eslint-config"
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@eslint/compat": "1.
|
|
33
|
+
"@eslint/compat": "1.2.7",
|
|
34
34
|
"@eslint/js": "9.10.0",
|
|
35
35
|
"@theguild/prettier-config": "3.0.0",
|
|
36
36
|
"@types/eslint": "9.6.1",
|
|
37
|
-
"@typescript-eslint/parser": "8.
|
|
37
|
+
"@typescript-eslint/parser": "8.26.0",
|
|
38
38
|
"commander": "13.1.0",
|
|
39
39
|
"eslint": "9.10.0",
|
|
40
|
-
"eslint-plugin-pnpm-catalogs": "0.0
|
|
40
|
+
"eslint-plugin-pnpm-catalogs": "0.1.0",
|
|
41
41
|
"eslint-plugin-svelte": "3.0.3",
|
|
42
42
|
"eslint-plugin-unused-imports": "4.1.4",
|
|
43
43
|
"globals": "16.0.0",
|
|
44
|
-
"
|
|
44
|
+
"jsonc-eslint-parser": "2.4.0",
|
|
45
|
+
"ora": "8.2.0",
|
|
45
46
|
"prettier": "3.5.3",
|
|
46
47
|
"prettier-plugin-svelte": "3.3.2",
|
|
47
48
|
"prettier-plugin-tailwindcss": "0.6.6",
|