diff --git a/packages/eslint-plugin/src/rules/no-empty-function.ts b/packages/eslint-plugin/src/rules/no-empty-function.ts index 06c04cb4eca..51ec13e3ff0 100644 --- a/packages/eslint-plugin/src/rules/no-empty-function.ts +++ b/packages/eslint-plugin/src/rules/no-empty-function.ts @@ -11,6 +11,7 @@ type Options = util.InferOptionsTypeFromRule; type MessageIds = util.InferMessageIdsTypeFromRule; const schema = util.deepMerge( + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument -- https://github.com/microsoft/TypeScript/issues/17002 Array.isArray(baseRule.meta.schema) ? baseRule.meta.schema[0] : baseRule.meta.schema, diff --git a/packages/eslint-plugin/src/rules/no-magic-numbers.ts b/packages/eslint-plugin/src/rules/no-magic-numbers.ts index e63c80686c3..d989ac0eec1 100644 --- a/packages/eslint-plugin/src/rules/no-magic-numbers.ts +++ b/packages/eslint-plugin/src/rules/no-magic-numbers.ts @@ -1,18 +1,32 @@ import { - TSESTree, AST_NODE_TYPES, + TSESTree, } from '@typescript-eslint/experimental-utils'; -import { getESLintCoreRule } from '../util/getESLintCoreRule'; import * as util from '../util'; +import { getESLintCoreRule } from '../util/getESLintCoreRule'; const baseRule = getESLintCoreRule('no-magic-numbers'); type Options = util.InferOptionsTypeFromRule; type MessageIds = util.InferMessageIdsTypeFromRule; -const baseRuleSchema = Array.isArray(baseRule.meta.schema) - ? baseRule.meta.schema[0] - : baseRule.meta.schema; +// Extend base schema with additional property to ignore TS numeric literal types +const schema = util.deepMerge( + { ...baseRule.meta.schema }, + { + properties: { + ignoreNumericLiteralTypes: { + type: 'boolean', + }, + ignoreEnums: { + type: 'boolean', + }, + ignoreReadonlyClassProperties: { + type: 'boolean', + }, + }, + }, +); export default util.createRule({ name: 'no-magic-numbers', @@ -23,25 +37,7 @@ export default util.createRule({ recommended: false, extendsBaseRule: true, }, - hasSuggestions: baseRule.meta.hasSuggestions, - // Extend base schema with additional property to ignore TS numeric literal types - schema: [ - { - ...baseRuleSchema, - properties: { - ...baseRuleSchema.properties, - ignoreNumericLiteralTypes: { - type: 'boolean', - }, - ignoreEnums: { - type: 'boolean', - }, - ignoreReadonlyClassProperties: { - type: 'boolean', - }, - }, - }, - ], + schema: [schema], messages: baseRule.meta.messages, }, defaultOptions: [ diff --git a/packages/experimental-utils/src/ts-eslint/Rule.ts b/packages/experimental-utils/src/ts-eslint/Rule.ts index cf3c5b8218b..bac1ef4e353 100644 --- a/packages/experimental-utils/src/ts-eslint/Rule.ts +++ b/packages/experimental-utils/src/ts-eslint/Rule.ts @@ -69,15 +69,15 @@ interface RuleMetaData { /** * The name of the rule this rule was replaced by, if it was deprecated. */ - replacedBy?: string[]; + replacedBy?: readonly string[]; /** * The options schema. Supply an empty array if there are no options. */ - schema: JSONSchema4 | JSONSchema4[]; + schema: JSONSchema4 | readonly JSONSchema4[]; } interface RuleFix { - range: AST.Range; + range: Readonly; text: string; } @@ -87,25 +87,25 @@ interface RuleFixer { text: string, ): RuleFix; - insertTextAfterRange(range: AST.Range, text: string): RuleFix; + insertTextAfterRange(range: Readonly, text: string): RuleFix; insertTextBefore( nodeOrToken: TSESTree.Node | TSESTree.Token, text: string, ): RuleFix; - insertTextBeforeRange(range: AST.Range, text: string): RuleFix; + insertTextBeforeRange(range: Readonly, text: string): RuleFix; remove(nodeOrToken: TSESTree.Node | TSESTree.Token): RuleFix; - removeRange(range: AST.Range): RuleFix; + removeRange(range: Readonly): RuleFix; replaceText( nodeOrToken: TSESTree.Node | TSESTree.Token, text: string, ): RuleFix; - replaceTextRange(range: AST.Range, text: string): RuleFix; + replaceTextRange(range: Readonly, text: string): RuleFix; } interface SuggestionReportDescriptor @@ -216,7 +216,7 @@ interface RuleContext< * Returns a list of variables declared by the given node. * This information can be used to track references to variables. */ - getDeclaredVariables(node: TSESTree.Node): Scope.Variable[]; + getDeclaredVariables(node: TSESTree.Node): readonly Scope.Variable[]; /** * Returns the current working directory passed to Linter. diff --git a/packages/experimental-utils/src/ts-eslint/RuleTester.ts b/packages/experimental-utils/src/ts-eslint/RuleTester.ts index 2049d9f90e7..5b748ed36a5 100644 --- a/packages/experimental-utils/src/ts-eslint/RuleTester.ts +++ b/packages/experimental-utils/src/ts-eslint/RuleTester.ts @@ -1,7 +1,7 @@ import { RuleTester as ESLintRuleTester } from 'eslint'; import { AST_NODE_TYPES, AST_TOKEN_TYPES } from '../ts-estree'; -import { ParserOptions } from './ParserOptions'; import { Linter } from './Linter'; +import { ParserOptions } from './ParserOptions'; import { RuleCreateFunction, RuleModule, @@ -112,7 +112,7 @@ interface TestCaseError { /** * Reported suggestions. */ - readonly suggestions?: SuggestionOutput[] | null; + readonly suggestions?: readonly SuggestionOutput[] | null; /** * The type of the reported AST node. */