@kitql/eslint-config 0.8.0-next.2 → 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/.prettierrc.js CHANGED
@@ -1,14 +1,14 @@
1
- import prettierConfig from '@theguild/prettier-config'
2
-
3
1
  const config = {
4
- ...prettierConfig,
5
2
  tabWidth: 1,
6
3
  useTabs: true,
7
4
  singleQuote: true,
5
+ trailingComma: 'all',
8
6
  semi: false,
9
7
  arrowParens: 'always',
8
+ printWidth: 100,
10
9
  plugins: [
11
- ...prettierConfig.plugins,
10
+ '@ianvs/prettier-plugin-sort-imports',
11
+ 'prettier-plugin-sh',
12
12
  'prettier-plugin-svelte',
13
13
  'prettier-plugin-tailwindcss', // MUST come last
14
14
  ],
@@ -31,15 +31,15 @@ const config = {
31
31
  '',
32
32
  '^[./]', // inside
33
33
  ],
34
- overrides: [
35
- {
36
- files: ['README.md', 'packages/**/README.md'],
37
- options: {
38
- useTabs: false,
39
- tabWidth: 2,
40
- },
41
- },
42
- ],
34
+ // overrides: [
35
+ // {
36
+ // files: ['README.md', 'packages/**/README.md'],
37
+ // options: {
38
+ // useTabs: false,
39
+ // tabWidth: 2,
40
+ // },
41
+ // },
42
+ // ],
43
43
  }
44
44
  export default config
45
45
 
package/cmd.js CHANGED
@@ -9,34 +9,26 @@ import { bgBlueBright, bgGreen, bgRedBright, gray, green, red } from '@kitql/hel
9
9
 
10
10
  import { findFileOrUp } from './helper/findFileOrUp.js'
11
11
 
12
- // df
13
- const spinner = ora({
14
- // hideCursor: true,
15
- prefixText: bgBlueBright(` kitql-lint `),
16
- text: 'check config',
17
- })
18
- spinner.start()
12
+ /** @type {('eslint' | 'prettier' | 'oxlint' | 'tsgolint')[]} */
13
+ const TOOLS_ALL = ['eslint', 'prettier', 'oxlint', 'tsgolint']
14
+ const TOOLS_DEFAULT = TOOLS_ALL.slice(0, 2)
19
15
 
20
16
  program.addOption(new Option('-f, --format', 'format'))
21
- program.addOption(new Option('-g, --glob <type>', 'file/dir/glob (. by default)').default('.'))
22
- program.addOption(new Option('--lint-only', 'only run lint').default(false))
23
- program.addOption(new Option('--format-only', 'only run format').default(false))
24
- program.addOption(new Option('--verbose', 'add more logs').default(false))
25
- program.addOption(new Option('--ox', 'using oxc tooling').default(false))
26
- program.addOption(new Option('--oxt', 'using oxc & type aware').default(false))
17
+ program.addOption(new Option('-g, --glob <type>', 'file/dir/glob').default('.'))
18
+ program.addOption(
19
+ new Option('-t, --tools <type>', 'tools to use (eslint, prettier, oxlint, tsgolint)').default(
20
+ TOOLS_DEFAULT.join(','),
21
+ ),
22
+ )
23
+ program.addOption(new Option('-v, --verbose', 'add more logs').default(false))
27
24
  program.addOption(
28
25
  new Option('-d, --diff-only', 'only check files changed against base branch').default(false),
29
26
  )
30
27
  program.addOption(
31
- new Option('--base-branch <type>', 'base branch to compare against (default: main)').default(
32
- 'main',
33
- ),
28
+ new Option('-b, --base-branch <type>', 'base branch to compare against').default('main'),
34
29
  )
35
30
  program.addOption(
36
- new Option(
37
- '-p, --prefix <type>',
38
- 'prefix by with "pnpm" or "npm" or "none" ("none" by default)',
39
- ).default('none'),
31
+ new Option('-p, --prefix <type>', 'prefix by with "pnpm" or "npm" or "none"').default('none'),
40
32
  )
41
33
  program.parse(process.argv)
42
34
  const options_cli = program.opts()
@@ -44,16 +36,23 @@ const options_cli = program.opts()
44
36
  const pathPrettierIgnore = findFileOrUp('.prettierignore')
45
37
  const pathPrettier_js = findFileOrUp('.prettierrc.js')
46
38
 
