Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(eslint-plugin): correct rule schemas to pass ajv validation #5531

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: [
{
definitions: {
arrayOption: {
enum: ['array', 'generic', 'array-simple'],
},
schema: {
definitions: {
arrayOption: {
enum: ['array', 'generic', 'array-simple'],
},
properties: {
default: {
$ref: '#/definitions/arrayOption',
description: 'The array type expected for mutable cases...',
},
readonly: {
$ref: '#/definitions/arrayOption',
description:
'The array type expected for readonly cases. If omitted, the value for `default` will be used.',
},
prefixItems: [
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This syntax is a little more heavyweight than schema: [ ... ] arrays. It would be nice if someone could figure out a way to use $refs within arrays. I couldn't.

cc @bchery 😁

{
properties: {
default: {
$ref: '#/definitions/arrayOption',
JoshuaKGoldberg marked this conversation as resolved.
Show resolved Hide resolved
description: 'The array type expected for mutable cases...',
},
readonly: {
$ref: '#/definitions/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: [
{
definitions: {
directiveConfigSchema: {
oneOf: [
{
type: 'boolean',
default: true,
schema: {
definitions: {
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: '#/definitions/directiveConfigSchema',
},
'ts-ignore': { $ref: '#/definitions/directiveConfigSchema' },
'ts-nocheck': { $ref: '#/definitions/directiveConfigSchema' },
'ts-check': { $ref: '#/definitions/directiveConfigSchema' },
minimumDescriptionLength: {
type: 'number',
default: defaultMinimumDescriptionLength,
},
prefixItems: [
{
properties: {
'ts-expect-error': {
$ref: '#/definitions/directiveConfigSchema',
},
'ts-ignore': { $ref: '#/definitions/directiveConfigSchema' },
'ts-nocheck': { $ref: '#/definitions/directiveConfigSchema' },
'ts-check': { $ref: '#/definitions/directiveConfigSchema' },
JoshuaKGoldberg marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -61,36 +61,41 @@ export default util.createRule<Options, MessageIds>({
unwantedPublicAccessibility:
'Public accessibility modifier on {{type}} {{name}}.',
},
schema: [
{
definitions: {
accessibilityLevel,
},
type: 'object',
properties: {
accessibility: { $ref: '#/definitions/accessibilityLevel' },
overrides: {
type: 'object',
properties: {
accessors: { $ref: '#/definitions/accessibilityLevel' },
constructors: { $ref: '#/definitions/accessibilityLevel' },
methods: { $ref: '#/definitions/accessibilityLevel' },
properties: { $ref: '#/definitions/accessibilityLevel' },
parameterProperties: { $ref: '#/definitions/accessibilityLevel' },
},
schema: {
definitions: {
accessibilityLevel,
},
prefixItems: [
{
type: 'object',
properties: {
accessibility: { $ref: '#/definitions/accessibilityLevel' },
overrides: {
type: 'object',
properties: {
accessors: { $ref: '#/definitions/accessibilityLevel' },
constructors: { $ref: '#/definitions/accessibilityLevel' },
methods: { $ref: '#/definitions/accessibilityLevel' },
properties: { $ref: '#/definitions/accessibilityLevel' },
parameterProperties: {
$ref: '#/definitions/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: [
{
definitions: {
modifier: {
enum: [
'readonly',
'private',
'protected',
'public',
'private readonly',
'protected readonly',
'public readonly',
],
},
schema: {
definitions: {
modifier: {
enum: [
'readonly',
'private',
'protected',
'public',
'private readonly',
'protected readonly',
'public readonly',
],
},
type: 'object',
properties: {
allow: {
type: 'array',
items: {
$ref: '#/definitions/modifier',
},
prefixItems: [
{
type: 'object',
properties: {
allow: {
type: 'array',
items: {
$ref: '#/definitions/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