initial commit
All checks were successful
Publish to npm / publish-npm (release) Successful in 9s

This commit is contained in:
rus07tam 2026-02-08 15:13:43 +00:00
commit b4f68f48c6
No known key found for this signature in database
14 changed files with 872 additions and 0 deletions

62
src/index.ts Normal file
View file

@ -0,0 +1,62 @@
/* eslint-disable @typescript-eslint/naming-convention */
import pluginPerfectionist from 'eslint-plugin-perfectionist';
import pluginPrettier from 'eslint-plugin-prettier';
import pluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
import pluginSonarjs from 'eslint-plugin-sonarjs';
import pluginUnicorn from 'eslint-plugin-unicorn';
import { defineConfig } from 'eslint/config';
import tseslint from 'typescript-eslint';
import { sortBaseRule, sortDetailedRule } from './sort';
const ignores = {
ignores: ['dist/**', '**/dist/**', 'build/**', '**/build/**'],
} as const;
const configs = [
tseslint.configs.stylisticTypeChecked,
tseslint.configs.eslintRecommended,
tseslint.configs.recommendedTypeChecked,
pluginPrettierRecommended,
pluginPerfectionist.configs['recommended-natural'],
pluginUnicorn.configs.all,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(pluginSonarjs.configs?.recommended ?? {}) as any, // broken sonarjs types?
] as const;
export const config = defineConfig([
...configs,
ignores,
{
languageOptions: {
parserOptions: {
projectService: true,
tsconfigRootDir: process.cwd(),
},
},
},
{
rules: {
'@typescript-eslint/naming-convention': 'error',
'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,
},
],
},
},
]);
export default config;

69
src/sort.ts Normal file
View file

@ -0,0 +1,69 @@
import { createSortGroups } from './utilities';
const namesOrder = [
'type',
'instance',
'id',
'name',
'meta',
'title',
'description',
'author',
'version',
'multiplicity',
];
export const sortBaseRule = {
alphabet: 'custom',
order: 'asc',
type: 'natural',
...createSortGroups(namesOrder, {
bottom: ['property', 'method', 'unknown'],
}),
};
export const sortDetailedRule = {
alphabet: 'custom',
order: 'asc',
type: 'natural',
...createSortGroups(namesOrder, {
bottom: [
// 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',
],
}),
};

30
src/utilities.ts Normal file
View file

@ -0,0 +1,30 @@
import { escapeRegExp } from 'lodash';
export function createSortGroups(
keys: readonly string[],
extra?: {
bottom?: (string | string[])[];
top?: (string | string[])[];
},
): {
customGroups: ReturnType<typeof createCustomSortGroups>;
groups: (string | string[])[];
} {
return {
customGroups: createCustomSortGroups(keys),
groups: [
...(extra?.bottom ?? []),
...keys.map((_, index) => `custom_group_${index}`),
...(extra?.top ?? []),
],
};
}
function createCustomSortGroups(
keys: readonly string[],
): { readonly elementNamePattern: string; readonly groupName: string }[] {
return keys.map((name, index) => ({
elementNamePattern: `^${escapeRegExp(name)}$`,
groupName: `custom_group_${index}`,
}));
}