47
- const format = options_cli.format ?? false
48
- let glob = options_cli.glob ?? '.'
49
- const verbose = options_cli.verbose ?? false
50
- const pre = options_cli.prefix ?? 'none'
51
- const lintOnly = options_cli.lintOnly ?? false
52
- const formatOnly = options_cli.formatOnly ?? false
53
- const diffOnly = options_cli.diffOnly ?? false
54
- const baseBranch = options_cli.baseBranch ?? 'main'
55
- const using_ox = options_cli.ox ?? false
56
- const using_oxt = options_cli.oxt ?? false
39
+ const format = /** @type {boolean} */ (options_cli.format ?? false)
40
+ let glob = /** @type {string} */ (options_cli.glob ?? '.')
41
+ const verbose = /** @type {boolean} */ (options_cli.verbose ?? false)
42
+ const pre = /** @type {string} */ (options_cli.prefix ?? 'none')
43
+ const tools = /** @type {typeof TOOLS_ALL} */ (options_cli.tools.split(',') ?? TOOLS_DEFAULT)
44
+ const diffOnly = /** @type {boolean} */ (options_cli.diffOnly ?? false)
45
+ const baseBranch = /** @type {string} */ (options_cli.baseBranch ?? 'main')
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'))
57
56
 
58
57
  let preToUse = ''
