Skip to content

Commit

Permalink
fix(eslint-plugin): correct rule schemas to pass ajv validation (#5531)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
JoshuaKGoldberg committed Aug 24, 2022
1 parent 96b6639 commit dbf8b56
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 107 deletions.
39 changes: 21 additions & 18 deletions packages/eslint-plugin/src/rules/array-type.ts
Expand Up @@ -102,27 +102,30 @@ export default util.createRule<Options, MessageIds>({
errorStringGenericSimple:
"Array type using '{{readonlyPrefix}}{{type}}[]' is forbidden for non-simple types. Use '{{className}}<{{type}}>' instead.",
},
schema: [
{
$defs: {
arrayOption: {
enum: ['array', 'generic', 'array-simple'],
},
schema: {
$defs: {
arrayOption: {
enum: ['array', 'generic', 'array-simple'],
},
properties: {
default: {
$ref: '#/$defs/arrayOption',
description: 'The array type expected for mutable cases...',
},
readonly: {
$ref: '#/$defs/arrayOption',
description:
'The array type expected for readonly cases. If omitted, the value for `default` will be used.',
},
prefixItems: [
{
properties: {
default: {
$ref: '#/$defs/arrayOption',
description: 'The array type expected for mutable cases...',
},
readonly: {
$ref: '#/$defs/arrayOption',
description:
'The array type expected for readonly cases. If omitted, the value for `default` will be used.',
},
},
type: 'object',
},
type: 'object',
},
],
],
type: 'array',
},
},
defaultOptions: [
{
Expand Down
68 changes: 35 additions & 33 deletions packages/eslint-plugin/src/rules/ban-ts-comment.ts
Expand Up @@ -38,43 +38,45 @@ export default util.createRule<[Options], MessageIds>({
tsDirectiveCommentDescriptionNotMatchPattern:
'The description for the "@ts-{{directive}}" directive must match the {{format}} format.',
},
schema: [
{
$defs: {
directiveConfigSchema: {
oneOf: [
{
type: 'boolean',
default: true,
schema: {
$defs: {
directiveConfigSchema: {
oneOf: [
{
type: 'boolean',
default: true,
},
{
enum: ['allow-with-description'],
},
{
type: 'object',
properties: {
descriptionFormat: { type: 'string' },
},
{
enum: ['allow-with-description'],
},
{
type: 'object',
properties: {
descriptionFormat: { type: 'string' },
},
},
],
},
},
],
},
type: 'object',
properties: {
'ts-expect-error': {
$ref: '#/$defs/directiveConfigSchema',
},
'ts-ignore': { $ref: '#/$defs/directiveConfigSchema' },
'ts-nocheck': { $ref: '#/$defs/directiveConfigSchema' },
'ts-check': { $ref: '#/$defs/directiveConfigSchema' },
minimumDescriptionLength: {
type: 'number',
default: defaultMinimumDescriptionLength,
},
prefixItems: [
{
properties: {
'ts-expect-error': {
$ref: '#/$defs/directiveConfigSchema',
},
'ts-ignore': { $ref: '#/$defs/directiveConfigSchema' },
'ts-nocheck': { $ref: '#/$defs/directiveConfigSchema' },
'ts-check': { $ref: '#/$defs/directiveConfigSchema' },
minimumDescriptionLength: {
type: 'number',
default: defaultMinimumDescriptionLength,
},
},
additionalProperties: false,
},
additionalProperties: false,
},
],
],
type: 'array',
},
},
defaultOptions: [
{
Expand Down
57 changes: 31 additions & 26 deletions packages/eslint-plugin/src/rules/explicit-member-accessibility.ts
Expand Up @@ -66,36 +66,41 @@ export default util.createRule<Options, MessageIds>({
'Public accessibility modifier on {{type}} {{name}}.',
addExplicitAccessibility: "Add '{{ type }}' accessibility modifier",
},
schema: [
{
$defs: {
accessibilityLevel,
},
type: 'object',
properties: {
accessibility: { $ref: '#/$defs/accessibilityLevel' },
overrides: {
type: 'object',
properties: {
accessors: { $ref: '#/$defs/accessibilityLevel' },
constructors: { $ref: '#/$defs/accessibilityLevel' },
methods: { $ref: '#/$defs/accessibilityLevel' },
properties: { $ref: '#/$defs/accessibilityLevel' },
parameterProperties: { $ref: '#/$defs/accessibilityLevel' },
},
schema: {
$defs: {
accessibilityLevel,
},
prefixItems: [
{
type: 'object',
properties: {
accessibility: { $ref: '#/$defs/accessibilityLevel' },
overrides: {
type: 'object',
properties: {
accessors: { $ref: '#/$defs/accessibilityLevel' },
constructors: { $ref: '#/$defs/accessibilityLevel' },
methods: { $ref: '#/$defs/accessibilityLevel' },
properties: { $ref: '#/$defs/accessibilityLevel' },
parameterProperties: {
$ref: '#/$defs/accessibilityLevel',
},
},

additionalProperties: false,
},
ignoredMethodNames: {
type: 'array',
items: {
type: 'string',
additionalProperties: false,
},
ignoredMethodNames: {
type: 'array',
items: {
type: 'string',
},
},
},
additionalProperties: false,
},
additionalProperties: false,
},
],
],
type: 'array',
},
},
defaultOptions: [{ accessibility: 'explicit' }],
create(context, [option]) {
Expand Down
57 changes: 30 additions & 27 deletions packages/eslint-plugin/src/rules/parameter-properties.ts
Expand Up @@ -36,37 +36,40 @@ export default util.createRule<Options, MessageIds>({
preferParameterProperty:
'Property {{parameter}} should be declared as a parameter property.',
},
schema: [
{
$defs: {
modifier: {
enum: [
'readonly',
'private',
'protected',
'public',
'private readonly',
'protected readonly',
'public readonly',
],
},
schema: {
$defs: {
modifier: {
enum: [
'readonly',
'private',
'protected',
'public',
'private readonly',
'protected readonly',
'public readonly',
],
},
type: 'object',
properties: {
allow: {
type: 'array',
items: {
$ref: '#/$defs/modifier',
},
prefixItems: [
{
type: 'object',
properties: {
allow: {
type: 'array',
items: {
$ref: '#/$defs/modifier',
},
minItems: 1,
},
prefer: {
enum: ['class-property', 'parameter-property'],
},
minItems: 1,
},
prefer: {
enum: ['class-property', 'parameter-property'],
},
additionalProperties: false,
},
additionalProperties: false,
},
],
],
type: 'array',
},
},
defaultOptions: [
{
Expand Down
19 changes: 16 additions & 3 deletions packages/website/plugins/generated-rule-docs.ts
Expand Up @@ -4,11 +4,12 @@ import * as mdast from 'mdast';
import * as path from 'path';
import { format } from 'prettier';
import type { Plugin } from 'unified';
import { compile } from 'json-schema-to-typescript';
import { compile, JSONSchema } from 'json-schema-to-typescript';

import * as tseslintParser from '@typescript-eslint/parser';
import * as eslintPlugin from '@typescript-eslint/eslint-plugin';
import { EOL } from 'os';
import { JSONSchema7 } from 'json-schema';

/**
* Rules whose options schema generate annoyingly complex schemas.
Expand Down Expand Up @@ -213,8 +214,20 @@ export const generatedRuleDocs: Plugin = () => {
type: 'paragraph',
} as mdast.Paragraph);
} else if (!COMPLICATED_RULE_OPTIONS.has(file.stem)) {
const optionsSchema =
meta.schema instanceof Array ? meta.schema[0] : meta.schema;
const optionsSchema: JSONSchema =
meta.schema instanceof Array
? meta.schema[0]
: meta.schema.type === 'array'
? {
...(meta.schema.definitions
? { definitions: meta.schema.definitions }
: {}),
...(meta.schema.$defs
? { $defs: (meta.schema as JSONSchema7).$defs }
: {}),
...(meta.schema.prefixItems as [JSONSchema])[0],
}
: meta.schema;

parent.children.splice(
optionsH2Index + 2,
Expand Down

0 comments on commit dbf8b56

Please sign in to comment.