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

Remove scanAllTokens and SkippableTokenAwareRuleWalker #2370

Merged
merged 2 commits into from
Mar 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions src/language/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,6 @@ export function doesIntersect(failure: RuleFailure, disabledIntervals: IDisabled
});
}

/** @deprecated use forEachToken instead */
export function scanAllTokens(scanner: ts.Scanner, callback: (s: ts.Scanner) => void) {
let lastStartPos = -1;
while (scanner.scan() !== ts.SyntaxKind.EndOfFileToken) {
const startPos = scanner.getStartPos();
if (startPos === lastStartPos) {
break;
}
lastStartPos = startPos;
callback(scanner);
}
}

/**
* @returns true if any modifier kinds passed along exist in the given modifiers array
*/
Expand Down
1 change: 0 additions & 1 deletion src/language/walker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export * from "./blockScopeAwareRuleWalker";
export * from "./programAwareRuleWalker";
export * from "./ruleWalker";
export * from "./scopeAwareRuleWalker";
export * from "./skippableTokenAwareRuleWalker";
export * from "./syntaxWalker";
export * from "./walkContext";
export * from "./walker";
52 changes: 0 additions & 52 deletions src/language/walker/skippableTokenAwareRuleWalker.ts

This file was deleted.

34 changes: 16 additions & 18 deletions src/rules/noImportSideEffectRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* limitations under the License.
*/

import * as utils from "tsutils";
import * as ts from "typescript";

import * as Lint from "../index";
Expand Down Expand Up @@ -50,29 +51,26 @@ export class Rule extends Lint.Rules.AbstractRule {
public static FAILURE_STRING = "import with explicit side-effect";

public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
return this.applyWithWalker(new NoImportSideEffectWalker(sourceFile, this.getOptions()));
const patternConfig = this.ruleArguments[this.ruleArguments.length - 1];
const ignorePattern = patternConfig && new RegExp(patternConfig[OPTION_IGNORE_MODULE]);
return this.applyWithFunction(sourceFile, walk, ignorePattern);
}
}

class NoImportSideEffectWalker extends Lint.SkippableTokenAwareRuleWalker {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This never even used the scanner.

private scanner: ts.Scanner;
private ignorePattern: RegExp | null;
function walk(ctx: Lint.WalkContext<RegExp | undefined>): void {
const { options: ignorePattern, sourceFile } = ctx;
for (const statement of sourceFile.statements) {
if (!utils.isImportDeclaration(statement)) {
continue;
}

constructor(sourceFile: ts.SourceFile, options: Lint.IOptions) {
super(sourceFile, options);
const patternConfig = this.getOptions().pop();
this.ignorePattern = patternConfig ? new RegExp(patternConfig[OPTION_IGNORE_MODULE]) : null;
this.scanner = ts.createScanner(ts.ScriptTarget.ES5, false, ts.LanguageVariant.Standard, sourceFile.text);
}
const { importClause, moduleSpecifier } = statement;
if (importClause || !utils.isStringLiteral(moduleSpecifier)) {
continue;
}

public visitImportDeclaration(node: ts.ImportDeclaration) {
const importClause = node.importClause;
if (importClause === undefined) {
const specifier = node.moduleSpecifier.getText();
if (this.ignorePattern === null || !this.ignorePattern.test(specifier.substring(1, specifier.length - 1))) {
this.addFailureAtNode(node, Rule.FAILURE_STRING);
}
if (!ignorePattern || !ignorePattern.test(moduleSpecifier.text)) {
ctx.addFailureAtNode(statement, Rule.FAILURE_STRING);
}
super.visitImportDeclaration(node);
}
}