59
58
  if (pre === 'npm') {
@@ -96,9 +95,9 @@ async function customSpawn(/** @type {string} */ cmd) {
96
95
 
97
96
  let filesLength = -1
98
97
  async function getDiffFiles() {
99
- spinner.text = verbose
100
- ? 'git diff ' + gray(`(getting changed files against ${baseBranch})`)
101
- : 'git diff'
98
+ updateSpinnerText(
99
+ verbose ? 'git diff ' + gray(`(getting changed files against ${baseBranch})`) : 'git diff',
100
+ )
102
101
 
103
102
  // First, get the git repository root
104
103
  let gitRootPath = ''
@@ -275,30 +274,23 @@ async function getDiffFiles() {
275
274
  }
276
275
  }
277
276
 
278
- async function lintRunOx() {
277
+ async function runOxc(/** @type {string} */ name) {
279
278
  const cmdLint =
280
279
  `oxlint` +
281
- `${using_oxt ? ' --type-aware' : ''}` +
280
+ `${tools.includes('tsgolint') ? ' --type-aware' : ''}` +
282
281
  // format or not
283
282
  `${format ? ' --fix' : ''}` +
284
283
  ` ${glob}`
285
284
 
286
- spinner.text = verbose ? 'lint ' + gray(`(${cmdLint}) `) : 'lint '
285
+ updateSpinnerText(gray(`${verbose ? cmdLint : name} `))
287
286
 
288
287
  const result_lint = await customSpawn(cmdLint)
289
288
 
290
289
  return result_lint
291
290
  }
292
291
 
293
- async function lintRun() {
294
- if (using_ox || using_oxt) {
295
- const result_lint = await lintRunOx()
296
- if (typeof result_lint === 'object' && 'status' in result_lint && result_lint.status) {
297
- return result_lint
298
- }
299
- }
300
-
301
- const cmdLint =
292
+ async function runEslint() {
293
+ const cmd =
302
294
  preToUse +
303
295
  `eslint --no-warn-ignored` +
304
296
  // format or not
@@ -306,14 +298,14 @@ async function lintRun() {
306
298
  // exec
307
299
  ` ${glob}`
308
300
 
309
- spinner.text = verbose ? 'lint ' + gray(`(${cmdLint}) `) : 'lint '
301
+ updateSpinnerText(gray(`${verbose ? cmd : 'eslint'} `))
310
302
 
311
- const result_lint = await customSpawn(cmdLint)
303
+ const result_lint = await customSpawn(cmd)
312
304
 
313
305
  return result_lint
314
306
  }
315
307
 
316
- async function formatRun() {
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
- spinner.text = verbose ? 'format ' + gray(`(${cmdFormat}) `) : 'format '
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
- if (!formatOnly && 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) {
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(lintCode.status)
377
+ process.exit(code.status)
373
378
  }
374
379
  }
375
380
 
376
- if (!lintOnly && 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) {
381
+ if (tools.includes('prettier') && glob) {
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(formatCode.status)
389
+ process.exit(code.status)
385
390
  }
386
391
  }
387
392
 
package/eslint.config.js CHANGED
@@ -173,9 +173,15 @@ const othersRules = () => {
173
173
  ]
174
174
  }
175
175
 
176
+ /**
177
+ * @typedef {Object} OxlintConfig
178
+ * @property {boolean} [enable] - Whether to enable oxlint
179
+ */
180
+
176
181
  /**
177
182
  * @typedef {Object} KitqlOptions
178
183
  * @property {PnpmCatalogsConfig} [pnpmCatalogs] - Configuration object for pnpm catalogs
184
+ * @property {OxlintConfig} [oxlint] - Configuration object for oxlint
179
185
  */
180
186
 
181
187
  /**
@@ -186,18 +192,27 @@ export const kitql = (options = {}) => {
186
192
  const pnpmCatalogsConfig = options?.pnpmCatalogs ?? { enable: false }
187
193
  const pnpmCatalogsEnabled = pnpmCatalogsConfig.enable !== false
188
194
 
189
- const pathOxlintrc = findFileOrUp('.oxlintrc.json') ?? './.oxlintrc.json'
190
-
191
- return [
192
- //
195
+ const arr = [
196
+ // default rules
193
197
  rulePrettierIgnore({ pnpmCatalogsEnabled }),
194
198
  ...othersRules(),
195
- ...(pnpmCatalogsEnabled ? rulePnpmCatalogs(pnpmCatalogsConfig) : []),
196
- ...oxlint.buildFromOxlintConfigFile(pathOxlintrc),
197
199
  ]
200
+
201
+ if (pnpmCatalogsEnabled) {
202
+ arr.push(...rulePnpmCatalogs(pnpmCatalogsConfig))
203
+ }
204
+
205
+ const oxlintConfig = options?.oxlint ?? { enable: false }
206
+ const oxlintEnabled = oxlintConfig.enable !== false
207
+ if (oxlintEnabled) {
208
+ const pathOxlintrc = findFileOrUp('.oxlintrc.json') ?? './.oxlintrc.json'
209
+ arr.push(...oxlint.buildFromOxlintConfigFile(pathOxlintrc))
210
+ }
211
+
212
+ return arr
198
213
  }
199
214
 
200
215
  /** @type {import('eslint').Linter.Config[]} */
201
- const config = kitql({ pnpmCatalogs: { enable: true } })
216
+ const config = kitql()
202
217
 
203
218
  export default config
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitql/eslint-config",
3
- "version": "0.8.0-next.2",
3
+ "version": "0.8.0-next.4",
4
4
  "type": "module",
5
5
  "description": "opinionated linting and formatting for projects",
6
6
  "repository": {
@@ -26,29 +26,38 @@
26
26
  "keywords": [
27
27
  "cli",
28
28
  "eslint",
29
- "eslint-config"
29
+ "eslint-config",
30
+ "oxc",
31
+ "lint",
32
+ "format"
30
33
  ],
31
34
  "peerDependencies": {
35
+ "eslint": "9.37.0",
32
36
  "oxlint": "1.23.0",
33
37
  "oxlint-tsgolint": "0.2.0",
34
38
  "prettier": "^3.6.1"
35
39
  },
36
40
  "peerDependenciesMeta": {
41
+ "eslint": {
42
+ "optional": true
43
+ },
37
44
  "oxlint": {
38
45
  "optional": true
39
46
  },
40
47
  "oxlint-tsgolint": {
41
48
  "optional": true
49
+ },
50
+ "prettier": {
51
+ "optional": true
42
52
  }
43
53
  },
44
54
  "dependencies": {
45
55
  "@eslint/compat": "1.4.0",
46
56
  "@eslint/js": "9.37.0",
47
- "@theguild/prettier-config": "3.0.0",
57
+ "@ianvs/prettier-plugin-sort-imports": "^4.7.0",
48
58
  "@types/eslint": "9.6.1",
49
59
  "@typescript-eslint/parser": "8.46.1",
50
60
  "commander": "14.0.0",
51
- "eslint": "9.37.0",
52
61
  "eslint-config-prettier": "10.1.5",
53
62
  "eslint-plugin-oxlint": "1.23.0",
54
63
  "eslint-plugin-pnpm": "1.2.0",
@@ -57,8 +66,9 @@
57
66
  "globals": "16.4.0",
58
67
  "jsonc-eslint-parser": "2.4.0",
59
68
  "ora": "9.0.0",
60
- "prettier-plugin-svelte": "3.4.0",
61
- "prettier-plugin-tailwindcss": "0.7.0",
69
+ "prettier-plugin-sh": "^0.18.0",
70
+ "prettier-plugin-svelte": "^3.4.0",
71
+ "prettier-plugin-tailwindcss": "^0.7.0",
62
72
  "typescript-eslint": "8.46.1",
63
73
  "yaml-eslint-parser": "1.3.0",
64
74
  "@kitql/helpers": "0.8.13"
@@ -68,10 +78,10 @@
68
78
  },
69
79
  "sideEffects": false,
70
80
  "scripts": {
71
- "format": "node ./cmd.js -f -d --verbose --oxt",
81
+ "format": "node ./cmd.js -f -t eslint,prettier,oxlint",
72
82
  "format:example": "kitql-lint --format",
73
83
  "inspector": "npx @eslint/config-inspector",
74
- "lint": "node ./cmd.js --verbose -p none --oxt",
84
+ "lint": "node ./cmd.js --verbose -p none",
75
85
  "lint:example": "kitql-lint"
76
86
  }
77
87
  }