Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dbf8b56

Browse files
fix(eslint-plugin): correct rule schemas to pass ajv validation (typescript-eslint#5531)
* fix(eslint-plugin): correct rule schemas to pass ajv validation * Fix: copy over meta.schema.prefixItems * A little more precise * Correct precision * Turns out it was I who had to docusaurus clear all along * fix explicit-member-accessibility
1 parent 96b6639 commit dbf8b56

File tree

5 files changed

+133
-107
lines changed

5 files changed

+133
-107
lines changed

packages/eslint-plugin/src/rules/array-type.ts

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -102,27 +102,30 @@ export default util.createRule<Options, MessageIds>({
102102
errorStringGenericSimple:
103103
"Array type using '{{readonlyPrefix}}{{type}}[]' is forbidden for non-simple types. Use '{{className}}<{{type}}>' instead.",
104104
},
105-
schema: [
106-
{
107-
$defs: {
108-
arrayOption: {
109-
enum: ['array', 'generic', 'array-simple'],
110-
},
105+
schema: {
106+
$defs: {
107+
arrayOption: {
108+
enum: ['array', 'generic', 'array-simple'],
111109
},
112-
properties: {
113-
default: {
114-
$ref: '#/$defs/arrayOption',
115-
description: 'The array type expected for mutable cases...',
116-
},
117-
readonly: {
118-
$ref: '#/$defs/arrayOption',
119-
description:
120-
'The array type expected for readonly cases. If omitted, the value for `default` will be used.',
110+
},
111+
prefixItems: [
112+
{
113+
properties: {
114+
default: {
115+
$ref: '#/$defs/arrayOption',
116+
description: 'The array type expected for mutable cases...',
117+
},
118+
readonly: {
119+
$ref: '#/$defs/arrayOption',
120+
description:
121+
'The array type expected for readonly cases. If omitted, the value for `default` will be used.',
122+
},
121123
},
124+
type: 'object',
122125
},
123-
type: 'object',
124-
},
125-
],
126+
],
127+
type: 'array',
128+
},
126129
},
127130
defaultOptions: [
128131
{

packages/eslint-plugin/src/rules/ban-ts-comment.ts

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -38,43 +38,45 @@ export default util.createRule<[Options], MessageIds>({
3838
tsDirectiveCommentDescriptionNotMatchPattern:
3939
'The description for the "@ts-{{directive}}" directive must match the {{format}} format.',
4040
},
41-
schema: [
42-
{
43-
$defs: {
44-
directiveConfigSchema: {
45-
oneOf: [
46-
{
47-
type: 'boolean',
48-
default: true,
41+
schema: {
42+
$defs: {
43+
directiveConfigSchema: {
44+
oneOf: [
45+
{
46+
type: 'boolean',
47+
default: true,
48+
},
49+
{
50+
enum: ['allow-with-description'],
51+
},
52+
{
53+
type: 'object',
54+
properties: {
55+
descriptionFormat: { type: 'string' },
4956
},
50-
{
51-
enum: ['allow-with-description'],
52-
},
53-
{
54-
type: 'object',
55-
properties: {
56-
descriptionFormat: { type: 'string' },
57-
},
58-
},
59-
],
60-
},
57+
},
58+
],
6159
},
62-
type: 'object',
63-
properties: {
64-
'ts-expect-error': {
65-
$ref: '#/$defs/directiveConfigSchema',
66-
},
67-
'ts-ignore': { $ref: '#/$defs/directiveConfigSchema' },
68-
'ts-nocheck': { $ref: '#/$defs/directiveConfigSchema' },
69-
'ts-check': { $ref: '#/$defs/directiveConfigSchema' },
70-
minimumDescriptionLength: {
71-
type: 'number',
72-
default: defaultMinimumDescriptionLength,
60+
},
61+
prefixItems: [
62+
{
63+
properties: {
64+
'ts-expect-error': {
65+
$ref: '#/$defs/directiveConfigSchema',
66+
},
67+
'ts-ignore': { $ref: '#/$defs/directiveConfigSchema' },
68+
'ts-nocheck': { $ref: '#/$defs/directiveConfigSchema' },
69+
'ts-check': { $ref: '#/$defs/directiveConfigSchema' },
70+
minimumDescriptionLength: {
71+
type: 'number',
72+
default: defaultMinimumDescriptionLength,
73+
},
7374
},
75+
additionalProperties: false,
7476
},
75-
additionalProperties: false,
76-
},
77-
],
77+
],
78+
type: 'array',
79+
},
7880
},
7981
defaultOptions: [
8082
{

packages/eslint-plugin/src/rules/explicit-member-accessibility.ts

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -66,36 +66,41 @@ export default util.createRule<Options, MessageIds>({
6666
'Public accessibility modifier on {{type}} {{name}}.',
6767
addExplicitAccessibility: "Add '{{ type }}' accessibility modifier",
6868
},
69-
schema: [
70-
{
71-
$defs: {
72-
accessibilityLevel,
73-
},
74-
type: 'object',
75-
properties: {
76-
accessibility: { $ref: '#/$defs/accessibilityLevel' },
77-
overrides: {
78-
type: 'object',
79-
properties: {
80-
accessors: { $ref: '#/$defs/accessibilityLevel' },
81-
constructors: { $ref: '#/$defs/accessibilityLevel' },
82-
methods: { $ref: '#/$defs/accessibilityLevel' },
83-
properties: { $ref: '#/$defs/accessibilityLevel' },
84-
parameterProperties: { $ref: '#/$defs/accessibilityLevel' },
85-
},
69+
schema: {
70+
$defs: {
71+
accessibilityLevel,
72+
},
73+
prefixItems: [
74+
{
75+
type: 'object',
76+
properties: {
77+
accessibility: { $ref: '#/$defs/accessibilityLevel' },
78+
overrides: {
79+
type: 'object',
80+
properties: {
81+
accessors: { $ref: '#/$defs/accessibilityLevel' },
82+
constructors: { $ref: '#/$defs/accessibilityLevel' },
83+
methods: { $ref: '#/$defs/accessibilityLevel' },
84+
properties: { $ref: '#/$defs/accessibilityLevel' },
85+
parameterProperties: {
86+
$ref: '#/$defs/accessibilityLevel',
87+
},
88+
},
8689

87-
additionalProperties: false,
88-
},
89-
ignoredMethodNames: {
90-
type: 'array',
91-
items: {
92-
type: 'string',
90+
additionalProperties: false,
91+
},
92+
ignoredMethodNames: {
93+
type: 'array',
94+
items: {
95+
type: 'string',
96+
},
9397
},
9498
},
99+
additionalProperties: false,
95100
},
96-
additionalProperties: false,
97-
},
98-
],
101+
],
102+
type: 'array',
103+
},
99104
},
100105
defaultOptions: [{ accessibility: 'explicit' }],
101106
create(context, [option]) {

packages/eslint-plugin/src/rules/parameter-properties.ts

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -36,37 +36,40 @@ export default util.createRule<Options, MessageIds>({
3636
preferParameterProperty:
3737
'Property {{parameter}} should be declared as a parameter property.',
3838
},
39-
schema: [
40-
{
41-
$defs: {
42-
modifier: {
43-
enum: [
44-
'readonly',
45-
'private',
46-
'protected',
47-
'public',
48-
'private readonly',
49-
'protected readonly',
50-
'public readonly',
51-
],
52-
},
39+
schema: {
40+
$defs: {
41+
modifier: {
42+
enum: [
43+
'readonly',
44+
'private',
45+
'protected',
46+
'public',
47+
'private readonly',
48+
'protected readonly',
49+
'public readonly',
50+
],
5351
},
54-
type: 'object',
55-
properties: {
56-
allow: {
57-
type: 'array',
58-
items: {
59-
$ref: '#/$defs/modifier',
52+
},
53+
prefixItems: [
54+
{
55+
type: 'object',
56+
properties: {
57+
allow: {
58+
type: 'array',
59+
items: {
60+
$ref: '#/$defs/modifier',
61+
},
62+
minItems: 1,
63+
},
64+
prefer: {
65+
enum: ['class-property', 'parameter-property'],
6066
},
61-
minItems: 1,
62-
},
63-
prefer: {
64-
enum: ['class-property', 'parameter-property'],
6567
},
68+
additionalProperties: false,
6669
},
67-
additionalProperties: false,
68-
},
69-
],
70+
],
71+
type: 'array',
72+
},
7073
},
7174
defaultOptions: [
7275
{

packages/website/plugins/generated-rule-docs.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import * as mdast from 'mdast';
44
import * as path from 'path';
55
import { format } from 'prettier';
66
import type { Plugin } from 'unified';
7-
import { compile } from 'json-schema-to-typescript';
7+
import { compile, JSONSchema } from 'json-schema-to-typescript';
88

99
import * as tseslintParser from '@typescript-eslint/parser';
1010
import * as eslintPlugin from '@typescript-eslint/eslint-plugin';
1111
import { EOL } from 'os';
12+
import { JSONSchema7 } from 'json-schema';
1213

1314
/**
1415
* Rules whose options schema generate annoyingly complex schemas.
@@ -213,8 +214,20 @@ export const generatedRuleDocs: Plugin = () => {
213214
type: 'paragraph',
214215
} as mdast.Paragraph);
215216
} else if (!COMPLICATED_RULE_OPTIONS.has(file.stem)) {
216-
const optionsSchema =
217-
meta.schema instanceof Array ? meta.schema[0] : meta.schema;
217+
const optionsSchema: JSONSchema =
218+
meta.schema instanceof Array
219+
? meta.schema[0]
220+
: meta.schema.type === 'array'
221+
? {
222+
...(meta.schema.definitions
223+
? { definitions: meta.schema.definitions }
224+
: {}),
225+
...(meta.schema.$defs
226+
? { $defs: (meta.schema as JSONSchema7).$defs }
227+
: {}),
228+
...(meta.schema.prefixItems as [JSONSchema])[0],
229+
}
230+
: meta.schema;
218231

219232
parent.children.splice(
220233
optionsH2Index + 2,

0 commit comments

Comments
 (0)