Skip to content

Commit

Permalink
fix(experimental-utils): support immutable members
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelss95 committed Sep 21, 2021
1 parent 13b7de5 commit 7625ee6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
6 changes: 4 additions & 2 deletions packages/eslint-plugin/src/rules/no-magic-numbers.ts
@@ -1,6 +1,7 @@
import {
TSESTree,
AST_NODE_TYPES,
JSONSchema,
TSESTree,
} from '@typescript-eslint/experimental-utils';
import baseRule from 'eslint/lib/rules/no-magic-numbers';
import * as util from '../util';
Expand All @@ -9,7 +10,8 @@ type Options = util.InferOptionsTypeFromRule<typeof baseRule>;
type MessageIds = util.InferMessageIdsTypeFromRule<typeof baseRule>;

const baseRuleSchema = Array.isArray(baseRule.meta.schema)
? baseRule.meta.schema[0]
? // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
(baseRule.meta.schema[0] as JSONSchema.JSONSchema4)
: baseRule.meta.schema;

export default util.createRule<Options, MessageIds>({
Expand Down
18 changes: 9 additions & 9 deletions packages/experimental-utils/src/ts-eslint/Rule.ts
Expand Up @@ -73,15 +73,15 @@ interface RuleMetaData<TMessageIds extends string> {
/**
* 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<AST.Range>;
text: string;
}

Expand All @@ -91,25 +91,25 @@ interface RuleFixer {
text: string,
): RuleFix;

insertTextAfterRange(range: AST.Range, text: string): RuleFix;
insertTextAfterRange(range: Readonly<AST.Range>, text: string): RuleFix;

insertTextBefore(
nodeOrToken: TSESTree.Node | TSESTree.Token,
text: string,
): RuleFix;

insertTextBeforeRange(range: AST.Range, text: string): RuleFix;
insertTextBeforeRange(range: Readonly<AST.Range>, text: string): RuleFix;

remove(nodeOrToken: TSESTree.Node | TSESTree.Token): RuleFix;

removeRange(range: AST.Range): RuleFix;
removeRange(range: Readonly<AST.Range>): RuleFix;

replaceText(
nodeOrToken: TSESTree.Node | TSESTree.Token,
text: string,
): RuleFix;

replaceTextRange(range: AST.Range, text: string): RuleFix;
replaceTextRange(range: Readonly<AST.Range>, text: string): RuleFix;
}

type ReportFixFunction = (
Expand Down Expand Up @@ -209,13 +209,13 @@ interface RuleContext<
* the root of the AST and continuing through the direct parent of the current node.
* This array does not include the currently-traversed node itself.
*/
getAncestors(): TSESTree.Node[];
getAncestors(): readonly TSESTree.Node[];

/**
* 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.
Expand Down

0 comments on commit 7625ee6

Please sign in to comment.