Created
April 18, 2018 04:31
-
-
Save hitode909/b3ed32a6abd46b8225a98b95eee7e7ad to your computer and use it in GitHub Desktop.
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 characters
import * as ts from "typescript"; | |
import * as Lint from "tslint"; | |
export class Rule extends Lint.Rules.AbstractRule { | |
/* tslint:disable:object-literal-sort-keys */ | |
public static metadata: Lint.IRuleMetadata = { | |
ruleName: "no-jquery-argument", | |
description: "Disallows receiving jQuery object in arguments.", | |
rationale: Lint.Utils.dedent` | |
Do not receive jQuery Object. You must receive HTMLElement or Array<HTMLElement>. | |
`, | |
optionsDescription: "Not configurable.", | |
options: null, | |
optionExamples: [true], | |
type: "maintainability", | |
typescriptOnly: true, | |
hasFix: false, | |
}; | |
/* tslint:enable:object-literal-sort-keys */ | |
public static FAILURE_STRING = "Don't receive jQuery Object."; | |
public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { | |
return this.applyWithWalker(new DontReceiveJQueryWalker(sourceFile, this.getOptions())); | |
} | |
} | |
class DontReceiveJQueryWalker extends Lint.RuleWalker { | |
protected visitTypeReference(node: ts.TypeReferenceNode) { | |
if (node.getText() === 'JQuery') { | |
const start = node.getStart(); | |
const width = node.getWidth(); | |
const fix = new Lint.Replacement(start, width, 'HTMLElement'); | |
this.addFailureAtNode(node, 'Treat as HTMLElement instead of JQuery.', fix); | |
} | |
super.visitTypeReference(node); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment