Skip to content

Commit f9c61ea

Browse files
committed
chore: eslint配置修改及格式化
1 parent c017fed commit f9c61ea

File tree

10 files changed

+61
-169
lines changed

10 files changed

+61
-169
lines changed

apps/docs/examples/directives/vFocus/basic.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<input type="text" v-focus value="123" />
2+
<input v-focus type="text" value="123" />
33
</template>
44

55
<script setup lang="ts">

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"build:docs": "pnpm -F @mylib/docs run build",
3131
"build:gulp": "gulp -f build/gulpfile.js",
3232
"publish": "turbo run publish",
33-
"lint:eslint": "eslint --max-warnings 0 \"**/*.{ts,tsx,js,jsx,cjs,mjs,vue}\" --fix",
33+
"lint:eslint": "eslint --max-warnings 0 \"**/*.{ts,tsx,js,jsx,cjs,mjs,vue}\" --fix",
3434
"lint:format": "prettier --write \"**/*.{js,jsx,cjs,ts,tsx,mjs,mts,md,vue,scss,css,less,html,json}\"",
3535
"lint:style": "stylelint \"**/*.{css,scss,less}\" --fix",
3636
"lint:all": "pnpm run lint:eslint && pnpm run lint:style && pnpm run lint:format",
Lines changed: 42 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,50 @@
1-
// 引入vue模版的eslint
2-
// vue文件解析器
3-
import vueParser from 'vue-eslint-parser';
4-
51
import eslint from '@eslint/js';
6-
import prettier from 'eslint-plugin-prettier';
7-
import pluginVue from 'eslint-plugin-vue';
8-
// ts-eslint解析器,使 eslint 可以解析 ts 语法
92
import tseslint from 'typescript-eslint';
3+
import pluginVue from 'eslint-plugin-vue';
104

