Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Commit

Permalink
update rule generation template to use walk function
Browse files Browse the repository at this point in the history
  • Loading branch information
drexler committed Dec 18, 2018
1 parent f1707e7 commit 00e02af
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions build-tasks/templates/rule.template.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import {AstUtils} from './utils/AstUtils';
// use Utils instead of Underscore functions // TODO: delete comment
import {Utils} from './utils/Utils';
const FAILURE_STRING: string = 'Some error message: '; // TODO: Define an error message
export class Rule extends Lint.Rules.AbstractRule {
public static metadata: ExtendedMetadata = {
Expand All @@ -28,16 +26,23 @@ export class Rule extends Lint.Rules.AbstractRule {
commonWeaknessEnumeration: '...' // if possible, please map your rule to a CWE (see cwe_descriptions.json and https://cwe.mitre.org)
};
public static FAILURE_STRING: string = 'Some error message: '; // TODO: Define an error message
public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
return this.applyWithWalker(new %WALKER_NAME%(sourceFile, this.getOptions()));
return this.applyWithFunction(sourceFile, walk);
}
}
class ${walkerName} extends Lint.RuleWalker {
protected visitNode(node: ts.Node): void {
console.log(ts.SyntaxKind[node.kind] + ' ' + node.getText());
super.visitNode(node);
function walk(ctx: Lint.WalkContext<void>) {
function cb(node: ts.Node): void {
const failingExpressionCondition = true; // TODO: Customize to rule.
if (failingExpressionCondition) {
const msg: string = Rule.FAILURE_STRING;
ctx.addFailureAt(node.getStart(), node.getWidth(), msg);
}
return ts.forEachChild(node, cb);
}
return ts.forEachChild(ctx.sourceFile, cb);
}
`;

0 comments on commit 00e02af

Please sign in to comment.