@kitql/eslint-config 0.8.0-next.6 → 0.8.0-next.7

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/.oxlintrc.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "$schema": "./node_modules/oxlint/configuration_schema.json",
3
3
  "plugins": ["unicorn", "typescript", "oxc"],
4
- "jsPlugins": ["eslint-plugin-svelte", "eslint-plugin-unused-imports"],
4
+ "jsPlugins": ["eslint-plugin-svelte"],
5
5
  "rules": {
6
- "no-unused-vars": [
7
- "error",
8
- { "caughtErrors": "none", "argsIgnorePattern": "^_", "varsIgnorePattern": "^_" }
9
- ],
6
+ // "no-unused-vars": [
7
+ // "error",
8
+ // { "caughtErrors": "none", "argsIgnorePattern": "^_", "varsIgnorePattern": "^_" }
9
+ // ],
10
10
  "no-console": [
11
11
  "error",
12
12
  {
package/cmd.js CHANGED
@@ -3,9 +3,8 @@ 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 { Spinner } from 'picospinner'
7
6
 
8
- import { bgBlueBright, bgGreen, bgRedBright, gray, green, red } from '@kitql/helpers'
7
+ import { gray, green, Log } from '@kitql/helpers'
9
8
 
10
9
  import { findFileOrUp } from './helper/findFileOrUp.js'
11
10
 
@@ -44,9 +43,11 @@ const tools = /** @type {typeof TOOLS_ALL} */ (options_cli.tools.split(',') ?? T
44
43
  const diffOnly = /** @type {boolean} */ (options_cli.diffOnly ?? false)
45
44
  const baseBranch = /** @type {string} */ (options_cli.baseBranch ?? 'main')
46
45
 
47
- const spinner = new Spinner({ symbolFormatter: (msg) => bgBlueBright(` kitql-lint `) + ' ' + msg })
48
- spinner.start()
49
- spinner.setText('Action: ' + green(format ? 'formatting' : 'linting'))
46
+ const log = new Log('kitql-lint')
47
+ // const spinner = new Spinner({ symbolFormatter: (msg) => bgBlueBright(` kitql-lint `) + ' ' + msg })
48
+ // spinner.start()
49
+ // spinner.setText('Action: ' + green(format ? 'formatting' : 'linting'))
50
+ log.info('Action: ' + green(format ? 'formatting' : 'linting'))
50
51
 
51
52
  let preToUse = ''
52
53
  if (pre === 'npm') {
@@ -89,7 +90,7 @@ async function customSpawn(/** @type {string} */ cmd) {
89
90
 
90
91
  let filesLength = -1
91
92
  async function getDiffFiles() {
92
- spinner.setText(
93
+ log.info(
93
94
  verbose ? 'git diff ' + gray(`(getting changed files against ${baseBranch})`) : 'git diff',
94
95
  )
95
96
 
@@ -114,11 +115,11 @@ async function getDiffFiles() {
114
115
  if (gitRootExitCode === 0) {
115
116
  gitRootPath = rootData.trim()
116
117
  } else {
117
- spinner.warn('Could not determine git repository root')
118
+ log.error('Could not determine git repository root')
118
119
  return null
119
120
  }
120
121
  } catch (error) {
121
- if (error instanceof Error) spinner.warn(`Error getting git root: ${error.message}`)
122
+ if (error instanceof Error) log.error(`Error getting git root: ${error.message}`)
122
123
  return null
123
124
  }
124
125
 
@@ -142,7 +143,7 @@ async function getDiffFiles() {
142
143
  if (branchExitCode === 0) {
143
144
  validBranch = branch
144
145
  if (verbose && branch !== baseBranch) {
145
- spinner.info(`Using '${branch}' as base branch instead of '${baseBranch}'`)
146
+ log.info(`Using '${branch}' as base branch instead of '${baseBranch}'`)
146
147
  }
147
148
  break
148
149
  }
@@ -158,14 +159,14 @@ async function getDiffFiles() {
158
159
  // In CI, we can try to get all staged and unstaged changes
159
160
  validBranch = 'HEAD'
160
161
  if (verbose) {
161
- spinner.info('In CI environment, checking all changes')
162
+ log.info('In CI environment, checking all changes')
162
163
  }
163
164
  } catch (error) {
164
- spinner.warn(`Could not find a valid base branch to compare against`)
165
+ log.error(`Could not find a valid base branch to compare against`)
165
166
  return null
166
167
  }
167
168
  } else {
168
- spinner.warn(`Could not find a valid base branch to compare against`)
169
+ log.error(`Could not find a valid base branch to compare against`)
169
170
  return null
170
171
  }
171
172
  }
@@ -216,18 +217,18 @@ async function getDiffFiles() {
216
217
  if (fallbackExitCode === 0 && fallbackData.trim()) {
217
218
  data = fallbackData
218
219
  if (verbose) {
219
- spinner.info('Using fallback method to get changed files in CI')
220
+ log.info('Using fallback method to get changed files in CI')
220
221
  }
221
222
  } else {
222
- spinner.warn(`Could not get changed files: ${error}`)
223
+ log.error(`Could not get changed files: ${error}`)
223
224
  return null
224
225
  }
225
226
  } catch {
226
- spinner.warn(`Could not get changed files: ${error}`)
227
+ log.error(`Could not get changed files: ${error}`)
227
228
  return null
228
229
  }
229
230
  } else {
230
- spinner.warn(`Could not get changed files: ${error}`)
231
+ log.error(`Could not get changed files: ${error}`)
231
232
  return null
232
233
  }
233
234
  }
@@ -257,13 +258,13 @@ async function getDiffFiles() {
257
258
 
258
259
  filesLength = files.length
259
260
  if (verbose) {
260
- spinner.info(`Found ${filesLength} changed files at or below current directory`)
261
+ log.info(`Found ${filesLength} changed files at or below current directory`)
261
262
  }
262
263
 
263
264
  // Format the files for the command line, wrapping each in quotes and joining with spaces
264
265
  return files.length > 0 ? files.map((f) => `'${f}'`).join(' ') : null
265
266
  } catch (error) {
266
- if (error instanceof Error) spinner.warn(`Error getting changed files: ${error.message}`)
267
+ if (error instanceof Error) log.error(`Error getting changed files: ${error.message}`)
267
268
  return null
268
269
  }
269
270
  }
@@ -276,7 +277,7 @@ async function runOxc(/** @type {string} */ name) {
276
277
  `${format ? ' --fix' : ''}` +
277
278
  ` ${glob}`
278
279
 
279
- spinner.setText(gray(`${verbose ? cmdLint : name} `))
280
+ log.info(gray(`${verbose ? cmdLint : name} `))
280
281
 
281
282
  const result_lint = await customSpawn(cmdLint)
282
283
 
@@ -292,8 +293,7 @@ async function runEslint() {
292
293
  // exec
293
294
  ` ${glob}`
294
295
 
295
- spinner.setText(gray(`${verbose ? cmd : 'eslint'} `))
296
-
296
+ log.info(gray(`${verbose ? cmd : 'eslint'} `))
297
297
  const result_lint = await customSpawn(cmd)
298
298
 
299
299
  return result_lint
@@ -313,7 +313,7 @@ async function runPrettier() {
313
313
  // exec
314
314
  ` ${glob}`
315
315
 
316
- spinner.setText(gray(`${verbose ? cmdFormat : 'prettier'} `))
316
+ log.info(gray(`${verbose ? cmdFormat : 'prettier'} `))
317
317
 
318
318
  const result_format = await customSpawn(cmdFormat)
319
319
 
@@ -354,11 +354,8 @@ if ((tools.includes('oxlint') || tools.includes('tsgolint')) && glob) {
354
354
  const stepTook = performance.now() - start
355
355
  took.push(display(name, stepTook))
356
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)
357
+ log.error(`lint failed, check logs above. ${displayTook()}`)
358
+ process.exit(Number(code.status))
362
359
  }
363
360
  }
364
361
 
@@ -368,11 +365,8 @@ if (tools.includes('eslint') && glob) {
368
365
  const stepTook = performance.now() - start
369
366
  took.push(display('eslint', stepTook))
370
367
  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)
368
+ log.error(`lint failed, check logs above. ${displayTook()}`)
369
+ process.exit(Number(code.status))
376
370
  }
377
371
  }
378
372
 
@@ -382,18 +376,13 @@ if (tools.includes('prettier') && glob) {
382
376
  const stepTook = performance.now() - start
383
377
  took.push(display('prettier', stepTook))
384
378
  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)
379
+ log.error(`format failed, check logs above. ${displayTook()}`)
380
+ process.exit(Number(code.status))
390
381
  }
391
382
  }
392
383
 
393
- spinner.succeed({
394
- symbolFormatter: (msg) => bgGreen(` kitql-lint `) + ' ' + msg,
395
- text:
396
- `All good, ` +
384
+ log.success(
385
+ `All good, ` +
397
386
  `${
398
387
  glob === ''
399
388
  ? 'nothing to do!'
@@ -402,6 +391,5 @@ spinner.succeed({
402
391
  : 'your files looks great!'
403
392
  } ` +
404
393
  displayTook(),
405
- })
406
- spinner.stop()
394
+ )
407
395
  process.exit(0)
@@ -0,0 +1,36 @@
1
+ import type { Linter } from 'eslint'
2
+
3
+ export interface PnpmCatalogsConfig {
4
+ /** Whether to enable pnpm catalogs rules */
5
+ enable?: boolean
6
+ /** Files to apply JSON rules to */
7
+ json_files?: string[]
8
+ /** JSON rules configuration */
9
+ json_rules?: Record<string, any>
10
+ /** Files to apply YAML rules to */
11
+ yaml_files?: string[]
12
+ /** YAML rules configuration */
13
+ yaml_rules?: Record<string, any>
14
+ }
15
+
16
+ export interface OxlintConfig {
17
+ /** Whether to enable oxlint */
18
+ enable?: boolean
19
+ }
20
+
21
+ export interface KitqlOptions {
22
+ /** Configuration object for pnpm catalogs */
23
+ pnpmCatalogs?: PnpmCatalogsConfig
24
+ /** Configuration object for oxlint */
25
+ oxlint?: OxlintConfig
26
+ /** Configuration object for svelte */
27
+ svelteConfig?: Record<string, any>
28
+ }
29
+
30
+ /**
31
+ * Creates a KitQL ESLint configuration
32
+ */
33
+ export function kitql(options?: KitqlOptions): Linter.Config[]
34
+
35
+ declare const config: Linter.Config[]
36
+ export default config
package/eslint.config.js CHANGED
@@ -5,7 +5,6 @@ import prettier from 'eslint-config-prettier'
5
5
  import oxlint from 'eslint-plugin-oxlint'
6
6
  import pluginPnpm from 'eslint-plugin-pnpm'
7
7
  import svelte from 'eslint-plugin-svelte'
8
- import unusedImports from 'eslint-plugin-unused-imports'
9
8
  import globals from 'globals'
10
9
  import * as jsoncParser from 'jsonc-eslint-parser'
11
10
  import ts from 'typescript-eslint'
@@ -124,24 +123,19 @@ const othersRules = ({ svelteConfig } = {}) => {
124
123
  },
125
124
  {
126
125
  name: '@kitql:unused-imports',
127
- plugins: {
128
- 'unused-imports': unusedImports,
129
- },
130
126
  rules: {
131
127
  'no-unused-vars': 'off',
132
- '@typescript-eslint/no-unused-vars': 'off',
133
-
134
- 'unused-imports/no-unused-imports': 'error',
135
- 'unused-imports/no-unused-vars': 'off',
136
- // 'unused-imports/no-unused-vars': [
137
- // 'warn',
138
- // {
139
- // vars: 'all',
140
- // varsIgnorePattern: '^_',
141
- // args: 'after-used',
142
- // argsIgnorePattern: '^_',
143
- // },
144
- // ],
128
+ '@typescript-eslint/no-unused-vars': [
129
+ 'error',
130
+ {
131
+ args: 'none',
132
+ caughtErrors: 'none',
133
+ enableAutofixRemoval: {
134
+ imports: true,
135
+ },
136
+ },
137
+ ],
138
+
145
139
  'no-empty': ['error', { allowEmptyCatch: true }],
146
140
  },
147
141
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitql/eslint-config",
3
- "version": "0.8.0-next.6",
3
+ "version": "0.8.0-next.7",
4
4
  "type": "module",
5
5
  "description": "opinionated linting and formatting for projects",
6
6
  "repository": {
@@ -16,11 +16,13 @@
16
16
  "kitql-lint": "./cmd.js"
17
17
  },
18
18
  "main": "eslint.config.js",
19
+ "types": "eslint.config.d.ts",
19
20
  "files": [
20
21
  ".oxlintrc.json",
21
22
  ".prettierrc.js",
22
23
  "cmd.js",
23
24
  "eslint.config.js",
25
+ "eslint.config.d.ts",
24
26
  "helper/findFileOrUp.js"
25
27
  ],
26
28
  "keywords": [
@@ -63,10 +65,8 @@
63
65
  "eslint-plugin-oxlint": "1.39.0",
64
66
  "eslint-plugin-pnpm": "1.4.3",
65
67
  "eslint-plugin-svelte": "3.14.0",
66
- "eslint-plugin-unused-imports": "4.3.0",
67
68
  "globals": "17.0.0",
68
69
  "jsonc-eslint-parser": "2.4.0",
69
- "picospinner": "3.0.0",
70
70
  "prettier-plugin-sh": "^0.18.0",
71
71
  "prettier-plugin-svelte": "^3.4.0",
72
72
  "prettier-plugin-tailwindcss": "^0.7.0",