diff options
author | Florian Dold <florian.dold@gmail.com> | 2017-05-28 00:38:50 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2017-05-28 00:40:43 +0200 |
commit | 7fff4499fd915bcea3fa93b1aa8b35f4fe7a6027 (patch) | |
tree | 6de9a1aebd150a23b7f8c273ec657a5d0a18fe3e /node_modules/tslint/lib/language | |
parent | 963b7a41feb29cc4be090a2446bdfe0c1f1bcd81 (diff) |
add linting (and some initial fixes)
Diffstat (limited to 'node_modules/tslint/lib/language')
30 files changed, 2471 insertions, 0 deletions
diff --git a/node_modules/tslint/lib/language/formatter/abstractFormatter.d.ts b/node_modules/tslint/lib/language/formatter/abstractFormatter.d.ts new file mode 100644 index 000000000..918f13803 --- /dev/null +++ b/node_modules/tslint/lib/language/formatter/abstractFormatter.d.ts @@ -0,0 +1,22 @@ +/** + * @license + * Copyright 2013 Palantir Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { RuleFailure } from "../rule/rule"; +import { IFormatter, IFormatterMetadata } from "./formatter"; +export declare abstract class AbstractFormatter implements IFormatter { + static metadata: IFormatterMetadata; + abstract format(failures: RuleFailure[]): string; +} diff --git a/node_modules/tslint/lib/language/formatter/abstractFormatter.js b/node_modules/tslint/lib/language/formatter/abstractFormatter.js new file mode 100644 index 000000000..63e037732 --- /dev/null +++ b/node_modules/tslint/lib/language/formatter/abstractFormatter.js @@ -0,0 +1,24 @@ +"use strict"; +/** + * @license + * Copyright 2013 Palantir Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +Object.defineProperty(exports, "__esModule", { value: true }); +var AbstractFormatter = (function () { + function AbstractFormatter() { + } + return AbstractFormatter; +}()); +exports.AbstractFormatter = AbstractFormatter; diff --git a/node_modules/tslint/lib/language/formatter/formatter.d.ts b/node_modules/tslint/lib/language/formatter/formatter.d.ts new file mode 100644 index 000000000..201054396 --- /dev/null +++ b/node_modules/tslint/lib/language/formatter/formatter.d.ts @@ -0,0 +1,51 @@ +/** + * @license + * Copyright 2013 Palantir Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { RuleFailure } from "../rule/rule"; +export interface IFormatterMetadata { + /** + * The name of the formatter. + */ + formatterName: string; + /** + * A short, one line description of what the formatter does. + */ + description: string; + /** + * More elaborate details about the formatter. + */ + descriptionDetails?: string; + /** + * Sample output from the formatter. + */ + sample: string; + /** + * Sample output from the formatter. + */ + consumer: ConsumerType; +} +export declare type ConsumerType = "human" | "machine"; +export interface FormatterConstructor { + new (): IFormatter; +} +export interface IFormatter { + /** + * Formats linter results + * @param {RuleFailure[]} failures Linter failures that were not fixed + * @param {RuleFailure[]} fixes Fixed linter failures. Available when the `--fix` argument is used on the command line + */ + format(failures: RuleFailure[], fixes?: RuleFailure[]): string; +} diff --git a/node_modules/tslint/lib/language/formatter/formatter.js b/node_modules/tslint/lib/language/formatter/formatter.js new file mode 100644 index 000000000..1c258a5da --- /dev/null +++ b/node_modules/tslint/lib/language/formatter/formatter.js @@ -0,0 +1,18 @@ +"use strict"; +/** + * @license + * Copyright 2013 Palantir Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/node_modules/tslint/lib/language/rule/abstractRule.d.ts b/node_modules/tslint/lib/language/rule/abstractRule.d.ts new file mode 100644 index 000000000..8a2362b5c --- /dev/null +++ b/node_modules/tslint/lib/language/rule/abstractRule.d.ts @@ -0,0 +1,39 @@ +/** + * @license + * Copyright 2013 Palantir Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import * as ts from "typescript"; +import { IWalker, WalkContext } from "../walker"; +import { IOptions, IRule, IRuleMetadata, RuleFailure, RuleSeverity } from "./rule"; +export declare abstract class AbstractRule implements IRule { + private options; + static metadata: IRuleMetadata; + protected readonly ruleArguments: any[]; + protected readonly ruleSeverity: RuleSeverity; + ruleName: string; + constructor(options: IOptions); + getOptions(): IOptions; + abstract apply(sourceFile: ts.SourceFile): RuleFailure[]; + applyWithWalker(walker: IWalker): RuleFailure[]; + isEnabled(): boolean; + protected applyWithFunction(sourceFile: ts.SourceFile, walkFn: (ctx: WalkContext<void>) => void): RuleFailure[]; + protected applyWithFunction<T, U extends T>(sourceFile: ts.SourceFile, walkFn: (ctx: WalkContext<T>) => void, options: U): RuleFailure[]; + /** + * @deprecated + * Failures will be filtered based on `tslint:disable` comments by tslint. + * This method now does nothing. + */ + protected filterFailures(failures: RuleFailure[]): RuleFailure[]; +} diff --git a/node_modules/tslint/lib/language/rule/abstractRule.js b/node_modules/tslint/lib/language/rule/abstractRule.js new file mode 100644 index 000000000..52f4c8f55 --- /dev/null +++ b/node_modules/tslint/lib/language/rule/abstractRule.js @@ -0,0 +1,50 @@ +"use strict"; +/** + * @license + * Copyright 2013 Palantir Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +Object.defineProperty(exports, "__esModule", { value: true }); +var walker_1 = require("../walker"); +var AbstractRule = (function () { + function AbstractRule(options) { + this.options = options; + this.ruleName = options.ruleName; + this.ruleArguments = options.ruleArguments; + this.ruleSeverity = options.ruleSeverity; + } + AbstractRule.prototype.getOptions = function () { + return this.options; + }; + AbstractRule.prototype.applyWithWalker = function (walker) { + walker.walk(walker.getSourceFile()); + return walker.getFailures(); + }; + AbstractRule.prototype.isEnabled = function () { + return this.ruleSeverity !== "off"; + }; + AbstractRule.prototype.applyWithFunction = function (sourceFile, walkFn, options) { + var ctx = new walker_1.WalkContext(sourceFile, this.ruleName, options); + walkFn(ctx); + return ctx.failures; + }; + /** + * @deprecated + * Failures will be filtered based on `tslint:disable` comments by tslint. + * This method now does nothing. + */ + AbstractRule.prototype.filterFailures = function (failures) { return failures; }; + return AbstractRule; +}()); +exports.AbstractRule = AbstractRule; diff --git a/node_modules/tslint/lib/language/rule/optionallyTypedRule.d.ts b/node_modules/tslint/lib/language/rule/optionallyTypedRule.d.ts new file mode 100644 index 000000000..f12d74f44 --- /dev/null +++ b/node_modules/tslint/lib/language/rule/optionallyTypedRule.d.ts @@ -0,0 +1,22 @@ +/** + * @license + * Copyright 2017 Palantir Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import * as ts from "typescript"; +import { AbstractRule } from "./abstractRule"; +import { ITypedRule, RuleFailure } from "./rule"; +export declare abstract class OptionallyTypedRule extends AbstractRule implements ITypedRule { + abstract applyWithProgram(sourceFile: ts.SourceFile, program: ts.Program): RuleFailure[]; +} diff --git a/node_modules/tslint/lib/language/rule/optionallyTypedRule.js b/node_modules/tslint/lib/language/rule/optionallyTypedRule.js new file mode 100644 index 000000000..1914eda40 --- /dev/null +++ b/node_modules/tslint/lib/language/rule/optionallyTypedRule.js @@ -0,0 +1,28 @@ +"use strict"; +/** + * @license + * Copyright 2017 Palantir Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +Object.defineProperty(exports, "__esModule", { value: true }); +var tslib_1 = require("tslib"); +var abstractRule_1 = require("./abstractRule"); +var OptionallyTypedRule = (function (_super) { + tslib_1.__extends(OptionallyTypedRule, _super); + function OptionallyTypedRule() { + return _super !== null && _super.apply(this, arguments) || this; + } + return OptionallyTypedRule; +}(abstractRule_1.AbstractRule)); +exports.OptionallyTypedRule = OptionallyTypedRule; diff --git a/node_modules/tslint/lib/language/rule/rule.d.ts b/node_modules/tslint/lib/language/rule/rule.d.ts new file mode 100644 index 000000000..e432ce375 --- /dev/null +++ b/node_modules/tslint/lib/language/rule/rule.d.ts @@ -0,0 +1,178 @@ +/** + * @license + * Copyright 2013 Palantir Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import * as ts from "typescript"; +import { IWalker } from "../walker"; +export interface RuleConstructor { + metadata: IRuleMetadata; + new (options: IOptions): IRule; +} +export interface IRuleMetadata { + /** + * The kebab-case name of the rule. + */ + ruleName: string; + /** + * The type of the rule - its overall purpose + */ + type: RuleType; + /** + * A rule deprecation message, if applicable. + */ + deprecationMessage?: string; + /** + * A short, one line description of what the rule does. + */ + description: string; + /** + * More elaborate details about the rule. + */ + descriptionDetails?: string; + /** + * Whether or not the rule will provide fix suggestions. + */ + hasFix?: boolean; + /** + * An explanation of the available options for the rule. + */ + optionsDescription: string; + /** + * Schema of the options the rule accepts. + * The first boolean for whether the rule is enabled or not is already implied. + * This field describes the options after that boolean. + * If null, this rule has no options and is not configurable. + */ + options: any; + /** + * Examples of what a standard config for the rule might look like. + * Using a string[] here is deprecated. Write the options as a JSON object instead. + */ + optionExamples?: Array<true | any[]> | string[]; + /** + * An explanation of why the rule is useful. + */ + rationale?: string; + /** + * Whether or not the rule requires type info to run. + */ + requiresTypeInfo?: boolean; + /** + * Whether or not the rule use for TypeScript only. If `false`, this rule may be used with .js files. + */ + typescriptOnly: boolean; +} +export declare type RuleType = "functionality" | "maintainability" | "style" | "typescript"; +export declare type RuleSeverity = "warning" | "error" | "off"; +export interface IOptions { + ruleArguments: any[]; + ruleSeverity: RuleSeverity; + ruleName: string; + /** + * @deprecated + * Tslint now handles disables itself. + * This will be empty. + */ + disabledIntervals: IDisabledInterval[]; +} +/** + * @deprecated + * These are now handled internally. + */ +export interface IDisabledInterval { + startPosition: number; + endPosition: number; +} +export interface IRule { + getOptions(): IOptions; + isEnabled(): boolean; + apply(sourceFile: ts.SourceFile): RuleFailure[]; + applyWithWalker(walker: IWalker): RuleFailure[]; +} +export interface ITypedRule extends IRule { + applyWithProgram(sourceFile: ts.SourceFile, program: ts.Program): RuleFailure[]; +} +export interface IRuleFailureJson { + endPosition: IRuleFailurePositionJson; + failure: string; + fix?: FixJson; + name: string; + ruleSeverity: string; + ruleName: string; + startPosition: IRuleFailurePositionJson; +} +export interface IRuleFailurePositionJson { + character: number; + line: number; + position: number; +} +export declare function isTypedRule(rule: IRule): rule is ITypedRule; +export interface ReplacementJson { + innerStart: number; + innerLength: number; + innerText: string; +} +export declare class Replacement { + readonly start: number; + readonly length: number; + readonly text: string; + static applyFixes(content: string, fixes: Fix[]): string; + static applyAll(content: string, replacements: Replacement[]): string; + static replaceNode(node: ts.Node, text: string, sourceFile?: ts.SourceFile): Replacement; + static replaceFromTo(start: number, end: number, text: string): Replacement; + static deleteText(start: number, length: number): Replacement; + static deleteFromTo(start: number, end: number): Replacement; + static appendText(start: number, text: string): Replacement; + constructor(start: number, length: number, text: string); + readonly end: number; + apply(content: string): string; + toJson(): ReplacementJson; +} +export declare class RuleFailurePosition { + private position; + private lineAndCharacter; + constructor(position: number, lineAndCharacter: ts.LineAndCharacter); + getPosition(): number; + getLineAndCharacter(): ts.LineAndCharacter; + toJson(): IRuleFailurePositionJson; + equals(ruleFailurePosition: RuleFailurePosition): boolean; +} +export declare type Fix = Replacement | Replacement[]; +export declare type FixJson = ReplacementJson | ReplacementJson[]; +export declare class RuleFailure { + private sourceFile; + private failure; + private ruleName; + private fix; + private fileName; + private startPosition; + private endPosition; + private rawLines; + private ruleSeverity; + constructor(sourceFile: ts.SourceFile, start: number, end: number, failure: string, ruleName: string, fix?: Fix); + getFileName(): string; + getRuleName(): string; + getStartPosition(): RuleFailurePosition; + getEndPosition(): RuleFailurePosition; + getFailure(): string; + hasFix(): boolean; + getFix(): Replacement | Replacement[] | undefined; + getRawLines(): string; + getRuleSeverity(): RuleSeverity; + setRuleSeverity(value: RuleSeverity): void; + toJson(): IRuleFailureJson; + equals(ruleFailure: RuleFailure): boolean; + private createFailurePosition(position); +} diff --git a/node_modules/tslint/lib/language/rule/rule.js b/node_modules/tslint/lib/language/rule/rule.js new file mode 100644 index 000000000..98291f25a --- /dev/null +++ b/node_modules/tslint/lib/language/rule/rule.js @@ -0,0 +1,168 @@ +"use strict"; +/** + * @license + * Copyright 2013 Palantir Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +Object.defineProperty(exports, "__esModule", { value: true }); +var utils_1 = require("../../utils"); +function isTypedRule(rule) { + return "applyWithProgram" in rule; +} +exports.isTypedRule = isTypedRule; +var Replacement = (function () { + function Replacement(start, length, text) { + this.start = start; + this.length = length; + this.text = text; + } + Replacement.applyFixes = function (content, fixes) { + return this.applyAll(content, utils_1.flatMap(fixes, utils_1.arrayify)); + }; + Replacement.applyAll = function (content, replacements) { + // sort in reverse so that diffs are properly applied + replacements.sort(function (a, b) { return b.end !== a.end ? b.end - a.end : b.start - a.start; }); + return replacements.reduce(function (text, r) { return r.apply(text); }, content); + }; + Replacement.replaceNode = function (node, text, sourceFile) { + return this.replaceFromTo(node.getStart(sourceFile), node.getEnd(), text); + }; + Replacement.replaceFromTo = function (start, end, text) { + return new Replacement(start, end - start, text); + }; + Replacement.deleteText = function (start, length) { + return new Replacement(start, length, ""); + }; + Replacement.deleteFromTo = function (start, end) { + return new Replacement(start, end - start, ""); + }; + Replacement.appendText = function (start, text) { + return new Replacement(start, 0, text); + }; + Object.defineProperty(Replacement.prototype, "end", { + get: function () { + return this.start + this.length; + }, + enumerable: true, + configurable: true + }); + Replacement.prototype.apply = function (content) { + return content.substring(0, this.start) + this.text + content.substring(this.start + this.length); + }; + Replacement.prototype.toJson = function () { + // tslint:disable object-literal-sort-keys + return { + innerStart: this.start, + innerLength: this.length, + innerText: this.text, + }; + // tslint:enable object-literal-sort-keys + }; + return Replacement; +}()); +exports.Replacement = Replacement; +var RuleFailurePosition = (function () { + function RuleFailurePosition(position, lineAndCharacter) { + this.position = position; + this.lineAndCharacter = lineAndCharacter; + } + RuleFailurePosition.prototype.getPosition = function () { + return this.position; + }; + RuleFailurePosition.prototype.getLineAndCharacter = function () { + return this.lineAndCharacter; + }; + RuleFailurePosition.prototype.toJson = function () { + return { + character: this.lineAndCharacter.character, + line: this.lineAndCharacter.line, + position: this.position, + }; + }; + RuleFailurePosition.prototype.equals = function (ruleFailurePosition) { + var ll = this.lineAndCharacter; + var rr = ruleFailurePosition.lineAndCharacter; + return this.position === ruleFailurePosition.position + && ll.line === rr.line + && ll.character === rr.character; + }; + return RuleFailurePosition; +}()); +exports.RuleFailurePosition = RuleFailurePosition; +var RuleFailure = (function () { + function RuleFailure(sourceFile, start, end, failure, ruleName, fix) { + this.sourceFile = sourceFile; + this.failure = failure; + this.ruleName = ruleName; + this.fix = fix; + this.fileName = sourceFile.fileName; + this.startPosition = this.createFailurePosition(start); + this.endPosition = this.createFailurePosition(end); + this.rawLines = sourceFile.text; + this.ruleSeverity = "error"; + } + RuleFailure.prototype.getFileName = function () { + return this.fileName; + }; + RuleFailure.prototype.getRuleName = function () { + return this.ruleName; + }; + RuleFailure.prototype.getStartPosition = function () { + return this.startPosition; + }; + RuleFailure.prototype.getEndPosition = function () { + return this.endPosition; + }; + RuleFailure.prototype.getFailure = function () { + return this.failure; + }; + RuleFailure.prototype.hasFix = function () { + return this.fix !== undefined; + }; + RuleFailure.prototype.getFix = function () { + return this.fix; + }; + RuleFailure.prototype.getRawLines = function () { + return this.rawLines; + }; + RuleFailure.prototype.getRuleSeverity = function () { + return this.ruleSeverity; + }; + RuleFailure.prototype.setRuleSeverity = function (value) { + this.ruleSeverity = value; + }; + RuleFailure.prototype.toJson = function () { + return { + endPosition: this.endPosition.toJson(), + failure: this.failure, + fix: this.fix === undefined ? undefined : Array.isArray(this.fix) ? this.fix.map(function (r) { return r.toJson(); }) : this.fix.toJson(), + name: this.fileName, + ruleName: this.ruleName, + ruleSeverity: this.ruleSeverity.toUpperCase(), + startPosition: this.startPosition.toJson(), + }; + }; + RuleFailure.prototype.equals = function (ruleFailure) { + return this.failure === ruleFailure.getFailure() + && this.fileName === ruleFailure.getFileName() + && this.startPosition.equals(ruleFailure.getStartPosition()) + && this.endPosition.equals(ruleFailure.getEndPosition()); + }; + RuleFailure.prototype.createFailurePosition = function (position) { + var lineAndCharacter = this.sourceFile.getLineAndCharacterOfPosition(position); + return new RuleFailurePosition(position, lineAndCharacter); + }; + return RuleFailure; +}()); +exports.RuleFailure = RuleFailure; diff --git a/node_modules/tslint/lib/language/rule/typedRule.d.ts b/node_modules/tslint/lib/language/rule/typedRule.d.ts new file mode 100644 index 000000000..a4d1fcca0 --- /dev/null +++ b/node_modules/tslint/lib/language/rule/typedRule.d.ts @@ -0,0 +1,23 @@ +/** + * @license + * Copyright 2016 Palantir Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import * as ts from "typescript"; +import { AbstractRule } from "./abstractRule"; +import { ITypedRule, RuleFailure } from "./rule"; +export declare abstract class TypedRule extends AbstractRule implements ITypedRule { + apply(): RuleFailure[]; + abstract applyWithProgram(sourceFile: ts.SourceFile, program: ts.Program): RuleFailure[]; +} diff --git a/node_modules/tslint/lib/language/rule/typedRule.js b/node_modules/tslint/lib/language/rule/typedRule.js new file mode 100644 index 000000000..45a2fb30d --- /dev/null +++ b/node_modules/tslint/lib/language/rule/typedRule.js @@ -0,0 +1,32 @@ +"use strict"; +/** + * @license + * Copyright 2016 Palantir Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +Object.defineProperty(exports, "__esModule", { value: true }); +var tslib_1 = require("tslib"); +var abstractRule_1 = require("./abstractRule"); +var TypedRule = (function (_super) { + tslib_1.__extends(TypedRule, _super); + function TypedRule() { + return _super !== null && _super.apply(this, arguments) || this; + } + TypedRule.prototype.apply = function () { + // if no program is given to the linter, throw an error + throw new Error("The '" + this.ruleName + "' rule requires type checking"); + }; + return TypedRule; +}(abstractRule_1.AbstractRule)); +exports.TypedRule = TypedRule; diff --git a/node_modules/tslint/lib/language/utils.d.ts b/node_modules/tslint/lib/language/utils.d.ts new file mode 100644 index 000000000..a8ccc2be1 --- /dev/null +++ b/node_modules/tslint/lib/language/utils.d.ts @@ -0,0 +1,97 @@ +import * as ts from "typescript"; +import { IDisabledInterval, RuleFailure } from "./rule/rule"; +export declare function getSourceFile(fileName: string, source: string): ts.SourceFile; +/** @deprecated See IDisabledInterval. */ +export declare function doesIntersect(failure: RuleFailure, disabledIntervals: IDisabledInterval[]): boolean; +/** + * @returns true if any modifier kinds passed along exist in the given modifiers array + */ +export declare function hasModifier(modifiers: ts.ModifiersArray | undefined, ...modifierKinds: ts.SyntaxKind[]): boolean; +/** + * Determines if the appropriate bit in the parent (VariableDeclarationList) is set, + * which indicates this is a "let" or "const". + */ +export declare function isBlockScopedVariable(node: ts.VariableDeclaration | ts.VariableStatement): boolean; +export declare function isBlockScopedBindingElement(node: ts.BindingElement): boolean; +export declare function getBindingElementVariableDeclaration(node: ts.BindingElement): ts.VariableDeclaration | null; +/** + * Finds a child of a given node with a given kind. + * Note: This uses `node.getChildren()`, which does extra parsing work to include tokens. + */ +export declare function childOfKind(node: ts.Node, kind: ts.SyntaxKind): ts.Node | undefined; +/** + * @returns true if some ancestor of `node` satisfies `predicate`, including `node` itself. + */ +export declare function someAncestor(node: ts.Node, predicate: (n: ts.Node) => boolean): boolean; +export declare function ancestorWhere<T extends ts.Node>(node: ts.Node, predicate: (n: ts.Node) => boolean): ts.Node | undefined; +export declare function isAssignment(node: ts.Node): boolean; +/** + * Bitwise check for node flags. + */ +export declare function isNodeFlagSet(node: ts.Node, flagToCheck: ts.NodeFlags): boolean; +/** + * Bitwise check for combined node flags. + */ +export declare function isCombinedNodeFlagSet(node: ts.Node, flagToCheck: ts.NodeFlags): boolean; +/** + * Bitwise check for combined modifier flags. + */ +export declare function isCombinedModifierFlagSet(node: ts.Node, flagToCheck: ts.ModifierFlags): boolean; +/** + * Bitwise check for type flags. + */ +export declare function isTypeFlagSet(type: ts.Type, flagToCheck: ts.TypeFlags): boolean; +/** + * Bitwise check for symbol flags. + */ +export declare function isSymbolFlagSet(symbol: ts.Symbol, flagToCheck: ts.SymbolFlags): boolean; +/** + * Bitwise check for object flags. + * Does not work with TypeScript 2.0.x + */ +export declare function isObjectFlagSet(objectType: ts.ObjectType, flagToCheck: ts.ObjectFlags): boolean; +/** + * @returns true if decl is a nested module declaration, i.e. represents a segment of a dotted module path. + */ +export declare function isNestedModuleDeclaration(decl: ts.ModuleDeclaration): boolean; +export declare function unwrapParentheses(node: ts.Expression): ts.Expression; +export declare function isScopeBoundary(node: ts.Node): boolean; +export declare function isBlockScopeBoundary(node: ts.Node): boolean; +export declare function isLoop(node: ts.Node): node is ts.IterationStatement; +export interface TokenPosition { + /** The start of the token including all trivia before it */ + fullStart: number; + /** The start of the token */ + tokenStart: number; + /** The end of the token */ + end: number; +} +export declare type ForEachTokenCallback = (fullText: string, kind: ts.SyntaxKind, pos: TokenPosition, parent: ts.Node) => void; +export declare type ForEachCommentCallback = (fullText: string, kind: ts.SyntaxKind, pos: TokenPosition) => void; +export declare type FilterCallback = (node: ts.Node) => boolean; +/** + * Iterate over all tokens of `node` + * + * @description JsDoc comments are treated like regular comments and only visited if `skipTrivia` === false. + * + * @param node The node whose tokens should be visited + * @param skipTrivia If set to false all trivia preceeding `node` or any of its children is included + * @param cb Is called for every token of `node`. It gets the full text of the SourceFile and the position of the token within that text. + * @param filter If provided, will be called for every Node and Token found. If it returns false `cb` will not be called for this subtree. + */ +export declare function forEachToken(node: ts.Node, skipTrivia: boolean, cb: ForEachTokenCallback, filter?: FilterCallback): void; +/** Iterate over all comments owned by `node` or its children */ +export declare function forEachComment(node: ts.Node, cb: ForEachCommentCallback): void; +/** + * Checks if there are any comments between `position` and the next non-trivia token + * + * @param text The text to scan + * @param position The position inside `text` where to start scanning. Make sure that this is a valid start position. + * This value is typically obtained from `node.getFullStart()` or `node.getEnd()` + */ +export declare function hasCommentAfterPosition(text: string, position: number): boolean; +export interface EqualsKind { + isPositive: boolean; + isStrict: boolean; +} +export declare function getEqualsKind(node: ts.BinaryOperatorToken): EqualsKind | undefined; diff --git a/node_modules/tslint/lib/language/utils.js b/node_modules/tslint/lib/language/utils.js new file mode 100644 index 000000000..4f1fa52cf --- /dev/null +++ b/node_modules/tslint/lib/language/utils.js @@ -0,0 +1,402 @@ +"use strict"; +/** + * @license + * Copyright 2013 Palantir Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +Object.defineProperty(exports, "__esModule", { value: true }); +var path = require("path"); +var tsutils_1 = require("tsutils"); +var ts = require("typescript"); +function getSourceFile(fileName, source) { + var normalizedName = path.normalize(fileName).replace(/\\/g, "/"); + return ts.createSourceFile(normalizedName, source, ts.ScriptTarget.ES5, /*setParentNodes*/ true); +} +exports.getSourceFile = getSourceFile; +/** @deprecated See IDisabledInterval. */ +function doesIntersect(failure, disabledIntervals) { + return disabledIntervals.some(function (interval) { + var maxStart = Math.max(interval.startPosition, failure.getStartPosition().getPosition()); + var minEnd = Math.min(interval.endPosition, failure.getEndPosition().getPosition()); + return maxStart <= minEnd; + }); +} +exports.doesIntersect = doesIntersect; +/** + * @returns true if any modifier kinds passed along exist in the given modifiers array + */ +function hasModifier(modifiers) { + var modifierKinds = []; + for (var _i = 1; _i < arguments.length; _i++) { + modifierKinds[_i - 1] = arguments[_i]; + } + if (modifiers === undefined || modifierKinds.length === 0) { + return false; + } + return modifiers.some(function (m) { + return modifierKinds.some(function (k) { return m.kind === k; }); + }); +} +exports.hasModifier = hasModifier; +/** + * Determines if the appropriate bit in the parent (VariableDeclarationList) is set, + * which indicates this is a "let" or "const". + */ +function isBlockScopedVariable(node) { + if (node.kind === ts.SyntaxKind.VariableDeclaration) { + var parent = node.parent; + return parent.kind === ts.SyntaxKind.CatchClause || tsutils_1.isBlockScopedVariableDeclarationList(parent); + } + else { + return tsutils_1.isBlockScopedVariableDeclarationList(node.declarationList); + } +} +exports.isBlockScopedVariable = isBlockScopedVariable; +function isBlockScopedBindingElement(node) { + var variableDeclaration = getBindingElementVariableDeclaration(node); + // if no variable declaration, it must be a function param, which is block scoped + return (variableDeclaration == null) || isBlockScopedVariable(variableDeclaration); +} +exports.isBlockScopedBindingElement = isBlockScopedBindingElement; +function getBindingElementVariableDeclaration(node) { + var currentParent = node.parent; + while (currentParent.kind !== ts.SyntaxKind.VariableDeclaration) { + if (currentParent.parent == null) { + return null; // function parameter, no variable declaration + } + else { + currentParent = currentParent.parent; + } + } + return currentParent; +} +exports.getBindingElementVariableDeclaration = getBindingElementVariableDeclaration; +/** + * Finds a child of a given node with a given kind. + * Note: This uses `node.getChildren()`, which does extra parsing work to include tokens. + */ +function childOfKind(node, kind) { + return node.getChildren().find(function (child) { return child.kind === kind; }); +} +exports.childOfKind = childOfKind; +/** + * @returns true if some ancestor of `node` satisfies `predicate`, including `node` itself. + */ +function someAncestor(node, predicate) { + return predicate(node) || (node.parent != null && someAncestor(node.parent, predicate)); +} +exports.someAncestor = someAncestor; +function ancestorWhere(node, predicate) { + var cur = node; + do { + if (predicate(cur)) { + return cur; + } + cur = cur.parent; + } while (cur !== undefined); + return undefined; +} +exports.ancestorWhere = ancestorWhere; +function isAssignment(node) { + if (node.kind === ts.SyntaxKind.BinaryExpression) { + var binaryExpression = node; + return binaryExpression.operatorToken.kind >= ts.SyntaxKind.FirstAssignment + && binaryExpression.operatorToken.kind <= ts.SyntaxKind.LastAssignment; + } + else { + return false; + } +} +exports.isAssignment = isAssignment; +/** + * Bitwise check for node flags. + */ +function isNodeFlagSet(node, flagToCheck) { + // tslint:disable-next-line:no-bitwise + return (node.flags & flagToCheck) !== 0; +} +exports.isNodeFlagSet = isNodeFlagSet; +/** + * Bitwise check for combined node flags. + */ +function isCombinedNodeFlagSet(node, flagToCheck) { + // tslint:disable-next-line:no-bitwise + return (ts.getCombinedNodeFlags(node) & flagToCheck) !== 0; +} +exports.isCombinedNodeFlagSet = isCombinedNodeFlagSet; +/** + * Bitwise check for combined modifier flags. + */ +function isCombinedModifierFlagSet(node, flagToCheck) { + // tslint:disable-next-line:no-bitwise + return (ts.getCombinedModifierFlags(node) & flagToCheck) !== 0; +} +exports.isCombinedModifierFlagSet = isCombinedModifierFlagSet; +/** + * Bitwise check for type flags. + */ +function isTypeFlagSet(type, flagToCheck) { + // tslint:disable-next-line:no-bitwise + return (type.flags & flagToCheck) !== 0; +} +exports.isTypeFlagSet = isTypeFlagSet; +/** + * Bitwise check for symbol flags. + */ +function isSymbolFlagSet(symbol, flagToCheck) { + // tslint:disable-next-line:no-bitwise + return (symbol.flags & flagToCheck) !== 0; +} +exports.isSymbolFlagSet = isSymbolFlagSet; +/** + * Bitwise check for object flags. + * Does not work with TypeScript 2.0.x + */ +function isObjectFlagSet(objectType, flagToCheck) { + // tslint:disable-next-line:no-bitwise + return (objectType.objectFlags & flagToCheck) !== 0; +} +exports.isObjectFlagSet = isObjectFlagSet; +/** + * @returns true if decl is a nested module declaration, i.e. represents a segment of a dotted module path. + */ +function isNestedModuleDeclaration(decl) { + // in a declaration expression like 'module a.b.c' - 'a' is the top level module declaration node and 'b' and 'c' + // are nested therefore we can depend that a node's position will only match with its name's position for nested + // nodes + return decl.name.pos === decl.pos; +} +exports.isNestedModuleDeclaration = isNestedModuleDeclaration; +function unwrapParentheses(node) { + while (node.kind === ts.SyntaxKind.ParenthesizedExpression) { + node = node.expression; + } + return node; +} +exports.unwrapParentheses = unwrapParentheses; +function isScopeBoundary(node) { + return node.kind === ts.SyntaxKind.FunctionDeclaration + || node.kind === ts.SyntaxKind.FunctionExpression + || node.kind === ts.SyntaxKind.PropertyAssignment + || node.kind === ts.SyntaxKind.ShorthandPropertyAssignment + || node.kind === ts.SyntaxKind.MethodDeclaration + || node.kind === ts.SyntaxKind.Constructor + || node.kind === ts.SyntaxKind.ModuleDeclaration + || node.kind === ts.SyntaxKind.ArrowFunction + || node.kind === ts.SyntaxKind.ParenthesizedExpression + || node.kind === ts.SyntaxKind.ClassDeclaration + || node.kind === ts.SyntaxKind.ClassExpression + || node.kind === ts.SyntaxKind.InterfaceDeclaration + || node.kind === ts.SyntaxKind.GetAccessor + || node.kind === ts.SyntaxKind.SetAccessor + || node.kind === ts.SyntaxKind.SourceFile && ts.isExternalModule(node); +} +exports.isScopeBoundary = isScopeBoundary; +function isBlockScopeBoundary(node) { + return isScopeBoundary(node) + || node.kind === ts.SyntaxKind.Block + || isLoop(node) + || node.kind === ts.SyntaxKind.WithStatement + || node.kind === ts.SyntaxKind.SwitchStatement + || node.parent !== undefined + && (node.parent.kind === ts.SyntaxKind.TryStatement + || node.parent.kind === ts.SyntaxKind.IfStatement); +} +exports.isBlockScopeBoundary = isBlockScopeBoundary; +function isLoop(node) { + return node.kind === ts.SyntaxKind.DoStatement + || node.kind === ts.SyntaxKind.WhileStatement + || node.kind === ts.SyntaxKind.ForStatement + || node.kind === ts.SyntaxKind.ForInStatement + || node.kind === ts.SyntaxKind.ForOfStatement; +} +exports.isLoop = isLoop; +/** + * Iterate over all tokens of `node` + * + * @description JsDoc comments are treated like regular comments and only visited if `skipTrivia` === false. + * + * @param node The node whose tokens should be visited + * @param skipTrivia If set to false all trivia preceeding `node` or any of its children is included + * @param cb Is called for every token of `node`. It gets the full text of the SourceFile and the position of the token within that text. + * @param filter If provided, will be called for every Node and Token found. If it returns false `cb` will not be called for this subtree. + */ +function forEachToken(node, skipTrivia, cb, filter) { + // this function will most likely be called with SourceFile anyways, so there is no need for an additional parameter + var sourceFile = node.getSourceFile(); + var fullText = sourceFile.text; + var iterateFn = filter === undefined ? iterateChildren : iterateWithFilter; + var handleTrivia = skipTrivia ? undefined : createTriviaHandler(sourceFile, cb); + iterateFn(node); + // this function is used to save the if condition for the common case where no filter is provided + function iterateWithFilter(child) { + if (filter(child)) { + return iterateChildren(child); + } + } + function iterateChildren(child) { + if (child.kind < ts.SyntaxKind.FirstNode || + // for backwards compatibility to typescript 2.0.10 + // JsxText was no Token, but a Node in that version + child.kind === ts.SyntaxKind.JsxText) { + // we found a token, tokens have no children, stop recursing here + return callback(child); + } + /* Exclude everything contained in JsDoc, it will be handled with the other trivia anyway. + * When we would handle JsDoc tokens like regular ones, we would scan some trivia multiple times. + * Even worse, we would scan for trivia inside the JsDoc comment, which yields unexpected results.*/ + if (child.kind !== ts.SyntaxKind.JSDocComment) { + // recurse into Node's children to find tokens + return child.getChildren(sourceFile).forEach(iterateFn); + } + } + function callback(token) { + var tokenStart = token.getStart(sourceFile); + if (!skipTrivia && tokenStart !== token.pos) { + // we only have to handle trivia before each token, because there is nothing after EndOfFileToken + handleTrivia(token.pos, tokenStart, token); + } + return cb(fullText, token.kind, { tokenStart: tokenStart, fullStart: token.pos, end: token.end }, token.parent); + } +} +exports.forEachToken = forEachToken; +function createTriviaHandler(sourceFile, cb) { + var fullText = sourceFile.text; + var scanner = ts.createScanner(sourceFile.languageVersion, false, sourceFile.languageVariant, fullText); + /** + * Scan the specified range to get all trivia tokens. + * This includes trailing trivia of the last token and the leading trivia of the current token + */ + function handleTrivia(start, end, token) { + var parent = token.parent; + // prevent false positives by not scanning inside JsxText + if (!canHaveLeadingTrivia(token.kind, parent)) { + return; + } + scanner.setTextPos(start); + var position; + // we only get here if start !== end, so we can scan at least one time + do { + var kind = scanner.scan(); + position = scanner.getTextPos(); + cb(fullText, kind, { tokenStart: scanner.getTokenPos(), end: position, fullStart: start }, parent); + } while (position < end); + } + return handleTrivia; +} +/** Iterate over all comments owned by `node` or its children */ +function forEachComment(node, cb) { + /* Visit all tokens and skip trivia. + Comment ranges between tokens are parsed without the need of a scanner. + forEachToken also does intentionally not pay attention to the correct comment ownership of nodes as it always + scans all trivia before each token, which could include trailing comments of the previous token. + Comment onwership is done right in this function*/ + return forEachToken(node, true, function (fullText, tokenKind, pos, parent) { + // don't search for comments inside JsxText + if (canHaveLeadingTrivia(tokenKind, parent)) { + // Comments before the first token (pos.fullStart === 0) are all considered leading comments, so no need for special treatment + var comments = ts.getLeadingCommentRanges(fullText, pos.fullStart); + if (comments !== undefined) { + for (var _i = 0, comments_1 = comments; _i < comments_1.length; _i++) { + var comment = comments_1[_i]; + cb(fullText, comment.kind, { fullStart: pos.fullStart, tokenStart: comment.pos, end: comment.end }); + } + } + } + if (canHaveTrailingTrivia(tokenKind, parent)) { + var comments = ts.getTrailingCommentRanges(fullText, pos.end); + if (comments !== undefined) { + for (var _a = 0, comments_2 = comments; _a < comments_2.length; _a++) { + var comment = comments_2[_a]; + cb(fullText, comment.kind, { fullStart: pos.fullStart, tokenStart: comment.pos, end: comment.end }); + } + } + } + }); +} +exports.forEachComment = forEachComment; +/** Exclude leading positions that would lead to scanning for trivia inside JsxText */ +function canHaveLeadingTrivia(tokenKind, parent) { + switch (tokenKind) { + case ts.SyntaxKind.JsxText: + return false; // there is no trivia before JsxText + case ts.SyntaxKind.OpenBraceToken: + // before a JsxExpression inside a JsxElement's body can only be other JsxChild, but no trivia + return parent.kind !== ts.SyntaxKind.JsxExpression || parent.parent.kind !== ts.SyntaxKind.JsxElement; + case ts.SyntaxKind.LessThanToken: + switch (parent.kind) { + case ts.SyntaxKind.JsxClosingElement: + return false; // would be inside the element body + case ts.SyntaxKind.JsxOpeningElement: + case ts.SyntaxKind.JsxSelfClosingElement: + // there can only be leading trivia if we are at the end of the top level element + return parent.parent.parent.kind !== ts.SyntaxKind.JsxElement; + default: + return true; + } + default: + return true; + } +} +/** Exclude trailing positions that would lead to scanning for trivia inside JsxText */ +function canHaveTrailingTrivia(tokenKind, parent) { + switch (tokenKind) { + case ts.SyntaxKind.JsxText: + // there is no trivia after JsxText + return false; + case ts.SyntaxKind.CloseBraceToken: + // after a JsxExpression inside a JsxElement's body can only be other JsxChild, but no trivia + return parent.kind !== ts.SyntaxKind.JsxExpression || parent.parent.kind !== ts.SyntaxKind.JsxElement; + case ts.SyntaxKind.GreaterThanToken: + switch (parent.kind) { + case ts.SyntaxKind.JsxOpeningElement: + return false; // would be inside the element + case ts.SyntaxKind.JsxClosingElement: + case ts.SyntaxKind.JsxSelfClosingElement: + // there can only be trailing trivia if we are at the end of the top level element + return parent.parent.parent.kind !== ts.SyntaxKind.JsxElement; + default: + return true; + } + default: + return true; + } +} +/** + * Checks if there are any comments between `position` and the next non-trivia token + * + * @param text The text to scan + * @param position The position inside `text` where to start scanning. Make sure that this is a valid start position. + * This value is typically obtained from `node.getFullStart()` or `node.getEnd()` + */ +function hasCommentAfterPosition(text, position) { + return ts.getTrailingCommentRanges(text, position) !== undefined || + ts.getLeadingCommentRanges(text, position) !== undefined; +} +exports.hasCommentAfterPosition = hasCommentAfterPosition; +function getEqualsKind(node) { + switch (node.kind) { + case ts.SyntaxKind.EqualsEqualsToken: + return { isPositive: true, isStrict: false }; + case ts.SyntaxKind.EqualsEqualsEqualsToken: + return { isPositive: true, isStrict: true }; + case ts.SyntaxKind.ExclamationEqualsToken: + return { isPositive: false, isStrict: false }; + case ts.SyntaxKind.ExclamationEqualsEqualsToken: + return { isPositive: false, isStrict: true }; + default: + return undefined; + } +} +exports.getEqualsKind = getEqualsKind; diff --git a/node_modules/tslint/lib/language/walker/blockScopeAwareRuleWalker.d.ts b/node_modules/tslint/lib/language/walker/blockScopeAwareRuleWalker.d.ts new file mode 100644 index 000000000..92a61039d --- /dev/null +++ b/node_modules/tslint/lib/language/walker/blockScopeAwareRuleWalker.d.ts @@ -0,0 +1,38 @@ +/** + * @license + * Copyright 2013 Palantir Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import * as ts from "typescript"; +import { IOptions } from "../rule/rule"; +import { ScopeAwareRuleWalker } from "./scopeAwareRuleWalker"; +/** + * @deprecated See comment on ScopeAwareRuleWalker. + * + * An AST walker that is aware of block scopes in addition to regular scopes. Block scopes + * are a superset of regular scopes (new block scopes are created more frequently in a program). + */ +export declare abstract class BlockScopeAwareRuleWalker<T, U> extends ScopeAwareRuleWalker<T> { + private blockScopeStack; + constructor(sourceFile: ts.SourceFile, options: IOptions); + abstract createBlockScope(node: ts.Node): U; + getAllBlockScopes(): U[]; + getCurrentBlockScope(): U; + getCurrentBlockDepth(): number; + onBlockScopeStart(): void; + onBlockScopeEnd(): void; + findBlockScope(predicate: (scope: U) => boolean): U | undefined; + protected visitNode(node: ts.Node): void; + private isBlockScopeBoundary(node); +} diff --git a/node_modules/tslint/lib/language/walker/blockScopeAwareRuleWalker.js b/node_modules/tslint/lib/language/walker/blockScopeAwareRuleWalker.js new file mode 100644 index 000000000..4dd311ddb --- /dev/null +++ b/node_modules/tslint/lib/language/walker/blockScopeAwareRuleWalker.js @@ -0,0 +1,82 @@ +"use strict"; +/** + * @license + * Copyright 2013 Palantir Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +Object.defineProperty(exports, "__esModule", { value: true }); +var tslib_1 = require("tslib"); +var ts = require("typescript"); +var utils_1 = require("../utils"); +// tslint:disable deprecation +var scopeAwareRuleWalker_1 = require("./scopeAwareRuleWalker"); +/** + * @deprecated See comment on ScopeAwareRuleWalker. + * + * An AST walker that is aware of block scopes in addition to regular scopes. Block scopes + * are a superset of regular scopes (new block scopes are created more frequently in a program). + */ +var BlockScopeAwareRuleWalker = (function (_super) { + tslib_1.__extends(BlockScopeAwareRuleWalker, _super); + function BlockScopeAwareRuleWalker(sourceFile, options) { + var _this = _super.call(this, sourceFile, options) || this; + // initialize with global scope if file is not a module + _this.blockScopeStack = ts.isExternalModule(sourceFile) ? [] : [_this.createBlockScope(sourceFile)]; + return _this; + } + // get all block scopes available at this depth + BlockScopeAwareRuleWalker.prototype.getAllBlockScopes = function () { + return this.blockScopeStack; + }; + BlockScopeAwareRuleWalker.prototype.getCurrentBlockScope = function () { + return this.blockScopeStack[this.blockScopeStack.length - 1]; + }; + BlockScopeAwareRuleWalker.prototype.getCurrentBlockDepth = function () { + return this.blockScopeStack.length; + }; + // callback notifier when a block scope begins + BlockScopeAwareRuleWalker.prototype.onBlockScopeStart = function () { + return; + }; + // callback notifier when a block scope ends + BlockScopeAwareRuleWalker.prototype.onBlockScopeEnd = function () { + return; + }; + BlockScopeAwareRuleWalker.prototype.findBlockScope = function (predicate) { + // look through block scopes from local -> global + for (var i = this.blockScopeStack.length - 1; i >= 0; i--) { + if (predicate(this.blockScopeStack[i])) { + return this.blockScopeStack[i]; + } + } + return undefined; + }; + BlockScopeAwareRuleWalker.prototype.visitNode = function (node) { + var isNewBlockScope = this.isBlockScopeBoundary(node); + if (isNewBlockScope) { + this.blockScopeStack.push(this.createBlockScope(node)); + this.onBlockScopeStart(); + } + _super.prototype.visitNode.call(this, node); + if (isNewBlockScope) { + this.onBlockScopeEnd(); + this.blockScopeStack.pop(); + } + }; + BlockScopeAwareRuleWalker.prototype.isBlockScopeBoundary = function (node) { + return utils_1.isBlockScopeBoundary(node); + }; + return BlockScopeAwareRuleWalker; +}(scopeAwareRuleWalker_1.ScopeAwareRuleWalker)); +exports.BlockScopeAwareRuleWalker = BlockScopeAwareRuleWalker; diff --git a/node_modules/tslint/lib/language/walker/index.d.ts b/node_modules/tslint/lib/language/walker/index.d.ts new file mode 100644 index 000000000..db3dc9492 --- /dev/null +++ b/node_modules/tslint/lib/language/walker/index.d.ts @@ -0,0 +1,23 @@ +/** + * @license + * Copyright 2013 Palantir Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export * from "./blockScopeAwareRuleWalker"; +export * from "./programAwareRuleWalker"; +export * from "./ruleWalker"; +export * from "./scopeAwareRuleWalker"; +export * from "./syntaxWalker"; +export * from "./walkContext"; +export * from "./walker"; diff --git a/node_modules/tslint/lib/language/walker/index.js b/node_modules/tslint/lib/language/walker/index.js new file mode 100644 index 000000000..c5bcb1b22 --- /dev/null +++ b/node_modules/tslint/lib/language/walker/index.js @@ -0,0 +1,28 @@ +"use strict"; +/** + * @license + * Copyright 2013 Palantir Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +function __export(m) { + for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; +} +Object.defineProperty(exports, "__esModule", { value: true }); +__export(require("./blockScopeAwareRuleWalker")); +__export(require("./programAwareRuleWalker")); +__export(require("./ruleWalker")); +__export(require("./scopeAwareRuleWalker")); +__export(require("./syntaxWalker")); +__export(require("./walkContext")); +__export(require("./walker")); diff --git a/node_modules/tslint/lib/language/walker/programAwareRuleWalker.d.ts b/node_modules/tslint/lib/language/walker/programAwareRuleWalker.d.ts new file mode 100644 index 000000000..d0ae8af52 --- /dev/null +++ b/node_modules/tslint/lib/language/walker/programAwareRuleWalker.d.ts @@ -0,0 +1,26 @@ +/** + * @license + * Copyright 2016 Palantir Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import * as ts from "typescript"; +import { IOptions } from "../rule/rule"; +import { RuleWalker } from "./ruleWalker"; +export declare class ProgramAwareRuleWalker extends RuleWalker { + private program; + private typeChecker; + constructor(sourceFile: ts.SourceFile, options: IOptions, program: ts.Program); + getProgram(): ts.Program; + getTypeChecker(): ts.TypeChecker; +} diff --git a/node_modules/tslint/lib/language/walker/programAwareRuleWalker.js b/node_modules/tslint/lib/language/walker/programAwareRuleWalker.js new file mode 100644 index 000000000..de68cb5a6 --- /dev/null +++ b/node_modules/tslint/lib/language/walker/programAwareRuleWalker.js @@ -0,0 +1,37 @@ +"use strict"; +/** + * @license + * Copyright 2016 Palantir Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +Object.defineProperty(exports, "__esModule", { value: true }); +var tslib_1 = require("tslib"); +var ruleWalker_1 = require("./ruleWalker"); +var ProgramAwareRuleWalker = (function (_super) { + tslib_1.__extends(ProgramAwareRuleWalker, _super); + function ProgramAwareRuleWalker(sourceFile, options, program) { + var _this = _super.call(this, sourceFile, options) || this; + _this.program = program; + _this.typeChecker = program.getTypeChecker(); + return _this; + } + ProgramAwareRuleWalker.prototype.getProgram = function () { + return this.program; + }; + ProgramAwareRuleWalker.prototype.getTypeChecker = function () { + return this.typeChecker; + }; + return ProgramAwareRuleWalker; +}(ruleWalker_1.RuleWalker)); +exports.ProgramAwareRuleWalker = ProgramAwareRuleWalker; diff --git a/node_modules/tslint/lib/language/walker/ruleWalker.d.ts b/node_modules/tslint/lib/language/walker/ruleWalker.d.ts new file mode 100644 index 000000000..f78b4c0ed --- /dev/null +++ b/node_modules/tslint/lib/language/walker/ruleWalker.d.ts @@ -0,0 +1,49 @@ +/** + * @license + * Copyright 2013 Palantir Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import * as ts from "typescript"; +import { Fix, IOptions, Replacement, RuleFailure } from "../rule/rule"; +import { SyntaxWalker } from "./syntaxWalker"; +import { IWalker } from "./walker"; +export declare class RuleWalker extends SyntaxWalker implements IWalker { + private sourceFile; + private limit; + private options?; + private failures; + private ruleName; + constructor(sourceFile: ts.SourceFile, options: IOptions); + getSourceFile(): ts.SourceFile; + getLineAndCharacterOfPosition(position: number): ts.LineAndCharacter; + getFailures(): RuleFailure[]; + getLimit(): number; + getOptions(): any; + hasOption(option: string): boolean; + /** @deprecated Prefer `addFailureAt` and its variants. */ + createFailure(start: number, width: number, failure: string, fix?: Fix): RuleFailure; + /** @deprecated Prefer `addFailureAt` and its variants. */ + addFailure(failure: RuleFailure): void; + /** Add a failure with any arbitrary span. Prefer `addFailureAtNode` if possible. */ + addFailureAt(start: number, width: number, failure: string, fix?: Fix): void; + /** Like `addFailureAt` but uses start and end instead of start and width. */ + addFailureFromStartToEnd(start: number, end: number, failure: string, fix?: Fix): void; + /** Add a failure using a node's span. */ + addFailureAtNode(node: ts.Node, failure: string, fix?: Fix): void; + createReplacement(start: number, length: number, text: string): Replacement; + appendText(start: number, text: string): Replacement; + deleteText(start: number, length: number): Replacement; + deleteFromTo(start: number, end: number): Replacement; + getRuleName(): string; +} diff --git a/node_modules/tslint/lib/language/walker/ruleWalker.js b/node_modules/tslint/lib/language/walker/ruleWalker.js new file mode 100644 index 000000000..b5146825e --- /dev/null +++ b/node_modules/tslint/lib/language/walker/ruleWalker.js @@ -0,0 +1,96 @@ +"use strict"; +/** + * @license + * Copyright 2013 Palantir Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +Object.defineProperty(exports, "__esModule", { value: true }); +var tslib_1 = require("tslib"); +var rule_1 = require("../rule/rule"); +var syntaxWalker_1 = require("./syntaxWalker"); +var RuleWalker = (function (_super) { + tslib_1.__extends(RuleWalker, _super); + function RuleWalker(sourceFile, options) { + var _this = _super.call(this) || this; + _this.sourceFile = sourceFile; + _this.failures = []; + _this.options = options.ruleArguments; + _this.limit = _this.sourceFile.getFullWidth(); + _this.ruleName = options.ruleName; + return _this; + } + RuleWalker.prototype.getSourceFile = function () { + return this.sourceFile; + }; + RuleWalker.prototype.getLineAndCharacterOfPosition = function (position) { + return this.sourceFile.getLineAndCharacterOfPosition(position); + }; + RuleWalker.prototype.getFailures = function () { + return this.failures; + }; + RuleWalker.prototype.getLimit = function () { + return this.limit; + }; + RuleWalker.prototype.getOptions = function () { + return this.options; + }; + RuleWalker.prototype.hasOption = function (option) { + if (this.options !== undefined) { + return this.options.indexOf(option) !== -1; + } + else { + return false; + } + }; + /** @deprecated Prefer `addFailureAt` and its variants. */ + RuleWalker.prototype.createFailure = function (start, width, failure, fix) { + var from = (start > this.limit) ? this.limit : start; + var to = ((start + width) > this.limit) ? this.limit : (start + width); + return new rule_1.RuleFailure(this.sourceFile, from, to, failure, this.ruleName, fix); + }; + /** @deprecated Prefer `addFailureAt` and its variants. */ + RuleWalker.prototype.addFailure = function (failure) { + this.failures.push(failure); + }; + /** Add a failure with any arbitrary span. Prefer `addFailureAtNode` if possible. */ + RuleWalker.prototype.addFailureAt = function (start, width, failure, fix) { + // tslint:disable-next-line deprecation + this.addFailure(this.createFailure(start, width, failure, fix)); + }; + /** Like `addFailureAt` but uses start and end instead of start and width. */ + RuleWalker.prototype.addFailureFromStartToEnd = function (start, end, failure, fix) { + this.addFailureAt(start, end - start, failure, fix); + }; + /** Add a failure using a node's span. */ + RuleWalker.prototype.addFailureAtNode = function (node, failure, fix) { + this.addFailureAt(node.getStart(this.sourceFile), node.getWidth(this.sourceFile), failure, fix); + }; + RuleWalker.prototype.createReplacement = function (start, length, text) { + return new rule_1.Replacement(start, length, text); + }; + RuleWalker.prototype.appendText = function (start, text) { + return this.createReplacement(start, 0, text); + }; + RuleWalker.prototype.deleteText = function (start, length) { + return this.createReplacement(start, length, ""); + }; + RuleWalker.prototype.deleteFromTo = function (start, end) { + return this.createReplacement(start, end - start, ""); + }; + RuleWalker.prototype.getRuleName = function () { + return this.ruleName; + }; + return RuleWalker; +}(syntaxWalker_1.SyntaxWalker)); +exports.RuleWalker = RuleWalker; diff --git a/node_modules/tslint/lib/language/walker/scopeAwareRuleWalker.d.ts b/node_modules/tslint/lib/language/walker/scopeAwareRuleWalker.d.ts new file mode 100644 index 000000000..64423e23b --- /dev/null +++ b/node_modules/tslint/lib/language/walker/scopeAwareRuleWalker.d.ts @@ -0,0 +1,65 @@ +/** + * @license + * Copyright 2013 Palantir Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import * as ts from "typescript"; +import { IOptions } from "../rule/rule"; +import { RuleWalker } from "./ruleWalker"; +/** + * @deprecated Prefer to manually maintain any contextual information. + * + * For example, imagine a `no-break` rule that warns on `break` in `for` but not in `switch`: + * + * function walk(ctx: Lint.WalkContext<void>): void { + * let isInFor = false; + * ts.forEachChild(ctx.sourceFile, function cb(node: ts.Node): void { + * switch (node.kind) { + * case ts.SyntaxKind.Break: + * if (isInFor) { + * ctx.addFailureAtNode(node, "!"); + * } + * break; + * case ts.SyntaxKind.ForStatement: { + * const old = isInFor; + * isInFor = true; + * ts.forEachChild(node, cb); + * isInFor = old; + * break; + * } + * case ts.SyntaxKind.SwitchStatement: { + * const old = isInFor; + * isInFor = false; + * ts.forEachChild(node, cb); + * isInFor = old; + * break; + * } + * default: + * ts.forEachChild(node, cb); + * } + * }); + * } + */ +export declare abstract class ScopeAwareRuleWalker<T> extends RuleWalker { + private scopeStack; + constructor(sourceFile: ts.SourceFile, options: IOptions); + abstract createScope(node: ts.Node): T; + getCurrentScope(): T; + getAllScopes(): T[]; + getCurrentDepth(): number; + onScopeStart(): void; + onScopeEnd(): void; + protected visitNode(node: ts.Node): void; + protected isScopeBoundary(node: ts.Node): boolean; +} diff --git a/node_modules/tslint/lib/language/walker/scopeAwareRuleWalker.js b/node_modules/tslint/lib/language/walker/scopeAwareRuleWalker.js new file mode 100644 index 000000000..081c29b6c --- /dev/null +++ b/node_modules/tslint/lib/language/walker/scopeAwareRuleWalker.js @@ -0,0 +1,100 @@ +"use strict"; +/** + * @license + * Copyright 2013 Palantir Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +Object.defineProperty(exports, "__esModule", { value: true }); +var tslib_1 = require("tslib"); +var ts = require("typescript"); +var utils_1 = require("../utils"); +var ruleWalker_1 = require("./ruleWalker"); +/** + * @deprecated Prefer to manually maintain any contextual information. + * + * For example, imagine a `no-break` rule that warns on `break` in `for` but not in `switch`: + * + * function walk(ctx: Lint.WalkContext<void>): void { + * let isInFor = false; + * ts.forEachChild(ctx.sourceFile, function cb(node: ts.Node): void { + * switch (node.kind) { + * case ts.SyntaxKind.Break: + * if (isInFor) { + * ctx.addFailureAtNode(node, "!"); + * } + * break; + * case ts.SyntaxKind.ForStatement: { + * const old = isInFor; + * isInFor = true; + * ts.forEachChild(node, cb); + * isInFor = old; + * break; + * } + * case ts.SyntaxKind.SwitchStatement: { + * const old = isInFor; + * isInFor = false; + * ts.forEachChild(node, cb); + * isInFor = old; + * break; + * } + * default: + * ts.forEachChild(node, cb); + * } + * }); + * } + */ +var ScopeAwareRuleWalker = (function (_super) { + tslib_1.__extends(ScopeAwareRuleWalker, _super); + function ScopeAwareRuleWalker(sourceFile, options) { + var _this = _super.call(this, sourceFile, options) || this; + // initialize with global scope if file is not a module + _this.scopeStack = ts.isExternalModule(sourceFile) ? [] : [_this.createScope(sourceFile)]; + return _this; + } + ScopeAwareRuleWalker.prototype.getCurrentScope = function () { + return this.scopeStack[this.scopeStack.length - 1]; + }; + // get all scopes available at this depth + ScopeAwareRuleWalker.prototype.getAllScopes = function () { + return this.scopeStack; + }; + ScopeAwareRuleWalker.prototype.getCurrentDepth = function () { + return this.scopeStack.length; + }; + // callback notifier when a scope begins + ScopeAwareRuleWalker.prototype.onScopeStart = function () { + return; + }; + // callback notifier when a scope ends + ScopeAwareRuleWalker.prototype.onScopeEnd = function () { + return; + }; + ScopeAwareRuleWalker.prototype.visitNode = function (node) { + var isNewScope = this.isScopeBoundary(node); + if (isNewScope) { + this.scopeStack.push(this.createScope(node)); + this.onScopeStart(); + } + _super.prototype.visitNode.call(this, node); + if (isNewScope) { + this.onScopeEnd(); + this.scopeStack.pop(); + } + }; + ScopeAwareRuleWalker.prototype.isScopeBoundary = function (node) { + return utils_1.isScopeBoundary(node); + }; + return ScopeAwareRuleWalker; +}(ruleWalker_1.RuleWalker)); +exports.ScopeAwareRuleWalker = ScopeAwareRuleWalker; diff --git a/node_modules/tslint/lib/language/walker/syntaxWalker.d.ts b/node_modules/tslint/lib/language/walker/syntaxWalker.d.ts new file mode 100644 index 000000000..a676a9de7 --- /dev/null +++ b/node_modules/tslint/lib/language/walker/syntaxWalker.d.ts @@ -0,0 +1,104 @@ +/** + * @license + * Copyright 2013 Palantir Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import * as ts from "typescript"; +export declare class SyntaxWalker { + walk(node: ts.Node): void; + protected visitAnyKeyword(node: ts.Node): void; + protected visitArrayLiteralExpression(node: ts.ArrayLiteralExpression): void; + protected visitArrayType(node: ts.ArrayTypeNode): void; + protected visitArrowFunction(node: ts.ArrowFunction): void; + protected visitBinaryExpression(node: ts.BinaryExpression): void; + protected visitBindingElement(node: ts.BindingElement): void; + protected visitBindingPattern(node: ts.BindingPattern): void; + protected visitBlock(node: ts.Block): void; + protected visitBreakStatement(node: ts.BreakOrContinueStatement): void; + protected visitCallExpression(node: ts.CallExpression): void; + protected visitCallSignature(node: ts.SignatureDeclaration): void; + protected visitCaseClause(node: ts.CaseClause): void; + protected visitClassDeclaration(node: ts.ClassDeclaration): void; + protected visitClassExpression(node: ts.ClassExpression): void; + protected visitCatchClause(node: ts.CatchClause): void; + protected visitConditionalExpression(node: ts.ConditionalExpression): void; + protected visitConstructSignature(node: ts.ConstructSignatureDeclaration): void; + protected visitConstructorDeclaration(node: ts.ConstructorDeclaration): void; + protected visitConstructorType(node: ts.FunctionOrConstructorTypeNode): void; + protected visitContinueStatement(node: ts.BreakOrContinueStatement): void; + protected visitDebuggerStatement(node: ts.Statement): void; + protected visitDefaultClause(node: ts.DefaultClause): void; + protected visitDoStatement(node: ts.DoStatement): void; + protected visitElementAccessExpression(node: ts.ElementAccessExpression): void; + protected visitEndOfFileToken(node: ts.Node): void; + protected visitEnumDeclaration(node: ts.EnumDeclaration): void; + protected visitExportAssignment(node: ts.ExportAssignment): void; + protected visitExpressionStatement(node: ts.ExpressionStatement): void; + protected visitForStatement(node: ts.ForStatement): void; + protected visitForInStatement(node: ts.ForInStatement): void; + protected visitForOfStatement(node: ts.ForOfStatement): void; + protected visitFunctionDeclaration(node: ts.FunctionDeclaration): void; + protected visitFunctionExpression(node: ts.FunctionExpression): void; + protected visitFunctionType(node: ts.FunctionOrConstructorTypeNode): void; + protected visitGetAccessor(node: ts.AccessorDeclaration): void; + protected visitIdentifier(node: ts.Identifier): void; + protected visitIfStatement(node: ts.IfStatement): void; + protected visitImportDeclaration(node: ts.ImportDeclaration): void; + protected visitImportEqualsDeclaration(node: ts.ImportEqualsDeclaration): void; + protected visitIndexSignatureDeclaration(node: ts.IndexSignatureDeclaration): void; + protected visitInterfaceDeclaration(node: ts.InterfaceDeclaration): void; + protected visitJsxAttribute(node: ts.JsxAttribute): void; + protected visitJsxElement(node: ts.JsxElement): void; + protected visitJsxExpression(node: ts.JsxExpression): void; + protected visitJsxSelfClosingElement(node: ts.JsxSelfClosingElement): void; + protected visitJsxSpreadAttribute(node: ts.JsxSpreadAttribute): void; + protected visitLabeledStatement(node: ts.LabeledStatement): void; + protected visitMethodDeclaration(node: ts.MethodDeclaration): void; + protected visitMethodSignature(node: ts.SignatureDeclaration): void; + protected visitModuleDeclaration(node: ts.ModuleDeclaration): void; + protected visitNamedImports(node: ts.NamedImports): void; + protected visitNamespaceImport(node: ts.NamespaceImport): void; + protected visitNewExpression(node: ts.NewExpression): void; + protected visitNonNullExpression(node: ts.NonNullExpression): void; + protected visitNumericLiteral(node: ts.NumericLiteral): void; + protected visitObjectLiteralExpression(node: ts.ObjectLiteralExpression): void; + protected visitParameterDeclaration(node: ts.ParameterDeclaration): void; + protected visitPostfixUnaryExpression(node: ts.PostfixUnaryExpression): void; + protected visitPrefixUnaryExpression(node: ts.PrefixUnaryExpression): void; + protected visitPropertyAccessExpression(node: ts.PropertyAccessExpression): void; + protected visitPropertyAssignment(node: ts.PropertyAssignment): void; + protected visitPropertyDeclaration(node: ts.PropertyDeclaration): void; + protected visitPropertySignature(node: ts.Node): void; + protected visitRegularExpressionLiteral(node: ts.Node): void; + protected visitReturnStatement(node: ts.ReturnStatement): void; + protected visitSetAccessor(node: ts.AccessorDeclaration): void; + protected visitSourceFile(node: ts.SourceFile): void; + protected visitStringLiteral(node: ts.StringLiteral): void; + protected visitSwitchStatement(node: ts.SwitchStatement): void; + protected visitTemplateExpression(node: ts.TemplateExpression): void; + protected visitThrowStatement(node: ts.ThrowStatement): void; + protected visitTryStatement(node: ts.TryStatement): void; + protected visitTupleType(node: ts.TupleTypeNode): void; + protected visitTypeAliasDeclaration(node: ts.TypeAliasDeclaration): void; + protected visitTypeAssertionExpression(node: ts.TypeAssertion): void; + protected visitTypeLiteral(node: ts.TypeLiteralNode): void; + protected visitTypeReference(node: ts.TypeReferenceNode): void; + protected visitVariableDeclaration(node: ts.VariableDeclaration): void; + protected visitVariableDeclarationList(node: ts.VariableDeclarationList): void; + protected visitVariableStatement(node: ts.VariableStatement): void; + protected visitWhileStatement(node: ts.WhileStatement): void; + protected visitWithStatement(node: ts.WithStatement): void; + protected visitNode(node: ts.Node): void; + protected walkChildren(node: ts.Node): void; +} diff --git a/node_modules/tslint/lib/language/walker/syntaxWalker.js b/node_modules/tslint/lib/language/walker/syntaxWalker.js new file mode 100644 index 000000000..2b800fc61 --- /dev/null +++ b/node_modules/tslint/lib/language/walker/syntaxWalker.js @@ -0,0 +1,534 @@ +"use strict"; +/** + * @license + * Copyright 2013 Palantir Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +Object.defineProperty(exports, "__esModule", { value: true }); +var ts = require("typescript"); +var SyntaxWalker = (function () { + function SyntaxWalker() { + } + SyntaxWalker.prototype.walk = function (node) { + this.visitNode(node); + }; + SyntaxWalker.prototype.visitAnyKeyword = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitArrayLiteralExpression = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitArrayType = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitArrowFunction = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitBinaryExpression = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitBindingElement = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitBindingPattern = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitBlock = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitBreakStatement = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitCallExpression = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitCallSignature = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitCaseClause = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitClassDeclaration = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitClassExpression = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitCatchClause = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitConditionalExpression = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitConstructSignature = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitConstructorDeclaration = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitConstructorType = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitContinueStatement = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitDebuggerStatement = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitDefaultClause = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitDoStatement = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitElementAccessExpression = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitEndOfFileToken = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitEnumDeclaration = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitExportAssignment = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitExpressionStatement = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitForStatement = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitForInStatement = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitForOfStatement = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitFunctionDeclaration = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitFunctionExpression = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitFunctionType = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitGetAccessor = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitIdentifier = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitIfStatement = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitImportDeclaration = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitImportEqualsDeclaration = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitIndexSignatureDeclaration = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitInterfaceDeclaration = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitJsxAttribute = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitJsxElement = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitJsxExpression = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitJsxSelfClosingElement = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitJsxSpreadAttribute = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitLabeledStatement = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitMethodDeclaration = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitMethodSignature = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitModuleDeclaration = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitNamedImports = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitNamespaceImport = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitNewExpression = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitNonNullExpression = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitNumericLiteral = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitObjectLiteralExpression = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitParameterDeclaration = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitPostfixUnaryExpression = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitPrefixUnaryExpression = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitPropertyAccessExpression = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitPropertyAssignment = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitPropertyDeclaration = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitPropertySignature = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitRegularExpressionLiteral = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitReturnStatement = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitSetAccessor = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitSourceFile = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitStringLiteral = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitSwitchStatement = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitTemplateExpression = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitThrowStatement = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitTryStatement = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitTupleType = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitTypeAliasDeclaration = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitTypeAssertionExpression = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitTypeLiteral = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitTypeReference = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitVariableDeclaration = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitVariableDeclarationList = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitVariableStatement = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitWhileStatement = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitWithStatement = function (node) { + this.walkChildren(node); + }; + SyntaxWalker.prototype.visitNode = function (node) { + switch (node.kind) { + case ts.SyntaxKind.AnyKeyword: + this.visitAnyKeyword(node); + break; + case ts.SyntaxKind.ArrayBindingPattern: + this.visitBindingPattern(node); + break; + case ts.SyntaxKind.ArrayLiteralExpression: + this.visitArrayLiteralExpression(node); + break; + case ts.SyntaxKind.ArrayType: + this.visitArrayType(node); + break; + case ts.SyntaxKind.ArrowFunction: + this.visitArrowFunction(node); + break; + case ts.SyntaxKind.BinaryExpression: + this.visitBinaryExpression(node); + break; + case ts.SyntaxKind.BindingElement: + this.visitBindingElement(node); + break; + case ts.SyntaxKind.Block: + this.visitBlock(node); + break; + case ts.SyntaxKind.BreakStatement: + this.visitBreakStatement(node); + break; + case ts.SyntaxKind.CallExpression: + this.visitCallExpression(node); + break; + case ts.SyntaxKind.CallSignature: + this.visitCallSignature(node); + break; + case ts.SyntaxKind.CaseClause: + this.visitCaseClause(node); + break; + case ts.SyntaxKind.ClassDeclaration: + this.visitClassDeclaration(node); + break; + case ts.SyntaxKind.ClassExpression: + this.visitClassExpression(node); + break; + case ts.SyntaxKind.CatchClause: + this.visitCatchClause(node); + break; + case ts.SyntaxKind.ConditionalExpression: + this.visitConditionalExpression(node); + break; + case ts.SyntaxKind.ConstructSignature: + this.visitConstructSignature(node); + break; + case ts.SyntaxKind.Constructor: + this.visitConstructorDeclaration(node); + break; + case ts.SyntaxKind.ConstructorType: + this.visitConstructorType(node); + break; + case ts.SyntaxKind.ContinueStatement: + this.visitContinueStatement(node); + break; + case ts.SyntaxKind.DebuggerStatement: + this.visitDebuggerStatement(node); + break; + case ts.SyntaxKind.DefaultClause: + this.visitDefaultClause(node); + break; + case ts.SyntaxKind.DoStatement: + this.visitDoStatement(node); + break; + case ts.SyntaxKind.ElementAccessExpression: + this.visitElementAccessExpression(node); + break; + case ts.SyntaxKind.EndOfFileToken: + this.visitEndOfFileToken(node); + break; + case ts.SyntaxKind.EnumDeclaration: + this.visitEnumDeclaration(node); + break; + case ts.SyntaxKind.ExportAssignment: + this.visitExportAssignment(node); + break; + case ts.SyntaxKind.ExpressionStatement: + this.visitExpressionStatement(node); + break; + case ts.SyntaxKind.ForStatement: + this.visitForStatement(node); + break; + case ts.SyntaxKind.ForInStatement: + this.visitForInStatement(node); + break; + case ts.SyntaxKind.ForOfStatement: + this.visitForOfStatement(node); + break; + case ts.SyntaxKind.FunctionDeclaration: + this.visitFunctionDeclaration(node); + break; + case ts.SyntaxKind.FunctionExpression: + this.visitFunctionExpression(node); + break; + case ts.SyntaxKind.FunctionType: + this.visitFunctionType(node); + break; + case ts.SyntaxKind.GetAccessor: + this.visitGetAccessor(node); + break; + case ts.SyntaxKind.Identifier: + this.visitIdentifier(node); + break; + case ts.SyntaxKind.IfStatement: + this.visitIfStatement(node); + break; + case ts.SyntaxKind.ImportDeclaration: + this.visitImportDeclaration(node); + break; + case ts.SyntaxKind.ImportEqualsDeclaration: + this.visitImportEqualsDeclaration(node); + break; + case ts.SyntaxKind.IndexSignature: + this.visitIndexSignatureDeclaration(node); + break; + case ts.SyntaxKind.InterfaceDeclaration: + this.visitInterfaceDeclaration(node); + break; + case ts.SyntaxKind.JsxAttribute: + this.visitJsxAttribute(node); + break; + case ts.SyntaxKind.JsxElement: + this.visitJsxElement(node); + break; + case ts.SyntaxKind.JsxExpression: + this.visitJsxExpression(node); + break; + case ts.SyntaxKind.JsxSelfClosingElement: + this.visitJsxSelfClosingElement(node); + break; + case ts.SyntaxKind.JsxSpreadAttribute: + this.visitJsxSpreadAttribute(node); + break; + case ts.SyntaxKind.LabeledStatement: + this.visitLabeledStatement(node); + break; + case ts.SyntaxKind.MethodDeclaration: + this.visitMethodDeclaration(node); + break; + case ts.SyntaxKind.MethodSignature: + this.visitMethodSignature(node); + break; + case ts.SyntaxKind.ModuleDeclaration: + this.visitModuleDeclaration(node); + break; + case ts.SyntaxKind.NamedImports: + this.visitNamedImports(node); + break; + case ts.SyntaxKind.NamespaceImport: + this.visitNamespaceImport(node); + break; + case ts.SyntaxKind.NewExpression: + this.visitNewExpression(node); + break; + case ts.SyntaxKind.NonNullExpression: + this.visitNonNullExpression(node); + break; + case ts.SyntaxKind.NumericLiteral: + this.visitNumericLiteral(node); + break; + case ts.SyntaxKind.ObjectBindingPattern: + this.visitBindingPattern(node); + break; + case ts.SyntaxKind.ObjectLiteralExpression: + this.visitObjectLiteralExpression(node); + break; + case ts.SyntaxKind.Parameter: + this.visitParameterDeclaration(node); + break; + case ts.SyntaxKind.PostfixUnaryExpression: + this.visitPostfixUnaryExpression(node); + break; + case ts.SyntaxKind.PrefixUnaryExpression: + this.visitPrefixUnaryExpression(node); + break; + case ts.SyntaxKind.PropertyAccessExpression: + this.visitPropertyAccessExpression(node); + break; + case ts.SyntaxKind.PropertyAssignment: + this.visitPropertyAssignment(node); + break; + case ts.SyntaxKind.PropertyDeclaration: + this.visitPropertyDeclaration(node); + break; + case ts.SyntaxKind.PropertySignature: + this.visitPropertySignature(node); + break; + case ts.SyntaxKind.RegularExpressionLiteral: + this.visitRegularExpressionLiteral(node); + break; + case ts.SyntaxKind.ReturnStatement: + this.visitReturnStatement(node); + break; + case ts.SyntaxKind.SetAccessor: + this.visitSetAccessor(node); + break; + case ts.SyntaxKind.SourceFile: + this.visitSourceFile(node); + break; + case ts.SyntaxKind.StringLiteral: + this.visitStringLiteral(node); + break; + case ts.SyntaxKind.SwitchStatement: + this.visitSwitchStatement(node); + break; + case ts.SyntaxKind.TemplateExpression: + this.visitTemplateExpression(node); + break; + case ts.SyntaxKind.ThrowStatement: + this.visitThrowStatement(node); + break; + case ts.SyntaxKind.TryStatement: + this.visitTryStatement(node); + break; + case ts.SyntaxKind.TupleType: + this.visitTupleType(node); + break; + case ts.SyntaxKind.TypeAliasDeclaration: + this.visitTypeAliasDeclaration(node); + break; + case ts.SyntaxKind.TypeAssertionExpression: + this.visitTypeAssertionExpression(node); + break; + case ts.SyntaxKind.TypeLiteral: + this.visitTypeLiteral(node); + break; + case ts.SyntaxKind.TypeReference: + this.visitTypeReference(node); + break; + case ts.SyntaxKind.VariableDeclaration: + this.visitVariableDeclaration(node); + break; + case ts.SyntaxKind.VariableDeclarationList: + this.visitVariableDeclarationList(node); + break; + case ts.SyntaxKind.VariableStatement: + this.visitVariableStatement(node); + break; + case ts.SyntaxKind.WhileStatement: + this.visitWhileStatement(node); + break; + case ts.SyntaxKind.WithStatement: + this.visitWithStatement(node); + break; + default: + this.walkChildren(node); + break; + } + }; + SyntaxWalker.prototype.walkChildren = function (node) { + var _this = this; + ts.forEachChild(node, function (child) { return _this.visitNode(child); }); + }; + return SyntaxWalker; +}()); +exports.SyntaxWalker = SyntaxWalker; diff --git a/node_modules/tslint/lib/language/walker/walkContext.d.ts b/node_modules/tslint/lib/language/walker/walkContext.d.ts new file mode 100644 index 000000000..38a413f3d --- /dev/null +++ b/node_modules/tslint/lib/language/walker/walkContext.d.ts @@ -0,0 +1,30 @@ +/** + * @license + * Copyright 2017 Palantir Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import * as ts from "typescript"; +import { Fix, RuleFailure } from "../rule/rule"; +export declare class WalkContext<T> { + readonly sourceFile: ts.SourceFile; + readonly ruleName: string; + readonly options: T; + readonly failures: RuleFailure[]; + constructor(sourceFile: ts.SourceFile, ruleName: string, options: T); + /** Add a failure with any arbitrary span. Prefer `addFailureAtNode` if possible. */ + addFailureAt(start: number, width: number, failure: string, fix?: Fix): void; + addFailure(start: number, end: number, failure: string, fix?: Fix): void; + /** Add a failure using a node's span. */ + addFailureAtNode(node: ts.Node, failure: string, fix?: Fix): void; +} diff --git a/node_modules/tslint/lib/language/walker/walkContext.js b/node_modules/tslint/lib/language/walker/walkContext.js new file mode 100644 index 000000000..b6d8224d3 --- /dev/null +++ b/node_modules/tslint/lib/language/walker/walkContext.js @@ -0,0 +1,41 @@ +"use strict"; +/** + * @license + * Copyright 2017 Palantir Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +Object.defineProperty(exports, "__esModule", { value: true }); +var rule_1 = require("../rule/rule"); +var WalkContext = (function () { + function WalkContext(sourceFile, ruleName, options) { + this.sourceFile = sourceFile; + this.ruleName = ruleName; + this.options = options; + this.failures = []; + } + /** Add a failure with any arbitrary span. Prefer `addFailureAtNode` if possible. */ + WalkContext.prototype.addFailureAt = function (start, width, failure, fix) { + this.addFailure(start, start + width, failure, fix); + }; + WalkContext.prototype.addFailure = function (start, end, failure, fix) { + var fileLength = this.sourceFile.end; + this.failures.push(new rule_1.RuleFailure(this.sourceFile, Math.min(start, fileLength), Math.min(end, fileLength), failure, this.ruleName, fix)); + }; + /** Add a failure using a node's span. */ + WalkContext.prototype.addFailureAtNode = function (node, failure, fix) { + this.addFailure(node.getStart(this.sourceFile), node.getEnd(), failure, fix); + }; + return WalkContext; +}()); +exports.WalkContext = WalkContext; diff --git a/node_modules/tslint/lib/language/walker/walker.d.ts b/node_modules/tslint/lib/language/walker/walker.d.ts new file mode 100644 index 000000000..dee30ece4 --- /dev/null +++ b/node_modules/tslint/lib/language/walker/walker.d.ts @@ -0,0 +1,30 @@ +/** + * @license + * Copyright 2017 Palantir Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import * as ts from "typescript"; +import { RuleFailure } from "../rule/rule"; +import { WalkContext } from "./walkContext"; +import { IWalker } from "./walker"; +export interface IWalker { + getSourceFile(): ts.SourceFile; + walk(sourceFile: ts.SourceFile): void; + getFailures(): RuleFailure[]; +} +export declare abstract class AbstractWalker<T> extends WalkContext<T> implements IWalker { + abstract walk(sourceFile: ts.SourceFile): void; + getSourceFile(): ts.SourceFile; + getFailures(): RuleFailure[]; +} diff --git a/node_modules/tslint/lib/language/walker/walker.js b/node_modules/tslint/lib/language/walker/walker.js new file mode 100644 index 000000000..ef0ff1828 --- /dev/null +++ b/node_modules/tslint/lib/language/walker/walker.js @@ -0,0 +1,34 @@ +"use strict"; +/** + * @license + * Copyright 2017 Palantir Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +Object.defineProperty(exports, "__esModule", { value: true }); +var tslib_1 = require("tslib"); +var walkContext_1 = require("./walkContext"); +var AbstractWalker = (function (_super) { + tslib_1.__extends(AbstractWalker, _super); + function AbstractWalker() { + return _super !== null && _super.apply(this, arguments) || this; + } + AbstractWalker.prototype.getSourceFile = function () { + return this.sourceFile; + }; + AbstractWalker.prototype.getFailures = function () { + return this.failures; + }; + return AbstractWalker; +}(walkContext_1.WalkContext)); +exports.AbstractWalker = AbstractWalker; |