-
Notifications
You must be signed in to change notification settings - Fork 43
/
index.ts
139 lines (130 loc) · 4.32 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
import type { ESLint, Linter, Rule } from 'eslint'
import sortVariableDeclarations from './rules/sort-variable-declarations'
import sortIntersectionTypes from './rules/sort-intersection-types'
import sortHeritageClauses from './rules/sort-heritage-clauses'
import sortArrayIncludes from './rules/sort-array-includes'
import sortNamedImports from './rules/sort-named-imports'
import sortNamedExports from './rules/sort-named-exports'
import sortObjectTypes from './rules/sort-object-types'
import sortSwitchCase from './rules/sort-switch-case'
import sortUnionTypes from './rules/sort-union-types'
import sortInterfaces from './rules/sort-interfaces'
import sortDecorators from './rules/sort-decorators'
import sortJsxProps from './rules/sort-jsx-props'
import sortClasses from './rules/sort-classes'
import sortImports from './rules/sort-imports'
import sortExports from './rules/sort-exports'
import sortObjects from './rules/sort-objects'
import sortModules from './rules/sort-modules'
import sortEnums from './rules/sort-enums'
import sortMaps from './rules/sort-maps'
import sortSets from './rules/sort-sets'
interface PluginConfig {
rules: {
'sort-variable-declarations': Rule.RuleModule
'sort-intersection-types': Rule.RuleModule
'sort-heritage-clauses': Rule.RuleModule
'sort-array-includes': Rule.RuleModule
'sort-named-imports': Rule.RuleModule
'sort-named-exports': Rule.RuleModule
'sort-object-types': Rule.RuleModule
'sort-union-types': Rule.RuleModule
'sort-switch-case': Rule.RuleModule
'sort-interfaces': Rule.RuleModule
'sort-decorators': Rule.RuleModule
'sort-jsx-props': Rule.RuleModule
'sort-modules': Rule.RuleModule
'sort-classes': Rule.RuleModule
'sort-imports': Rule.RuleModule
'sort-exports': Rule.RuleModule
'sort-objects': Rule.RuleModule
'sort-enums': Rule.RuleModule
'sort-sets': Rule.RuleModule
'sort-maps': Rule.RuleModule
}
configs: {
'recommended-alphabetical-legacy': Linter.LegacyConfig
'recommended-line-length-legacy': Linter.LegacyConfig
'recommended-natural-legacy': Linter.LegacyConfig
'recommended-alphabetical': Linter.Config
'recommended-line-length': Linter.Config
'recommended-natural': Linter.Config
}
name: string
}
interface BaseOptions {
type: 'alphabetical' | 'line-length' | 'natural'
order: 'desc' | 'asc'
}
let name = 'perfectionist'
let plugin = {
rules: {
'sort-variable-declarations': sortVariableDeclarations,
'sort-intersection-types': sortIntersectionTypes,
'sort-heritage-clauses': sortHeritageClauses,
'sort-array-includes': sortArrayIncludes,
'sort-named-imports': sortNamedImports,
'sort-named-exports': sortNamedExports,
'sort-object-types': sortObjectTypes,
'sort-union-types': sortUnionTypes,
'sort-switch-case': sortSwitchCase,
'sort-decorators': sortDecorators,
'sort-interfaces': sortInterfaces,
'sort-jsx-props': sortJsxProps,
'sort-modules': sortModules,
'sort-classes': sortClasses,
'sort-imports': sortImports,
'sort-exports': sortExports,
'sort-objects': sortObjects,
'sort-enums': sortEnums,
'sort-sets': sortSets,
'sort-maps': sortMaps,
},
name,
} as unknown as ESLint.Plugin
let getRules = (options: BaseOptions): Linter.RulesRecord =>
Object.fromEntries(
Object.keys(plugin.rules!).map(ruleName => [
`${name}/${ruleName}`,
['error', options],
]),
)
let createConfig = (options: BaseOptions): Linter.Config => ({
plugins: {
[name]: plugin,
},
rules: getRules(options),
})
let createLegacyConfig = (options: BaseOptions): Linter.LegacyConfig => ({
rules: getRules(options),
plugins: [name],
})
export default {
...plugin,
configs: {
'recommended-alphabetical-legacy': createLegacyConfig({
type: 'alphabetical',
order: 'asc',
}),
'recommended-line-length-legacy': createLegacyConfig({
type: 'line-length',
order: 'desc',
}),
'recommended-natural-legacy': createLegacyConfig({
type: 'natural',
order: 'asc',
}),
'recommended-alphabetical': createConfig({
type: 'alphabetical',
order: 'asc',
}),
'recommended-line-length': createConfig({
type: 'line-length',
order: 'desc',
}),
'recommended-natural': createConfig({
type: 'natural',
order: 'asc',
}),
},
} as PluginConfig