Skip to content
This repository has been archived by the owner on Feb 21, 2022. It is now read-only.

Commit

Permalink
Merge pull request #203 from ajafff/max-len
Browse files Browse the repository at this point in the history
Remove usage of deprecated tslint features
  • Loading branch information
jmlopez-rod authored Mar 23, 2017
2 parents cd1c464 + e1909f1 commit bfb3d4e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 15 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"tslint": "^4.5.0"
},
"dependencies": {
"doctrine": "^0.7.2"
"doctrine": "^0.7.2",
"tsutils": "^1.4.0"
}
}
19 changes: 6 additions & 13 deletions src/rules/terMaxLenRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import * as ts from 'typescript';
import * as Lint from 'tslint';

import { forEachTokenWithTrivia } from 'tsutils';
import { IDisabledInterval } from 'tslint/lib/language/rule/rule';

const RULE_NAME = 'ter-max-len';
Expand Down Expand Up @@ -249,7 +250,7 @@ interface INode {
kind: number;
}

class MaxLenWalker extends Lint.SkippableTokenAwareRuleWalker {
class MaxLenWalker extends Lint.RuleWalker {
private ignoredIntervals: IDisabledInterval[] = [];
private optionsObj: { [key: string]: any } = {};
private comments: INode[] = [];
Expand Down Expand Up @@ -301,25 +302,17 @@ class MaxLenWalker extends Lint.SkippableTokenAwareRuleWalker {
public visitSourceFile(node: ts.SourceFile) {
super.visitSourceFile(node);

Lint.scanAllTokens(ts.createScanner(ts.ScriptTarget.ES5, false, ts.LanguageVariant.Standard, node.text), (scanner: ts.Scanner) => {
const token = scanner.getToken();
const startPos = scanner.getStartPos();
if (this.getSkipEndFromStart(startPos)) {
// tokens to skip are places where the scanner gets confused about what the token is, without the proper context
// (specifically, regex, identifiers, and templates). So skip those tokens.
scanner.setTextPos(this.getSkipEndFromStart(startPos));
return;
}

forEachTokenWithTrivia(node, (text, token, range) => {
if (
token === ts.SyntaxKind.SingleLineCommentTrivia ||
token === ts.SyntaxKind.MultiLineCommentTrivia
) {
this.comments.push(this.getINode(token, scanner.getTokenText(), startPos));
this.comments.push(this.getINode(token, text.substring(range.pos, range.end), range.pos));
} else if (token === ts.SyntaxKind.FirstTemplateToken) {
this.templates.push(this.getINode(token, scanner.getTokenText(), startPos));
this.templates.push(this.getINode(token, text.substring(range.pos, range.end), range.pos));
}
});

// We should have all the ignored intervals, comments, strings, templates, etc...
// lets find those long lines
this.findFailures(node);
Expand Down
2 changes: 1 addition & 1 deletion src/rules/validJsdocRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ declare interface IReturnPresent {
returnPresent: boolean;
}

class ValidJsdocWalker extends Lint.SkippableTokenAwareRuleWalker {
class ValidJsdocWalker extends Lint.RuleWalker {
private fns: Array<IReturnPresent> = [];

protected visitSourceFile(node: ts.SourceFile) {
Expand Down

0 comments on commit bfb3d4e

Please sign in to comment.