uniai/eslint.config.ts
rus07tam 14bec5c5cd
All checks were successful
Publish to npm / publish-npm (release) Successful in 9s
initial commit
2026-02-08 12:25:57 +00:00

147 lines
4 KiB
TypeScript

import pluginPerfectionist from 'eslint-plugin-perfectionist';
import pluginPrettier from 'eslint-plugin-prettier';
import pluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
import pluginSecurity from 'eslint-plugin-security';
import pluginSonarjs from 'eslint-plugin-sonarjs';
import pluginUnicorn from 'eslint-plugin-unicorn';
import { defineConfig } from 'eslint/config';
import tseslint from 'typescript-eslint';
const topNamesOrder = [
'type',
'id',
'name',
'role',
'description',
'version',
'priority',
] satisfies string[];
const bottomNamesOrder = [] satisfies string[];
const topSortGroups = topNamesOrder.map((name, index) => ({
elementNamePattern: `^${RegExp.escape(name)}$`,
groupName: `group_${index}`,
}));
const topSortGroupNames = topNamesOrder.map((_, index) => `group_${index}`);
const bottomSortGroups = bottomNamesOrder.map((name, index) => ({
elementNamePattern: `^${RegExp.escape(name)}$`,
groupName: `group_${index + topNamesOrder.length}`,
}));
const bottomSortGroupNames = bottomNamesOrder.map(
(_, index) => `group_${index + topNamesOrder.length}`,
);
const sortBaseRule = {
type: 'natural',
alphabet: 'custom',
customGroups: [...topSortGroups, ...bottomSortGroups],
groups: [
...topSortGroupNames,
'property',
'method',
'unknown',
...bottomSortGroupNames,
],
order: 'asc',
};
const sortDetailedRule = {
type: 'natural',
alphabet: 'custom',
customGroups: [...topSortGroups, ...bottomSortGroups],
groups: [
...topSortGroupNames,
// static public property
['static-property', 'static-accessor-property'],
['static-get-method', 'static-set-method'],
// static protected property
['protected-static-property', 'protected-static-accessor-property'],
['protected-static-get-method', 'protected-static-set-method'],
// private protected property
['private-static-property', 'private-static-accessor-property'],
['private-static-get-method', 'private-static-set-method'],
// static block
'static-block',
// normal properties
'property',
'protected-property',
'private-property',
// constructor
'constructor',
// public callable
'accessor-property',
['get-method', 'set-method'],
// protected callable
'protected-accessor-property',
['protected-get-method', 'protected-set-method'],
// private callable
'private-accessor-property',
['private-get-method', 'private-set-method'],
// static methods
['static-method', 'static-function-property'],
['protected-static-method', 'protected-static-function-property'],
['private-static-method', 'private-static-function-property'],
// methods
['method', 'function-property'],
['protected-method', 'protected-function-property'],
['private-method', 'private-function-property'],
// unknown
'unknown',
// bottom
...bottomSortGroupNames,
],
order: 'asc',
};
export default defineConfig([
tseslint.configs.stylisticTypeChecked,
tseslint.configs.eslintRecommended,
pluginPrettierRecommended,
pluginPerfectionist.configs['recommended-natural'],
pluginUnicorn.configs.all,
pluginSecurity.configs.recommended,
pluginSonarjs.configs.recommended,
{
rules: {
'@typescript-eslint/no-unsafe-call': 'off',
},
},
{
ignores: ['dist/**', '**/dist/**'],
},
{
languageOptions: {
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
},
{
rules: {
'functional/no-classes': 'off',
},
},
{
rules: {
'perfectionist/sort-classes': ['error', sortDetailedRule],
'perfectionist/sort-interfaces': ['error', sortBaseRule],
'perfectionist/sort-object-types': ['error', sortBaseRule],
'perfectionist/sort-objects': ['error', sortBaseRule],
},
},
{
plugins: {
prettier: pluginPrettier,
},
rules: {
'prettier/prettier': [
'error',
{
singleQuote: true,
},
],
},
},
]);