forked from ParadigmEducation/snowflake-notes
6cc96a7126
- Astro+TS 严格模式(禁止 any、显式返回类型) - ESLint Flat Config + Prettier 格式化 - 内容集合(posts)与示例文章 - OSS 图床可配置 Img 组件 - 抽离 posts 数据逻辑(更易类型检查) - getStaticPaths 修正(rest 路由传字符串) - README/AGENTS 中文文档与约定 - Gitea CI:typecheck + lint - 忽略 ref/(仅作临时参考)
68 lines
2.1 KiB
JavaScript
68 lines
2.1 KiB
JavaScript
// Flat config for ESLint v9
|
|
import tseslint from 'typescript-eslint';
|
|
import astro from 'eslint-plugin-astro';
|
|
import astroParser from 'astro-eslint-parser';
|
|
|
|
export default [
|
|
// Astro flat recommended
|
|
...astro.configs['flat/recommended'],
|
|
|
|
// TS typed linting only for TS files
|
|
...tseslint.configs.recommendedTypeChecked,
|
|
...tseslint.configs.stylisticTypeChecked,
|
|
{
|
|
files: ['**/*.{ts,tsx}'],
|
|
languageOptions: {
|
|
parser: tseslint.parser,
|
|
parserOptions: {
|
|
project: true,
|
|
tsconfigRootDir: process.cwd(),
|
|
sourceType: 'module',
|
|
ecmaVersion: 'latest'
|
|
}
|
|
},
|
|
plugins: { '@typescript-eslint': tseslint.plugin },
|
|
rules: {
|
|
'@typescript-eslint/no-explicit-any': 'error',
|
|
'@typescript-eslint/consistent-type-imports': ['error', { prefer: 'type-imports' }],
|
|
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
|
|
'@typescript-eslint/explicit-module-boundary-types': 'error',
|
|
'@typescript-eslint/explicit-function-return-type': [
|
|
'error',
|
|
{
|
|
allowExpressions: false,
|
|
allowHigherOrderFunctions: true,
|
|
allowDirectConstAssertionInArrowFunctions: true,
|
|
allowTypedFunctionExpressions: true
|
|
}
|
|
]
|
|
}
|
|
},
|
|
|
|
// Astro files: use astro parser; do not inject TS typed rules here
|
|
{
|
|
files: ['**/*.astro'],
|
|
languageOptions: {
|
|
parser: astroParser,
|
|
parserOptions: {
|
|
parser: tseslint.parser,
|
|
project: true,
|
|
tsconfigRootDir: process.cwd(),
|
|
ecmaVersion: 'latest',
|
|
sourceType: 'module'
|
|
}
|
|
},
|
|
plugins: { '@typescript-eslint': tseslint.plugin, astro },
|
|
rules: {
|
|
// 在 .astro 文件中放宽部分 type-aware 规则,避免模板区误报
|
|
'@typescript-eslint/no-unsafe-return': 'off',
|
|
'@typescript-eslint/no-unsafe-assignment': 'off',
|
|
'@typescript-eslint/no-unsafe-member-access': 'off',
|
|
'@typescript-eslint/non-nullable-type-assertion-style': 'off'
|
|
}
|
|
},
|
|
|
|
// Ignores
|
|
{ ignores: ['dist', 'node_modules', 'eslint.config.js', '.astro', 'astro.config.*', 'ref/**'] }
|
|
];
|