Files

76 lines
2.3 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'
}
},
// Allow triple-slash reference in env.d.ts for Astro types
{
files: ['src/env.d.ts'],
rules: {
'@typescript-eslint/triple-slash-reference': 'off'
}
},
// Ignores
{ ignores: ['dist', 'node_modules', 'eslint.config.js', '.astro', 'astro.config.*', 'ref/**'] }
];