@kitql/eslint-config 0.5.5 → 0.5.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/.prettierrc.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import prettierConfig from '@theguild/prettier-config'
2
2
 
3
- export default {
3
+ const config = {
4
4
  ...prettierConfig,
5
5
  tabWidth: 1,
6
6
  useTabs: true,
@@ -39,3 +39,8 @@ export default {
39
39
  },
40
40
  ],
41
41
  }
42
+ export default config
43
+
44
+ export const kitql = () => {
45
+ return config
46
+ }
package/cmd.js CHANGED
@@ -312,6 +312,7 @@ const took = []
312
312
  const display = (text, time) => {
313
313
  return `${gray(text)} ${green((time / 1000).toFixed(3))}${gray('s')}`
314
314
  }
315
+ const displayTook = () => `${gray('(')}${took.join(gray(', '))}${gray(')')}`
315
316
 
316
317
  // If changed-only flag is set, get the list of changed files
317
318
  if (diffOnly) {
@@ -335,7 +336,7 @@ if (!prettierOnly && glob) {
335
336
  took.push(display('eslint', esLintTook))
336
337
  if (eslintCode.status) {
337
338
  spinner.prefixText = bgRedBright(` kitql-lint `)
338
- spinner.fail(red(`eslint failed, check logs above.`))
339
+ spinner.fail(red(`eslint failed, check logs above. ${displayTook()}`))
339
340
  process.exit(eslintCode.status)
340
341
  }
341
342
  }
@@ -347,14 +348,22 @@ if (!eslintOnly && glob) {
347
348
  took.push(display('prettier', prettierTook))
348
349
  if (prettierCode.status) {
349
350
  spinner.prefixText = bgRedBright(` kitql-lint `)
350
- spinner.fail(red(`prettier failed, check logs above.`))
351
+ spinner.fail(red(`prettier failed, check logs above. ${displayTook()}`))
351
352
  process.exit(prettierCode.status)
352
353
  }
353
354
  }
354
355
 
355
356
  spinner.prefixText = bgGreen(` kitql-lint `)
356
357
  spinner.succeed(
357
- `All good, ${glob === '' ? 'nothing to do!' : filesLength !== -1 ? `your ${filesLength} files looks great!` : 'your files looks great!'} ${gray('(')}${took.join(gray(', '))}${gray(')')}`,
358
+ `All good, ` +
359
+ `${
360
+ glob === ''
361
+ ? 'nothing to do!'
362
+ : filesLength !== -1
363
+ ? `your ${filesLength === 1 ? 'single file' : `${filesLength} files`} looks great!`
364
+ : 'your files looks great!'
365
+ } ` +
366
+ displayTook(),
358
367
  )
359
368
  spinner.stop()
360
369
  process.exit(0)
@@ -0,0 +1,17 @@
1
+ import type { Linter } from 'eslint'
2
+
3
+ export default config
4
+
5
+ /**
6
+ * KitQL's ESLint configuration with customizable options
7
+ *
8
+ * @param options - Configuration options
9
+ * @returns ESLint configuration array
10
+ */
11
+ export function kitql(options?: {
12
+ /**
13
+ * Whether to include pnpm catalogs rules
14
+ * @default true
15
+ */
16
+ pnpmCatalogs?: boolean
17
+ }): Linter.Config[]
package/eslint.config.js CHANGED
@@ -9,68 +9,18 @@ import ts from 'typescript-eslint'
9
9
 
10
10
  import { findFileOrUp } from './helper/findFileOrUp.js'
11
11
 
12
- const pathPrettierIgnore = findFileOrUp('.prettierignore', { absolute: true })
13
-
14
- /** @type {import('eslint').Linter.Config[]} */
15
- export const config = [
16
- {
12
+ const rulePrettierIgnore = ({ pnpmCatalogs = true }) => {
13
+ const pathPrettierIgnore = findFileOrUp('.prettierignore', { absolute: true })
14
+ const rowIgnore = pathPrettierIgnore ? includeIgnoreFile(pathPrettierIgnore).ignores : []
15
+ const ignores = pnpmCatalogs ? rowIgnore.filter((c) => !c.includes('package.json')) : rowIgnore
16
+ return {
17
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',
18
+ ignores,
19
+ }
20
+ }
58
21
 
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
- {
22
+ const rulePnpmCatalogs = () => {
23
+ return {
74
24
  name: 'pnpm-catalogs:package.json',
75
25
  files: ['package.json'],
76
26
  languageOptions: {
@@ -83,34 +33,113 @@ export const config = [
83
33
  'pnpm-catalogs/enforce-catalog': 'error',
84
34
  'pnpm-catalogs/valid-catalog': 'error',
85
35
  },
86
- },
87
- {
88
- name: '@kitql:rules',
89
- rules: {
90
- 'no-console': [
91
- 'error',
92
- {
93
- allow: ['info', 'warn', 'error', 'time', 'timeEnd', 'dir'],
36
+ }
37
+ }
38
+
39
+ const othersRules = () => {
40
+ return [
41
+ {
42
+ name: 'eslint/defaults/recommended',
43
+ ...js.configs.recommended, // TODO, would be nice to have a name by default?
44
+ },
45
+ ...ts.configs.recommended,
46
+ ...svelte.configs['flat/recommended'],
47
+ {
48
+ name: '@kitql:languages',
49
+ languageOptions: {
50
+ globals: {
51
+ ...globals.browser,
52
+ ...globals.node,
94
53
  },
95
- ],
54
+ },
55
+ },
56
+ {
57
+ name: '@kitql:svelte:languages',
58
+ files: ['**/*.svelte'],
59
+ languageOptions: {
60
+ parserOptions: {
61
+ parser: ts.parser,
62
+ },
63
+ },
64
+ },
65
+ {
66
+ name: '@kitql:ignores',
67
+ ignores: ['build/', '.svelte-kit/', 'dist/', '**/build/', '**/.svelte-kit/', '**/dist/'],
68
+ },
69
+ {
70
+ name: '@kitql:unused-imports',
71
+ plugins: {
72
+ 'unused-imports': unusedImports,
73
+ },
74
+ rules: {
75
+ 'no-unused-vars': 'off',
76
+ '@typescript-eslint/no-unused-vars': 'off',
96
77
 
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',
78
+ 'unused-imports/no-unused-imports': 'error',
79
+ 'unused-imports/no-unused-vars': 'off',
80
+ // 'unused-imports/no-unused-vars': [
81
+ // 'warn',
82
+ // {
83
+ // vars: 'all',
84
+ // varsIgnorePattern: '^_',
85
+ // args: 'after-used',
86
+ // argsIgnorePattern: '^_',
87
+ // },
88
+ // ],
89
+ 'no-empty': ['error', { allowEmptyCatch: true }],
90
+ },
91
+ },
92
+ {
93
+ name: '@kitql:rules',
94
+ rules: {
95
+ 'no-console': [
96
+ 'error',
97
+ {
98
+ allow: ['info', 'warn', 'error', 'time', 'timeEnd', 'dir'],
99
+ },
100
+ ],
104
101
 
105
- 'no-undef': 'off',
106
- 'no-inner-declarations': 'off',
102
+ '@typescript-eslint/no-require-imports': 'off',
103
+ '@typescript-eslint/ban-ts-ignore': 'off',
104
+ '@typescript-eslint/ban-ts-comment': 'off',
105
+ '@typescript-eslint/no-explicit-any': 'off',
106
+ '@typescript-eslint/no-non-null-assertion': 'off',
107
+ '@typescript-eslint/no-unused-expressions': 'off',
108
+ '@typescript-eslint/no-empty-object-type': 'off',
107
109
 
108
- 'svelte/no-at-html-tags': 'off',
109
- 'svelte/no-inner-declarations': 'off',
110
+ 'no-undef': 'off',
111
+ 'no-inner-declarations': 'off',
110
112
 
111
- 'svelte/require-each-key': 'warn',
113
+ 'svelte/no-at-html-tags': 'off',
114
+ 'svelte/no-inner-declarations': 'off',
115
+
116
+ 'svelte/require-each-key': 'warn',
117
+ },
112
118
  },
113
- },
119
+ ]
120
+ }
121
+
122
+ /** @type {import('eslint').Linter.Config[]} */
123
+ const config = [
124
+ //
125
+ rulePrettierIgnore({ pnpmCatalogs: true }),
126
+ ...othersRules(),
127
+ rulePnpmCatalogs(),
114
128
  ]
115
129
 
116
130
  export default config
131
+
132
+ /**
133
+ * @param {Object} options
134
+ * @param {boolean} options.pnpmCatalogs
135
+ * @returns {import('eslint').Linter.Config[]}
136
+ */
137
+ export const kitql = (options) => {
138
+ const pnpmCatalogs = options?.pnpmCatalogs ?? true
139
+ return [
140
+ //
141
+ rulePrettierIgnore({ pnpmCatalogs }),
142
+ ...othersRules(),
143
+ ...(pnpmCatalogs ? [rulePnpmCatalogs()] : []),
144
+ ]
145
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitql/eslint-config",
3
- "version": "0.5.5",
3
+ "version": "0.5.7",
4
4
  "type": "module",
5
5
  "description": "opinionated linting and formatting for projects",
6
6
  "repository": {
@@ -16,6 +16,7 @@
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
  ".prettierrc.mjs",
21
22
  "cmd.js",