Skip to content

Commit 45306fa

Browse files
authored
fix(sort-imports): fix weak json schema typings generated
1 parent 9177831 commit 45306fa

2 files changed

Lines changed: 19 additions & 33 deletions

File tree

rules/sort-imports.ts

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -464,41 +464,9 @@ export default createEslintRule<Options, MESSAGE_ID>({
464464
internalPattern: regexJsonSchema,
465465
groups: groupsJsonSchema,
466466
},
467-
allOf: [
468-
{
469-
$ref: '#/definitions/max-line-length-requires-line-length-type',
470-
},
471-
],
472-
dependencies: {
473-
maxLineLength: ['type'],
474-
},
475467
additionalProperties: false,
476468
type: 'object',
477469
},
478-
definitions: {
479-
'max-line-length-requires-line-length-type': {
480-
anyOf: [
481-
{
482-
not: {
483-
required: ['maxLineLength'],
484-
type: 'object',
485-
},
486-
type: 'object',
487-
},
488-
{
489-
$ref: '#/definitions/is-line-length',
490-
},
491-
],
492-
},
493-
'is-line-length': {
494-
properties: {
495-
type: { enum: ['line-length'], type: 'string' },
496-
},
497-
required: ['type'],
498-
type: 'object',
499-
},
500-
},
501-
id: 'sort-imports',
502470
uniqueItems: true,
503471
type: 'array',
504472
},

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import type { JSONSchema4 } from '@typescript-eslint/utils/json-schema'
33
import { compile as compileSchemaForTs } from 'json-schema-to-typescript-lite'
44
import Ajv from 'ajv-draft-04'
55

6+
import { commonJsonSchemas } from '../../utils/common-json-schemas'
7+
68
export let validateRuleJsonSchema = async (
79
schemaOrSchemas: readonly JSONSchema4[] | JSONSchema4,
810
): Promise<void> => {
@@ -18,5 +20,21 @@ export let validateRuleJsonSchema = async (
1820

1921
let validateJsonSchema = async (schema: JSONSchema4): Promise<void> => {
2022
new Ajv().compile(schema)
21-
await compileSchemaForTs(schema, 'id')
23+
await validateTsJsonSchema(schema)
24+
}
25+
26+
let validateTsJsonSchema = async (schema: JSONSchema4): Promise<void> => {
27+
let generatedTypescript = await compileSchemaForTs(schema, 'id')
28+
for (let [commonJsonSchemaKey, commonJsonSchema] of Object.entries(
29+
commonJsonSchemas,
30+
)) {
31+
if (
32+
commonJsonSchema.description &&
33+
!generatedTypescript.includes(commonJsonSchema.description)
34+
) {
35+
throw new Error(
36+
`TypeScript generated from JSON schema seems wrong: no description found for ${commonJsonSchemaKey}:\n${generatedTypescript}`,
37+
)
38+
}
39+
}
2240
}

0 commit comments

Comments
 (0)