forked from azat-io/eslint-plugin-perfectionist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
151 lines (147 loc) · 4.99 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import sortIntersectionTypes, { RULE_NAME as sortIntersectionTypesName } from './rules/sort-intersection-types'
import sortSvelteAttributes, { RULE_NAME as sortSvelteAttributesName } from './rules/sort-svelte-attributes'
import sortAstroAttributes, { RULE_NAME as sortAstroAttributesName } from './rules/sort-astro-attributes'
import sortArrayIncludes, { RULE_NAME as sortArrayIncludesName } from './rules/sort-array-includes'
import sortVueAttributes, { RULE_NAME as sortVueAttributesName } from './rules/sort-vue-attributes'
import sortNamedExports, { RULE_NAME as sortNamedExportsName } from './rules/sort-named-exports'
import sortNamedImports, { RULE_NAME as sortNamedImportsName } from './rules/sort-named-imports'
import sortObjectTypes, { RULE_NAME as sortObjectTypesName } from './rules/sort-object-types'
import sortUnionTypes, { RULE_NAME as sortUnionTypesName } from './rules/sort-union-types'
import sortInterfaces, { RULE_NAME as sortInterfacesName } from './rules/sort-interfaces'
import sortJsxProps, { RULE_NAME as sortJsxPropsName } from './rules/sort-jsx-props'
import sortExports, { RULE_NAME as sortExportsName } from './rules/sort-exports'
import sortImports, { RULE_NAME as sortImportsName } from './rules/sort-imports'
import sortObjects, { RULE_NAME as sortObjectsName } from './rules/sort-objects'
import sortClasses, { RULE_NAME as sortClassesName } from './rules/sort-classes'
import sortEnums, { RULE_NAME as sortEnumsName } from './rules/sort-enums'
import sortMaps, { RULE_NAME as sortMapsName } from './rules/sort-maps'
import { SortOrder, SortType } from './typings'
import { name } from './package.json'
type RuleSeverity = 'error' | 'warn' | 'off'
type RuleDeclaration = [RuleSeverity, { [key: string]: unknown }?]
let createConfigWithOptions = (options: {
'ignore-case'?: boolean
order: SortOrder
type: SortType
}): {
rules: {
[key: string]: RuleDeclaration
}
plugins: ['perfectionist']
} => {
let recommendedRules: {
[key: string]: RuleDeclaration
} = {
[sortImportsName]: [
'error',
{
groups: [
'type',
['builtin', 'external'],
'internal-type',
'internal',
['parent-type', 'sibling-type', 'index-type'],
['parent', 'sibling', 'index'],
'object',
'unknown',
],
'custom-groups': {
value: {},
type: {},
},
'newlines-between': 'always',
'internal-pattern': ['~/**'],
},
],
[sortClassesName]: [
'error',
{
groups: [
'index-signature',
'static-property',
'private-property',
'property',
'constructor',
'static-method',
'private-method',
'method',
['get-method', 'set-method'],
'unknown',
],
},
],
[sortObjectsName]: [
'error',
{
'partition-by-comment': false,
},
],
[sortArrayIncludesName]: [
'error',
{
'spread-last': true,
},
],
[sortIntersectionTypesName]: ['error'],
[sortSvelteAttributesName]: ['error'],
[sortAstroAttributesName]: ['error'],
[sortVueAttributesName]: ['error'],
[sortNamedExportsName]: ['error'],
[sortNamedImportsName]: ['error'],
[sortObjectTypesName]: ['error'],
[sortUnionTypesName]: ['error'],
[sortInterfacesName]: ['error'],
[sortJsxPropsName]: ['error'],
[sortExportsName]: ['error'],
[sortEnumsName]: ['error'],
[sortMapsName]: ['error'],
}
return {
rules: Object.fromEntries(
Object.entries(recommendedRules).map(([key, [message, baseOptions = {}]]) => [
`perfectionist/${key}`,
[message, Object.assign(baseOptions, options)],
]),
),
plugins: ['perfectionist'],
}
}
/* eslint-disable perfectionist/sort-objects */
export default {
rules: {
[sortArrayIncludesName]: sortArrayIncludes,
[sortAstroAttributesName]: sortAstroAttributes,
[sortClassesName]: sortClasses,
[sortEnumsName]: sortEnums,
[sortExportsName]: sortExports,
[sortImportsName]: sortImports,
[sortInterfacesName]: sortInterfaces,
[sortJsxPropsName]: sortJsxProps,
[sortMapsName]: sortMaps,
[sortNamedExportsName]: sortNamedExports,
[sortNamedImportsName]: sortNamedImports,
[sortObjectTypesName]: sortObjectTypes,
[sortObjectsName]: sortObjects,
[sortSvelteAttributesName]: sortSvelteAttributes,
[sortIntersectionTypesName]: sortIntersectionTypes,
[sortUnionTypesName]: sortUnionTypes,
[sortVueAttributesName]: sortVueAttributes,
},
configs: {
'recommended-alphabetical': createConfigWithOptions({
type: SortType.alphabetical,
order: SortOrder.asc,
'ignore-case': false,
}),
'recommended-natural': createConfigWithOptions({
type: SortType.natural,
order: SortOrder.asc,
'ignore-case': false,
}),
'recommended-line-length': createConfigWithOptions({
type: SortType['line-length'],
order: SortOrder.desc,
}),
},
name,
}