11-
export default tseslint.config({
12-
ignores: ['node_modules', 'dist', 'dist*'],
13-
files: ['**/**/*.ts', '**/**/*.tsx', '**/**/*.vue'],
14-
// tseslint.config添加了extends扁平函数,直接用。否则是eslint9.0版本是没有extends的
15-
extends: [
16-
eslint.configs.recommended,
17-
...tseslint.configs.recommended,
18-
...pluginVue.configs['flat/essential'],
19-
],
20-
plugins: {
21-
prettier,
22-
},
23-
languageOptions: {
24-
parser: vueParser, // 使用vue解析器,这个可以识别vue文件
25-
parserOptions: {
26-
parser: tseslint.parser, // 在vue文件上使用ts解析器
27-
sourceType: 'module',
28-
ecmaVersion: 2020,
29-
ecmaFeatures: {
30-
jsx: true,
5+
export default tseslint.config(
6+
{ ignores: ['**/node_modules', '**/dist', '**/*.js'] }, // 忽略 node_modules 和 dist 目录
7+
eslint.configs.recommended, // 使用 ESLint 的推荐配置
8+
tseslint.configs.base, // 使用 TypeScript ESLint 的基础配置
9+
...pluginVue.configs['flat/recommended'], // 使用 Vue ESLint 的推荐配置
10+
{
11+
files: ['**/*.vue'], // 针对所有 .vue 文件
12+
languageOptions: {
13+
parserOptions: {
14+
parser: '@typescript-eslint/parser', // 使用 TypeScript ESLint 解析器
3115
},
3216
},
3317
},
34-
rules: {
35-
// Prettier 错误提示
36-
'prettier/prettier': 'error',
37-
// 允许使用转义字符
38-
'no-useless-escape': 0,
39-
// 允许未定义的变量(通常用于全局变量)
40-
'no-undef': 0,
41-
// 允许在 setup 中解构 props
42-
'vue/no-setup-props-destructure': 0,
43-
// setup 中的变量检查
44-
'vue/script-setup-uses-vars': 1,
45-
// 允许使用保留的组件名
46-
'vue/no-reserved-component-names': 0,
47-
// TypeScript 相关规则
48-
'@typescript-eslint/ban-ts-ignore': 0,
49-
'@typescript-eslint/explicit-function-return-type': 0,
50-
'@typescript-eslint/no-explicit-any': 0,
51-
'@typescript-eslint/no-var-requires': 0,
52-
'@typescript-eslint/no-empty-function': 0,
53-
// Vue 自定义事件名称规则
54-
'vue/custom-event-name-casing': 0,
55-
// 允许在定义前使用变量
56-
'no-use-before-define': 0,
57-
'@typescript-eslint/no-use-before-define': 0,
58-
// TypeScript 注释相关规则
59-
'@typescript-eslint/ban-ts-comment': 0,
60-
'@typescript-eslint/ban-types': 0,
61-
'@typescript-eslint/no-non-null-assertion': 0,
62-
'@typescript-eslint/explicit-module-boundary-types': 0,
63-
// 未使用变量的规则
64-
'@typescript-eslint/no-unused-vars': 0,
65-
'no-unused-vars': 0,
66-
// 函数括号前的空格规则
67-
'space-before-function-paren': 0,
68-
69-
// Vue 模板相关规则
70-
'vue/attributes-order': 0,
71-
'vue/one-component-per-file': 0,
72-
'vue/html-closing-bracket-newline': 0,
73-
'vue/max-attributes-per-line': 0,
74-
'vue/multiline-html-element-content-newline': 0,
75-
'vue/singleline-html-element-content-newline': 0,
76-
'vue/attribute-hyphenation': 0,
77-
'vue/require-default-prop': 0,
78-
'vue/require-explicit-emits': 0,
79-
// HTML 标签自闭合规则
80-
'vue/html-self-closing': [
81-
1,
82-
{
83-
html: {
84-
void: 'always', // 空元素总是自闭合
85-
normal: 'never', // 普通元素不自闭合
86-
component: 'always', // 组件总是自闭合
18+
{
19+
rules: {
20+
'no-debugger': 'error', // 禁止使用 debugger 语句
21+
// 'no-console': ['error', { allow: ['warn', 'error', 'info', 'clear'] }], // 禁止使用 console 语句,但允许 warn, error, info 和 clear
22+
'prefer-const': 'error', // 强制使用 const 而不是 let
23+
'sort-imports': ['error', { ignoreDeclarationSort: true }], // 强制排序导入语句,但忽略声明排序
24+
'no-duplicate-imports': 'error', // 禁止重复导入
25+
// 该规则强制使用 '@ts-expect-error' 注释在 TypeScript 代码中指示故意的类型错误,提高代码的清晰度和可维护性。
26+
'@typescript-eslint/prefer-ts-expect-error': 'error', // 强制使用 @ts-expect-error 而不是 @ts-ignore
27+
// 强制使用 'import type' 进行类型导入
28+
'@typescript-eslint/consistent-type-imports': [
29+
'error',
30+
{
31+
fixStyle: 'inline-type-imports', // 使用内联类型导入样式
32+
disallowTypeAnnotations: false, // 允许类型注解
8733
},
88-
svg: 'always',
89-
math: 'always',
90-
},
91-
],
92-
// 允许单个单词的组件名
93-
'vue/multi-word-component-names': 0,
94-
// 允许使用 v-html
95-
'vue/no-v-html': 0,
96-
// transition 组件内的 toggle 规则
97-
'vue/require-toggle-inside-transition': 0,
98-
// 允许使用空对象类型 {}
99-
'@typescript-eslint/no-empty-object-type': 0,
34+
],
35+
// 强制在导入仅包含内联类型限定符的规范时使用顶级导入类型限定符
36+
'@typescript-eslint/no-import-type-side-effects': 'error', // 禁止导入类型时产生副作用
37+
'vue/max-attributes-per-line': 'off', // 关闭每行最多属性数的限制
38+
'vue/singleline-html-element-content-newline': 'off', // 关闭单行 HTML 元素内容换行的限制
39+
'vue/multi-word-component-names': 'off', // 关闭多单词组件名称的限制
40+
'vue/html-self-closing': [
41+
'error',
42+
{
43+
html: { component: 'always', normal: 'always', void: 'any' }, // 强制 HTML 组件和普通元素始终自闭合,void 元素可以自闭合或不自闭合
44+
math: 'always', // 强制 math 元素始终自闭合
45+
svg: 'always', // 强制 svg 元素始终自闭合
46+
},
47+
],
48+
},
10049
},
101-
});
50+
);

packages/lint-configs/eslint-config/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717
"devDependencies": {
1818
"typescript-eslint": "^8.18.0",
1919
"eslint-plugin-vue": "^9.32.0",
20-
"eslint-plugin-prettier": "^5.2.1",
21-
"@eslint/js": "9.16.0",
22-
"vue-eslint-parser": "^9.4.3"
20+
"@eslint/js": "9.16.0"
2321
},
2422
"peerDependencies": {
2523
"eslint": "^9.16.0"

packages/ui/src/components/Button/Button.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
:disabled="disabled"
1313
@click="handleClick"
1414
>
15-
<slot></slot>
15+
<slot />
1616
</button>
1717
</template>
1818

1919
<script setup lang="ts">
20-
import { ButtonProps, ButtonEmits } from './Button.types';
20+
import type { ButtonEmits, ButtonProps } from './Button.types';
2121
2222
defineOptions({
2323
name: 'VButton',

packages/ui/src/components/Dialog/Dialog.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<template>
2-
<dialog class="v-dialog" v-if="open">
3-
<div class="v-dialog__overlay" @click="close"></div>
2+
<dialog v-if="open" class="v-dialog">
3+
<div class="v-dialog__overlay" @click="close" />
44
<div class="v-dialog__content">
5-
<slot></slot>
5+
<slot />
66
</div>
77
</dialog>
88
</template>
99

1010
<script setup lang="ts">
11-
import { DialogProps, DialogEmits } from './Dialog.types';
11+
import type { DialogEmits, DialogProps } from './Dialog.types';
1212
1313
defineOptions({
1414
name: 'VDialog',

playground/src/layouts/MainLayout.vue

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
<template>
22
<a-layout style="min-height: 100vh">
33
<a-layout-sider v-model:collapsed="collapsed" collapsible>
4-
<div class="logo"></div>
5-
<a-menu v-model:selectedKeys="selectedKeys" theme="dark" mode="inline" @select="onMenuSelect">
4+
<div class="logo" />
5+
<a-menu
6+
v-model:selected-keys="selectedKeys"
7+
theme="dark"
8+
mode="inline"
9+
@select="onMenuSelect"
10+
>
611
<a-menu-item v-for="route in routes" :key="route.path">
712
<template #icon>
813
<component :is="route.meta?.icon" />
@@ -25,7 +30,7 @@
2530
</template>
2631

2732
<script setup lang="ts">
28-
import { ref, computed } from 'vue';
33+
import { computed, ref } from 'vue';
2934
import { useRouter } from 'vue-router';
3035
import { routes } from '@/router';
3136
import type { MenuProps } from 'ant-design-vue';

playground/src/layouts/TabsView.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div :class="`${name}-demo`">
3-
<a-tabs v-model:activeKey="activeKey" type="card">
3+
<a-tabs v-model:active-key="activeKey" type="card">
44
<a-tab-pane v-for="item in renderCmp" :key="item.index" :tab="item.name" />
55
</a-tabs>
66
<component :is="renderCmp[activeKey]?.component" />

playground/src/views/Directives/vFocus.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<input type="text" v-focus value="123" />
2+
<input v-focus type="text" value="123" />
33
</template>
44

55
<script setup lang="ts">

0 commit comments

Comments
 (0)