eslint-rules/src/presets/typescript.ts
2024-08-04 21:59:18 -04:00

85 lines
2.9 KiB
TypeScript

import { error, off, warn } from '../constants';
import type { TypeScriptRulesObject } from '@aet/eslint-define-config/src/rules/typescript-eslint';
import type { ImportXRulesObject } from '@aet/eslint-define-config/src/rules/import-x';
import { defineMiddleware } from '../middleware';
const importRules: Partial<ImportXRulesObject> = {
'import-x/export': off,
'import-x/no-duplicates': error,
'import-x/order': [error, { groups: ['builtin', 'external'] }],
};
const typescriptRules: Partial<TypeScriptRulesObject> = {
'@typescript-eslint/ban-ts-comment': [
error,
{
'ts-expect-error': 'allow-with-description',
'ts-check': false,
'ts-ignore': 'allow-with-description',
'ts-nocheck': 'allow-with-description',
},
],
'@typescript-eslint/consistent-type-imports': [
error,
{ disallowTypeAnnotations: false, fixStyle: 'inline-type-imports' },
],
'@typescript-eslint/explicit-member-accessibility': [
warn,
{ accessibility: 'no-public' },
],
'@typescript-eslint/no-empty-interface': [error, { allowSingleExtends: true }],
'@typescript-eslint/no-explicit-any': off,
'@typescript-eslint/no-misused-promises': [error, { checksVoidReturn: false }],
'@typescript-eslint/no-namespace': off,
'@typescript-eslint/no-unnecessary-type-assertion': error,
'@typescript-eslint/no-unsafe-argument': off,
'@typescript-eslint/no-unsafe-assignment': off,
'@typescript-eslint/no-unsafe-call': off,
'@typescript-eslint/no-unsafe-member-access': off,
'@typescript-eslint/no-unsafe-return': off,
'@typescript-eslint/no-unused-vars': off,
'@typescript-eslint/no-use-before-define': off,
'@typescript-eslint/no-var-requires': off,
'@typescript-eslint/restrict-template-expressions': off,
'@typescript-eslint/triple-slash-reference': off,
'@typescript-eslint/unbound-method': off,
};
export const importTypeScript = defineMiddleware((config, { addRules, addSettings }) => {
config.parser = '@typescript-eslint/parser';
config.plugins.push('@typescript-eslint', 'import-x');
config.extends.push(
'plugin:@typescript-eslint/recommended-type-checked',
'plugin:import-x/errors',
'plugin:import-x/typescript',
);
addSettings({
'import-x/parsers': {
'@typescript-eslint/parser': ['.ts', '.tsx', '.mts', '.cts'],
},
'import-x/resolver': {
typescript: true,
},
});
config.overrides.push(
{
files: ['.eslintrc.js', '.eslintrc.cjs', '*.config.js', 'index.js'],
extends: ['plugin:@typescript-eslint/disable-type-checked'],
rules: {
'@typescript-eslint/no-require-imports': off,
'import-x/no-commonjs': off,
'rules/restrict-template-expressions': off,
},
},
{
files: ['*.d.ts'],
rules: {
'@typescript-eslint/consistent-type-imports': off,
},
},
);
addRules(importRules);
addRules(typescriptRules);
});