| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- // ESLint 9 flat config(monorepo 根,遍历 packages/ + apps/):vue3 + TS strict 配套。
- //
- // 与 PC 端(单项目)差异:
- // ① ignores 补 monorepo 路径(apps/*/dist、packages/shared/dist、各 node_modules、vendor/);
- // ② 禁值 import 清单**只含 UMD 全局框架**(vue/vue-router/pinia/axios)——
- // Vant 4 走 npm 编译(官方无 UMD 构建,混合方案),`import Vant from 'vant'` 仅允许
- // 出现在 apps/*/src/main.ts 的 app.use(Vant) 装配点,不在本清单限内。
- import js from '@eslint/js';
- import tseslint from 'typescript-eslint';
- import pluginVue from 'eslint-plugin-vue';
- import prettier from 'eslint-config-prettier';
- /**
- * 框架运行时模块名(UMD 全局框架;业务代码禁"值 import",见 README 编码规范)。
- *
- * 精确边界(同 PC 端):
- * - `import type { Ref } from 'vue'` 属**类型导入**(编译期擦除、零运行时足迹)——放行;
- * - `import { ref } from 'vue'` 属**值导入**——会把框架运行时打包进 dist,必须拦。
- *
- * 实现用 `no-restricted-syntax`(importKind='value' 只匹配值导入,放行 type 导入)。
- */
- const FRAMEWORK_MODULE_SELECTOR =
- ":is([source.value='vue'],[source.value='vue-router'],[source.value='pinia'],[source.value='axios'])";
- export default [
- js.configs.recommended,
- ...tseslint.configs.recommended,
- ...pluginVue.configs['flat/essential'],
- prettier,
- {
- // shims/ 由 scripts/gen-shims.cjs 生成(含逐行 eslint-disable 注释);
- // scripts/ 是 Node CJS 工具脚本;vendor/ 是 UMD 源文件——均不 lint。
- ignores: [
- 'dist/**',
- 'vendor/**',
- 'node_modules/**',
- 'shims/**',
- 'scripts/**',
- 'packages/*/dist/**',
- 'apps/*/dist/**',
- '**/node_modules/**',
- '**/*.cjs',
- ],
- },
- {
- // .vue:SFC 内 <script lang="ts"> 交给 @typescript-eslint/parser,
- // 否则 TS 语法(类型注解 / interface / 泛型)在 SFC 内触发 Parsing error。
- files: ['**/*.vue'],
- languageOptions: {
- parserOptions: {
- parser: tseslint.parser,
- sourceType: 'module',
- },
- },
- },
- {
- // TS 项目里 no-undef 由 TS 编译器负责(global.d.ts 声明的裸标识符对 JS 规则不可见,会误报)。
- files: ['**/*.ts', '**/*.vue', '**/*.tsx'],
- rules: {
- 'no-undef': 'off',
- },
- },
- {
- rules: {
- '@typescript-eslint/no-explicit-any': 'error',
- 'vue/multi-word-component-names': 'off',
- '@typescript-eslint/no-unused-vars': [
- 'error',
- { argsIgnorePattern: '^_', varsIgnorePattern: '^_' },
- ],
- // 拦截"值 import UMD 全局框架"(值导入会把框架运行时打包进 dist)。
- // 放行 import type(编译期擦除)。
- 'no-restricted-syntax': [
- 'error',
- {
- selector: `ImportDeclaration[importKind='value']${FRAMEWORK_MODULE_SELECTOR}`,
- message:
- 'UMD 全局框架经 index.html 加载(vendor/ 自托管),业务代码禁止值 import;仅允许 `import type`(编译期擦除,零运行时足迹)。',
- },
- ],
- },
- },
- ];
|