From 51af82fe2a05001c2759aec8746b27a61a2e7987 Mon Sep 17 00:00:00 2001 From: Andrew Kazakov Date: Wed, 16 Jul 2025 15:35:23 +0300 Subject: [PATCH] fix: disallow extra properties in rule options --- src/rules/dynamic-import-chunkname.ts | 1 + src/rules/extensions.ts | 1 + src/rules/no-namespace.ts | 1 + src/rules/no-unused-modules.ts | 80 +++++++++++++++------------ 4 files changed, 47 insertions(+), 36 deletions(-) diff --git a/src/rules/dynamic-import-chunkname.ts b/src/rules/dynamic-import-chunkname.ts index c304575f..39324c1c 100644 --- a/src/rules/dynamic-import-chunkname.ts +++ b/src/rules/dynamic-import-chunkname.ts @@ -48,6 +48,7 @@ export default createRule<[Options?], MessageId>({ type: 'string', }, }, + additionalProperties: false, }, ], messages: { diff --git a/src/rules/extensions.ts b/src/rules/extensions.ts index 7f8c5f82..86ae3dc6 100644 --- a/src/rules/extensions.ts +++ b/src/rules/extensions.ts @@ -58,6 +58,7 @@ const properties = { type: 'boolean', }, }, + additionalProperties: false, } satisfies JSONSchema.JSONSchema4 export type Modifier = (typeof modifierValues)[number] diff --git a/src/rules/no-namespace.ts b/src/rules/no-namespace.ts index 985df7b5..90fdb168 100644 --- a/src/rules/no-namespace.ts +++ b/src/rules/no-namespace.ts @@ -32,6 +32,7 @@ export default createRule<[Options?], MessageId>({ uniqueItems: true, }, }, + additionalProperties: false, }, ], messages: { diff --git a/src/rules/no-unused-modules.ts b/src/rules/no-unused-modules.ts index 6312e665..adc4324c 100644 --- a/src/rules/no-unused-modules.ts +++ b/src/rules/no-unused-modules.ts @@ -6,7 +6,7 @@ import path from 'node:path' import { TSESTree } from '@typescript-eslint/types' -import type { TSESLint } from '@typescript-eslint/utils' +import type { JSONSchema, TSESLint } from '@typescript-eslint/utils' // eslint-disable-next-line import-x/default -- incorrect types , commonjs actually import eslintUnsupportedApi from 'eslint/use-at-your-own-risk' @@ -444,13 +444,47 @@ const fileIsInPkg = (file: string) => { export interface Options { src?: string[] ignoreExports?: string[] - missingExports?: true + missingExports?: boolean unusedExports?: boolean ignoreUnusedTypeExports?: boolean } type MessageId = 'notFound' | 'unused' +const SHARED_OPTIONS_SCHEMA_PROPERTIES = { + src: { + description: 'files/paths to be analyzed (only for unused exports)', + type: 'array', + uniqueItems: true, + items: { + type: 'string', + minLength: 1, + }, + }, + ignoreExports: { + description: + 'files/paths for which unused exports will not be reported (e.g module entry points)', + type: 'array', + uniqueItems: true, + items: { + type: 'string', + minLength: 1, + }, + }, + missingExports: { + description: 'report modules without any exports', + type: 'boolean', + }, + unusedExports: { + description: 'report exports without any usage', + type: 'boolean', + }, + ignoreUnusedTypeExports: { + description: 'ignore type exports without any usage', + type: 'boolean', + }, +} satisfies JSONSchema.JSONSchema4ObjectSchema['properties'] + export default createRule({ name: 'no-unused-modules', meta: { @@ -462,45 +496,14 @@ export default createRule({ }, schema: [ { - type: 'object', - properties: { - src: { - description: 'files/paths to be analyzed (only for unused exports)', - type: 'array', - uniqueItems: true, - items: { - type: 'string', - minLength: 1, - }, - }, - ignoreExports: { - description: - 'files/paths for which unused exports will not be reported (e.g module entry points)', - type: 'array', - uniqueItems: true, - items: { - type: 'string', - minLength: 1, - }, - }, - missingExports: { - description: 'report modules without any exports', - type: 'boolean', - }, - unusedExports: { - description: 'report exports without any usage', - type: 'boolean', - }, - ignoreUnusedTypeExports: { - description: 'ignore type exports without any usage', - type: 'boolean', - }, - }, anyOf: [ { type: 'object', properties: { + ...SHARED_OPTIONS_SCHEMA_PROPERTIES, unusedExports: { + description: + SHARED_OPTIONS_SCHEMA_PROPERTIES.unusedExports.description, type: 'boolean', enum: [true], }, @@ -510,16 +513,21 @@ export default createRule({ }, }, required: ['unusedExports'], + additionalProperties: false, }, { type: 'object', properties: { + ...SHARED_OPTIONS_SCHEMA_PROPERTIES, missingExports: { + description: + SHARED_OPTIONS_SCHEMA_PROPERTIES.missingExports.description, type: 'boolean', enum: [true], }, }, required: ['missingExports'], + additionalProperties: false, }, ], },