@kitql/eslint-config 0.8.0-next.3 → 0.8.0-next.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.
Files changed (3) hide show
  1. package/cmd.js +65 -59
  2. package/eslint.config.js +10 -2
  3. package/package.json +23 -16
package/cmd.js CHANGED
@@ -3,7 +3,7 @@ import { spawn } from 'node:child_process'
3
3
  import fs from 'node:fs'
4
4
  import path from 'node:path'
5
5
  import { Option, program } from 'commander'
6
- import ora from 'ora'
6
+ import { Spinner } from 'picospinner'
7
7
 
8
8
  import { bgBlueBright, bgGreen, bgRedBright, gray, green, red } from '@kitql/helpers'
9
9
 
@@ -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,10 @@ 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 = new Spinner({ symbolFormatter: (msg) => bgBlueBright(` kitql-lint `) + ' ' + msg })
48
+ spinner.start()
49
+ spinner.setText('Action: ' + green(format ? 'formatting' : 'linting'))
50
+
54
51
  let preToUse = ''
55
52
  if (pre === 'npm') {
56
53
  preToUse = 'npm exec '
@@ -92,9 +89,9 @@ async function customSpawn(/** @type {string} */ cmd) {
92
89
 
93
90
  let filesLength = -1
94
91
  async function getDiffFiles() {
95
- spinner.text = verbose
96
- ? 'git diff ' + gray(`(getting changed files against ${baseBranch})`)
97
- : 'git diff'
92
+ spinner.setText(
93
+ verbose ? 'git diff ' + gray(`(getting changed files against ${baseBranch})`) : 'git diff',
94
+ )
98
95
 
99
96
  // First, get the git repository root
100
97
  let gitRootPath = ''
@@ -271,7 +268,7 @@ async function getDiffFiles() {
271
268
  }
272
269
  }
273
270
 
274
- async function lintRunOx() {
271
+ async function runOxc(/** @type {string} */ name) {
275
272
  const cmdLint =
276
273
  `oxlint` +
277
274
  `${tools.includes('tsgolint') ? ' --type-aware' : ''}` +
@@ -279,41 +276,30 @@ async function lintRunOx() {
279
276
  `${format ? ' --fix' : ''}` +
280
277
  ` ${glob}`
281
278
 
282
- spinner.text = 'linting ' + gray(`(${verbose ? cmdLint : 'oxc'}) `)
279
+ spinner.setText(gray(`${verbose ? cmdLint : name} `))
283
280
 
284
281
  const result_lint = await customSpawn(cmdLint)
285
282
 
286
283
  return result_lint
287
284
  }
288
285
 
289
- async function lintRun() {
290
- if (tools.includes('oxlint')) {
291
- const result_lint = await lintRunOx()
292
- if (typeof result_lint === 'object' && 'status' in result_lint && result_lint.status) {
293
- return result_lint
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'}) `)
286
+ async function runEslint() {
287
+ const cmd =
288
+ preToUse +
289
+ `eslint --no-warn-ignored` +
290
+ // format or not
291
+ `${format ? ' --fix' : ''}` +
292
+ // exec
293
+ ` ${glob}`
307
294
 
308
- const result_lint = await customSpawn(cmdLint)
295
+ spinner.setText(gray(`${verbose ? cmd : 'eslint'} `))
309
296
 
310
- return result_lint
311
- }
297
+ const result_lint = await customSpawn(cmd)
312
298
 
313
- return ''
299
+ return result_lint
314
300
  }
315
301
 
316
- async function formatRun() {
302
+ async function runPrettier() {
317
303
  const cmdFormat =
318
304
  preToUse +
319
305
  `prettier` +
@@ -327,7 +313,7 @@ async function formatRun() {
327
313
  // exec
328
314
  ` ${glob}`
329
315
 
330
- spinner.text = 'formating ' + gray(`(${verbose ? cmdFormat : 'prettier'}) `)
316
+ spinner.setText(gray(`${verbose ? cmdFormat : 'prettier'} `))
331
317
 
332
318
  const result_format = await customSpawn(cmdFormat)
333
319
 
@@ -348,7 +334,6 @@ const displayTook = () => `${gray('(')}${took.join(gray(', '))}${gray(')')}`
348
334
 
349
335
  // If changed-only flag is set, get the list of changed files
350
336
  if (diffOnly) {
351
- spinner.text = 'Checking for changed files'
352
337
  const changedFilesStart = performance.now()
353
338
  const changedFiles = await getDiffFiles()
354
339
  const changedFilesTook = performance.now() - changedFilesStart
@@ -361,33 +346,54 @@ if (diffOnly) {
361
346
  }
362
347
  }
363
348
 
364
- if ((tools.includes('eslint') || tools.includes('oxlint')) && glob) {
365
- const lintStart = performance.now()
366
- const lintCode = await lintRun()
367
- const lintTook = performance.now() - lintStart
368
- took.push(display('lint', lintTook))
369
- if (typeof lintCode === 'object' && 'status' in lintCode && lintCode.status) {
370
- spinner.prefixText = bgRedBright(` kitql-lint `)
371
- spinner.fail(red(`lint failed, check logs above. ${displayTook()}`))
372
- process.exit(lintCode.status)
349
+ // yes, when we have tsgolint, we need to run oxlint too...
350
+ if ((tools.includes('oxlint') || tools.includes('tsgolint')) && glob) {
351
+ const start = performance.now()
352
+ const name = tools.includes('tsgolint') ? 'oxlint (+type)' : 'oxlint'
353
+ const code = await runOxc(name)
354
+ const stepTook = performance.now() - start
355
+ took.push(display(name, stepTook))
356
+ if (typeof code === 'object' && 'status' in code && code.status) {
357
+ spinner.fail({
358
+ symbolFormatter: (msg) => bgRedBright(` kitql-lint `) + ' ' + msg,
359
+ text: red(`lint failed, check logs above. ${displayTook()}`),
360
+ })
361
+ process.exit(code.status)
362
+ }
363
+ }
364
+
365
+ if (tools.includes('eslint') && glob) {
366
+ const start = performance.now()
367
+ const code = await runEslint()
368
+ const stepTook = performance.now() - start
369
+ took.push(display('eslint', stepTook))
370
+ if (typeof code === 'object' && 'status' in code && code.status) {
371
+ spinner.fail({
372
+ symbolFormatter: (msg) => bgRedBright(` kitql-lint `) + ' ' + msg,
373
+ text: red(`lint failed, check logs above. ${displayTook()}`),
374
+ })
375
+ process.exit(code.status)
373
376
  }
374
377
  }
375
378
 
376
379
  if (tools.includes('prettier') && glob) {
377
- const formatStart = performance.now()
378
- const formatCode = await formatRun()
379
- const formatTook = performance.now() - formatStart
380
- took.push(display('format', formatTook))
381
- if (typeof formatCode === 'object' && 'status' in formatCode && formatCode.status) {
382
- spinner.prefixText = bgRedBright(` kitql-lint `)
383
- spinner.fail(red(`format failed, check logs above. ${displayTook()}`))
384
- process.exit(formatCode.status)
380
+ const start = performance.now()
381
+ const code = await runPrettier()
382
+ const stepTook = performance.now() - start
383
+ took.push(display('prettier', stepTook))
384
+ if (typeof code === 'object' && 'status' in code && code.status) {
385
+ spinner.fail({
386
+ symbolFormatter: (msg) => bgRedBright(` kitql-lint `) + ' ' + msg,
387
+ text: red(`format failed, check logs above. ${displayTook()}`),
388
+ })
389
+ process.exit(code.status)
385
390
  }
386
391
  }
387
392
 
388
- spinner.prefixText = bgGreen(` kitql-lint `)
389
- spinner.succeed(
390
- `All good, ` +
393
+ spinner.succeed({
394
+ symbolFormatter: (msg) => bgGreen(` kitql-lint `) + ' ' + msg,
395
+ text:
396
+ `All good, ` +
391
397
  `${
392
398
  glob === ''
393
399
  ? 'nothing to do!'
@@ -396,6 +402,6 @@ spinner.succeed(
396
402
  : 'your files looks great!'
397
403
  } ` +
398
404
  displayTook(),
399
- )
405
+ })
400
406
  spinner.stop()
401
407
  process.exit(0)
package/eslint.config.js CHANGED
@@ -1,3 +1,4 @@
1
+ import e18e from '@e18e/eslint-plugin'
1
2
  import { includeIgnoreFile } from '@eslint/compat'
2
3
  import js from '@eslint/js'
3
4
  import prettier from 'eslint-config-prettier'
@@ -82,7 +83,10 @@ const rulePnpmCatalogs = (options = {}) => {
82
83
  ]
83
84
  }
84
85
 
85
- const othersRules = () => {
86
+ /**
87
+ * @param {{svelteConfig?: import('@sveltejs/kit').Config}} options
88
+ */
89
+ const othersRules = ({ svelteConfig } = {}) => {
86
90
  return [
87
91
  {
88
92
  name: 'eslint/defaults/recommended',
@@ -92,6 +96,7 @@ const othersRules = () => {
92
96
  ...svelte.configs.recommended,
93
97
  { name: 'eslint/prettier', ...prettier },
94
98
  ...svelte.configs.prettier,
99
+ e18e?.configs?.recommended,
95
100
  {
96
101
  name: '@kitql:languages',
97
102
  languageOptions: {
@@ -109,6 +114,7 @@ const othersRules = () => {
109
114
  projectService: true,
110
115
  extraFileExtensions: ['.svelte'],
111
116
  parser: ts.parser,
117
+ svelteConfig,
112
118
  },
113
119
  },
114
120
  },
@@ -182,6 +188,7 @@ const othersRules = () => {
182
188
  * @typedef {Object} KitqlOptions
183
189
  * @property {PnpmCatalogsConfig} [pnpmCatalogs] - Configuration object for pnpm catalogs
184
190
  * @property {OxlintConfig} [oxlint] - Configuration object for oxlint
191
+ * @property {import('@sveltejs/kit').Config} [svelteConfig] - Configuration object for svelte
185
192
  */
186
193
 
187
194
  /**
@@ -189,13 +196,14 @@ const othersRules = () => {
189
196
  * @returns {import('eslint').Linter.Config[]}
190
197
  */
191
198
  export const kitql = (options = {}) => {
199
+ const svelteConfig = options?.svelteConfig ?? {}
192
200
  const pnpmCatalogsConfig = options?.pnpmCatalogs ?? { enable: false }
193
201
  const pnpmCatalogsEnabled = pnpmCatalogsConfig.enable !== false
194
202
 
195
203
  const arr = [
196
204
  // default rules
197
205
  rulePrettierIgnore({ pnpmCatalogsEnabled }),
198
- ...othersRules(),
206
+ ...othersRules({ svelteConfig }),
199
207
  ]
200
208
 
201
209
  if (pnpmCatalogsEnabled) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitql/eslint-config",
3
- "version": "0.8.0-next.3",
3
+ "version": "0.8.0-next.5",
4
4
  "type": "module",
5
5
  "description": "opinionated linting and formatting for projects",
6
6
  "repository": {
@@ -32,38 +32,45 @@
32
32
  "format"
33
33
  ],
34
34
  "peerDependencies": {
35
- "eslint": "9.37.0",
36
- "oxlint": "1.23.0",
37
- "oxlint-tsgolint": "0.2.0",
35
+ "eslint": "9.39.1",
36
+ "oxlint": "1.34.0",
37
+ "oxlint-tsgolint": "0.10.0",
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": {
55
+ "@e18e/eslint-plugin": "^0.1.1",
49
56
  "@eslint/compat": "1.4.0",
50
- "@eslint/js": "9.37.0",
57
+ "@eslint/js": "9.39.1",
51
58
  "@ianvs/prettier-plugin-sort-imports": "^4.7.0",
52
59
  "@types/eslint": "9.6.1",
53
- "@typescript-eslint/parser": "8.46.1",
60
+ "@typescript-eslint/parser": "8.50.0",
54
61
  "commander": "14.0.0",
55
62
  "eslint-config-prettier": "10.1.5",
56
- "eslint-plugin-oxlint": "1.23.0",
57
- "eslint-plugin-pnpm": "1.2.0",
58
- "eslint-plugin-svelte": "3.12.4",
59
- "eslint-plugin-unused-imports": "4.2.0",
60
- "globals": "16.4.0",
63
+ "eslint-plugin-oxlint": "1.34.0",
64
+ "eslint-plugin-pnpm": "1.4.3",
65
+ "eslint-plugin-svelte": "3.13.0",
66
+ "eslint-plugin-unused-imports": "4.3.0",
67
+ "globals": "16.5.0",
61
68
  "jsonc-eslint-parser": "2.4.0",
62
- "ora": "9.0.0",
69
+ "picospinner": "3.0.0",
63
70
  "prettier-plugin-sh": "^0.18.0",
64
- "prettier-plugin-svelte": "3.4.0",
65
- "prettier-plugin-tailwindcss": "0.7.0",
66
- "typescript-eslint": "8.46.1",
71
+ "prettier-plugin-svelte": "^3.4.0",
72
+ "prettier-plugin-tailwindcss": "^0.7.0",
73
+ "typescript-eslint": "8.50.0",
67
74
  "yaml-eslint-parser": "1.3.0",
68
75
  "@kitql/helpers": "0.8.13"
69
76
  },
@@ -72,7 +79,7 @@
72
79
  },
73
80
  "sideEffects": false,
74
81
  "scripts": {
75
- "format": "node ./cmd.js -f -d --verbose",
82
+ "format": "node ./cmd.js -f -t eslint,prettier,oxlint",
76
83
  "format:example": "kitql-lint --format",
77
84
  "inspector": "npx @eslint/config-inspector",
78
85
  "lint": "node ./cmd.js --verbose -p none",