Skip to content

Commit 8caee91

Browse files
committed
feat: 优化eslint配置,lint:all格式化
1 parent 9699dc9 commit 8caee91

File tree

8 files changed

+66
-20
lines changed

8 files changed

+66
-20
lines changed

apps/docs/.vitepress/config/shared.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { defineConfig } from 'vitepress';
22
import { vitepressDemoPlugin } from 'vitepress-demo-plugin';
33
import path from 'node:path';
4+
import { fileURLToPath } from 'node:url'; // 新增导入
5+
6+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
47

58
export const shared = defineConfig({
69
// 设置基础路径,用于GitHub Pages部署

apps/docs/.vitepress/utils/useGlobalComp.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { App, type Component } from 'vue';
1+
import type { App, Component } from 'vue';
22
// 如果报:“找不到模块“@mylib/ui”或其相应的类型声明”的错误,记得先build打包一下
33
import * as UI from '@mylib/ui';
44

packages/lint-configs/eslint-config/index.mjs

Lines changed: 57 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,70 @@ import tseslint from 'typescript-eslint';
33
import pluginVue from 'eslint-plugin-vue';
44

55
export default tseslint.config(
6-
{ ignores: ['**/node_modules', '**/dist', '**/*.js'] }, // 忽略 node_modules 和 dist 目录
6+
// 全局忽略配置
7+
{ ignores: ['**/node_modules', '**/dist', '**/*.js'] },
8+
9+
// 基础配置
710
eslint.configs.recommended, // 使用 ESLint 的推荐配置
811
tseslint.configs.base, // 使用 TypeScript ESLint 的基础配置
912
...pluginVue.configs['flat/recommended'], // 使用 Vue ESLint 的推荐配置
10-
{
11-
files: ['**/*.vue'], // 针对所有 .vue 文件
12-
languageOptions: {
13-
parserOptions: {
14-
parser: '@typescript-eslint/parser', // 使用 TypeScript ESLint 解析器
15-
},
16-
},
17-
},
13+
14+
// 通用规则配置(适用于所有文件)
1815
{
1916
rules: {
20-
'no-debugger': 'error', // 禁止使用 debugger 语句
2117
// 'no-console': ['error', { allow: ['warn', 'error', 'info', 'clear'] }], // 禁止使用 console 语句,但允许 warn, error, info 和 clear
18+
'no-debugger': 'error', // 禁止使用 debugger 语句
2219
'prefer-const': 'error', // 强制使用 const 而不是 let
2320
'sort-imports': ['error', { ignoreDeclarationSort: true }], // 强制排序导入语句,但忽略声明排序
2421
'no-duplicate-imports': 'error', // 禁止重复导入
25-
// 该规则强制使用 '@ts-expect-error' 注释在 TypeScript 代码中指示故意的类型错误,提高代码的清晰度和可维护性。
22+
// 禁用对未使用变量的检查(针对类型声明)
23+
'no-unused-vars': 'off',
24+
// 改用 TypeScript 专属规则(更智能)
25+
'@typescript-eslint/no-unused-vars': ['error'],
26+
},
27+
},
28+
29+
// TypeScript 文件配置
30+
{
31+
files: ['**/*.ts', '**/*.tsx'],
32+
languageOptions: {
33+
parser: tseslint.parser,
34+
parserOptions: {
35+
createDefaultProgram: false,
36+
ecmaFeatures: {
37+
jsx: true,
38+
},
39+
ecmaVersion: 'latest',
40+
extraFileExtensions: ['.vue'],
41+
jsxPragma: 'React',
42+
project: './tsconfig.*.json',
43+
sourceType: 'module',
44+
},
45+
},
46+
rules: {
47+
// TypeScript 特定规则
2648
'@typescript-eslint/prefer-ts-expect-error': 'error', // 强制使用 @ts-expect-error 而不是 @ts-ignore
27-
// 强制使用 'import type' 进行类型导入
2849
'@typescript-eslint/consistent-type-imports': [
2950
'error',
3051
{
3152
fixStyle: 'inline-type-imports', // 使用内联类型导入样式
3253
disallowTypeAnnotations: false, // 允许类型注解
3354
},
3455
],
35-
// 强制在导入仅包含内联类型限定符的规范时使用顶级导入类型限定符
3656
'@typescript-eslint/no-import-type-side-effects': 'error', // 禁止导入类型时产生副作用
57+
},
58+
},
59+
60+
// Vue 文件配置
61+
{
62+
files: ['**/*.vue'],
63+
languageOptions: {
64+
parserOptions: {
65+
parser: '@typescript-eslint/parser', // 使用 TypeScript ESLint 解析器解析 Vue 文件中的 TypeScript
66+
},
67+
},
68+
rules: {
69+
// Vue 特定规则
3770
'vue/max-attributes-per-line': 'off', // 关闭每行最多属性数的限制
3871
'vue/singleline-html-element-content-newline': 'off', // 关闭单行 HTML 元素内容换行的限制
3972
'vue/multi-word-component-names': 'off', // 关闭多单词组件名称的限制
@@ -45,6 +78,17 @@ export default tseslint.config(
4578
svg: 'always', // 强制 svg 元素始终自闭合
4679
},
4780
],
81+
82+
// Vue 文件中的 TypeScript 规则
83+
'@typescript-eslint/prefer-ts-expect-error': 'error',
84+
'@typescript-eslint/consistent-type-imports': [
85+
'error',
86+
{
87+
fixStyle: 'inline-type-imports',
88+
disallowTypeAnnotations: false,
89+
},
90+
],
91+
'@typescript-eslint/no-import-type-side-effects': 'error',
4892
},
4993
},
5094
);

packages/ui/src/types/env.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
declare module '*.vue' {
2-
import { DefineComponent } from 'vue';
2+
import type { DefineComponent } from 'vue';
33
const component: DefineComponent<{}, {}, any>;
44
export default component;
55
}

playground/src/router/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router';
1+
import { type RouteRecordRaw, createRouter, createWebHistory } from 'vue-router';
22
import {
33
CommentOutlined,
44
ExperimentOutlined,
5-
ToolOutlined,
65
SettingOutlined,
6+
ToolOutlined,
77
} from '@ant-design/icons-vue';
88

99
export const routes: RouteRecordRaw[] = [

playground/src/types/router.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { Component } from 'vue';
2-
import type { RouteRecordRaw } from 'vue-router';
32

43
interface RouteMetaCustom extends Record<string | number | symbol, unknown> {
54
title?: string;

playground/src/views/Utils/__test__/array.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { unique, chunk } from '@mylib/utils';
1+
import { chunk, unique } from '@mylib/utils';
22
import { describe, expect, it } from 'vitest';
33

44
describe('array工具', () => {

playground/src/views/Utils/__test__/string.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { capitalize, camelToKebab, isString } from '@mylib/utils';
1+
import { camelToKebab, capitalize, isString } from '@mylib/utils';
22
import { describe, expect, it } from 'vitest';
33

44
describe('string工具', () => {

0 commit comments

Comments
 (0)