Created
April 6, 2018 12:29
-
-
Save danreeves/cd50ae91ffc46bfeb76b013e2cc40c4e to your computer and use it in GitHub Desktop.
Revisions
-
danreeves created this gist
Apr 6, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ import * as ts from "typescript"; import * as Lint from "tslint"; export class Rule extends Lint.Rules.AbstractRule { public static FAILURE_STRING = "Prefer keyCode to key or code"; public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { return this.applyWithWalker(new PreferKeyCodeWalker(sourceFile, this.getOptions())); } } // The walker takes care of all the work. class PreferKeyCodeWalker extends Lint.RuleWalker { public visitPropertyAccessExpression(node: ts.ImportDeclaration) { if (node.expression.text === 'KeyboardEvent' && node.name.text === 'code') { // create a failure at the current position this.addFailure(this.createFailure(node.getStart(), node.getWidth(), Rule.FAILURE_STRING)); } // call the base version of this visitor to actually parse this node super.visitPropertyAccessExpression(node); } }