Content-Length: 978508 | pFad | https://github.com/azat-io/eslint-plugin-perfectionist/commit/c7f62a0

79 fix: strengthen json schemas · azat-io/eslint-plugin-perfectionist@c7f62a0 · GitHub
Skip to content

Commit c7f62a0

Browse files
authored
fix: strengthen json schemas
1 parent 2537aed commit c7f62a0

9 files changed

+55
-30
lines changed

rules/sort-decorators.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import type {
1010
import type { SortingNode } from '../types/sorting-node'
1111

1212
import {
13+
deprecatedCustomGroupsJsonSchema,
1314
partitionByCommentJsonSchema,
14-
customGroupsJsonSchema,
1515
commonJsonSchemas,
1616
groupsJsonSchema,
1717
} from '../utils/common-json-schemas'
@@ -161,7 +161,7 @@ export default createEslintRule<Options, MESSAGE_ID>({
161161
type: 'boolean',
162162
},
163163
partitionByComment: partitionByCommentJsonSchema,
164-
customGroups: customGroupsJsonSchema,
164+
customGroups: deprecatedCustomGroupsJsonSchema,
165165
groups: groupsJsonSchema,
166166
},
167167
additionalProperties: false,

rules/sort-enums.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import type { Options } from './sort-enums/types'
77

88
import {
99
buildCustomGroupsArrayJsonSchema,
10+
deprecatedCustomGroupsJsonSchema,
1011
partitionByCommentJsonSchema,
1112
partitionByNewLineJsonSchema,
1213
newlinesBetweenJsonSchema,
13-
customGroupsJsonSchema,
1414
commonJsonSchemas,
1515
groupsJsonSchema,
1616
} from '../utils/common-json-schemas'
@@ -260,17 +260,17 @@ export default createEslintRule<Options, MESSAGE_ID>({
260260
{
261261
properties: {
262262
...commonJsonSchemas,
263-
forceNumericSort: {
264-
description:
265-
'Will always sort numeric enums by their value regardless of the sort type specified.',
266-
type: 'boolean',
267-
},
268263
customGroups: {
269264
oneOf: [
270-
customGroupsJsonSchema,
265+
deprecatedCustomGroupsJsonSchema,
271266
buildCustomGroupsArrayJsonSchema({ singleCustomGroupJsonSchema }),
272267
],
273268
},
269+
forceNumericSort: {
270+
description:
271+
'Will always sort numeric enums by their value regardless of the sort type specified.',
272+
type: 'boolean',
273+
},
274274
sortByValue: {
275275
description: 'Compare enum values instead of names.',
276276
type: 'boolean',

rules/sort-heritage-clauses.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type {
99
import type { SortingNode } from '../types/sorting-node'
1010

1111
import {
12-
customGroupsJsonSchema,
12+
deprecatedCustomGroupsJsonSchema,
1313
commonJsonSchemas,
1414
groupsJsonSchema,
1515
} from '../utils/common-json-schemas'
@@ -60,7 +60,7 @@ export default createEslintRule<Options, MESSAGE_ID>({
6060
{
6161
properties: {
6262
...commonJsonSchemas,
63-
customGroups: customGroupsJsonSchema,
63+
customGroups: deprecatedCustomGroupsJsonSchema,
6464
groups: groupsJsonSchema,
6565
},
6666
additionalProperties: false,

rules/sort-imports.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import type {
1515

1616
import {
1717
buildCustomGroupsArrayJsonSchema,
18+
deprecatedCustomGroupsJsonSchema,
1819
partitionByCommentJsonSchema,
1920
partitionByNewLineJsonSchema,
2021
newlinesBetweenJsonSchema,
@@ -423,12 +424,12 @@ export default createEslintRule<Options, MESSAGE_ID>({
423424
{
424425
properties: {
425426
value: {
427+
...deprecatedCustomGroupsJsonSchema,
426428
description: 'Specifies custom groups for value imports.',
427-
type: 'object',
428429
},
429430
type: {
431+
...deprecatedCustomGroupsJsonSchema,
430432
description: 'Specifies custom groups for type imports.',
431-
type: 'object',
432433
},
433434
},
434435
description: 'Specifies custom groups.',

rules/sort-jsx-props.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import type { Options } from './sort-jsx-props/types'
77
import {
88
buildUseConfigurationIfJsonSchema,
99
buildCustomGroupsArrayJsonSchema,
10+
deprecatedCustomGroupsJsonSchema,
1011
partitionByNewLineJsonSchema,
1112
newlinesBetweenJsonSchema,
12-
customGroupsJsonSchema,
1313
commonJsonSchemas,
1414
groupsJsonSchema,
1515
regexJsonSchema,
@@ -229,7 +229,7 @@ export default createEslintRule<Options, MESSAGE_ID>({
229229
...commonJsonSchemas,
230230
customGroups: {
231231
oneOf: [
232-
customGroupsJsonSchema,
232+
deprecatedCustomGroupsJsonSchema,
233233
buildCustomGroupsArrayJsonSchema({
234234
singleCustomGroupJsonSchema,
235235
}),

rules/sort-object-types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ import type {
1313
import {
1414
buildUseConfigurationIfJsonSchema,
1515
buildCustomGroupsArrayJsonSchema,
16+
deprecatedCustomGroupsJsonSchema,
1617
partitionByCommentJsonSchema,
1718
partitionByNewLineJsonSchema,
1819
newlinesBetweenJsonSchema,
19-
customGroupsJsonSchema,
2020
buildCommonJsonSchemas,
2121
groupsJsonSchema,
2222
regexJsonSchema,
@@ -95,7 +95,7 @@ export let jsonSchema: JSONSchema4 = {
9595
}),
9696
customGroups: {
9797
oneOf: [
98-
customGroupsJsonSchema,
98+
deprecatedCustomGroupsJsonSchema,
9999
buildCustomGroupsArrayJsonSchema({
100100
additionalFallbackSortProperties: { sortBy: sortByJsonSchema },
101101
singleCustomGroupJsonSchema,

rules/sort-objects.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import type { Modifier, Selector, Options } from './sort-objects/types'
99
import {
1010
buildUseConfigurationIfJsonSchema,
1111
buildCustomGroupsArrayJsonSchema,
12+
deprecatedCustomGroupsJsonSchema,
1213
partitionByCommentJsonSchema,
1314
partitionByNewLineJsonSchema,
1415
newlinesBetweenJsonSchema,
15-
customGroupsJsonSchema,
1616
commonJsonSchemas,
1717
groupsJsonSchema,
1818
regexJsonSchema,
@@ -447,7 +447,7 @@ export default createEslintRule<Options, MESSAGE_ID>({
447447
},
448448
customGroups: {
449449
oneOf: [
450-
customGroupsJsonSchema,
450+
deprecatedCustomGroupsJsonSchema,
451451
buildCustomGroupsArrayJsonSchema({ singleCustomGroupJsonSchema }),
452452
],
453453
},

test/utils/validate-rule-json-schema.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ let validateJsonSchema = async (schema: JSONSchema4): Promise<void> => {
2525

2626
let validateTsJsonSchema = async (schema: JSONSchema4): Promise<void> => {
2727
let generatedTypescript = await compileSchemaForTs(schema, 'id')
28+
29+
assertGeneratedTsSeemsCorrect(generatedTypescript)
30+
assertNoWeakIndexSignature(generatedTypescript)
31+
}
32+
33+
let assertGeneratedTsSeemsCorrect = (generatedTypescript: string): void => {
2834
for (let [commonJsonSchemaKey, commonJsonSchema] of Object.entries(
2935
commonJsonSchemas,
3036
)) {
@@ -38,3 +44,11 @@ let validateTsJsonSchema = async (schema: JSONSchema4): Promise<void> => {
3844
}
3945
}
4046
}
47+
48+
let assertNoWeakIndexSignature = (generatedTypescript: string): void => {
49+
if (generatedTypescript.includes('[k: string]: unknown')) {
50+
throw new Error(
51+
`Weak TypeScript generated from JSON schema: '[k: string]: unknown' index signature found:\n${generatedTypescript}`,
52+
)
53+
}
54+
}

utils/common-json-schemas.ts

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ let typeJsonSchema: JSONSchema4 = {
88

99
let orderJsonSchema: JSONSchema4 = {
1010
description:
11-
'Determines whether the sorted items should be in ascending or descending order.',
11+
'Specifies whether to sort items in ascending or descending order.',
1212
enum: ['asc', 'desc'],
1313
type: 'string',
1414
}
1515

1616
let alphabetJsonSchema: JSONSchema4 = {
17-
description: 'Alphabet to use for the `custom` sort type.',
17+
description:
18+
"Used only when the `type` option is set to `'custom'`. Specifies the custom alphabet for sorting.",
1819
type: 'string',
1920
}
2021

@@ -40,7 +41,7 @@ let ignoreCaseJsonSchema: JSONSchema4 = {
4041

4142
let specialCharactersJsonSchema: JSONSchema4 = {
4243
description:
43-
'Controls how special characters should be handled before sorting.',
44+
'Specifies whether to trim, remove, or keep special characters before sorting.',
4445
enum: ['remove', 'trim', 'keep'],
4546
type: 'string',
4647
}
@@ -56,6 +57,7 @@ let buildFallbackSortJsonSchema = ({
5657
...additionalProperties,
5758
},
5859
description: 'Fallback sort order.',
60+
additionalProperties: false,
5961
type: 'object',
6062
})
6163

@@ -64,7 +66,9 @@ export let buildCommonJsonSchemas = ({
6466
}: {
6567
additionalFallbackSortProperties?: Record<string, JSONSchema4>
6668
} = {}): Record<string, JSONSchema4> => ({
67-
fallbackSort: buildFallbackSortJsonSchema(additionalFallbackSortProperties),
69+
fallbackSort: buildFallbackSortJsonSchema({
70+
additionalProperties: additionalFallbackSortProperties,
71+
}),
6872
specialCharacters: specialCharactersJsonSchema,
6973
ignoreCase: ignoreCaseJsonSchema,
7074
alphabet: alphabetJsonSchema,
@@ -77,7 +81,7 @@ export let commonJsonSchemas: Record<string, JSONSchema4> =
7781
buildCommonJsonSchemas()
7882

7983
export let newlinesBetweenJsonSchema: JSONSchema4 = {
80-
description: 'Specifies how new lines should be handled between groups.',
84+
description: 'Specifies how to handle new lines between groups.',
8185
enum: ['ignore', 'always', 'never'],
8286
type: 'string',
8387
}
@@ -103,11 +107,11 @@ export let groupsJsonSchema: JSONSchema4 = {
103107
},
104108
],
105109
},
106-
description: 'Specifies the order of the groups.',
110+
description: 'Specifies a list of groups for sorting.',
107111
type: 'array',
108112
}
109113

110-
export let customGroupsJsonSchema: JSONSchema4 = {
114+
export let deprecatedCustomGroupsJsonSchema: JSONSchema4 = {
111115
additionalProperties: {
112116
oneOf: [
113117
{
@@ -130,9 +134,11 @@ let singleRegexJsonSchema: JSONSchema4 = {
130134
{
131135
properties: {
132136
pattern: {
137+
description: 'Regular expression pattern.',
133138
type: 'string',
134139
},
135140
flags: {
141+
description: 'Regular expression flags.',
136142
type: 'string',
137143
},
138144
},
@@ -172,9 +178,11 @@ export let partitionByCommentJsonSchema: JSONSchema4 = {
172178
{
173179
properties: {
174180
block: {
181+
description: 'Enables specific block comments to separate the nodes.',
175182
oneOf: allowedPartitionByCommentJsonSchemas,
176183
},
177184
line: {
185+
description: 'Enables specific line comments to separate the nodes.',
178186
oneOf: allowedPartitionByCommentJsonSchemas,
179187
},
180188
},
@@ -183,12 +191,12 @@ export let partitionByCommentJsonSchema: JSONSchema4 = {
183191
},
184192
],
185193
description:
186-
'Allows to use comments to separate members into logical groups.',
194+
'Enables the use of comments to separate the nodes into logical groups.',
187195
}
188196

189197
export let partitionByNewLineJsonSchema: JSONSchema4 = {
190198
description:
191-
'Allows to use newlines to separate the nodes into logical groups.',
199+
'Enables the use of newlines to separate the nodes into logical groups.',
192200
type: 'boolean',
193201
}
194202

@@ -197,6 +205,8 @@ export let buildUseConfigurationIfJsonSchema = ({
197205
}: {
198206
additionalProperties?: Record<string, JSONSchema4>
199207
} = {}): JSONSchema4 => ({
208+
description:
209+
'Specifies filters to match a particular options configuration for a given element to sort.',
200210
properties: {
201211
allNamesMatchPattern: regexJsonSchema,
202212
...additionalProperties,
@@ -212,7 +222,7 @@ let buildCommonCustomGroupJsonSchemas = ({
212222
} = {}): Record<string, JSONSchema4> => ({
213223
newlinesInside: {
214224
description:
215-
'Specifies how new lines should be handled between members of the custom group.',
225+
'Specifies how to handle new lines between members of the custom group.',
216226
enum: ['always', 'never'],
217227
type: 'string',
218228
},
@@ -270,7 +280,7 @@ export let buildCustomGroupsArrayJsonSchema = ({
270280
},
271281
],
272282
},
273-
description: 'Specifies custom groups.',
283+
description: 'Defines custom groups to match specific members.',
274284
type: 'array',
275285
})
276286

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/azat-io/eslint-plugin-perfectionist/commit/c7f62a0

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy