@kitql/eslint-config 0.8.0-next.3 → 0.8.0-next.4
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/cmd.js +55 -50
- package/package.json +10 -4
package/cmd.js
CHANGED
|
@@ -13,13 +13,6 @@ import { findFileOrUp } from './helper/findFileOrUp.js'
|
|
|
13
13
|
const TOOLS_ALL = ['eslint', 'prettier', 'oxlint', 'tsgolint']
|
|
14
14
|
const TOOLS_DEFAULT = TOOLS_ALL.slice(0, 2)
|
|
15
15
|
|
|
16
|
-
const spinner = ora({
|
|
17
|
-
// hideCursor: true,
|
|
18
|
-
prefixText: bgBlueBright(` kitql-lint `),
|
|
19
|
-
text: 'check config',
|
|
20
|
-
})
|
|
21
|
-
spinner.start()
|
|
22
|
-
|
|
23
16
|
program.addOption(new Option('-f, --format', 'format'))
|
|
24
17
|
program.addOption(new Option('-g, --glob <type>', 'file/dir/glob').default('.'))
|
|
25
18
|
program.addOption(
|
|
@@ -51,6 +44,16 @@ const tools = /** @type {typeof TOOLS_ALL} */ (options_cli.tools.split(',') ?? T
|
|
|
51
44
|
const diffOnly = /** @type {boolean} */ (options_cli.diffOnly ?? false)
|
|
52
45
|
const baseBranch = /** @type {string} */ (options_cli.baseBranch ?? 'main')
|
|
53
46
|
|
|
47
|
+
const spinner = ora({
|
|
48
|
+
prefixText: bgBlueBright(` kitql-lint `),
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
function updateSpinnerText(/** @type {string} */ msg) {
|
|
52
|
+
spinner.text = msg
|
|
53
|
+
spinner.start()
|
|
54
|
+
}
|
|
55
|
+
updateSpinnerText('Action: ' + green(format ? 'formatting' : 'linting'))
|
|
56
|
+
|
|
54
57
|
let preToUse = ''
|
|
55
58
|
if (pre === 'npm') {
|
|
56
59
|
preToUse = 'npm exec '
|
|
@@ -92,9 +95,9 @@ async function customSpawn(/** @type {string} */ cmd) {
|
|
|
92
95
|
|
|
93
96
|
let filesLength = -1
|
|
94
97
|
async function getDiffFiles() {
|
|
95
|
-
|
|
96
|
-
? 'git diff ' + gray(`(getting changed files against ${baseBranch})`)
|
|
97
|
-
|
|
98
|
+
updateSpinnerText(
|
|
99
|
+
verbose ? 'git diff ' + gray(`(getting changed files against ${baseBranch})`) : 'git diff',
|
|
100
|
+
)
|
|
98
101
|
|
|
99
102
|
// First, get the git repository root
|
|
100
103
|
let gitRootPath = ''
|
|
@@ -271,7 +274,7 @@ async function getDiffFiles() {
|
|
|
271
274
|
}
|
|
272
275
|
}
|
|
273
276
|
|
|
274
|
-
async function
|
|
277
|
+
async function runOxc(/** @type {string} */ name) {
|
|
275
278
|
const cmdLint =
|
|
276
279
|
`oxlint` +
|
|
277
280
|
`${tools.includes('tsgolint') ? ' --type-aware' : ''}` +
|
|
@@ -279,41 +282,30 @@ async function lintRunOx() {
|
|
|
279
282
|
`${format ? ' --fix' : ''}` +
|
|
280
283
|
` ${glob}`
|
|
281
284
|
|
|
282
|
-
|
|
285
|
+
updateSpinnerText(gray(`${verbose ? cmdLint : name} `))
|
|
283
286
|
|
|
284
287
|
const result_lint = await customSpawn(cmdLint)
|
|
285
288
|
|
|
286
289
|
return result_lint
|
|
287
290
|
}
|
|
288
291
|
|
|
289
|
-
async function
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
if (tools.includes('eslint')) {
|
|
298
|
-
const cmdLint =
|
|
299
|
-
preToUse +
|
|
300
|
-
`eslint --no-warn-ignored` +
|
|
301
|
-
// format or not
|
|
302
|
-
`${format ? ' --fix' : ''}` +
|
|
303
|
-
// exec
|
|
304
|
-
` ${glob}`
|
|
305
|
-
|
|
306
|
-
spinner.text = 'linting ' + gray(`(${verbose ? cmdLint : 'eslint'}) `)
|
|
292
|
+
async function runEslint() {
|
|
293
|
+
const cmd =
|
|
294
|
+
preToUse +
|
|
295
|
+
`eslint --no-warn-ignored` +
|
|
296
|
+
// format or not
|
|
297
|
+
`${format ? ' --fix' : ''}` +
|
|
298
|
+
// exec
|
|
299
|
+
` ${glob}`
|
|
307
300
|
|
|
308
|
-
|
|
301
|
+
updateSpinnerText(gray(`${verbose ? cmd : 'eslint'} `))
|
|
309
302
|
|
|
310
|
-
|
|
311
|
-
}
|
|
303
|
+
const result_lint = await customSpawn(cmd)
|
|
312
304
|
|
|
313
|
-
return
|
|
305
|
+
return result_lint
|
|
314
306
|
}
|
|
315
307
|
|
|
316
|
-
async function
|
|
308
|
+
async function runPrettier() {
|
|
317
309
|
const cmdFormat =
|
|
318
310
|
preToUse +
|
|
319
311
|
`prettier` +
|
|
@@ -327,7 +319,7 @@ async function formatRun() {
|
|
|
327
319
|
// exec
|
|
328
320
|
` ${glob}`
|
|
329
321
|
|
|
330
|
-
|
|
322
|
+
updateSpinnerText(gray(`${verbose ? cmdFormat : 'prettier'} `))
|
|
331
323
|
|
|
332
324
|
const result_format = await customSpawn(cmdFormat)
|
|
333
325
|
|
|
@@ -348,7 +340,6 @@ const displayTook = () => `${gray('(')}${took.join(gray(', '))}${gray(')')}`
|
|
|
348
340
|
|
|
349
341
|
// If changed-only flag is set, get the list of changed files
|
|
350
342
|
if (diffOnly) {
|
|
351
|
-
spinner.text = 'Checking for changed files'
|
|
352
343
|
const changedFilesStart = performance.now()
|
|
353
344
|
const changedFiles = await getDiffFiles()
|
|
354
345
|
const changedFilesTook = performance.now() - changedFilesStart
|
|
@@ -361,27 +352,41 @@ if (diffOnly) {
|
|
|
361
352
|
}
|
|
362
353
|
}
|
|
363
354
|
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
const
|
|
367
|
-
const
|
|
368
|
-
|
|
369
|
-
|
|
355
|
+
// yes, when we have tsgolint, we need to run oxlint too...
|
|
356
|
+
if ((tools.includes('oxlint') || tools.includes('tsgolint')) && glob) {
|
|
357
|
+
const start = performance.now()
|
|
358
|
+
const name = tools.includes('tsgolint') ? 'oxlint (+type)' : 'oxlint'
|
|
359
|
+
const code = await runOxc(name)
|
|
360
|
+
const stepTook = performance.now() - start
|
|
361
|
+
took.push(display(name, stepTook))
|
|
362
|
+
if (typeof code === 'object' && 'status' in code && code.status) {
|
|
363
|
+
spinner.prefixText = bgRedBright(` kitql-lint `)
|
|
364
|
+
spinner.fail(red(`lint failed, check logs above. ${displayTook()}`))
|
|
365
|
+
process.exit(code.status)
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
if (tools.includes('eslint') && glob) {
|
|
370
|
+
const start = performance.now()
|
|
371
|
+
const code = await runEslint()
|
|
372
|
+
const stepTook = performance.now() - start
|
|
373
|
+
took.push(display('eslint', stepTook))
|
|
374
|
+
if (typeof code === 'object' && 'status' in code && code.status) {
|
|
370
375
|
spinner.prefixText = bgRedBright(` kitql-lint `)
|
|
371
376
|
spinner.fail(red(`lint failed, check logs above. ${displayTook()}`))
|
|
372
|
-
process.exit(
|
|
377
|
+
process.exit(code.status)
|
|
373
378
|
}
|
|
374
379
|
}
|
|
375
380
|
|
|
376
381
|
if (tools.includes('prettier') && glob) {
|
|
377
|
-
const
|
|
378
|
-
const
|
|
379
|
-
const
|
|
380
|
-
took.push(display('
|
|
381
|
-
if (typeof
|
|
382
|
+
const start = performance.now()
|
|
383
|
+
const code = await runPrettier()
|
|
384
|
+
const stepTook = performance.now() - start
|
|
385
|
+
took.push(display('prettier', stepTook))
|
|
386
|
+
if (typeof code === 'object' && 'status' in code && code.status) {
|
|
382
387
|
spinner.prefixText = bgRedBright(` kitql-lint `)
|
|
383
388
|
spinner.fail(red(`format failed, check logs above. ${displayTook()}`))
|
|
384
|
-
process.exit(
|
|
389
|
+
process.exit(code.status)
|
|
385
390
|
}
|
|
386
391
|
}
|
|
387
392
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kitql/eslint-config",
|
|
3
|
-
"version": "0.8.0-next.
|
|
3
|
+
"version": "0.8.0-next.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "opinionated linting and formatting for projects",
|
|
6
6
|
"repository": {
|
|
@@ -38,11 +38,17 @@
|
|
|
38
38
|
"prettier": "^3.6.1"
|
|
39
39
|
},
|
|
40
40
|
"peerDependenciesMeta": {
|
|
41
|
+
"eslint": {
|
|
42
|
+
"optional": true
|
|
43
|
+
},
|
|
41
44
|
"oxlint": {
|
|
42
45
|
"optional": true
|
|
43
46
|
},
|
|
44
47
|
"oxlint-tsgolint": {
|
|
45
48
|
"optional": true
|
|
49
|
+
},
|
|
50
|
+
"prettier": {
|
|
51
|
+
"optional": true
|
|
46
52
|
}
|
|
47
53
|
},
|
|
48
54
|
"dependencies": {
|
|
@@ -61,8 +67,8 @@
|
|
|
61
67
|
"jsonc-eslint-parser": "2.4.0",
|
|
62
68
|
"ora": "9.0.0",
|
|
63
69
|
"prettier-plugin-sh": "^0.18.0",
|
|
64
|
-
"prettier-plugin-svelte": "3.4.0",
|
|
65
|
-
"prettier-plugin-tailwindcss": "0.7.0",
|
|
70
|
+
"prettier-plugin-svelte": "^3.4.0",
|
|
71
|
+
"prettier-plugin-tailwindcss": "^0.7.0",
|
|
66
72
|
"typescript-eslint": "8.46.1",
|
|
67
73
|
"yaml-eslint-parser": "1.3.0",
|
|
68
74
|
"@kitql/helpers": "0.8.13"
|
|
@@ -72,7 +78,7 @@
|
|
|
72
78
|
},
|
|
73
79
|
"sideEffects": false,
|
|
74
80
|
"scripts": {
|
|
75
|
-
"format": "node ./cmd.js -f -
|
|
81
|
+
"format": "node ./cmd.js -f -t eslint,prettier,oxlint",
|
|
76
82
|
"format:example": "kitql-lint --format",
|
|
77
83
|
"inspector": "npx @eslint/config-inspector",
|
|
78
84
|
"lint": "node ./cmd.js --verbose -p none",
|