Skip to content

Commit

Permalink
fix: correct handling of additionalProperties in object schemas (#6939)
Browse files Browse the repository at this point in the history
Co-authored-by: Adam Jones <domdomegg+git@gmail.com>
  • Loading branch information
bradzacher and domdomegg committed Apr 21, 2023
1 parent acc1a43 commit 489c7a5
Show file tree
Hide file tree
Showing 19 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/eslint-plugin/src/rules/array-type.ts
Expand Up @@ -112,6 +112,7 @@ export default util.createRule<Options, MessageIds>({
enum: ['array', 'generic', 'array-simple'],
},
},
additionalProperties: false,
properties: {
default: {
$ref: '#/items/0/$defs/arrayOption',
Expand Down
1 change: 1 addition & 0 deletions packages/eslint-plugin/src/rules/ban-ts-comment.ts
Expand Up @@ -53,6 +53,7 @@ export default util.createRule<[Options], MessageIds>({
},
{
type: 'object',
additionalProperties: false,
properties: {
descriptionFormat: { type: 'string' },
},
Expand Down
Expand Up @@ -40,6 +40,7 @@ const $DEFS: Record<string, JSONSchema.JSONSchema4> = {
},
matchRegexConfig: {
type: 'object',
additionalProperties: false,
properties: {
match: { type: 'boolean' },
regex: { type: 'string' },
Expand Down
1 change: 1 addition & 0 deletions packages/eslint-plugin/src/rules/no-misused-promises.ts
Expand Up @@ -83,6 +83,7 @@ export default util.createRule<Options, MessageId>({
schema: [
{
type: 'object',
additionalProperties: false,
properties: {
checksConditionals: {
type: 'boolean',
Expand Down
Expand Up @@ -31,6 +31,7 @@ export default util.createRule<Options, MessageIds>({
schema: [
{
type: 'object',
additionalProperties: false,
properties: {
typesToIgnore: {
description: 'A list of type names to ignore.',
Expand Down
Expand Up @@ -30,6 +30,7 @@ export default util.createRule<Options, MessageIds>({
schema: [
{
type: 'object',
additionalProperties: false,
properties: {
ignoreStringArrays: {
description:
Expand Down
Expand Up @@ -33,6 +33,7 @@ export default util.createRule<Options, MessageId>({
schema: [
{
type: 'object',
additionalProperties: false,
properties: {
allowNumber: {
description:
Expand Down
1 change: 1 addition & 0 deletions packages/eslint-plugin/src/rules/sort-type-constituents.ts
Expand Up @@ -124,6 +124,7 @@ export default util.createRule<Options, MessageIds>({
schema: [
{
type: 'object',
additionalProperties: false,
properties: {
checkIntersections: {
description: 'Whether to check intersection types.',
Expand Down
1 change: 1 addition & 0 deletions packages/eslint-plugin/src/rules/typedef.ts
Expand Up @@ -31,6 +31,7 @@ export default util.createRule<[Options], MessageIds>({
schema: [
{
type: 'object',
additionalProperties: false,
properties: {
[OptionKeys.ArrayDestructuring]: { type: 'boolean' },
[OptionKeys.ArrowParameter]: { type: 'boolean' },
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/eslint-plugin/tests/schema-snapshots/typedef.shot

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -13,13 +13,16 @@ export function generateObjectType(
const commentLines = getCommentLines(schema);

let indexSignature: AST | null = null;
if (schema.additionalProperties === true) {
if (
schema.additionalProperties === true ||
schema.additionalProperties === undefined
) {
indexSignature = {
type: 'type-reference',
typeName: 'unknown',
commentLines: [],
};
} else if (schema.additionalProperties) {
} else if (typeof schema.additionalProperties === 'object') {
const indexSigType = generateType(schema.additionalProperties, refMap);
indexSignature = indexSigType;
}
Expand Down

0 comments on commit 489c7a5

Please sign in to comment.