Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Commit

Permalink
no-invalid-this: stylistic cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
amacleay committed Nov 7, 2018
1 parent 65e2dfd commit cad840a
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions src/rules/noInvalidThisRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,18 @@ export class Rule extends Lint.Rules.AbstractRule {
}
}

const enum parentType {
None,
Class,
ClassMethod,
BoundRegularFunction,
UnboundRegularFunction,
}
const thisAllowedParents = new Set([parentType.ClassMethod, parentType.BoundRegularFunction]);

function walk(ctx: Lint.WalkContext<boolean>): void {
const { sourceFile, options: checkFuncInMethod } = ctx;

const enum parentType {
None,
Class,
ClassMethod,
BoundRegularFunction,
UnboundRegularFunction,
}

function thisIsAllowed(parent: parentType): boolean {
return [parentType.ClassMethod, parentType.BoundRegularFunction]
.some((t) => parent === t);
}
let currentParent: parentType = parentType.None;
let inClass = false;

Expand Down Expand Up @@ -111,7 +108,7 @@ function walk(ctx: Lint.WalkContext<boolean>): void {
}

case ts.SyntaxKind.ThisKeyword:
if (!thisIsAllowed(currentParent)) {
if (!thisAllowedParents.has(currentParent)) {
if (!inClass) {
ctx.addFailureAtNode(node, Rule.FAILURE_STRING_OUTSIDE);
} else if (checkFuncInMethod) {
Expand Down

0 comments on commit cad840a

Please sign in to comment.