This repository has been archived by the owner on Jul 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
586 walk in new rule template (#702)
* Used a walk function instead of extending RuleWalker in the new rule template. * Used EJS for the new rule template. * Added a prompt asking whether the new rule has options. * Replaced EJS templates with Underscore templates.
- Loading branch information
Showing
3 changed files
with
60 additions
and
59 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import * as ts from 'typescript'; | ||
import * as Lint from 'tslint'; | ||
|
||
import { ExtendedMetadata } from './utils/ExtendedMetadata'; | ||
import { AstUtils } from './utils/AstUtils'; | ||
import { Utils } from './utils/Utils'; | ||
|
||
const FAILURE_STRING: string = 'Some error message: '; // TODO: Define an error message | ||
<% if (hasOptions) { %> | ||
interface Options { | ||
// TODO: Add option properties. | ||
} | ||
<% } %> | ||
export class Rule extends Lint.Rules.AbstractRule { | ||
public static metadata: ExtendedMetadata = { | ||
ruleName: '<%= name %>', | ||
type: '<%= type %>', | ||
description: '<%= description %>',<% if (hasOptions) { %> | ||
options: { | ||
// TODO: Fill in the options. | ||
}, | ||
optionsDescription: '', // TODO: Fill in the options description. | ||
optionExamples: [], // TODO: Add option examples. | ||
<% } else { %> | ||
options: null, // tslint:disable-line:no-null-keyword | ||
optionsDescription: '', | ||
<% } %>typescriptOnly: <%= typescriptOnly %>, | ||
issueClass: '<%= issueClass %>', | ||
issueType: '<%= issueType %>', | ||
severity: '<%= severity %>', | ||
level: '<%= level %>', | ||
group: '<%= group %>', | ||
commonWeaknessEnumeration: '...' // if possible, please map your rule to a CWE (see cwe_descriptions.json and https://cwe.mitre.org) | ||
}; | ||
|
||
public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { | ||
return this.applyWithFunction(sourceFile, walk<% if (hasOptions) { %>, this.getOptions()<% } %>); | ||
} | ||
} | ||
|
||
function walk(ctx: Lint.WalkContext<<% if (hasOptions) { %>Options<% } else { %>void<% } %>>) { | ||
function cb(node: ts.Node): void { | ||
// TODO: Implement the rule here. | ||
return ts.forEachChild(node, cb); | ||
} | ||
|
||
return ts.forEachChild(ctx.sourceFile, cb); | ||
} |
This file was deleted.
Oops, something went wrong.