@cuiqg/eslint-config 2.5.7 → 2.5.9

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.
@@ -0,0 +1,143 @@
1
+ import { GLOB_VUE } from '../globs'
2
+ import { interopDefault } from '../utils'
3
+
4
+ export async function vue() {
5
+ const files = [GLOB_VUE]
6
+
7
+ const [pluginVue, parserVue] = await Promise.all([
8
+ interopDefault(import('eslint-plugin-vue')),
9
+ interopDefault(import('vue-eslint-parser'))
10
+ ])
11
+
12
+ return [
13
+ {
14
+ files,
15
+ languageOptions: {
16
+ globals: {
17
+ computed: 'readonly',
18
+ defineEmits: 'readonly',
19
+ defineExpose: 'readonly',
20
+ defineModel: 'readonly',
21
+ defineOptions: 'readonly',
22
+ defineProps: 'readonly',
23
+ defineSlots: 'readonly',
24
+ onActivated: 'readonly',
25
+ onDeactivated: 'readonly',
26
+ onMounted: 'readonly',
27
+ onUnmounted: 'readonly',
28
+ reactive: 'readonly',
29
+ ref: 'readonly',
30
+ toRef: 'readonly',
31
+ toRefs: 'readonly',
32
+ useAttrs: 'readonly',
33
+ useSlots: 'readonly',
34
+ watch: 'readonly',
35
+ watchEffect: 'readonly'
36
+ },
37
+ parser: parserVue,
38
+ parserOptions: {
39
+ ecmaFeatures: {
40
+ jsx: true
41
+ },
42
+ extraFileExtensions: ['.vue'],
43
+ parser: null,
44
+ sourceType: 'module'
45
+ }
46
+ },
47
+ name: 'cuiqg/vue',
48
+ plugins: {
49
+ vue: pluginVue
50
+ },
51
+ processor: pluginVue.processors['.vue'],
52
+ rules: {
53
+ ...(pluginVue.configs['flat/recommended']
54
+ .map(c => c.rules)
55
+ .reduce((acc, c) => ({ ...acc, ...c }), {})),
56
+
57
+ 'node/prefer-global/process': 'off',
58
+ 'vue/array-bracket-spacing': ['error', 'never'],
59
+ 'vue/arrow-spacing': ['error', { after: true, before: true }],
60
+ 'vue/block-order': [
61
+ 'error',
62
+ {
63
+ order: ['script', 'template', 'style']
64
+ }
65
+ ],
66
+ 'vue/block-spacing': ['error', 'always'],
67
+ 'vue/block-tag-newline': [
68
+ 'error',
69
+ {
70
+ multiline: 'always',
71
+ singleline: 'always'
72
+ }
73
+ ],
74
+ 'vue/brace-style': ['error', 'stroustrup', { allowSingleLine: true }],
75
+ 'vue/comma-dangle': ['error', 'always-multiline'],
76
+ 'vue/comma-spacing': ['error', { after: true, before: false }],
77
+ 'vue/comma-style': ['error', 'last'],
78
+ 'vue/custom-event-name-casing': ['error', 'camelCase'],
79
+ 'vue/define-macros-order': [
80
+ 'error',
81
+ {
82
+ order: ['defineOptions', 'defineProps', 'defineEmits', 'defineSlots']
83
+ }
84
+ ],
85
+ 'vue/dot-location': ['error', 'property'],
86
+ 'vue/dot-notation': ['error', { allowKeywords: true }],
87
+ 'vue/eqeqeq': ['error', 'smart'],
88
+ 'vue/html-comment-content-spacing': [
89
+ 'error',
90
+ 'always',
91
+ {
92
+ exceptions: ['-']
93
+ }
94
+ ],
95
+ 'vue/html-indent': ['error', 2],
96
+ 'vue/html-quotes': ['error', 'double'],
97
+ 'vue/key-spacing': ['error', { afterColon: true, beforeColon: false }],
98
+ 'vue/keyword-spacing': ['error', { after: true, before: true }],
99
+ 'vue/max-attributes-per-line': 'off',
100
+ 'vue/multi-word-component-names': 'off',
101
+ 'vue/no-dupe-keys': 'off',
102
+ 'vue/no-empty-pattern': 'error',
103
+ 'vue/no-irregular-whitespace': 'error',
104
+ 'vue/no-loss-of-precision': 'error',
105
+ 'vue/no-restricted-syntax': [
106
+ 'error',
107
+ 'DebuggerStatement',
108
+ 'LabeledStatement',
109
+ 'WithStatement'
110
+ ],
111
+ 'vue/no-restricted-v-bind': ['error', '/^v-/'],
112
+ 'vue/no-setup-props-reactivity-loss': 'off',
113
+ 'vue/no-sparse-arrays': 'error',
114
+ 'vue/no-unused-refs': 'error',
115
+ 'vue/no-useless-v-bind': 'error',
116
+ 'vue/no-v-html': 'off',
117
+ 'vue/object-curly-newline': 'off',
118
+ 'vue/object-curly-spacing': ['error', 'always'],
119
+ 'vue/object-property-newline': ['error', { allowAllPropertiesOnSameLine: true }],
120
+ 'vue/object-shorthand': [
121
+ 'error',
122
+ 'always',
123
+ {
124
+ avoidQuotes: true,
125
+ ignoreConstructors: false
126
+ }
127
+ ],
128
+ 'vue/operator-linebreak': ['error', 'before'],
129
+ 'vue/padding-line-between-blocks': ['error', 'always'],
130
+ 'vue/prefer-separate-static-class': 'error',
131
+ 'vue/prefer-template': 'error',
132
+ 'vue/prop-name-casing': ['error', 'camelCase'],
133
+ 'vue/quote-props': ['error', 'consistent-as-needed'],
134
+ 'vue/require-default-prop': 'off',
135
+ 'vue/require-prop-types': 'off',
136
+ 'vue/space-in-parens': ['error', 'never'],
137
+ 'vue/space-infix-ops': 'error',
138
+ 'vue/space-unary-ops': ['error', { nonwords: false, words: true }],
139
+ 'vue/template-curly-spacing': 'error'
140
+ }
141
+ }
142
+ ]
143
+ }
package/src/env.js ADDED
@@ -0,0 +1,27 @@
1
+ import process from 'node:process'
2
+ import { isPackageExists } from 'local-pkg'
3
+
4
+ export const isInGitHookOrLintStaged = () => {
5
+ return !!(
6
+ process.env.GIT_PARAMS
7
+ || process.env.VSCODE_GIT_COMMAND
8
+ || process.env.npm_lifecycle_script?.startsWith('lint-staged')
9
+ )
10
+ }
11
+
12
+ export const isInEditor = () => {
13
+ if (process.env.CI) return false
14
+ if (isInGitHookOrLintStaged()) return false
15
+ return !!(
16
+ process.env.VSCODE_PID
17
+ || process.env.VSCODE_CWD
18
+ || process.env.JETBRAINS_IDE
19
+ || process.env.VIM
20
+ || process.env.NVIM
21
+ )
22
+ }
23
+
24
+ export const hasVue = () =>
25
+ ['vue', 'nuxt', 'vitepress', '@slidev/cli'].some(i => isPackageExists(i))
26
+ export const hasTypeScript = () => isPackageExists('typescript')
27
+ export const hasUnoCss = () => isPackageExists('unocss')
package/src/globs.js ADDED
@@ -0,0 +1,70 @@
1
+ export const GLOB_SRC_EXT = '?([cm])[jt]s?(x)'
2
+ export const GLOB_SRC = `**/*.${GLOB_SRC_EXT}`
3
+
4
+ export const GLOB_TS = `**/*.?([cm])ts`
5
+ export const GLOB_TSX = `**/*.?([cm])tsx`
6
+
7
+ export const GLOB_JS = `**/*.?([cm])js`
8
+ export const GLOB_JSX = `**/*.?([cm])jsx`
9
+
10
+ export const GLOB_STYLE = '**/*.{c,le,sc}ss'
11
+ export const GLOB_CSS = '**/*.css'
12
+ export const GLOB_SCSS = '**/*.scss'
13
+ export const GLOB_LESS = '**/*.less'
14
+ export const GLOB_STYLUS = '**/*.styl'
15
+ export const GLOB_POSTCSS = '**/*.{p,post}css'
16
+
17
+ export const GLOB_JSON = '**/*.json'
18
+ export const GLOB_JSON5 = '**/*.json5'
19
+ export const GLOB_JSONC = '**/*.jsonc'
20
+
21
+ export const GLOB_MARKDOWN = '**/*.md'
22
+ export const GLOB_VUE = '**/*.vue'
23
+ export const GLOB_YAML = '**/*.y?(a)ml'
24
+ export const GLOB_TOML = '**/*.toml'
25
+ export const GLOB_XML = '**/*.xml'
26
+ export const GLOB_SVG = '**/*.svg'
27
+ export const GLOB_HTML = '**/*.htm?(l)'
28
+
29
+ export const GLOB_EXCLUDE = [
30
+ '**/node_modules',
31
+ '**/dist',
32
+ '**/package-lock.json',
33
+ '**/yarn.lock',
34
+ '**/pnpm-lock.yaml',
35
+ '**/bun.lockb',
36
+
37
+ '**/output',
38
+ '**/coverage',
39
+ '**/temp',
40
+ '**/.temp',
41
+ '**/tmp',
42
+ '**/.tmp',
43
+ '**/.history',
44
+ '**/.vitepress/cache',
45
+ '**/.nuxt',
46
+ '**/.next',
47
+ '**/.svelte-kit',
48
+ '**/.vercel',
49
+ '**/.changeset',
50
+ '**/.idea',
51
+ '**/.DS_Store',
52
+ '**/Thumbs.db',
53
+ '**/ehthumbs.db',
54
+ '**/Desktop.ini',
55
+ '**/$RECYCLE.BIN',
56
+ '**/.cache',
57
+ '**/.output',
58
+ '**/.vite-inspect',
59
+ '**/.yarn',
60
+ '**/vite.config.*.timestamp-*',
61
+
62
+ '**/CHANGELOG*.md',
63
+ '**/*.min.*',
64
+ '**/LICENSE*',
65
+ '**/__snapshots__',
66
+ '**/auto-import?(s).d.ts',
67
+ '**/components.d.ts',
68
+ '**/typed-router.d.ts',
69
+ '**/.eslint-config-inspector'
70
+ ]
package/src/index.js ADDED
@@ -0,0 +1,8 @@
1
+ import { cuiqg } from './presets'
2
+
3
+ export * from './configs'
4
+ export * from './env'
5
+ export * from './globs'
6
+ export * from './presets'
7
+
8
+ export default cuiqg
package/src/presets.js ADDED
@@ -0,0 +1,70 @@
1
+ import { FlatConfigComposer } from 'eslint-flat-config-utils'
2
+
3
+ import {
4
+ compat,
5
+ ignores,
6
+ javascript,
7
+ jsdoc,
8
+ macros,
9
+ packageJson,
10
+ prettier,
11
+ stylistic,
12
+ unocss,
13
+ vue,
14
+ unicorn
15
+ } from './configs'
16
+
17
+ import { hasUnoCss, hasVue } from './env'
18
+
19
+ export const defaultPluginRenaming = {
20
+ '@stylistic': 'style'
21
+ }
22
+
23
+ /**
24
+ *
25
+ * @param {object} options - 设置选项
26
+ * @param {...any} userConfigs - 用户配置
27
+ * @returns {Promise<any[]>} 合并后的配置
28
+ */
29
+ export function cuiqg(
30
+ options = {},
31
+ ...userConfigs
32
+ ) {
33
+ const {
34
+ prettier: enablePrettier = false,
35
+ unocss: enableUnocss = hasUnoCss(),
36
+ vue: enableVue = hasVue()
37
+ } = options
38
+
39
+ const configs = []
40
+
41
+ configs.push(
42
+ compat(),
43
+ ignores(),
44
+ javascript(),
45
+ jsdoc(),
46
+ stylistic(),
47
+ packageJson(),
48
+ unicorn()
49
+ )
50
+
51
+ if (enableVue) {
52
+ configs.push(vue(), macros())
53
+ }
54
+
55
+ if (enableUnocss) {
56
+ configs.push(unocss())
57
+ }
58
+
59
+ if (enablePrettier) {
60
+ configs.push(prettier())
61
+ }
62
+
63
+ let composer = new FlatConfigComposer()
64
+
65
+ composer = composer
66
+ .append(...configs, ...userConfigs)
67
+ .renamePlugins(defaultPluginRenaming)
68
+
69
+ return composer
70
+ }
package/src/utils.js ADDED
@@ -0,0 +1,24 @@
1
+ export async function interopDefault(
2
+ module
3
+ ) {
4
+ try {
5
+ let resolved = await module
6
+ return resolved?.default || resolved
7
+ }
8
+ catch (error) {
9
+ throw new Error(`Cannot import module: ${String(error)}`)
10
+ }
11
+ }
12
+
13
+ export function renameRules(rules, map) {
14
+ return Object.fromEntries(
15
+ Object.entries(rules).map(([key, value]) => {
16
+ for (const [from, to] of Object.entries(map)) {
17
+ if (key.startsWith(`${from}/`)) {
18
+ return [to + key.slice(from.length), value]
19
+ }
20
+ }
21
+ return [key, value]
22
+ })
23
+ )
24
+ }
@@ -0,0 +1,9 @@
1
+ import { defineConfig } from 'tsdown'
2
+
3
+ export default defineConfig({
4
+ entry: 'src/index.js',
5
+ clean: true,
6
+ shims: true,
7
+ format: ['esm'],
8
+ exports: true
9
+ })
package/vercel.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "$schema": "https://openapi.vercel.sh/vercel.json",
3
+ "framework": null,
4
+ "buildCommand": "npm run build:inspect",
5
+ "outputDirectory": ".eslint-config-inspector",
6
+ "installCommand": "npm install"
7
+ }