@lntvow/eslint-config 8.5.0 → 9.1.2
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/.czrc +3 -0
- package/.editorconfig +14 -0
- package/.env.development +1 -0
- package/.env.production +1 -0
- package/.env.uat +1 -0
- package/.github/workflows/publish-npm.yml +44 -0
- package/.husky/commit-msg +4 -0
- package/.husky/pre-commit +4 -0
- package/.lintstagedrc +4 -0
- package/.prettierrc +10 -0
- package/.vscode/settings.json +14 -0
- package/README.md +19 -27
- package/api/basic.js +22 -0
- package/api/vue.js +34 -0
- package/commitlint.config.cjs +4 -0
- package/eslint.config.js +21 -0
- package/package.json +46 -11
- package/packages/eslint-config-ts/index.js +85 -0
- package/packages/eslint-config-ts/package.json +18 -0
- package/packages/eslint-plugin/index.js +5 -0
- package/packages/eslint-plugin/package.json +16 -0
- package/packages/eslint-plugin/rules/get.js +18 -0
- package/packages/eslint-plugin/test/get.test.js +39 -0
- package/src/configs/gitignore.ts +34 -0
- package/src/configs/ignores.ts +10 -0
- package/src/configs/imports.ts +17 -0
- package/src/configs/index.ts +8 -0
- package/src/configs/javascript.ts +161 -0
- package/src/configs/prettier.ts +18 -0
- package/src/configs/stylistic.ts +59 -0
- package/src/configs/typescript.ts +63 -0
- package/src/configs/vue.ts +316 -0
- package/src/factory.ts +167 -0
- package/src/globs.ts +86 -0
- package/src/index.ts +7 -0
- package/src/typegen.d.ts +15123 -0
- package/src/types.ts +127 -0
- package/src/typings/index.d.ts +3 -0
- package/src/utils/index.ts +30 -0
- package/test/js.vue +28 -0
- package/test/jsx.vue +27 -0
- package/test/test.js +11 -0
- package/test/test.ts +18 -0
- package/test/ts.vue +26 -0
- package/test/tsx.vue +23 -0
- package/tsconfig.json +20 -0
- package/tsup.config.ts +10 -0
- package/index.js +0 -3
package/src/factory.ts
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { FlatConfigComposer } from 'eslint-flat-config-utils'
|
|
2
|
+
import type { Linter } from 'eslint'
|
|
3
|
+
import { isBoolean } from '@lntvow/utils'
|
|
4
|
+
import { isPackageExists } from 'local-pkg'
|
|
5
|
+
import { gitignore, ignores, javascript, typescript, vue } from './configs'
|
|
6
|
+
import type { Awaitable, ConfigNames, OptionsConfig, TypedFlatConfigItem } from './types'
|
|
7
|
+
import { stylistic } from './configs/stylistic'
|
|
8
|
+
import { imports } from './configs/imports'
|
|
9
|
+
import { prettier } from './configs/prettier'
|
|
10
|
+
|
|
11
|
+
const flatConfigProps: (keyof TypedFlatConfigItem)[] = [
|
|
12
|
+
'name',
|
|
13
|
+
'files',
|
|
14
|
+
'ignores',
|
|
15
|
+
'languageOptions',
|
|
16
|
+
'linterOptions',
|
|
17
|
+
'processor',
|
|
18
|
+
'plugins',
|
|
19
|
+
'rules',
|
|
20
|
+
'settings',
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
export function lntvow(
|
|
24
|
+
options: OptionsConfig & TypedFlatConfigItem = {},
|
|
25
|
+
...userConfigs: Awaitable<TypedFlatConfigItem | TypedFlatConfigItem[] | FlatConfigComposer | Linter.FlatConfig[]>[]
|
|
26
|
+
): FlatConfigComposer<TypedFlatConfigItem, ConfigNames> {
|
|
27
|
+
const {
|
|
28
|
+
// autoRenamePlugins = true,
|
|
29
|
+
componentExts = [],
|
|
30
|
+
gitignore: enableGitignore = true,
|
|
31
|
+
// regexp: enableRegexp = true,
|
|
32
|
+
typescript: enableTypeScript = isPackageExists('typescript'),
|
|
33
|
+
vue: enableVue = ['vue', 'nuxt', 'vitepress'].some(i => isPackageExists(i)),
|
|
34
|
+
} = options
|
|
35
|
+
|
|
36
|
+
const stylisticOptions =
|
|
37
|
+
options.stylistic === false ? false : typeof options.stylistic === 'object' ? options.stylistic : {}
|
|
38
|
+
|
|
39
|
+
// if (stylisticOptions && !('jsx' in stylisticOptions)) stylisticOptions.jsx = options.jsx ?? true
|
|
40
|
+
|
|
41
|
+
const configs: Awaitable<TypedFlatConfigItem[]>[] = []
|
|
42
|
+
|
|
43
|
+
// Base configs
|
|
44
|
+
configs.push(
|
|
45
|
+
ignores(),
|
|
46
|
+
javascript({
|
|
47
|
+
...resolveSubOptions(options, 'javascript'),
|
|
48
|
+
}),
|
|
49
|
+
imports()
|
|
50
|
+
// comments(),
|
|
51
|
+
// node(),
|
|
52
|
+
// jsdoc({
|
|
53
|
+
// stylistic: stylisticOptions,
|
|
54
|
+
// }),
|
|
55
|
+
// unicorn(),
|
|
56
|
+
// command(),
|
|
57
|
+
|
|
58
|
+
// Optional plugins (installed but not enabled by default)
|
|
59
|
+
// perfectionist(),
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
if (enableGitignore) {
|
|
63
|
+
configs.push(gitignore(resolveSubOptions(options, 'gitignore')))
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (enableVue) {
|
|
67
|
+
componentExts.push('vue')
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (enableTypeScript) {
|
|
71
|
+
configs.push(typescript({ ...resolveSubOptions(options, 'typescript'), componentExts }))
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (stylisticOptions) {
|
|
75
|
+
configs.push(stylistic({ ...stylisticOptions }))
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// if (enableRegexp)
|
|
79
|
+
// configs.push(regexp(typeof enableRegexp === 'boolean' ? {} : enableRegexp))
|
|
80
|
+
|
|
81
|
+
// if (options.test ?? true) {
|
|
82
|
+
// configs.push(test({
|
|
83
|
+
// isInEditor,
|
|
84
|
+
// overrides: getOverrides(options, 'test'),
|
|
85
|
+
// }))
|
|
86
|
+
// }
|
|
87
|
+
|
|
88
|
+
if (enableVue) {
|
|
89
|
+
configs.push(vue({ ...resolveSubOptions(options, 'vue') }))
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// if (options.jsonc ?? true) {
|
|
93
|
+
// configs.push(
|
|
94
|
+
// jsonc({
|
|
95
|
+
// overrides: getOverrides(options, 'jsonc'),
|
|
96
|
+
// stylistic: stylisticOptions,
|
|
97
|
+
// }),
|
|
98
|
+
// sortPackageJson(),
|
|
99
|
+
// sortTsconfig(),
|
|
100
|
+
// )
|
|
101
|
+
// }
|
|
102
|
+
|
|
103
|
+
// if (options.yaml ?? true) {
|
|
104
|
+
// configs.push(yaml({
|
|
105
|
+
// overrides: getOverrides(options, 'yaml'),
|
|
106
|
+
// stylistic: stylisticOptions,
|
|
107
|
+
// }))
|
|
108
|
+
// }
|
|
109
|
+
|
|
110
|
+
// if (options.toml ?? true) {
|
|
111
|
+
// configs.push(toml({
|
|
112
|
+
// overrides: getOverrides(options, 'toml'),
|
|
113
|
+
// stylistic: stylisticOptions,
|
|
114
|
+
// }))
|
|
115
|
+
// }
|
|
116
|
+
|
|
117
|
+
// if (options.markdown ?? true) {
|
|
118
|
+
// configs.push(
|
|
119
|
+
// markdown(
|
|
120
|
+
// {
|
|
121
|
+
// componentExts,
|
|
122
|
+
// overrides: getOverrides(options, 'markdown'),
|
|
123
|
+
// },
|
|
124
|
+
// ),
|
|
125
|
+
// )
|
|
126
|
+
// }
|
|
127
|
+
|
|
128
|
+
// if (options.formatters) {
|
|
129
|
+
// configs.push(formatters(
|
|
130
|
+
// options.formatters,
|
|
131
|
+
// typeof stylisticOptions === 'boolean' ? {} : stylisticOptions,
|
|
132
|
+
// ))
|
|
133
|
+
// }
|
|
134
|
+
|
|
135
|
+
configs.push(prettier())
|
|
136
|
+
|
|
137
|
+
// User can optionally pass a flat config item to the first argument
|
|
138
|
+
const fusedConfig = flatConfigProps.reduce((acc, key) => {
|
|
139
|
+
if (key in options) {
|
|
140
|
+
acc[key] = options[key] as any
|
|
141
|
+
}
|
|
142
|
+
return acc
|
|
143
|
+
}, {} as TypedFlatConfigItem)
|
|
144
|
+
|
|
145
|
+
if (Object.keys(fusedConfig).length) {
|
|
146
|
+
configs.push([fusedConfig])
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Merge all configs
|
|
150
|
+
let composer = new FlatConfigComposer<TypedFlatConfigItem, ConfigNames>()
|
|
151
|
+
composer = composer.append(...configs, ...(userConfigs as any))
|
|
152
|
+
|
|
153
|
+
// if (autoRenamePlugins) {
|
|
154
|
+
// composer = composer.renamePlugins(defaultPluginRenaming)
|
|
155
|
+
// }
|
|
156
|
+
|
|
157
|
+
return composer
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export type ResolvedOptions<T> = T extends boolean ? never : NonNullable<T>
|
|
161
|
+
|
|
162
|
+
export function resolveSubOptions<K extends keyof OptionsConfig>(
|
|
163
|
+
options: OptionsConfig,
|
|
164
|
+
key: K
|
|
165
|
+
): ResolvedOptions<OptionsConfig[K]> {
|
|
166
|
+
return isBoolean(options[key]) ? ({} as any) : options[key] || {}
|
|
167
|
+
}
|
package/src/globs.ts
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
export const GLOB_SRC_EXT = '?([cm])[jt]s?(x)'
|
|
2
|
+
export const GLOB_SRC = '**/*.?([cm])[jt]s?(x)'
|
|
3
|
+
|
|
4
|
+
export const GLOB_JS = '**/*.?([cm])js'
|
|
5
|
+
export const GLOB_JSX = '**/*.?([cm])jsx'
|
|
6
|
+
|
|
7
|
+
export const GLOB_TS = '**/*.?([cm])ts'
|
|
8
|
+
export const GLOB_TSX = '**/*.?([cm])tsx'
|
|
9
|
+
|
|
10
|
+
export const GLOB_STYLE = '**/*.{c,le,sc}ss'
|
|
11
|
+
export const GLOB_CSS = '**/*.css'
|
|
12
|
+
export const GLOB_POSTCSS = '**/*.{p,post}css'
|
|
13
|
+
export const GLOB_LESS = '**/*.less'
|
|
14
|
+
export const GLOB_SCSS = '**/*.scss'
|
|
15
|
+
|
|
16
|
+
export const GLOB_JSON = '**/*.json'
|
|
17
|
+
export const GLOB_JSON5 = '**/*.json5'
|
|
18
|
+
export const GLOB_JSONC = '**/*.jsonc'
|
|
19
|
+
|
|
20
|
+
export const GLOB_MARKDOWN = '**/*.md'
|
|
21
|
+
export const GLOB_MARKDOWN_IN_MARKDOWN = '**/*.md/*.md'
|
|
22
|
+
export const GLOB_SVELTE = '**/*.svelte'
|
|
23
|
+
export const GLOB_VUE = '**/*.vue'
|
|
24
|
+
export const GLOB_YAML = '**/*.y?(a)ml'
|
|
25
|
+
export const GLOB_TOML = '**/*.toml'
|
|
26
|
+
export const GLOB_XML = '**/*.xml'
|
|
27
|
+
export const GLOB_HTML = '**/*.htm?(l)'
|
|
28
|
+
export const GLOB_ASTRO = '**/*.astro'
|
|
29
|
+
export const GLOB_GRAPHQL = '**/*.{g,graph}ql'
|
|
30
|
+
|
|
31
|
+
export const GLOB_MARKDOWN_CODE = `${GLOB_MARKDOWN}/${GLOB_SRC}`
|
|
32
|
+
|
|
33
|
+
export const GLOB_TESTS = [
|
|
34
|
+
`**/__tests__/**/*.${GLOB_SRC_EXT}`,
|
|
35
|
+
`**/*.spec.${GLOB_SRC_EXT}`,
|
|
36
|
+
`**/*.test.${GLOB_SRC_EXT}`,
|
|
37
|
+
`**/*.bench.${GLOB_SRC_EXT}`,
|
|
38
|
+
`**/*.benchmark.${GLOB_SRC_EXT}`,
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
export const GLOB_ALL_SRC = [
|
|
42
|
+
GLOB_SRC,
|
|
43
|
+
GLOB_STYLE,
|
|
44
|
+
GLOB_JSON,
|
|
45
|
+
GLOB_JSON5,
|
|
46
|
+
GLOB_MARKDOWN,
|
|
47
|
+
GLOB_SVELTE,
|
|
48
|
+
GLOB_VUE,
|
|
49
|
+
GLOB_YAML,
|
|
50
|
+
GLOB_XML,
|
|
51
|
+
GLOB_HTML,
|
|
52
|
+
]
|
|
53
|
+
|
|
54
|
+
export const GLOB_EXCLUDE = [
|
|
55
|
+
'**/node_modules',
|
|
56
|
+
'**/dist',
|
|
57
|
+
'**/package-lock.json',
|
|
58
|
+
'**/yarn.lock',
|
|
59
|
+
'**/pnpm-lock.yaml',
|
|
60
|
+
'**/bun.lockb',
|
|
61
|
+
|
|
62
|
+
'**/output',
|
|
63
|
+
'**/coverage',
|
|
64
|
+
'**/temp',
|
|
65
|
+
'**/.temp',
|
|
66
|
+
'**/tmp',
|
|
67
|
+
'**/.tmp',
|
|
68
|
+
'**/.history',
|
|
69
|
+
'**/.vitepress/cache',
|
|
70
|
+
'**/.nuxt',
|
|
71
|
+
'**/.next',
|
|
72
|
+
'**/.vercel',
|
|
73
|
+
'**/.changeset',
|
|
74
|
+
'**/.idea',
|
|
75
|
+
'**/.cache',
|
|
76
|
+
'**/.output',
|
|
77
|
+
'**/.vite-inspect',
|
|
78
|
+
'**/.yarn',
|
|
79
|
+
|
|
80
|
+
'**/CHANGELOG*.md',
|
|
81
|
+
'**/*.min.*',
|
|
82
|
+
'**/LICENSE*',
|
|
83
|
+
'**/__snapshots__',
|
|
84
|
+
'**/auto-import?(s).d.ts',
|
|
85
|
+
'**/components.d.ts',
|
|
86
|
+
]
|