Skip to content

Commit b5f56c1

Browse files
committed
refactor: exports json schema
1 parent 9cce535 commit b5f56c1

File tree

2 files changed

+29
-57
lines changed

2 files changed

+29
-57
lines changed

rules/sort-intersection-types.ts

+6-35
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
1-
import type { Options as SortUnionTypesOptions } from './sort-union-types'
1+
import type {Options as SortUnionTypesOptions} from './sort-union-types';
22

3-
import {
4-
partitionByCommentJsonSchema,
5-
partitionByNewLineJsonSchema,
6-
specialCharactersJsonSchema,
7-
newlinesBetweenJsonSchema,
8-
ignoreCaseJsonSchema,
9-
buildTypeJsonSchema,
10-
alphabetJsonSchema,
11-
localesJsonSchema,
12-
groupsJsonSchema,
13-
orderJsonSchema,
14-
} from '../utils/common-json-schemas'
153
import { sortUnionOrIntersectionTypes } from './sort-union-types'
164
import { createEslintRule } from '../utils/create-eslint-rule'
5+
import {
6+
7+
jsonSchema
8+
} from './sort-union-types'
179

1810
type MESSAGE_ID =
1911
| 'missedSpacingBetweenIntersectionTypes'
@@ -38,28 +30,6 @@ let defaultOptions: Required<Options[0]> = {
3830

3931
export default createEslintRule<Options, MESSAGE_ID>({
4032
meta: {
41-
schema: [
42-
{
43-
properties: {
44-
partitionByComment: {
45-
...partitionByCommentJsonSchema,
46-
description:
47-
'Allows you to use comments to separate the intersection types members into logical groups.',
48-
},
49-
partitionByNewLine: partitionByNewLineJsonSchema,
50-
specialCharacters: specialCharactersJsonSchema,
51-
newlinesBetween: newlinesBetweenJsonSchema,
52-
ignoreCase: ignoreCaseJsonSchema,
53-
alphabet: alphabetJsonSchema,
54-
type: buildTypeJsonSchema(),
55-
locales: localesJsonSchema,
56-
groups: groupsJsonSchema,
57-
order: orderJsonSchema,
58-
},
59-
additionalProperties: false,
60-
type: 'object',
61-
},
62-
],
6333
messages: {
6434
unexpectedIntersectionTypesGroupOrder:
6535
'Expected "{{right}}" ({{rightGroup}}) to come before "{{left}}" ({{leftGroup}}).',
@@ -75,6 +45,7 @@ export default createEslintRule<Options, MESSAGE_ID>({
7545
description: 'Enforce sorted intersection types.',
7646
recommended: true,
7747
},
48+
schema: [jsonSchema],
7849
type: 'suggestion',
7950
fixable: 'code',
8051
},

rules/sort-union-types.ts

+23-22
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { JSONSchema4 } from '@typescript-eslint/utils/json-schema'
12
import type { RuleContext } from '@typescript-eslint/utils/ts-eslint'
23
import type { TSESTree } from '@typescript-eslint/types'
34

@@ -98,30 +99,29 @@ let defaultOptions: Required<Options[0]> = {
9899
groups: [],
99100
}
100101

102+
export let jsonSchema: JSONSchema4 = {
103+
properties: {
104+
partitionByComment: {
105+
...partitionByCommentJsonSchema,
106+
description:
107+
'Allows you to use comments to separate the union types into logical groups.',
108+
},
109+
partitionByNewLine: partitionByNewLineJsonSchema,
110+
specialCharacters: specialCharactersJsonSchema,
111+
newlinesBetween: newlinesBetweenJsonSchema,
112+
ignoreCase: ignoreCaseJsonSchema,
113+
alphabet: alphabetJsonSchema,
114+
type: buildTypeJsonSchema(),
115+
locales: localesJsonSchema,
116+
groups: groupsJsonSchema,
117+
order: orderJsonSchema,
118+
},
119+
additionalProperties: false,
120+
type: 'object',
121+
}
122+
101123
export default createEslintRule<Options, MESSAGE_ID>({
102124
meta: {
103-
schema: [
104-
{
105-
properties: {
106-
partitionByComment: {
107-
...partitionByCommentJsonSchema,
108-
description:
109-
'Allows you to use comments to separate the union types into logical groups.',
110-
},
111-
partitionByNewLine: partitionByNewLineJsonSchema,
112-
specialCharacters: specialCharactersJsonSchema,
113-
newlinesBetween: newlinesBetweenJsonSchema,
114-
ignoreCase: ignoreCaseJsonSchema,
115-
alphabet: alphabetJsonSchema,
116-
type: buildTypeJsonSchema(),
117-
locales: localesJsonSchema,
118-
groups: groupsJsonSchema,
119-
order: orderJsonSchema,
120-
},
121-
additionalProperties: false,
122-
type: 'object',
123-
},
124-
],
125125
messages: {
126126
unexpectedUnionTypesGroupOrder:
127127
'Expected "{{right}}" ({{rightGroup}}) to come before "{{left}}" ({{leftGroup}}).',
@@ -137,6 +137,7 @@ export default createEslintRule<Options, MESSAGE_ID>({
137137
description: 'Enforce sorted union types.',
138138
recommended: true,
139139
},
140+
schema: [jsonSchema],
140141
type: 'suggestion',
141142
fixable: 'code',
142143
},

0 commit comments

Comments
 (0)