aboutsummaryrefslogtreecommitdiff
path: root/node_modules/tslint/lib/rules
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/tslint/lib/rules')
-rw-r--r--node_modules/tslint/lib/rules/arrowParensRule.js4
-rw-r--r--node_modules/tslint/lib/rules/awaitPromiseRule.d.ts1
-rw-r--r--node_modules/tslint/lib/rules/awaitPromiseRule.js36
-rw-r--r--node_modules/tslint/lib/rules/banCommaOperatorRule.d.ts7
-rw-r--r--node_modules/tslint/lib/rules/banCommaOperatorRule.js53
-rw-r--r--node_modules/tslint/lib/rules/callableTypesRule.js15
-rw-r--r--node_modules/tslint/lib/rules/completed-docs/blockExclusion.d.ts26
-rw-r--r--node_modules/tslint/lib/rules/completed-docs/blockExclusion.js42
-rw-r--r--node_modules/tslint/lib/rules/completed-docs/classExclusion.d.ts30
-rw-r--r--node_modules/tslint/lib/rules/completed-docs/classExclusion.js59
-rw-r--r--node_modules/tslint/lib/rules/completed-docs/exclusion.d.ts25
-rw-r--r--node_modules/tslint/lib/rules/completed-docs/exclusion.js33
-rw-r--r--node_modules/tslint/lib/rules/completed-docs/exclusionDescriptors.d.ts28
-rw-r--r--node_modules/tslint/lib/rules/completed-docs/exclusionDescriptors.js18
-rw-r--r--node_modules/tslint/lib/rules/completed-docs/exclusionFactory.d.ts8
-rw-r--r--node_modules/tslint/lib/rules/completed-docs/exclusionFactory.js60
-rw-r--r--node_modules/tslint/lib/rules/completed-docs/tagExclusion.d.ts34
-rw-r--r--node_modules/tslint/lib/rules/completed-docs/tagExclusion.js82
-rw-r--r--node_modules/tslint/lib/rules/completedDocsRule.d.ts38
-rw-r--r--node_modules/tslint/lib/rules/completedDocsRule.js301
-rw-r--r--node_modules/tslint/lib/rules/curlyRule.js27
-rw-r--r--node_modules/tslint/lib/rules/deprecationRule.js35
-rw-r--r--node_modules/tslint/lib/rules/importBlacklistRule.js45
-rw-r--r--node_modules/tslint/lib/rules/jsdocFormatRule.js27
-rw-r--r--node_modules/tslint/lib/rules/maxClassesPerFileRule.js18
-rw-r--r--node_modules/tslint/lib/rules/memberAccessRule.js34
-rw-r--r--node_modules/tslint/lib/rules/memberOrderingRule.js11
-rw-r--r--node_modules/tslint/lib/rules/noAngleBracketTypeAssertionRule.js17
-rw-r--r--node_modules/tslint/lib/rules/noConditionalAssignmentRule.d.ts16
-rw-r--r--node_modules/tslint/lib/rules/noConditionalAssignmentRule.js119
-rw-r--r--node_modules/tslint/lib/rules/noDuplicateImportsRule.js44
-rw-r--r--node_modules/tslint/lib/rules/noDuplicateSwitchCaseRule.d.ts23
-rw-r--r--node_modules/tslint/lib/rules/noDuplicateSwitchCaseRule.js65
-rw-r--r--node_modules/tslint/lib/rules/noEmptyInterfaceRule.js15
-rw-r--r--node_modules/tslint/lib/rules/noImplicitDependenciesRule.d.ts7
-rw-r--r--node_modules/tslint/lib/rules/noImplicitDependenciesRule.js132
-rw-r--r--node_modules/tslint/lib/rules/noInvalidThisRule.d.ts18
-rw-r--r--node_modules/tslint/lib/rules/noInvalidThisRule.js6
-rw-r--r--node_modules/tslint/lib/rules/noNonNullAssertionRule.js2
-rw-r--r--node_modules/tslint/lib/rules/noRedundantJsdocRule.d.ts9
-rw-r--r--node_modules/tslint/lib/rules/noRedundantJsdocRule.js133
-rw-r--r--node_modules/tslint/lib/rules/noReferenceImportRule.js63
-rw-r--r--node_modules/tslint/lib/rules/noRequireImportsRule.js18
-rw-r--r--node_modules/tslint/lib/rules/noReturnAwaitRule.d.ts7
-rw-r--r--node_modules/tslint/lib/rules/noReturnAwaitRule.js110
-rw-r--r--node_modules/tslint/lib/rules/noShadowedVariableRule.js2
-rw-r--r--node_modules/tslint/lib/rules/noStringLiteralRule.js4
-rw-r--r--node_modules/tslint/lib/rules/noSubmoduleImportsRule.js72
-rw-r--r--node_modules/tslint/lib/rules/noTrailingWhitespaceRule.js9
-rw-r--r--node_modules/tslint/lib/rules/noUnboundMethodRule.js1
-rw-r--r--node_modules/tslint/lib/rules/noUnnecessaryClassRule.d.ts25
-rw-r--r--node_modules/tslint/lib/rules/noUnnecessaryClassRule.js113
-rw-r--r--node_modules/tslint/lib/rules/noUnnecessaryQualifierRule.js2
-rw-r--r--node_modules/tslint/lib/rules/noUnnecessaryTypeAssertionRule.js26
-rw-r--r--node_modules/tslint/lib/rules/noUnsafeAnyRule.js360
-rw-r--r--node_modules/tslint/lib/rules/noUnusedVariableRule.js24
-rw-r--r--node_modules/tslint/lib/rules/noVarRequiresRule.js3
-rw-r--r--node_modules/tslint/lib/rules/objectLiteralShorthandRule.d.ts3
-rw-r--r--node_modules/tslint/lib/rules/objectLiteralShorthandRule.js40
-rw-r--r--node_modules/tslint/lib/rules/objectLiteralSortKeysRule.js26
-rw-r--r--node_modules/tslint/lib/rules/oneLineRule.d.ts4
-rw-r--r--node_modules/tslint/lib/rules/oneLineRule.js280
-rw-r--r--node_modules/tslint/lib/rules/onlyArrowFunctionsRule.js13
-rw-r--r--node_modules/tslint/lib/rules/orderedImportsRule.d.ts1
-rw-r--r--node_modules/tslint/lib/rules/orderedImportsRule.js156
-rw-r--r--node_modules/tslint/lib/rules/preferConstRule.js3
-rw-r--r--node_modules/tslint/lib/rules/restrictPlusOperandsRule.d.ts1
-rw-r--r--node_modules/tslint/lib/rules/restrictPlusOperandsRule.js8
-rw-r--r--node_modules/tslint/lib/rules/returnUndefinedRule.js33
-rw-r--r--node_modules/tslint/lib/rules/semicolonRule.js14
-rw-r--r--node_modules/tslint/lib/rules/spaceBeforeFunctionParenRule.js13
-rw-r--r--node_modules/tslint/lib/rules/strictBooleanExpressionsRule.js2
-rw-r--r--node_modules/tslint/lib/rules/trailingCommaRule.d.ts1
-rw-r--r--node_modules/tslint/lib/rules/trailingCommaRule.js77
-rw-r--r--node_modules/tslint/lib/rules/typeofCompareRule.js3
-rw-r--r--node_modules/tslint/lib/rules/variableNameRule.js2
-rw-r--r--node_modules/tslint/lib/rules/whitespaceRule.js1
77 files changed, 2270 insertions, 953 deletions
diff --git a/node_modules/tslint/lib/rules/arrowParensRule.js b/node_modules/tslint/lib/rules/arrowParensRule.js
index 6fa9f5537..5af83227d 100644
--- a/node_modules/tslint/lib/rules/arrowParensRule.js
+++ b/node_modules/tslint/lib/rules/arrowParensRule.js
@@ -70,8 +70,8 @@ function walk(ctx) {
else if (ctx.options.banSingleArgParens) {
var closeParen = tsutils_1.getChildOfKind(node, ts.SyntaxKind.CloseParenToken);
ctx.addFailureAtNode(node.parameters[0], Rule.FAILURE_STRING_EXISTS, [
- Lint.Replacement.deleteText(openParen.end - 1, 1),
- Lint.Replacement.deleteText(closeParen.end - 1, 1),
+ Lint.Replacement.replaceFromTo(openParen.pos, node.parameters[0].getStart(ctx.sourceFile), " "),
+ Lint.Replacement.deleteFromTo(node.parameters[0].end, closeParen.end),
]);
}
}
diff --git a/node_modules/tslint/lib/rules/awaitPromiseRule.d.ts b/node_modules/tslint/lib/rules/awaitPromiseRule.d.ts
index d2d51d1d1..b5a31ed7b 100644
--- a/node_modules/tslint/lib/rules/awaitPromiseRule.d.ts
+++ b/node_modules/tslint/lib/rules/awaitPromiseRule.d.ts
@@ -3,5 +3,6 @@ import * as Lint from "../index";
export declare class Rule extends Lint.Rules.TypedRule {
static metadata: Lint.IRuleMetadata;
static FAILURE_STRING: string;
+ static FAILURE_FOR_AWAIT_OF: string;
applyWithProgram(sourceFile: ts.SourceFile, program: ts.Program): Lint.RuleFailure[];
}
diff --git a/node_modules/tslint/lib/rules/awaitPromiseRule.js b/node_modules/tslint/lib/rules/awaitPromiseRule.js
index 69855f49f..cb1c35b08 100644
--- a/node_modules/tslint/lib/rules/awaitPromiseRule.js
+++ b/node_modules/tslint/lib/rules/awaitPromiseRule.js
@@ -47,7 +47,8 @@ var Rule = /** @class */ (function (_super) {
requiresTypeInfo: true,
};
/* tslint:enable:object-literal-sort-keys */
- Rule.FAILURE_STRING = "'await' of non-Promise.";
+ Rule.FAILURE_STRING = "Invalid 'await' of a non-Promise value.";
+ Rule.FAILURE_FOR_AWAIT_OF = "Invalid 'for-await-of' of a non-AsyncIterable value.";
return Rule;
}(Lint.Rules.TypedRule));
exports.Rule = Rule;
@@ -55,24 +56,31 @@ function walk(ctx, tc) {
var promiseTypes = ctx.options;
return ts.forEachChild(ctx.sourceFile, cb);
function cb(node) {
- if (tsutils_1.isAwaitExpression(node) && !couldBePromise(tc.getTypeAtLocation(node.expression))) {
+ if (tsutils_1.isAwaitExpression(node) && !containsType(tc.getTypeAtLocation(node.expression), isPromiseType)) {
ctx.addFailureAtNode(node, Rule.FAILURE_STRING);
}
+ else if (tsutils_1.isForOfStatement(node) && node.awaitModifier !== undefined &&
+ !containsType(tc.getTypeAtLocation(node.expression), isAsyncIterable)) {
+ ctx.addFailureAtNode(node.expression, Rule.FAILURE_FOR_AWAIT_OF);
+ }
return ts.forEachChild(node, cb);
}
- function couldBePromise(type) {
- if (Lint.isTypeFlagSet(type, ts.TypeFlags.Any) || isPromiseType(type)) {
- return true;
- }
- if (tsutils_1.isUnionOrIntersectionType(type)) {
- return type.types.some(couldBePromise);
- }
- var bases = type.getBaseTypes();
- return bases !== undefined && bases.some(couldBePromise);
+ function isPromiseType(name) {
+ return promiseTypes.has(name);
}
- function isPromiseType(type) {
- var target = type.target;
- return target !== undefined && target.symbol !== undefined && promiseTypes.has(target.symbol.name);
+}
+function containsType(type, predicate) {
+ if (Lint.isTypeFlagSet(type, ts.TypeFlags.Any) ||
+ tsutils_1.isTypeReference(type) && type.target.symbol !== undefined && predicate(type.target.symbol.name)) {
+ return true;
+ }
+ if (tsutils_1.isUnionOrIntersectionType(type)) {
+ return type.types.some(function (t) { return containsType(t, predicate); });
}
+ var bases = type.getBaseTypes();
+ return bases !== undefined && bases.some(function (t) { return containsType(t, predicate); });
+}
+function isAsyncIterable(name) {
+ return name === "AsyncIterable" || name === "AsyncIterableIterator";
}
var _a;
diff --git a/node_modules/tslint/lib/rules/banCommaOperatorRule.d.ts b/node_modules/tslint/lib/rules/banCommaOperatorRule.d.ts
new file mode 100644
index 000000000..cce59d100
--- /dev/null
+++ b/node_modules/tslint/lib/rules/banCommaOperatorRule.d.ts
@@ -0,0 +1,7 @@
+import * as ts from "typescript";
+import * as Lint from "../index";
+export declare class Rule extends Lint.Rules.AbstractRule {
+ static metadata: Lint.IRuleMetadata;
+ static FAILURE_STRING: string;
+ apply(sourceFile: ts.SourceFile): Lint.RuleFailure[];
+}
diff --git a/node_modules/tslint/lib/rules/banCommaOperatorRule.js b/node_modules/tslint/lib/rules/banCommaOperatorRule.js
new file mode 100644
index 000000000..2a5bcede0
--- /dev/null
+++ b/node_modules/tslint/lib/rules/banCommaOperatorRule.js
@@ -0,0 +1,53 @@
+"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 tsutils_1 = require("tsutils");
+var ts = require("typescript");
+var Lint = require("../index");
+var Rule = /** @class */ (function (_super) {
+ tslib_1.__extends(Rule, _super);
+ function Rule() {
+ return _super !== null && _super.apply(this, arguments) || this;
+ }
+ Rule.prototype.apply = function (sourceFile) {
+ return this.applyWithFunction(sourceFile, walk);
+ };
+ /* tslint:disable:object-literal-sort-keys */
+ Rule.metadata = {
+ ruleName: "ban-comma-operator",
+ description: "Bans the comma operator.",
+ options: null,
+ optionsDescription: "",
+ optionExamples: [true],
+ type: "typescript",
+ typescriptOnly: true,
+ };
+ /* tslint:enable:object-literal-sort-keys */
+ Rule.FAILURE_STRING = "Don't use the comma operator.";
+ return Rule;
+}(Lint.Rules.AbstractRule));
+exports.Rule = Rule;
+function walk(ctx) {
+ return ts.forEachChild(ctx.sourceFile, function cb(node) {
+ if (tsutils_1.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.CommaToken) {
+ ctx.addFailureAtNode(node, Rule.FAILURE_STRING);
+ }
+ return ts.forEachChild(node, cb);
+ });
+}
diff --git a/node_modules/tslint/lib/rules/callableTypesRule.js b/node_modules/tslint/lib/rules/callableTypesRule.js
index 07bd7bd0f..8c4813225 100644
--- a/node_modules/tslint/lib/rules/callableTypesRule.js
+++ b/node_modules/tslint/lib/rules/callableTypesRule.js
@@ -48,8 +48,7 @@ var Rule = /** @class */ (function (_super) {
exports.Rule = Rule;
function walk(ctx) {
return ts.forEachChild(ctx.sourceFile, function cb(node) {
- if ((tsutils_1.isInterfaceDeclaration(node) && noSupertype(node)
- || tsutils_1.isTypeLiteralNode(node))
+ if ((tsutils_1.isInterfaceDeclaration(node) && noSupertype(node) || tsutils_1.isTypeLiteralNode(node))
&& node.members.length === 1) {
var member = node.members[0];
if (tsutils_1.isCallSignatureDeclaration(member) &&
@@ -81,6 +80,9 @@ function renderSuggestion(call, parent, sourceFile) {
var colonPos = call.type.pos - 1 - start;
var text = sourceFile.text.substring(start, call.end);
var suggestion = text.substr(0, colonPos) + " =>" + text.substr(colonPos + 1);
+ if (shouldWrapSuggestion(parent.parent)) {
+ suggestion = "(" + suggestion + ")";
+ }
if (parent.kind === ts.SyntaxKind.InterfaceDeclaration) {
if (parent.typeParameters !== undefined) {
return "type" + sourceFile.text.substring(parent.name.pos, parent.typeParameters.end + 1) + " = " + suggestion;
@@ -91,3 +93,12 @@ function renderSuggestion(call, parent, sourceFile) {
}
return suggestion.endsWith(";") ? suggestion.slice(0, -1) : suggestion;
}
+function shouldWrapSuggestion(parent) {
+ switch (parent.kind) {
+ case ts.SyntaxKind.UnionType:
+ case ts.SyntaxKind.IntersectionType:
+ return true;
+ default:
+ return false;
+ }
+}
diff --git a/node_modules/tslint/lib/rules/completed-docs/blockExclusion.d.ts b/node_modules/tslint/lib/rules/completed-docs/blockExclusion.d.ts
new file mode 100644
index 000000000..57eea1745
--- /dev/null
+++ b/node_modules/tslint/lib/rules/completed-docs/blockExclusion.d.ts
@@ -0,0 +1,26 @@
+/**
+ * @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 { Visibility } from "../completedDocsRule";
+import { Exclusion } from "./exclusion";
+export interface IBlockExclusionDescriptor {
+ visibilities?: Visibility[];
+}
+export declare class BlockExclusion extends Exclusion<IBlockExclusionDescriptor> {
+ readonly visibilities: Set<Visibility>;
+ excludes(node: ts.Node): boolean;
+}
diff --git a/node_modules/tslint/lib/rules/completed-docs/blockExclusion.js b/node_modules/tslint/lib/rules/completed-docs/blockExclusion.js
new file mode 100644
index 000000000..fdc7dabd0
--- /dev/null
+++ b/node_modules/tslint/lib/rules/completed-docs/blockExclusion.js
@@ -0,0 +1,42 @@
+"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 ts = require("typescript");
+var Lint = require("../../index");
+var completedDocsRule_1 = require("../completedDocsRule");
+var exclusion_1 = require("./exclusion");
+var BlockExclusion = /** @class */ (function (_super) {
+ tslib_1.__extends(BlockExclusion, _super);
+ function BlockExclusion() {
+ var _this = _super !== null && _super.apply(this, arguments) || this;
+ _this.visibilities = _this.createSet(_this.descriptor.visibilities);
+ return _this;
+ }
+ BlockExclusion.prototype.excludes = function (node) {
+ if (this.visibilities.has(completedDocsRule_1.ALL)) {
+ return false;
+ }
+ if (Lint.hasModifier(node.modifiers, ts.SyntaxKind.ExportKeyword)) {
+ return !this.visibilities.has(completedDocsRule_1.VISIBILITY_EXPORTED);
+ }
+ return !this.visibilities.has(completedDocsRule_1.VISIBILITY_INTERNAL);
+ };
+ return BlockExclusion;
+}(exclusion_1.Exclusion));
+exports.BlockExclusion = BlockExclusion;
diff --git a/node_modules/tslint/lib/rules/completed-docs/classExclusion.d.ts b/node_modules/tslint/lib/rules/completed-docs/classExclusion.d.ts
new file mode 100644
index 000000000..a6f24bbe7
--- /dev/null
+++ b/node_modules/tslint/lib/rules/completed-docs/classExclusion.d.ts
@@ -0,0 +1,30 @@
+/**
+ * @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 { Location, Privacy } from "../completedDocsRule";
+import { Exclusion } from "./exclusion";
+export interface IClassExclusionDescriptor {
+ locations?: Location[];
+ privacies?: Privacy[];
+}
+export declare class ClassExclusion extends Exclusion<IClassExclusionDescriptor> {
+ readonly locations: Set<Location>;
+ readonly privacies: Set<Privacy>;
+ excludes(node: ts.Node): boolean;
+ private shouldLocationBeDocumented(node);
+ private shouldPrivacyBeDocumented(node);
+}
diff --git a/node_modules/tslint/lib/rules/completed-docs/classExclusion.js b/node_modules/tslint/lib/rules/completed-docs/classExclusion.js
new file mode 100644
index 000000000..4c8c8ec57
--- /dev/null
+++ b/node_modules/tslint/lib/rules/completed-docs/classExclusion.js
@@ -0,0 +1,59 @@
+"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 Lint = require("../../index");
+var completedDocsRule_1 = require("../completedDocsRule");
+var exclusion_1 = require("./exclusion");
+var ClassExclusion = /** @class */ (function (_super) {
+ tslib_1.__extends(ClassExclusion, _super);
+ function ClassExclusion() {
+ var _this = _super !== null && _super.apply(this, arguments) || this;
+ _this.locations = _this.createSet(_this.descriptor.locations);
+ _this.privacies = _this.createSet(_this.descriptor.privacies);
+ return _this;
+ }
+ ClassExclusion.prototype.excludes = function (node) {
+ return !(this.shouldLocationBeDocumented(node)
+ && this.shouldPrivacyBeDocumented(node));
+ };
+ ClassExclusion.prototype.shouldLocationBeDocumented = function (node) {
+ if (this.locations.has(completedDocsRule_1.ALL)) {
+ return true;
+ }
+ if (Lint.hasModifier(node.modifiers, ts.SyntaxKind.StaticKeyword)) {
+ return this.locations.has(completedDocsRule_1.LOCATION_STATIC);
+ }
+ return this.locations.has(completedDocsRule_1.LOCATION_INSTANCE);
+ };
+ ClassExclusion.prototype.shouldPrivacyBeDocumented = function (node) {
+ if (this.privacies.has(completedDocsRule_1.ALL)) {
+ return true;
+ }
+ if (Lint.hasModifier(node.modifiers, ts.SyntaxKind.PrivateKeyword)) {
+ return this.privacies.has(completedDocsRule_1.PRIVACY_PRIVATE);
+ }
+ if (Lint.hasModifier(node.modifiers, ts.SyntaxKind.ProtectedKeyword)) {
+ return this.privacies.has(completedDocsRule_1.PRIVACY_PROTECTED);
+ }
+ return this.privacies.has(completedDocsRule_1.PRIVACY_PUBLIC);
+ };
+ return ClassExclusion;
+}(exclusion_1.Exclusion));
+exports.ClassExclusion = ClassExclusion;
diff --git a/node_modules/tslint/lib/rules/completed-docs/exclusion.d.ts b/node_modules/tslint/lib/rules/completed-docs/exclusion.d.ts
new file mode 100644
index 000000000..49c905491
--- /dev/null
+++ b/node_modules/tslint/lib/rules/completed-docs/exclusion.d.ts
@@ -0,0 +1,25 @@
+/**
+ * @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 { All } from "../completedDocsRule";
+import { ExclusionDescriptor } from "./exclusionDescriptors";
+export declare abstract class Exclusion<TDescriptor extends ExclusionDescriptor> {
+ protected readonly descriptor: Partial<TDescriptor>;
+ constructor(descriptor?: Partial<TDescriptor>);
+ abstract excludes(node: ts.Node): boolean;
+ protected createSet<T extends All | string>(values?: T[]): Set<T>;
+}
diff --git a/node_modules/tslint/lib/rules/completed-docs/exclusion.js b/node_modules/tslint/lib/rules/completed-docs/exclusion.js
new file mode 100644
index 000000000..ff22207c6
--- /dev/null
+++ b/node_modules/tslint/lib/rules/completed-docs/exclusion.js
@@ -0,0 +1,33 @@
+"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 completedDocsRule_1 = require("../completedDocsRule");
+var Exclusion = /** @class */ (function () {
+ function Exclusion(descriptor) {
+ if (descriptor === void 0) { descriptor = {}; }
+ this.descriptor = descriptor;
+ }
+ Exclusion.prototype.createSet = function (values) {
+ if (values === undefined || values.length === 0) {
+ values = [completedDocsRule_1.ALL];
+ }
+ return new Set(values);
+ };
+ return Exclusion;
+}());
+exports.Exclusion = Exclusion;
diff --git a/node_modules/tslint/lib/rules/completed-docs/exclusionDescriptors.d.ts b/node_modules/tslint/lib/rules/completed-docs/exclusionDescriptors.d.ts
new file mode 100644
index 000000000..9fa377421
--- /dev/null
+++ b/node_modules/tslint/lib/rules/completed-docs/exclusionDescriptors.d.ts
@@ -0,0 +1,28 @@
+/**
+ * @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 { DocType } from "../completedDocsRule";
+import { IBlockExclusionDescriptor } from "./blockExclusion";
+import { IClassExclusionDescriptor } from "./classExclusion";
+import { ITagExclusionDescriptor } from "./tagExclusion";
+export declare type ExclusionDescriptor = IBlockExclusionDescriptor | IClassExclusionDescriptor | ITagExclusionDescriptor;
+export declare type InputExclusionDescriptor = boolean | ExclusionDescriptor;
+export interface IExclusionDescriptors {
+ [type: string]: ExclusionDescriptor;
+}
+export declare type IInputExclusionDescriptors = DocType | {
+ [type: string]: InputExclusionDescriptor;
+};
diff --git a/node_modules/tslint/lib/rules/completed-docs/exclusionDescriptors.js b/node_modules/tslint/lib/rules/completed-docs/exclusionDescriptors.js
new file mode 100644
index 000000000..1c258a5da
--- /dev/null
+++ b/node_modules/tslint/lib/rules/completed-docs/exclusionDescriptors.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/rules/completed-docs/exclusionFactory.d.ts b/node_modules/tslint/lib/rules/completed-docs/exclusionFactory.d.ts
new file mode 100644
index 000000000..aacf39d73
--- /dev/null
+++ b/node_modules/tslint/lib/rules/completed-docs/exclusionFactory.d.ts
@@ -0,0 +1,8 @@
+import { DocType } from "../completedDocsRule";
+import { Exclusion } from "./exclusion";
+import { IInputExclusionDescriptors } from "./exclusionDescriptors";
+export declare class ExclusionFactory {
+ constructExclusionsMap(ruleArguments: IInputExclusionDescriptors[]): Map<DocType, Array<Exclusion<any>>>;
+ private addRequirements(exclusionsMap, descriptors);
+ private createRequirementsForDocType(docType, descriptor);
+}
diff --git a/node_modules/tslint/lib/rules/completed-docs/exclusionFactory.js b/node_modules/tslint/lib/rules/completed-docs/exclusionFactory.js
new file mode 100644
index 000000000..6b8f5f35a
--- /dev/null
+++ b/node_modules/tslint/lib/rules/completed-docs/exclusionFactory.js
@@ -0,0 +1,60 @@
+"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");
+var blockExclusion_1 = require("./blockExclusion");
+var classExclusion_1 = require("./classExclusion");
+var tagExclusion_1 = require("./tagExclusion");
+var ExclusionFactory = /** @class */ (function () {
+ function ExclusionFactory() {
+ }
+ ExclusionFactory.prototype.constructExclusionsMap = function (ruleArguments) {
+ var exclusionsMap = new Map();
+ for (var _i = 0, ruleArguments_1 = ruleArguments; _i < ruleArguments_1.length; _i++) {
+ var ruleArgument = ruleArguments_1[_i];
+ this.addRequirements(exclusionsMap, ruleArgument);
+ }
+ return exclusionsMap;
+ };
+ ExclusionFactory.prototype.addRequirements = function (exclusionsMap, descriptors) {
+ if (typeof descriptors === "string") {
+ exclusionsMap.set(descriptors, this.createRequirementsForDocType(descriptors, {}));
+ return;
+ }
+ for (var docType in descriptors) {
+ if (utils_1.hasOwnProperty(descriptors, docType)) {
+ exclusionsMap.set(docType, this.createRequirementsForDocType(docType, descriptors[docType]));
+ }
+ }
+ };
+ ExclusionFactory.prototype.createRequirementsForDocType = function (docType, descriptor) {
+ var requirements = [];
+ if (docType === "methods" || docType === "properties") {
+ requirements.push(new classExclusion_1.ClassExclusion(descriptor));
+ }
+ else {
+ requirements.push(new blockExclusion_1.BlockExclusion(descriptor));
+ }
+ if (descriptor.tags !== undefined) {
+ requirements.push(new tagExclusion_1.TagExclusion(descriptor));
+ }
+ return requirements;
+ };
+ return ExclusionFactory;
+}());
+exports.ExclusionFactory = ExclusionFactory;
diff --git a/node_modules/tslint/lib/rules/completed-docs/tagExclusion.d.ts b/node_modules/tslint/lib/rules/completed-docs/tagExclusion.d.ts
new file mode 100644
index 000000000..d13121323
--- /dev/null
+++ b/node_modules/tslint/lib/rules/completed-docs/tagExclusion.d.ts
@@ -0,0 +1,34 @@
+/**
+ * @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 { Exclusion } from "./exclusion";
+export interface ITagExclusionDescriptor {
+ tags?: {
+ content: IContentTags;
+ existence: string[];
+ };
+}
+export interface IContentTags {
+ [i: string]: string;
+}
+export declare class TagExclusion extends Exclusion<ITagExclusionDescriptor> {
+ private readonly contentTags;
+ private readonly existenceTags;
+ excludes(node: ts.Node): boolean;
+ private getDocumentationNode(node);
+ private parseTagsWithContents(nodeText);
+}
diff --git a/node_modules/tslint/lib/rules/completed-docs/tagExclusion.js b/node_modules/tslint/lib/rules/completed-docs/tagExclusion.js
new file mode 100644
index 000000000..78e9babe7
--- /dev/null
+++ b/node_modules/tslint/lib/rules/completed-docs/tagExclusion.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 exclusion_1 = require("./exclusion");
+var TagExclusion = /** @class */ (function (_super) {
+ tslib_1.__extends(TagExclusion, _super);
+ function TagExclusion() {
+ var _this = _super !== null && _super.apply(this, arguments) || this;
+ _this.contentTags = _this.descriptor.tags === undefined
+ ? {}
+ : _this.descriptor.tags.content;
+ _this.existenceTags = new Set(_this.descriptor.tags !== undefined && _this.descriptor.tags.existence !== undefined
+ ? _this.descriptor.tags.existence
+ : undefined);
+ return _this;
+ }
+ TagExclusion.prototype.excludes = function (node) {
+ var documentationNode = this.getDocumentationNode(node);
+ var tagsWithContents = this.parseTagsWithContents(documentationNode.getFullText());
+ for (var _i = 0, tagsWithContents_1 = tagsWithContents; _i < tagsWithContents_1.length; _i++) {
+ var tagWithContent = tagsWithContents_1[_i];
+ if (this.existenceTags.has(tagWithContent[0])) {
+ return true;
+ }
+ var matcherBody = this.contentTags[tagWithContent[0]];
+ if (matcherBody === undefined) {
+ continue;
+ }
+ if (new RegExp(matcherBody).test(tagWithContent[1])) {
+ return true;
+ }
+ }
+ return false;
+ };
+ TagExclusion.prototype.getDocumentationNode = function (node) {
+ if (node.kind === ts.SyntaxKind.VariableDeclaration) {
+ return node.parent;
+ }
+ return node;
+ };
+ TagExclusion.prototype.parseTagsWithContents = function (nodeText) {
+ if (nodeText === undefined) {
+ return [];
+ }
+ var docMatches = nodeText.match((/\/\*\*\s*\n([^\*]*(\*[^\/])?)*\*\//));
+ if (docMatches === null || docMatches.length === 0) {
+ return [];
+ }
+ var lines = docMatches[0].match(/[\r\n\s]*\*\s*@.*[\r\n\s]/g);
+ if (lines === null) {
+ return [];
+ }
+ return lines
+ .map(function (line) {
+ var body = line.substring(line.indexOf("@"));
+ var firstSpaceIndex = body.search(/\s/);
+ return [
+ body.substring(1, firstSpaceIndex),
+ body.substring(firstSpaceIndex).trim(),
+ ];
+ });
+ };
+ return TagExclusion;
+}(exclusion_1.Exclusion));
+exports.TagExclusion = TagExclusion;
diff --git a/node_modules/tslint/lib/rules/completedDocsRule.d.ts b/node_modules/tslint/lib/rules/completedDocsRule.d.ts
index 560f436e7..67c76d562 100644
--- a/node_modules/tslint/lib/rules/completedDocsRule.d.ts
+++ b/node_modules/tslint/lib/rules/completedDocsRule.d.ts
@@ -1,16 +1,6 @@
import * as ts from "typescript";
import * as Lint from "../index";
-export interface IBlockRequirementDescriptor {
- visibilities?: Visibility[];
-}
-export interface IClassRequirementDescriptor {
- locations?: Location[];
- privacies?: Privacy[];
-}
-export declare type RequirementDescriptor = IBlockRequirementDescriptor | IClassRequirementDescriptor;
-export interface IRequirementDescriptors {
- [type: string]: RequirementDescriptor;
-}
+import { IInputExclusionDescriptors } from "./completed-docs/exclusionDescriptors";
export declare const ALL = "all";
export declare const ARGUMENT_CLASSES = "classes";
export declare const ARGUMENT_ENUMS = "enums";
@@ -22,6 +12,7 @@ export declare const ARGUMENT_NAMESPACES = "namespaces";
export declare const ARGUMENT_PROPERTIES = "properties";
export declare const ARGUMENT_TYPES = "types";
export declare const ARGUMENT_VARIABLES = "variables";
+export declare const DESCRIPTOR_TAGS = "tags";
export declare const DESCRIPTOR_LOCATIONS = "locations";
export declare const DESCRIPTOR_PRIVACIES = "privacies";
export declare const DESCRIPTOR_VISIBILITIES = "visibilities";
@@ -30,6 +21,8 @@ export declare const LOCATION_STATIC = "static";
export declare const PRIVACY_PRIVATE = "private";
export declare const PRIVACY_PROTECTED = "protected";
export declare const PRIVACY_PUBLIC = "public";
+export declare const TAGS_FOR_CONTENT = "content";
+export declare const TAGS_FOR_EXISTENCE = "exists";
export declare const VISIBILITY_EXPORTED = "exported";
export declare const VISIBILITY_INTERNAL = "internal";
export declare type All = typeof ALL;
@@ -39,10 +32,19 @@ export declare type Privacy = All | typeof PRIVACY_PRIVATE | typeof PRIVACY_PROT
export declare type Visibility = All | typeof VISIBILITY_EXPORTED | typeof VISIBILITY_INTERNAL;
export declare class Rule extends Lint.Rules.TypedRule {
static FAILURE_STRING_EXIST: string;
- static defaultArguments: DocType[];
+ static defaultArguments: IInputExclusionDescriptors;
static ARGUMENT_DESCRIPTOR_BLOCK: {
properties: {
[x: string]: {
+ properties: {
+ [x: string]: {
+ items: {
+ type: string;
+ };
+ type: string;
+ };
+ };
+ } | {
enum: string[];
type: string;
};
@@ -52,6 +54,15 @@ export declare class Rule extends Lint.Rules.TypedRule {
static ARGUMENT_DESCRIPTOR_CLASS: {
properties: {
[x: string]: {
+ properties: {
+ [x: string]: {
+ items: {
+ type: string;
+ };
+ type: string;
+ };
+ };
+ } | {
enum: string[];
type: string;
};
@@ -59,6 +70,7 @@ export declare class Rule extends Lint.Rules.TypedRule {
type: string;
};
static metadata: Lint.IRuleMetadata;
+ private readonly exclusionFactory;
applyWithProgram(sourceFile: ts.SourceFile, program: ts.Program): Lint.RuleFailure[];
- private getRequirements(ruleArguments);
+ private getExclusionsMap(ruleArguments);
}
diff --git a/node_modules/tslint/lib/rules/completedDocsRule.js b/node_modules/tslint/lib/rules/completedDocsRule.js
index 5c3bf5cf2..d64315563 100644
--- a/node_modules/tslint/lib/rules/completedDocsRule.js
+++ b/node_modules/tslint/lib/rules/completedDocsRule.js
@@ -20,7 +20,7 @@ var tslib_1 = require("tslib");
var tsutils_1 = require("tsutils");
var ts = require("typescript");
var Lint = require("../index");
-var utils_1 = require("../utils");
+var exclusionFactory_1 = require("./completed-docs/exclusionFactory");
exports.ALL = "all";
exports.ARGUMENT_CLASSES = "classes";
exports.ARGUMENT_ENUMS = "enums";
@@ -32,6 +32,7 @@ exports.ARGUMENT_NAMESPACES = "namespaces";
exports.ARGUMENT_PROPERTIES = "properties";
exports.ARGUMENT_TYPES = "types";
exports.ARGUMENT_VARIABLES = "variables";
+exports.DESCRIPTOR_TAGS = "tags";
exports.DESCRIPTOR_LOCATIONS = "locations";
exports.DESCRIPTOR_PRIVACIES = "privacies";
exports.DESCRIPTOR_VISIBILITIES = "visibilities";
@@ -40,36 +41,76 @@ exports.LOCATION_STATIC = "static";
exports.PRIVACY_PRIVATE = "private";
exports.PRIVACY_PROTECTED = "protected";
exports.PRIVACY_PUBLIC = "public";
+exports.TAGS_FOR_CONTENT = "content";
+exports.TAGS_FOR_EXISTENCE = "exists";
exports.VISIBILITY_EXPORTED = "exported";
exports.VISIBILITY_INTERNAL = "internal";
var Rule = /** @class */ (function (_super) {
tslib_1.__extends(Rule, _super);
function Rule() {
- return _super !== null && _super.apply(this, arguments) || this;
+ var _this = _super !== null && _super.apply(this, arguments) || this;
+ /* tslint:enable:object-literal-sort-keys */
+ _this.exclusionFactory = new exclusionFactory_1.ExclusionFactory();
+ return _this;
}
- /* tslint:enable:object-literal-sort-keys */
Rule.prototype.applyWithProgram = function (sourceFile, program) {
var options = this.getOptions();
var completedDocsWalker = new CompletedDocsWalker(sourceFile, options, program);
- completedDocsWalker.setRequirements(this.getRequirements(options.ruleArguments));
+ completedDocsWalker.setExclusionsMap(this.getExclusionsMap(options.ruleArguments));
return this.applyWithWalker(completedDocsWalker);
};
- Rule.prototype.getRequirements = function (ruleArguments) {
+ Rule.prototype.getExclusionsMap = function (ruleArguments) {
if (ruleArguments.length === 0) {
- ruleArguments = Rule.defaultArguments;
+ ruleArguments = [Rule.defaultArguments];
}
- return Requirement.constructRequirements(ruleArguments);
+ return this.exclusionFactory.constructExclusionsMap(ruleArguments);
};
Rule.FAILURE_STRING_EXIST = "Documentation must exist for ";
- Rule.defaultArguments = [
- exports.ARGUMENT_CLASSES,
- exports.ARGUMENT_FUNCTIONS,
- exports.ARGUMENT_METHODS,
- exports.ARGUMENT_PROPERTIES,
- ];
+ Rule.defaultArguments = (_a = {},
+ _a[exports.ARGUMENT_CLASSES] = true,
+ _a[exports.ARGUMENT_FUNCTIONS] = true,
+ _a[exports.ARGUMENT_METHODS] = (_b = {},
+ _b[exports.DESCRIPTOR_TAGS] = (_c = {},
+ _c[exports.TAGS_FOR_CONTENT] = {
+ see: ".*",
+ },
+ _c[exports.TAGS_FOR_EXISTENCE] = [
+ "deprecated",
+ "inheritdoc",
+ ],
+ _c),
+ _b),
+ _a[exports.ARGUMENT_PROPERTIES] = (_d = {},
+ _d[exports.DESCRIPTOR_TAGS] = (_e = {},
+ _e[exports.TAGS_FOR_CONTENT] = {
+ see: ".*",
+ },
+ _e[exports.TAGS_FOR_EXISTENCE] = [
+ "deprecated",
+ "inheritdoc",
+ ],
+ _e),
+ _d),
+ _a);
Rule.ARGUMENT_DESCRIPTOR_BLOCK = {
- properties: (_a = {},
- _a[exports.DESCRIPTOR_VISIBILITIES] = {
+ properties: (_f = {},
+ _f[exports.DESCRIPTOR_TAGS] = {
+ properties: (_g = {},
+ _g[exports.TAGS_FOR_CONTENT] = {
+ items: {
+ type: "string",
+ },
+ type: "object",
+ },
+ _g[exports.TAGS_FOR_EXISTENCE] = {
+ items: {
+ type: "string",
+ },
+ type: "array",
+ },
+ _g),
+ },
+ _f[exports.DESCRIPTOR_VISIBILITIES] = {
enum: [
exports.ALL,
exports.VISIBILITY_EXPORTED,
@@ -77,12 +118,28 @@ var Rule = /** @class */ (function (_super) {
],
type: "string",
},
- _a),
+ _f),
type: "object",
};
Rule.ARGUMENT_DESCRIPTOR_CLASS = {
- properties: (_b = {},
- _b[exports.DESCRIPTOR_LOCATIONS] = {
+ properties: (_h = {},
+ _h[exports.DESCRIPTOR_TAGS] = {
+ properties: (_j = {},
+ _j[exports.TAGS_FOR_CONTENT] = {
+ items: {
+ type: "string",
+ },
+ type: "object",
+ },
+ _j[exports.TAGS_FOR_EXISTENCE] = {
+ items: {
+ type: "string",
+ },
+ type: "array",
+ },
+ _j),
+ },
+ _h[exports.DESCRIPTOR_LOCATIONS] = {
enum: [
exports.ALL,
exports.LOCATION_INSTANCE,
@@ -90,7 +147,7 @@ var Rule = /** @class */ (function (_super) {
],
type: "string",
},
- _b[exports.DESCRIPTOR_PRIVACIES] = {
+ _h[exports.DESCRIPTOR_PRIVACIES] = {
enum: [
exports.ALL,
exports.PRIVACY_PRIVATE,
@@ -99,36 +156,46 @@ var Rule = /** @class */ (function (_super) {
],
type: "string",
},
- _b),
+ _h),
type: "object",
};
/* tslint:disable:object-literal-sort-keys */
Rule.metadata = {
ruleName: "completed-docs",
description: "Enforces documentation for important items be filled out.",
- optionsDescription: (_c = ["\n `true` to enable for [\"", "\", \"", "\", \"", "\", \"", "\"],\n or an array with each item in one of two formats:\n\n * `string` to enable for that type\n * `object` keying types to when their documentation is required:\n * `\"", "\"` and `\"", "\"` may specify:\n * `\"", "\"`:\n * `\"", "\"`\n * `\"", "\"`\n * `\"", "\"`\n * `\"", "\"`\n * `\"", "\"`:\n * `\"", "\"`\n * `\"", "\"`\n * `\"", "\"`\n * All other types may specify `\"", "\"`:\n * `\"", "\"`\n * `\"", "\"`\n * `\"", "\"`\n\n Types that may be enabled are:\n\n * `\"", "\"`\n * `\"", "\"`\n * `\"", "\"`\n * `\"", "\"`\n * `\"", "\"`\n * `\"", "\"`\n * `\"", "\"`\n * `\"", "\"`\n * `\"", "\"`\n * `\"", "\"`"], _c.raw = ["\n \\`true\\` to enable for [\"", "\", \"", "\", \"", "\", \"", "\"],\n or an array with each item in one of two formats:\n\n * \\`string\\` to enable for that type\n * \\`object\\` keying types to when their documentation is required:\n * \\`\"", "\"\\` and \\`\"", "\"\\` may specify:\n * \\`\"", "\"\\`:\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`:\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n * All other types may specify \\`\"", "\"\\`:\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n\n Types that may be enabled are:\n\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`"], Lint.Utils.dedent(_c, exports.ARGUMENT_CLASSES, exports.ARGUMENT_FUNCTIONS, exports.ARGUMENT_METHODS, exports.ARGUMENT_PROPERTIES, exports.ARGUMENT_METHODS, exports.ARGUMENT_PROPERTIES, exports.DESCRIPTOR_PRIVACIES, exports.ALL, exports.PRIVACY_PRIVATE, exports.PRIVACY_PROTECTED, exports.PRIVACY_PUBLIC, exports.DESCRIPTOR_LOCATIONS, exports.ALL, exports.LOCATION_INSTANCE, exports.LOCATION_STATIC, exports.DESCRIPTOR_VISIBILITIES, exports.ALL, exports.VISIBILITY_EXPORTED, exports.VISIBILITY_INTERNAL, exports.ARGUMENT_CLASSES, exports.ARGUMENT_ENUMS, exports.ARGUMENT_ENUM_MEMBERS, exports.ARGUMENT_FUNCTIONS, exports.ARGUMENT_INTERFACES, exports.ARGUMENT_METHODS, exports.ARGUMENT_NAMESPACES, exports.ARGUMENT_PROPERTIES, exports.ARGUMENT_TYPES, exports.ARGUMENT_VARIABLES)),
+ optionsDescription: (_k = ["\n `true` to enable for [", "]],\n or an array with each item in one of two formats:\n\n * `string` to enable for that type\n * `object` keying types to when their documentation is required:\n * `\"", "\"` and `\"", "\"` may specify:\n * `\"", "\"`:\n * `\"", "\"`\n * `\"", "\"`\n * `\"", "\"`\n * `\"", "\"`\n * `\"", "\"`:\n * `\"", "\"`\n * `\"", "\"`\n * `\"", "\"`\n * Other types may specify `\"", "\"`:\n * `\"", "\"`\n * `\"", "\"`\n * `\"", "\"`\n * All types may also provide `\"", "\"`\n with members specifying tags that allow the docs to not have a body.\n * `\"", "\"`: Object mapping tags to `RegExp` bodies content allowed to count as complete docs.\n * `\"", "\"`: Array of tags that must only exist to count as complete docs.\n\n Types that may be enabled are:\n\n * `\"", "\"`\n * `\"", "\"`\n * `\"", "\"`\n * `\"", "\"`\n * `\"", "\"`\n * `\"", "\"`\n * `\"", "\"`\n * `\"", "\"`\n * `\"", "\"`\n * `\"", "\"`"], _k.raw = ["\n \\`true\\` to enable for [", "]],\n or an array with each item in one of two formats:\n\n * \\`string\\` to enable for that type\n * \\`object\\` keying types to when their documentation is required:\n * \\`\"", "\"\\` and \\`\"", "\"\\` may specify:\n * \\`\"", "\"\\`:\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`:\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n * Other types may specify \\`\"", "\"\\`:\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n * All types may also provide \\`\"", "\"\\`\n with members specifying tags that allow the docs to not have a body.\n * \\`\"", "\"\\`: Object mapping tags to \\`RegExp\\` bodies content allowed to count as complete docs.\n * \\`\"", "\"\\`: Array of tags that must only exist to count as complete docs.\n\n Types that may be enabled are:\n\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`"], Lint.Utils.dedent(_k, Object.keys(Rule.defaultArguments).join(", "), exports.ARGUMENT_METHODS, exports.ARGUMENT_PROPERTIES, exports.DESCRIPTOR_PRIVACIES, exports.ALL, exports.PRIVACY_PRIVATE, exports.PRIVACY_PROTECTED, exports.PRIVACY_PUBLIC, exports.DESCRIPTOR_LOCATIONS, exports.ALL, exports.LOCATION_INSTANCE, exports.LOCATION_STATIC, exports.DESCRIPTOR_VISIBILITIES, exports.ALL, exports.VISIBILITY_EXPORTED, exports.VISIBILITY_INTERNAL, exports.DESCRIPTOR_TAGS, exports.TAGS_FOR_CONTENT, exports.TAGS_FOR_EXISTENCE, exports.ARGUMENT_CLASSES, exports.ARGUMENT_ENUMS, exports.ARGUMENT_ENUM_MEMBERS, exports.ARGUMENT_FUNCTIONS, exports.ARGUMENT_INTERFACES, exports.ARGUMENT_METHODS, exports.ARGUMENT_NAMESPACES, exports.ARGUMENT_PROPERTIES, exports.ARGUMENT_TYPES, exports.ARGUMENT_VARIABLES)),
options: {
type: "array",
items: {
anyOf: [
{
- enum: Rule.defaultArguments,
+ options: [
+ exports.ARGUMENT_CLASSES,
+ exports.ARGUMENT_ENUMS,
+ exports.ARGUMENT_FUNCTIONS,
+ exports.ARGUMENT_INTERFACES,
+ exports.ARGUMENT_METHODS,
+ exports.ARGUMENT_NAMESPACES,
+ exports.ARGUMENT_PROPERTIES,
+ exports.ARGUMENT_TYPES,
+ exports.ARGUMENT_VARIABLES,
+ ],
type: "string",
},
{
type: "object",
- properties: (_d = {},
- _d[exports.ARGUMENT_CLASSES] = Rule.ARGUMENT_DESCRIPTOR_BLOCK,
- _d[exports.ARGUMENT_ENUMS] = Rule.ARGUMENT_DESCRIPTOR_BLOCK,
- _d[exports.ARGUMENT_ENUM_MEMBERS] = Rule.ARGUMENT_DESCRIPTOR_BLOCK,
- _d[exports.ARGUMENT_FUNCTIONS] = Rule.ARGUMENT_DESCRIPTOR_BLOCK,
- _d[exports.ARGUMENT_INTERFACES] = Rule.ARGUMENT_DESCRIPTOR_BLOCK,
- _d[exports.ARGUMENT_METHODS] = Rule.ARGUMENT_DESCRIPTOR_CLASS,
- _d[exports.ARGUMENT_NAMESPACES] = Rule.ARGUMENT_DESCRIPTOR_BLOCK,
- _d[exports.ARGUMENT_PROPERTIES] = Rule.ARGUMENT_DESCRIPTOR_CLASS,
- _d[exports.ARGUMENT_TYPES] = Rule.ARGUMENT_DESCRIPTOR_BLOCK,
- _d[exports.ARGUMENT_VARIABLES] = Rule.ARGUMENT_DESCRIPTOR_BLOCK,
- _d),
+ properties: (_l = {},
+ _l[exports.ARGUMENT_CLASSES] = Rule.ARGUMENT_DESCRIPTOR_BLOCK,
+ _l[exports.ARGUMENT_ENUMS] = Rule.ARGUMENT_DESCRIPTOR_BLOCK,
+ _l[exports.ARGUMENT_ENUM_MEMBERS] = Rule.ARGUMENT_DESCRIPTOR_BLOCK,
+ _l[exports.ARGUMENT_FUNCTIONS] = Rule.ARGUMENT_DESCRIPTOR_BLOCK,
+ _l[exports.ARGUMENT_INTERFACES] = Rule.ARGUMENT_DESCRIPTOR_BLOCK,
+ _l[exports.ARGUMENT_METHODS] = Rule.ARGUMENT_DESCRIPTOR_CLASS,
+ _l[exports.ARGUMENT_NAMESPACES] = Rule.ARGUMENT_DESCRIPTOR_BLOCK,
+ _l[exports.ARGUMENT_PROPERTIES] = Rule.ARGUMENT_DESCRIPTOR_CLASS,
+ _l[exports.ARGUMENT_TYPES] = Rule.ARGUMENT_DESCRIPTOR_BLOCK,
+ _l[exports.ARGUMENT_VARIABLES] = Rule.ARGUMENT_DESCRIPTOR_BLOCK,
+ _l),
},
],
},
@@ -138,118 +205,38 @@ var Rule = /** @class */ (function (_super) {
[true, exports.ARGUMENT_ENUMS, exports.ARGUMENT_FUNCTIONS, exports.ARGUMENT_METHODS],
[
true,
- (_e = {},
- _e[exports.ARGUMENT_ENUMS] = true,
- _e[exports.ARGUMENT_FUNCTIONS] = (_f = {},
- _f[exports.DESCRIPTOR_VISIBILITIES] = [exports.VISIBILITY_EXPORTED],
- _f),
- _e[exports.ARGUMENT_METHODS] = (_g = {},
- _g[exports.DESCRIPTOR_LOCATIONS] = exports.LOCATION_INSTANCE,
- _g[exports.DESCRIPTOR_PRIVACIES] = [exports.PRIVACY_PUBLIC, exports.PRIVACY_PROTECTED],
- _g),
- _e),
+ (_m = {},
+ _m[exports.ARGUMENT_ENUMS] = true,
+ _m[exports.ARGUMENT_FUNCTIONS] = (_o = {},
+ _o[exports.DESCRIPTOR_VISIBILITIES] = [exports.VISIBILITY_EXPORTED],
+ _o),
+ _m[exports.ARGUMENT_METHODS] = (_p = {},
+ _p[exports.DESCRIPTOR_LOCATIONS] = exports.LOCATION_INSTANCE,
+ _p[exports.DESCRIPTOR_PRIVACIES] = [exports.PRIVACY_PUBLIC, exports.PRIVACY_PROTECTED],
+ _p),
+ _m[exports.DESCRIPTOR_TAGS] = (_q = {},
+ _q[exports.TAGS_FOR_CONTENT] = {
+ see: ["#.*"],
+ },
+ _q[exports.TAGS_FOR_EXISTENCE] = ["inheritdoc"],
+ _q),
+ _m),
],
],
type: "style",
typescriptOnly: false,
+ requiresTypeInfo: true,
};
return Rule;
}(Lint.Rules.TypedRule));
exports.Rule = Rule;
-var Requirement = /** @class */ (function () {
- // tslint:disable-next-line no-object-literal-type-assertion
- function Requirement(descriptor) {
- if (descriptor === void 0) { descriptor = {}; }
- this.descriptor = descriptor;
- }
- Requirement.constructRequirements = function (ruleArguments) {
- var requirements = new Map();
- for (var _i = 0, ruleArguments_1 = ruleArguments; _i < ruleArguments_1.length; _i++) {
- var ruleArgument = ruleArguments_1[_i];
- Requirement.addRequirements(requirements, ruleArgument);
- }
- return requirements;
- };
- Requirement.addRequirements = function (requirements, descriptor) {
- if (typeof descriptor === "string") {
- requirements.set(descriptor, new BlockRequirement());
- return;
- }
- for (var type in descriptor) {
- if (utils_1.hasOwnProperty(descriptor, type)) {
- requirements.set(type, (type === "methods" || type === "properties")
- ? new ClassRequirement(descriptor[type])
- : new BlockRequirement(descriptor[type]));
- }
- }
- };
- Requirement.prototype.createSet = function (values) {
- if (values === undefined || values.length === 0) {
- values = [exports.ALL];
- }
- return new Set(values);
- };
- return Requirement;
-}());
-var BlockRequirement = /** @class */ (function (_super) {
- tslib_1.__extends(BlockRequirement, _super);
- function BlockRequirement() {
- var _this = _super !== null && _super.apply(this, arguments) || this;
- _this.visibilities = _this.createSet(_this.descriptor.visibilities);
- return _this;
- }
- BlockRequirement.prototype.shouldNodeBeDocumented = function (node) {
- if (this.visibilities.has(exports.ALL)) {
- return true;
- }
- if (Lint.hasModifier(node.modifiers, ts.SyntaxKind.ExportKeyword)) {
- return this.visibilities.has(exports.VISIBILITY_EXPORTED);
- }
- return this.visibilities.has(exports.VISIBILITY_INTERNAL);
- };
- return BlockRequirement;
-}(Requirement));
-var ClassRequirement = /** @class */ (function (_super) {
- tslib_1.__extends(ClassRequirement, _super);
- function ClassRequirement() {
- var _this = _super !== null && _super.apply(this, arguments) || this;
- _this.locations = _this.createSet(_this.descriptor.locations);
- _this.privacies = _this.createSet(_this.descriptor.privacies);
- return _this;
- }
- ClassRequirement.prototype.shouldNodeBeDocumented = function (node) {
- return this.shouldLocationBeDocumented(node) && this.shouldPrivacyBeDocumented(node);
- };
- ClassRequirement.prototype.shouldLocationBeDocumented = function (node) {
- if (this.locations.has(exports.ALL)) {
- return true;
- }
- if (Lint.hasModifier(node.modifiers, ts.SyntaxKind.StaticKeyword)) {
- return this.locations.has(exports.LOCATION_STATIC);
- }
- return this.locations.has(exports.LOCATION_INSTANCE);
- };
- ClassRequirement.prototype.shouldPrivacyBeDocumented = function (node) {
- if (this.privacies.has(exports.ALL)) {
- return true;
- }
- if (Lint.hasModifier(node.modifiers, ts.SyntaxKind.PrivateKeyword)) {
- return this.privacies.has(exports.PRIVACY_PRIVATE);
- }
- if (Lint.hasModifier(node.modifiers, ts.SyntaxKind.ProtectedKeyword)) {
- return this.privacies.has(exports.PRIVACY_PROTECTED);
- }
- return this.privacies.has(exports.PRIVACY_PUBLIC);
- };
- return ClassRequirement;
-}(Requirement));
var CompletedDocsWalker = /** @class */ (function (_super) {
tslib_1.__extends(CompletedDocsWalker, _super);
function CompletedDocsWalker() {
return _super !== null && _super.apply(this, arguments) || this;
}
- CompletedDocsWalker.prototype.setRequirements = function (requirements) {
- this.requirements = requirements;
+ CompletedDocsWalker.prototype.setExclusionsMap = function (exclusionsMap) {
+ this.exclusionsMap = exclusionsMap;
};
CompletedDocsWalker.prototype.visitClassDeclaration = function (node) {
this.checkNode(node, exports.ARGUMENT_CLASSES);
@@ -293,6 +280,29 @@ var CompletedDocsWalker = /** @class */ (function (_super) {
this.checkVariable(node);
_super.prototype.visitVariableDeclaration.call(this, node);
};
+ CompletedDocsWalker.prototype.checkNode = function (node, nodeType, requirementNode) {
+ if (requirementNode === void 0) { requirementNode = node; }
+ var name = node.name;
+ if (name === undefined) {
+ return;
+ }
+ var exclusions = this.exclusionsMap.get(nodeType);
+ if (exclusions === undefined) {
+ return;
+ }
+ for (var _i = 0, exclusions_1 = exclusions; _i < exclusions_1.length; _i++) {
+ var exclusion = exclusions_1[_i];
+ if (exclusion.excludes(requirementNode)) {
+ return;
+ }
+ }
+ var symbol = this.getTypeChecker().getSymbolAtLocation(name);
+ if (symbol === undefined) {
+ return;
+ }
+ var comments = symbol.getDocumentationComment();
+ this.checkComments(node, this.describeNode(nodeType), comments, requirementNode);
+ };
CompletedDocsWalker.prototype.checkVariable = function (node) {
// Only check variables in variable declaration lists
// and not variables in catch clauses and for loops.
@@ -312,26 +322,6 @@ var CompletedDocsWalker = /** @class */ (function (_super) {
this.checkNode(node, exports.ARGUMENT_VARIABLES, statement);
}
};
- CompletedDocsWalker.prototype.checkNode = function (node, nodeType, requirementNode) {
- if (requirementNode === void 0) { requirementNode = node; }
- var name = node.name;
- if (name === undefined) {
- return;
- }
- var requirement = this.requirements.get(nodeType);
- if (requirement === undefined || !requirement.shouldNodeBeDocumented(requirementNode)) {
- return;
- }
- var symbol = this.getTypeChecker().getSymbolAtLocation(name);
- if (symbol === undefined) {
- return;
- }
- var comments = symbol.getDocumentationComment();
- this.checkComments(node, this.describeNode(nodeType), comments, requirementNode);
- };
- CompletedDocsWalker.prototype.describeNode = function (nodeType) {
- return nodeType.replace("-", " ");
- };
CompletedDocsWalker.prototype.checkComments = function (node, nodeDescriptor, comments, requirementNode) {
if (comments.map(function (comment) { return comment.text; }).join("").trim() === "") {
this.addDocumentationFailure(node, nodeDescriptor, requirementNode);
@@ -356,9 +346,12 @@ var CompletedDocsWalker = /** @class */ (function (_super) {
var alias = CompletedDocsWalker.modifierAliases[description];
return alias !== undefined ? alias : description;
};
+ CompletedDocsWalker.prototype.describeNode = function (nodeType) {
+ return nodeType.replace("-", " ");
+ };
CompletedDocsWalker.modifierAliases = {
export: "exported",
};
return CompletedDocsWalker;
}(Lint.ProgramAwareRuleWalker));
-var _a, _b, _c, _d, _e, _f, _g;
+var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
diff --git a/node_modules/tslint/lib/rules/curlyRule.js b/node_modules/tslint/lib/rules/curlyRule.js
index dbd14038d..906201a12 100644
--- a/node_modules/tslint/lib/rules/curlyRule.js
+++ b/node_modules/tslint/lib/rules/curlyRule.js
@@ -61,6 +61,7 @@ var Rule = /** @class */ (function (_super) {
],
type: "functionality",
typescriptOnly: false,
+ hasFix: true,
};
/* tslint:enable:object-literal-sort-keys */
Rule.FAILURE_STRING_AS_NEEDED = "Block contains only one statement; remove the curly braces.";
@@ -120,11 +121,33 @@ var CurlyWalker = /** @class */ (function (_super) {
};
CurlyWalker.prototype.checkStatement = function (statement, node, childIndex, end) {
if (end === void 0) { end = statement.end; }
+ var sameLine = tsutils_1.isSameLine(this.sourceFile, statement.pos, statement.end);
if (statement.kind !== ts.SyntaxKind.Block &&
- !(this.options.ignoreSameLine && tsutils_1.isSameLine(this.sourceFile, statement.pos, statement.end))) {
+ !(this.options.ignoreSameLine && sameLine)) {
var token = node.getChildAt(childIndex, this.sourceFile);
var tokenText = ts.tokenToString(token.kind);
- this.addFailure(token.end - tokenText.length, end, Rule.FAILURE_STRING_FACTORY(tokenText));
+ this.addFailure(token.end - tokenText.length, end, Rule.FAILURE_STRING_FACTORY(tokenText), this.createMissingBraceFix(statement, node, sameLine));
+ }
+ };
+ /** Generate the necessary replacement to add braces to a statement that needs them. */
+ CurlyWalker.prototype.createMissingBraceFix = function (statement, node, sameLine) {
+ if (sameLine) {
+ return [
+ Lint.Replacement.appendText(statement.getStart(), "{ "),
+ Lint.Replacement.appendText(statement.getEnd(), " }"),
+ ];
+ }
+ else {
+ var match = /\n([\t ])/.exec(node.getFullText(this.sourceFile)); // determine which character to use (tab or space)
+ var indentation = match === null ?
+ "" :
+ // indentation should match start of statement
+ match[1].repeat(ts.getLineAndCharacterOfPosition(this.sourceFile, node.getStart(this.sourceFile)).character);
+ var maybeCarriageReturn = this.sourceFile.text[this.sourceFile.getLineEndOfPosition(node.pos) - 1] === "\r" ? "\r" : "";
+ return [
+ Lint.Replacement.appendText(this.sourceFile.getLineEndOfPosition(statement.pos), " {"),
+ Lint.Replacement.appendText(statement.getEnd(), maybeCarriageReturn + "\n" + indentation + "}"),
+ ];
}
};
return CurlyWalker;
diff --git a/node_modules/tslint/lib/rules/deprecationRule.js b/node_modules/tslint/lib/rules/deprecationRule.js
index ef6180125..bcd8a7da4 100644
--- a/node_modules/tslint/lib/rules/deprecationRule.js
+++ b/node_modules/tslint/lib/rules/deprecationRule.js
@@ -88,16 +88,17 @@ function isDeclaration(identifier) {
case ts.SyntaxKind.GetAccessor:
case ts.SyntaxKind.SetAccessor:
case ts.SyntaxKind.EnumDeclaration:
+ case ts.SyntaxKind.ModuleDeclaration:
return true;
case ts.SyntaxKind.VariableDeclaration:
- case ts.SyntaxKind.TypeAliasDeclaration:
case ts.SyntaxKind.Parameter:
- case ts.SyntaxKind.ModuleDeclaration:
case ts.SyntaxKind.PropertyDeclaration:
- case ts.SyntaxKind.PropertyAssignment:
case ts.SyntaxKind.EnumMember:
case ts.SyntaxKind.ImportEqualsDeclaration:
return parent.name === identifier;
+ case ts.SyntaxKind.PropertyAssignment:
+ return parent.name === identifier &&
+ !tsutils_1.isReassignmentTarget(identifier.parent.parent);
case ts.SyntaxKind.BindingElement:
// return true for `b` in `const {a: b} = obj"`
return parent.name === identifier &&
@@ -112,7 +113,9 @@ function getCallExpresion(node) {
node = parent;
parent = node.parent;
}
- return tsutils_1.isTaggedTemplateExpression(parent) || tsutils_1.isCallExpression(parent) && parent.expression === node ? parent : undefined;
+ return tsutils_1.isTaggedTemplateExpression(parent) || (tsutils_1.isCallExpression(parent) || tsutils_1.isNewExpression(parent)) && parent.expression === node
+ ? parent
+ : undefined;
}
function getDeprecation(node, tc) {
var callExpression = getCallExpresion(node);
@@ -122,7 +125,18 @@ function getDeprecation(node, tc) {
return result;
}
}
- var symbol = tc.getSymbolAtLocation(node);
+ var symbol;
+ var parent = node.parent;
+ if (parent.kind === ts.SyntaxKind.BindingElement) {
+ symbol = tc.getTypeAtLocation(parent.parent).getProperty(node.text);
+ }
+ else if (tsutils_1.isPropertyAssignment(parent) && parent.name === node ||
+ tsutils_1.isShorthandPropertyAssignment(parent) && parent.name === node && tsutils_1.isReassignmentTarget(node)) {
+ symbol = tc.getPropertySymbolOfDestructuringAssignment(node);
+ }
+ else {
+ symbol = tc.getSymbolAtLocation(node);
+ }
if (symbol !== undefined && Lint.isSymbolFlagSet(symbol, ts.SymbolFlags.Alias)) {
symbol = tc.getAliasedSymbol(symbol);
}
@@ -184,15 +198,12 @@ function getDeprecationFromDeclarations(declarations) {
return undefined;
}
function getDeprecationFromDeclaration(declaration) {
- for (var _i = 0, _a = declaration.getChildren(); _i < _a.length; _i++) {
- var child = _a[_i];
- if (!tsutils_1.isJsDoc(child)) {
- break;
- }
- if (child.tags === undefined) {
+ for (var _i = 0, _a = tsutils_1.getJsDoc(declaration); _i < _a.length; _i++) {
+ var comment = _a[_i];
+ if (comment.tags === undefined) {
continue;
}
- for (var _b = 0, _c = child.tags; _b < _c.length; _b++) {
+ for (var _b = 0, _c = comment.tags; _b < _c.length; _b++) {
var tag = _c[_b];
if (tag.tagName.text === "deprecated") {
return tag.comment === undefined ? "" : tag.comment;
diff --git a/node_modules/tslint/lib/rules/importBlacklistRule.js b/node_modules/tslint/lib/rules/importBlacklistRule.js
index c99110b96..c79242cfa 100644
--- a/node_modules/tslint/lib/rules/importBlacklistRule.js
+++ b/node_modules/tslint/lib/rules/importBlacklistRule.js
@@ -18,7 +18,6 @@
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var tsutils_1 = require("tsutils");
-var ts = require("typescript");
var Lint = require("../index");
var Rule = /** @class */ (function (_super) {
tslib_1.__extends(Rule, _super);
@@ -29,7 +28,7 @@ var Rule = /** @class */ (function (_super) {
return _super.prototype.isEnabled.call(this) && this.ruleArguments.length > 0;
};
Rule.prototype.apply = function (sourceFile) {
- return this.applyWithWalker(new ImportBlacklistWalker(sourceFile, this.ruleName, this.ruleArguments));
+ return this.applyWithFunction(sourceFile, walk, this.ruleArguments);
};
/* tslint:disable:object-literal-sort-keys */
Rule.metadata = {
@@ -52,40 +51,12 @@ var Rule = /** @class */ (function (_super) {
return Rule;
}(Lint.Rules.AbstractRule));
exports.Rule = Rule;
-var ImportBlacklistWalker = /** @class */ (function (_super) {
- tslib_1.__extends(ImportBlacklistWalker, _super);
- function ImportBlacklistWalker() {
- return _super !== null && _super.apply(this, arguments) || this;
- }
- ImportBlacklistWalker.prototype.walk = function (sourceFile) {
- var _this = this;
- var findRequire = function (node) {
- if (tsutils_1.isCallExpression(node) && node.arguments.length === 1 &&
- tsutils_1.isIdentifier(node.expression) && node.expression.text === "require") {
- _this.checkForBannedImport(node.arguments[0]);
- }
- return ts.forEachChild(node, findRequire);
- };
- for (var _i = 0, _a = sourceFile.statements; _i < _a.length; _i++) {
- var statement = _a[_i];
- if (tsutils_1.isImportDeclaration(statement)) {
- this.checkForBannedImport(statement.moduleSpecifier);
- }
- else if (tsutils_1.isImportEqualsDeclaration(statement)) {
- if (tsutils_1.isExternalModuleReference(statement.moduleReference) && statement.moduleReference.expression !== undefined) {
- this.checkForBannedImport(statement.moduleReference.expression);
- }
- }
- else {
- ts.forEachChild(statement, findRequire);
- }
- }
- };
- ImportBlacklistWalker.prototype.checkForBannedImport = function (expression) {
- if (tsutils_1.isTextualLiteral(expression) && this.options.indexOf(expression.text) !== -1) {
- this.addFailure(expression.getStart(this.sourceFile) + 1, expression.end - 1, Rule.FAILURE_STRING);
+function walk(ctx) {
+ for (var _i = 0, _a = tsutils_1.findImports(ctx.sourceFile, 31 /* All */); _i < _a.length; _i++) {
+ var name = _a[_i];
+ if (ctx.options.indexOf(name.text) !== -1) {
+ ctx.addFailure(name.getStart(ctx.sourceFile) + 1, name.end - 1, Rule.FAILURE_STRING);
}
- };
- return ImportBlacklistWalker;
-}(Lint.AbstractWalker));
+ }
+}
var _a, _b;
diff --git a/node_modules/tslint/lib/rules/jsdocFormatRule.js b/node_modules/tslint/lib/rules/jsdocFormatRule.js
index 329cf2538..b75550a6d 100644
--- a/node_modules/tslint/lib/rules/jsdocFormatRule.js
+++ b/node_modules/tslint/lib/rules/jsdocFormatRule.js
@@ -20,23 +20,34 @@ var tslib_1 = require("tslib");
var utils = require("tsutils");
var ts = require("typescript");
var Lint = require("../index");
+var OPTION_CHECK_MULTILINE_START = "check-multiline-start";
var Rule = /** @class */ (function (_super) {
tslib_1.__extends(Rule, _super);
function Rule() {
return _super !== null && _super.apply(this, arguments) || this;
}
Rule.prototype.apply = function (sourceFile) {
- return this.applyWithFunction(sourceFile, walk);
+ return this.applyWithFunction(sourceFile, walk, {
+ firstLineOfMultiline: this.ruleArguments.indexOf(OPTION_CHECK_MULTILINE_START) !== -1,
+ });
};
/* tslint:disable:object-literal-sort-keys */
Rule.metadata = {
ruleName: "jsdoc-format",
description: "Enforces basic format rules for JSDoc comments.",
- descriptionDetails: (_a = ["\n The following rules are enforced for JSDoc comments (comments starting with `/**`):\n\n * each line contains an asterisk and asterisks must be aligned\n * each asterisk must be followed by either a space or a newline (except for the first and the last)\n * the only characters before the asterisk on each line must be whitespace characters\n * one line comments must start with `/** ` and end with `*/`"], _a.raw = ["\n The following rules are enforced for JSDoc comments (comments starting with \\`/**\\`):\n\n * each line contains an asterisk and asterisks must be aligned\n * each asterisk must be followed by either a space or a newline (except for the first and the last)\n * the only characters before the asterisk on each line must be whitespace characters\n * one line comments must start with \\`/** \\` and end with \\`*/\\`"], Lint.Utils.dedent(_a)),
+ descriptionDetails: (_a = ["\n The following rules are enforced for JSDoc comments (comments starting with `/**`):\n\n * each line contains an asterisk and asterisks must be aligned\n * each asterisk must be followed by either a space or a newline (except for the first and the last)\n * the only characters before the asterisk on each line must be whitespace characters\n * one line comments must start with `/** ` and end with `*/`\n * multiline comments don't allow text after `/** ` in the first line (with option `\"", "\"`)\n "], _a.raw = ["\n The following rules are enforced for JSDoc comments (comments starting with \\`/**\\`):\n\n * each line contains an asterisk and asterisks must be aligned\n * each asterisk must be followed by either a space or a newline (except for the first and the last)\n * the only characters before the asterisk on each line must be whitespace characters\n * one line comments must start with \\`/** \\` and end with \\`*/\\`\n * multiline comments don't allow text after \\`/** \\` in the first line (with option \\`\"", "\"\\`)\n "], Lint.Utils.dedent(_a, OPTION_CHECK_MULTILINE_START)),
rationale: "Helps maintain a consistent, readable style for JSDoc comments.",
- optionsDescription: "Not configurable.",
- options: null,
- optionExamples: [true],
+ optionsDescription: (_b = ["\n You can optionally specify the option `\"", "\"` to enforce the first line of a\n multiline JSDoc comment to be empty.\n "], _b.raw = ["\n You can optionally specify the option \\`\"", "\"\\` to enforce the first line of a\n multiline JSDoc comment to be empty.\n "], Lint.Utils.dedent(_b, OPTION_CHECK_MULTILINE_START)),
+ options: {
+ type: "array",
+ minItems: 0,
+ maxItems: 1,
+ items: {
+ type: "string",
+ enum: [OPTION_CHECK_MULTILINE_START],
+ },
+ },
+ optionExamples: [true, [true, OPTION_CHECK_MULTILINE_START]],
type: "style",
typescriptOnly: false,
};
@@ -62,6 +73,10 @@ function walk(ctx) {
return;
}
var alignColumn = getAlignColumn(ctx.sourceFile, pos + 1);
+ if (ctx.options.firstLineOfMultiline && /\S/.test(firstLine)) {
+ // first line of multiline JSDoc should be empty, i.e. only contain whitespace
+ ctx.addFailureAt(pos, firstLine.length + 3, Rule.FORMAT_FAILURE_STRING);
+ }
var lineStart = pos + firstLine.length + 4; // +3 for the comment start "/**" and +1 for the newline
var endIndex = lines.length - 1;
for (var i = 1; i < endIndex; ++i) {
@@ -93,4 +108,4 @@ function getAlignColumn(sourceFile, pos) {
? result.character - 1
: result.character;
}
-var _a;
+var _a, _b;
diff --git a/node_modules/tslint/lib/rules/maxClassesPerFileRule.js b/node_modules/tslint/lib/rules/maxClassesPerFileRule.js
index c5921368b..74092147c 100644
--- a/node_modules/tslint/lib/rules/maxClassesPerFileRule.js
+++ b/node_modules/tslint/lib/rules/maxClassesPerFileRule.js
@@ -20,6 +20,7 @@ var tslib_1 = require("tslib");
var tsutils_1 = require("tsutils");
var ts = require("typescript");
var Lint = require("../index");
+var OPTION_EXCLUDE_CLASS_EXPRESSIONS = "exclude-class-expressions";
var Rule = /** @class */ (function (_super) {
tslib_1.__extends(Rule, _super);
function Rule() {
@@ -33,14 +34,17 @@ var Rule = /** @class */ (function (_super) {
Rule.prototype.apply = function (sourceFile) {
var argument = this.ruleArguments[0];
var maxClasses = isNaN(argument) || argument > 0 ? argument : 1;
- return this.applyWithFunction(sourceFile, walk, { maxClasses: maxClasses });
+ return this.applyWithFunction(sourceFile, walk, {
+ excludeClassExpressions: this.ruleArguments.indexOf(OPTION_EXCLUDE_CLASS_EXPRESSIONS) !== -1,
+ maxClasses: maxClasses,
+ });
};
/* tslint:disable:object-literal-sort-keys */
Rule.metadata = {
ruleName: "max-classes-per-file",
description: (_a = ["\n A file may not contain more than the specified number of classes"], _a.raw = ["\n A file may not contain more than the specified number of classes"], Lint.Utils.dedent(_a)),
rationale: (_b = ["\n Ensures that files have a single responsibility so that that classes each exist in their own files"], _b.raw = ["\n Ensures that files have a single responsibility so that that classes each exist in their own files"], Lint.Utils.dedent(_b)),
- optionsDescription: (_c = ["\n The one required argument is an integer indicating the maximum number of classes that can appear in a file."], _c.raw = ["\n The one required argument is an integer indicating the maximum number of classes that can appear in a file."], Lint.Utils.dedent(_c)),
+ optionsDescription: (_c = ["\n The one required argument is an integer indicating the maximum number of classes that can appear in a\n file. An optional argument `\"exclude-class-expressions\"` can be provided to exclude class expressions\n from the overall class count."], _c.raw = ["\n The one required argument is an integer indicating the maximum number of classes that can appear in a\n file. An optional argument \\`\"exclude-class-expressions\"\\` can be provided to exclude class expressions\n from the overall class count."], Lint.Utils.dedent(_c)),
options: {
type: "array",
items: [
@@ -48,12 +52,16 @@ var Rule = /** @class */ (function (_super) {
type: "number",
minimum: 1,
},
+ {
+ type: "string",
+ enum: [OPTION_EXCLUDE_CLASS_EXPRESSIONS],
+ },
],
additionalItems: false,
minLength: 1,
maxLength: 2,
},
- optionExamples: [[true, 1], [true, 5]],
+ optionExamples: [[true, 1], [true, 5, OPTION_EXCLUDE_CLASS_EXPRESSIONS]],
type: "maintainability",
typescriptOnly: false,
};
@@ -61,10 +69,10 @@ var Rule = /** @class */ (function (_super) {
}(Lint.Rules.AbstractRule));
exports.Rule = Rule;
function walk(ctx) {
- var sourceFile = ctx.sourceFile, maxClasses = ctx.options.maxClasses;
+ var sourceFile = ctx.sourceFile, _a = ctx.options, maxClasses = _a.maxClasses, excludeClassExpressions = _a.excludeClassExpressions;
var classes = 0;
return ts.forEachChild(sourceFile, function cb(node) {
- if (tsutils_1.isClassLikeDeclaration(node)) {
+ if (tsutils_1.isClassDeclaration(node) || (!excludeClassExpressions && tsutils_1.isClassExpression(node))) {
classes++;
if (classes > maxClasses) {
ctx.addFailureAtNode(node, Rule.FAILURE_STRING(maxClasses));
diff --git a/node_modules/tslint/lib/rules/memberAccessRule.js b/node_modules/tslint/lib/rules/memberAccessRule.js
index 599a0952e..abb843b04 100644
--- a/node_modules/tslint/lib/rules/memberAccessRule.js
+++ b/node_modules/tslint/lib/rules/memberAccessRule.js
@@ -24,6 +24,7 @@ var Lint = require("../index");
var OPTION_NO_PUBLIC = "no-public";
var OPTION_CHECK_ACCESSOR = "check-accessor";
var OPTION_CHECK_CONSTRUCTOR = "check-constructor";
+var OPTION_CHECK_PARAMETER_PROPERTY = "check-parameter-property";
var Rule = /** @class */ (function (_super) {
tslib_1.__extends(Rule, _super);
function Rule() {
@@ -38,16 +39,18 @@ var Rule = /** @class */ (function (_super) {
var noPublic = options.indexOf(OPTION_NO_PUBLIC) !== -1;
var checkAccessor = options.indexOf(OPTION_CHECK_ACCESSOR) !== -1;
var checkConstructor = options.indexOf(OPTION_CHECK_CONSTRUCTOR) !== -1;
+ var checkParameterProperty = options.indexOf(OPTION_CHECK_PARAMETER_PROPERTY) !== -1;
if (noPublic) {
- if (checkAccessor || checkConstructor) {
+ if (checkAccessor || checkConstructor || checkParameterProperty) {
error_1.showWarningOnce("Warning: " + this.ruleName + " - If 'no-public' is present, it should be the only option.");
return [];
}
- checkAccessor = checkConstructor = true;
+ checkAccessor = checkConstructor = checkParameterProperty = true;
}
return this.applyWithFunction(sourceFile, walk, {
checkAccessor: checkAccessor,
checkConstructor: checkConstructor,
+ checkParameterProperty: checkParameterProperty,
noPublic: noPublic,
});
};
@@ -56,15 +59,15 @@ var Rule = /** @class */ (function (_super) {
ruleName: "member-access",
description: "Requires explicit visibility declarations for class members.",
rationale: "Explicit visibility declarations can make code more readable and accessible for those new to TS.",
- optionsDescription: (_a = ["\n These arguments may be optionally provided:\n\n * `\"no-public\"` forbids public accessibility to be specified, because this is the default.\n * `\"check-accessor\"` enforces explicit visibility on get/set accessors\n * `\"check-constructor\"` enforces explicit visibility on constructors"], _a.raw = ["\n These arguments may be optionally provided:\n\n * \\`\"no-public\"\\` forbids public accessibility to be specified, because this is the default.\n * \\`\"check-accessor\"\\` enforces explicit visibility on get/set accessors\n * \\`\"check-constructor\"\\` enforces explicit visibility on constructors"], Lint.Utils.dedent(_a)),
+ optionsDescription: (_a = ["\n These arguments may be optionally provided:\n\n * `\"no-public\"` forbids public accessibility to be specified, because this is the default.\n * `\"check-accessor\"` enforces explicit visibility on get/set accessors\n * `\"check-constructor\"` enforces explicit visibility on constructors\n * `\"check-parameter-property\"` enforces explicit visibility on parameter properties"], _a.raw = ["\n These arguments may be optionally provided:\n\n * \\`\"no-public\"\\` forbids public accessibility to be specified, because this is the default.\n * \\`\"check-accessor\"\\` enforces explicit visibility on get/set accessors\n * \\`\"check-constructor\"\\` enforces explicit visibility on constructors\n * \\`\"check-parameter-property\"\\` enforces explicit visibility on parameter properties"], Lint.Utils.dedent(_a)),
options: {
type: "array",
items: {
type: "string",
- enum: [OPTION_NO_PUBLIC, OPTION_CHECK_ACCESSOR, OPTION_CHECK_CONSTRUCTOR],
+ enum: [OPTION_NO_PUBLIC, OPTION_CHECK_ACCESSOR, OPTION_CHECK_CONSTRUCTOR, OPTION_CHECK_PARAMETER_PROPERTY],
},
minLength: 0,
- maxLength: 3,
+ maxLength: 4,
},
optionExamples: [true, [true, OPTION_NO_PUBLIC], [true, OPTION_CHECK_ACCESSOR]],
type: "typescript",
@@ -77,7 +80,7 @@ var Rule = /** @class */ (function (_super) {
}(Lint.Rules.AbstractRule));
exports.Rule = Rule;
function walk(ctx) {
- var _a = ctx.options, noPublic = _a.noPublic, checkAccessor = _a.checkAccessor, checkConstructor = _a.checkConstructor;
+ var _a = ctx.options, noPublic = _a.noPublic, checkAccessor = _a.checkAccessor, checkConstructor = _a.checkConstructor, checkParameterProperty = _a.checkParameterProperty;
return ts.forEachChild(ctx.sourceFile, function recur(node) {
if (tsutils_1.isClassLikeDeclaration(node)) {
for (var _i = 0, _a = node.members; _i < _a.length; _i++) {
@@ -85,6 +88,14 @@ function walk(ctx) {
if (shouldCheck(child)) {
check(child);
}
+ if (checkParameterProperty && tsutils_1.isConstructorDeclaration(child) && child.body !== undefined) {
+ for (var _b = 0, _c = child.parameters; _b < _c.length; _b++) {
+ var param = _c[_b];
+ if (tsutils_1.isParameterProperty(param)) {
+ check(param);
+ }
+ }
+ }
}
}
return ts.forEachChild(node, recur);
@@ -109,8 +120,13 @@ function walk(ctx) {
}
var publicKeyword = tsutils_1.getModifier(node, ts.SyntaxKind.PublicKeyword);
if (noPublic && publicKeyword !== undefined) {
- var start = publicKeyword.end - "public".length;
- ctx.addFailure(start, publicKeyword.end, Rule.FAILURE_STRING_NO_PUBLIC, Lint.Replacement.deleteFromTo(start, tsutils_1.getNextToken(publicKeyword, ctx.sourceFile).getStart(ctx.sourceFile)));
+ var readonlyKeyword = tsutils_1.getModifier(node, ts.SyntaxKind.ReadonlyKeyword);
+ // public is not optional for parameter property without the readonly modifier
+ var isPublicOptional = node.kind !== ts.SyntaxKind.Parameter || readonlyKeyword !== undefined;
+ if (isPublicOptional) {
+ var start = publicKeyword.end - "public".length;
+ ctx.addFailure(start, publicKeyword.end, Rule.FAILURE_STRING_NO_PUBLIC, Lint.Replacement.deleteFromTo(start, tsutils_1.getNextToken(publicKeyword, ctx.sourceFile).getStart(ctx.sourceFile)));
+ }
}
if (!noPublic && publicKeyword === undefined) {
var nameNode = node.kind === ts.SyntaxKind.Constructor
@@ -137,6 +153,8 @@ function typeToString(node) {
return "get property accessor";
case ts.SyntaxKind.SetAccessor:
return "set property accessor";
+ case ts.SyntaxKind.Parameter:
+ return "parameter property";
default:
throw new Error("unhandled node type " + ts.SyntaxKind[node.kind]);
}
diff --git a/node_modules/tslint/lib/rules/memberOrderingRule.js b/node_modules/tslint/lib/rules/memberOrderingRule.js
index f5b6d0683..e2e35a548 100644
--- a/node_modules/tslint/lib/rules/memberOrderingRule.js
+++ b/node_modules/tslint/lib/rules/memberOrderingRule.js
@@ -152,9 +152,12 @@ var Rule = /** @class */ (function (_super) {
[true, { order: "fields-first" }],
[true, {
order: [
- "static-field",
- "instance-field",
- "constructor",
+ "public-static-field",
+ "public-instance-field",
+ "public-constructor",
+ "private-static-field",
+ "private-instance-field",
+ "private-constructor",
"public-instance-method",
"protected-instance-method",
"private-instance-method",
@@ -340,7 +343,7 @@ function parseOptions(options) {
return { order: order, alphabetize: alphabetize };
}
function getOptionsJson(allOptions) {
- if (allOptions == null || allOptions.length === 0 || allOptions[0] == null) {
+ if (allOptions == undefined || allOptions.length === 0 || allOptions[0] == undefined) {
throw new Error("Got empty options");
}
var firstOption = allOptions[0];
diff --git a/node_modules/tslint/lib/rules/noAngleBracketTypeAssertionRule.js b/node_modules/tslint/lib/rules/noAngleBracketTypeAssertionRule.js
index 18d780e31..2634398da 100644
--- a/node_modules/tslint/lib/rules/noAngleBracketTypeAssertionRule.js
+++ b/node_modules/tslint/lib/rules/noAngleBracketTypeAssertionRule.js
@@ -48,13 +48,26 @@ exports.Rule = Rule;
function walk(ctx) {
return ts.forEachChild(ctx.sourceFile, function cb(node) {
if (tsutils_1.isTypeAssertion(node)) {
+ var expression = node.expression;
var start = node.getStart(ctx.sourceFile);
+ var addParens = needsParens(node);
+ var replaceText = " as " + node.type.getText(ctx.sourceFile) + (addParens ? ")" : "");
+ while (tsutils_1.isTypeAssertion(expression)) {
+ replaceText = " as " + expression.type.getText(ctx.sourceFile) + replaceText;
+ expression = expression.expression;
+ }
ctx.addFailure(start, node.end, Rule.FAILURE_STRING, [
- Lint.Replacement.appendText(node.end, " as " + node.type.getText(ctx.sourceFile)),
- Lint.Replacement.deleteFromTo(start, node.expression.getStart(ctx.sourceFile)),
+ Lint.Replacement.appendText(node.end, replaceText),
+ Lint.Replacement.replaceFromTo(start, expression.getStart(ctx.sourceFile), addParens ? "(" : ""),
]);
+ return cb(expression);
}
return ts.forEachChild(node, cb);
});
}
+function needsParens(node) {
+ var parent = node.parent;
+ return tsutils_1.isBinaryExpression(parent) &&
+ (parent.operatorToken.kind === ts.SyntaxKind.AmpersandToken || parent.operatorToken.kind === ts.SyntaxKind.BarToken);
+}
var _a;
diff --git a/node_modules/tslint/lib/rules/noConditionalAssignmentRule.d.ts b/node_modules/tslint/lib/rules/noConditionalAssignmentRule.d.ts
index 06b7c4bbe..cce59d100 100644
--- a/node_modules/tslint/lib/rules/noConditionalAssignmentRule.d.ts
+++ b/node_modules/tslint/lib/rules/noConditionalAssignmentRule.d.ts
@@ -1,19 +1,3 @@
-/**
- * @license
- * Copyright 2015 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 * as Lint from "../index";
export declare class Rule extends Lint.Rules.AbstractRule {
diff --git a/node_modules/tslint/lib/rules/noConditionalAssignmentRule.js b/node_modules/tslint/lib/rules/noConditionalAssignmentRule.js
index f437d1a63..30e77aa84 100644
--- a/node_modules/tslint/lib/rules/noConditionalAssignmentRule.js
+++ b/node_modules/tslint/lib/rules/noConditionalAssignmentRule.js
@@ -17,6 +17,7 @@
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
+var tsutils_1 = require("tsutils");
var ts = require("typescript");
var Lint = require("../index");
var Rule = /** @class */ (function (_super) {
@@ -25,14 +26,13 @@ var Rule = /** @class */ (function (_super) {
return _super !== null && _super.apply(this, arguments) || this;
}
Rule.prototype.apply = function (sourceFile) {
- var walker = new NoConditionalAssignmentWalker(sourceFile, this.getOptions());
- return this.applyWithWalker(walker);
+ return this.applyWithFunction(sourceFile, walk);
};
/* tslint:disable:object-literal-sort-keys */
Rule.metadata = {
ruleName: "no-conditional-assignment",
description: "Disallows any type of assignment in conditionals.",
- descriptionDetails: "This applies to `do-while`, `for`, `if`, and `while` statements.",
+ descriptionDetails: "This applies to `do-while`, `for`, `if`, and `while` statements and conditional (ternary) expressions.",
rationale: (_a = ["\n Assignments in conditionals are often typos:\n for example `if (var1 = var2)` instead of `if (var1 == var2)`.\n They also can be an indicator of overly clever code which decreases maintainability."], _a.raw = ["\n Assignments in conditionals are often typos:\n for example \\`if (var1 = var2)\\` instead of \\`if (var1 == var2)\\`.\n They also can be an indicator of overly clever code which decreases maintainability."], Lint.Utils.dedent(_a)),
optionsDescription: "Not configurable.",
options: null,
@@ -45,55 +45,74 @@ var Rule = /** @class */ (function (_super) {
return Rule;
}(Lint.Rules.AbstractRule));
exports.Rule = Rule;
-var NoConditionalAssignmentWalker = /** @class */ (function (_super) {
- tslib_1.__extends(NoConditionalAssignmentWalker, _super);
- function NoConditionalAssignmentWalker() {
- var _this = _super !== null && _super.apply(this, arguments) || this;
- _this.isInConditional = false;
- return _this;
- }
- NoConditionalAssignmentWalker.prototype.visitIfStatement = function (node) {
- this.validateConditionalExpression(node.expression);
- _super.prototype.visitIfStatement.call(this, node);
- };
- NoConditionalAssignmentWalker.prototype.visitWhileStatement = function (node) {
- this.validateConditionalExpression(node.expression);
- _super.prototype.visitWhileStatement.call(this, node);
- };
- NoConditionalAssignmentWalker.prototype.visitDoStatement = function (node) {
- this.validateConditionalExpression(node.expression);
- _super.prototype.visitDoStatement.call(this, node);
- };
- NoConditionalAssignmentWalker.prototype.visitForStatement = function (node) {
- if (node.condition != null) {
- this.validateConditionalExpression(node.condition);
+function walk(ctx) {
+ var checking = 0;
+ return ts.forEachChild(ctx.sourceFile, cb);
+ function cb(node) {
+ var kind = node.kind;
+ if (!tsutils_1.isNodeKind(kind)) {
+ return; // return early for tokens
}
- _super.prototype.visitForStatement.call(this, node);
- };
- NoConditionalAssignmentWalker.prototype.visitBinaryExpression = function (expression) {
- if (this.isInConditional) {
- this.checkForAssignment(expression);
- }
- _super.prototype.visitBinaryExpression.call(this, expression);
- };
- NoConditionalAssignmentWalker.prototype.validateConditionalExpression = function (expression) {
- this.isInConditional = true;
- if (expression.kind === ts.SyntaxKind.BinaryExpression) {
- // check for simple assignment in a conditional, like `if (a = 1) {`
- this.checkForAssignment(expression);
+ switch (kind) {
+ case ts.SyntaxKind.ConditionalExpression:
+ check(node.condition);
+ cb(node.whenTrue);
+ cb(node.whenFalse);
+ return;
+ case ts.SyntaxKind.IfStatement:
+ check(node.expression);
+ cb(node.thenStatement);
+ maybeCallback(cb, node.elseStatement);
+ return;
+ case ts.SyntaxKind.DoStatement:
+ case ts.SyntaxKind.WhileStatement:
+ check(node.expression);
+ cb(node.statement);
+ return;
+ case ts.SyntaxKind.ForStatement:
+ maybeCallback(cb, node.initializer);
+ maybeCallback(check, node.condition);
+ maybeCallback(cb, node.incrementor);
+ cb(node.statement);
+ return;
}
- // walk the children of the conditional expression for nested assignments, like `if ((a = 1) && (b == 1)) {`
- this.walkChildren(expression);
- this.isInConditional = false;
- };
- NoConditionalAssignmentWalker.prototype.checkForAssignment = function (expression) {
- if (isAssignmentToken(expression.operatorToken)) {
- this.addFailureAtNode(expression, Rule.FAILURE_STRING);
+ if (checking !== 0) {
+ switch (kind) {
+ case ts.SyntaxKind.BinaryExpression:
+ if (tsutils_1.isAssignmentKind(node.operatorToken.kind)) {
+ ctx.addFailureAtNode(node, Rule.FAILURE_STRING);
+ }
+ cb(node.left);
+ cb(node.right);
+ return;
+ case ts.SyntaxKind.ParenthesizedExpression:
+ case ts.SyntaxKind.NonNullExpression:
+ case ts.SyntaxKind.AsExpression:
+ case ts.SyntaxKind.TypeAssertionExpression:
+ return cb(node.expression);
+ case ts.SyntaxKind.PrefixUnaryExpression:
+ return cb(node.operand);
+ default:
+ return noCheck(node);
+ }
}
- };
- return NoConditionalAssignmentWalker;
-}(Lint.RuleWalker));
-function isAssignmentToken(token) {
- return token.kind >= ts.SyntaxKind.FirstAssignment && token.kind <= ts.SyntaxKind.LastAssignment;
+ return ts.forEachChild(node, cb);
+ }
+ function check(node) {
+ ++checking;
+ cb(node);
+ --checking;
+ }
+ function noCheck(node) {
+ var old = checking;
+ checking = 0;
+ ts.forEachChild(node, cb);
+ checking = old;
+ }
+}
+function maybeCallback(cb, node) {
+ if (node !== undefined) {
+ cb(node);
+ }
}
var _a;
diff --git a/node_modules/tslint/lib/rules/noDuplicateImportsRule.js b/node_modules/tslint/lib/rules/noDuplicateImportsRule.js
index f8bd79d04..af7c741f8 100644
--- a/node_modules/tslint/lib/rules/noDuplicateImportsRule.js
+++ b/node_modules/tslint/lib/rules/noDuplicateImportsRule.js
@@ -18,7 +18,6 @@
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var tsutils_1 = require("tsutils");
-var ts = require("typescript");
var Lint = require("../index");
var Rule = /** @class */ (function (_super) {
tslib_1.__extends(Rule, _super);
@@ -29,7 +28,7 @@ var Rule = /** @class */ (function (_super) {
return "Multiple imports from '" + module + "' can be combined into one.";
};
Rule.prototype.apply = function (sourceFile) {
- return this.applyWithWalker(new NoDuplicateImportsWalker(sourceFile, this.ruleName, undefined));
+ return this.applyWithFunction(sourceFile, walk);
};
/* tslint:disable:object-literal-sort-keys */
Rule.metadata = {
@@ -45,37 +44,16 @@ var Rule = /** @class */ (function (_super) {
return Rule;
}(Lint.Rules.AbstractRule));
exports.Rule = Rule;
-var NoDuplicateImportsWalker = /** @class */ (function (_super) {
- tslib_1.__extends(NoDuplicateImportsWalker, _super);
- function NoDuplicateImportsWalker() {
- var _this = _super !== null && _super.apply(this, arguments) || this;
- _this.seenImports = new Set();
- return _this;
- }
- NoDuplicateImportsWalker.prototype.walk = function (sourceFile) {
- this.checkStatements(sourceFile.statements);
- };
- NoDuplicateImportsWalker.prototype.checkStatements = function (statements) {
- for (var _i = 0, statements_1 = statements; _i < statements_1.length; _i++) {
- var statement = statements_1[_i];
- if (tsutils_1.isImportDeclaration(statement)) {
- this.checkImport(statement);
- }
- else if (this.sourceFile.isDeclarationFile && tsutils_1.isModuleDeclaration(statement) &&
- statement.body !== undefined && statement.name.kind === ts.SyntaxKind.StringLiteral) {
- // module augmentations in declaration files can contain imports
- this.checkStatements(statement.body.statements);
- }
+function walk(ctx) {
+ var seen = new Set();
+ for (var _i = 0, _a = tsutils_1.findImports(ctx.sourceFile, 1 /* ImportDeclaration */); _i < _a.length; _i++) {
+ var _b = _a[_i], text = _b.text, parent = _b.parent;
+ if (seen.has(text)) {
+ ctx.addFailureAtNode(parent, Rule.FAILURE_STRING(text));
}
- };
- NoDuplicateImportsWalker.prototype.checkImport = function (statement) {
- if (tsutils_1.isTextualLiteral(statement.moduleSpecifier)) {
- if (this.seenImports.has(statement.moduleSpecifier.text)) {
- return this.addFailureAtNode(statement, Rule.FAILURE_STRING(statement.moduleSpecifier.text));
- }
- this.seenImports.add(statement.moduleSpecifier.text);
+ else {
+ seen.add(text);
}
- };
- return NoDuplicateImportsWalker;
-}(Lint.AbstractWalker));
+ }
+}
var _a, _b;
diff --git a/node_modules/tslint/lib/rules/noDuplicateSwitchCaseRule.d.ts b/node_modules/tslint/lib/rules/noDuplicateSwitchCaseRule.d.ts
new file mode 100644
index 000000000..af720ee58
--- /dev/null
+++ b/node_modules/tslint/lib/rules/noDuplicateSwitchCaseRule.d.ts
@@ -0,0 +1,23 @@
+/**
+ * @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 * as Lint from "../index";
+export declare class Rule extends Lint.Rules.AbstractRule {
+ static metadata: Lint.IRuleMetadata;
+ static readonly FAILURE_STRING_FACTORY: (text: string) => string;
+ apply(sourceFile: ts.SourceFile): Lint.RuleFailure[];
+}
diff --git a/node_modules/tslint/lib/rules/noDuplicateSwitchCaseRule.js b/node_modules/tslint/lib/rules/noDuplicateSwitchCaseRule.js
new file mode 100644
index 000000000..18b026a9d
--- /dev/null
+++ b/node_modules/tslint/lib/rules/noDuplicateSwitchCaseRule.js
@@ -0,0 +1,65 @@
+"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 ts = require("typescript");
+var Lint = require("../index");
+var Rule = /** @class */ (function (_super) {
+ tslib_1.__extends(Rule, _super);
+ function Rule() {
+ return _super !== null && _super.apply(this, arguments) || this;
+ }
+ Rule.prototype.apply = function (sourceFile) {
+ return this.applyWithFunction(sourceFile, walk);
+ };
+ Rule.metadata = {
+ description: "Prevents duplicate cases in switch statements.",
+ optionExamples: [true],
+ options: null,
+ optionsDescription: "",
+ ruleName: "no-duplicate-switch-case",
+ type: "functionality",
+ typescriptOnly: false,
+ };
+ Rule.FAILURE_STRING_FACTORY = function (text) { return "Duplicate switch case: '" + text + "'."; };
+ return Rule;
+}(Lint.Rules.AbstractRule));
+exports.Rule = Rule;
+function walk(ctx) {
+ ts.forEachChild(ctx.sourceFile, function cb(node) {
+ if (node.kind === ts.SyntaxKind.CaseBlock) {
+ visitCaseBlock(node);
+ }
+ ts.forEachChild(node, cb);
+ });
+ function visitCaseBlock(node) {
+ var previousCases = new Set();
+ for (var _i = 0, _a = node.clauses; _i < _a.length; _i++) {
+ var clause = _a[_i];
+ if (clause.kind === ts.SyntaxKind.DefaultClause) {
+ continue;
+ }
+ var text = clause.expression.getText(ctx.sourceFile);
+ if (!previousCases.has(text)) {
+ previousCases.add(text);
+ continue;
+ }
+ ctx.addFailureAtNode(clause.expression, Rule.FAILURE_STRING_FACTORY(text));
+ }
+ }
+}
diff --git a/node_modules/tslint/lib/rules/noEmptyInterfaceRule.js b/node_modules/tslint/lib/rules/noEmptyInterfaceRule.js
index ae42d72e6..f23f3aade 100644
--- a/node_modules/tslint/lib/rules/noEmptyInterfaceRule.js
+++ b/node_modules/tslint/lib/rules/noEmptyInterfaceRule.js
@@ -48,11 +48,20 @@ function walk(ctx) {
return ts.forEachChild(ctx.sourceFile, function cb(node) {
if (tsutils_1.isInterfaceDeclaration(node) &&
node.members.length === 0 &&
- (node.heritageClauses === undefined ||
- // allow interfaces that extend 2 or more interfaces
- node.heritageClauses[0].types.length < 2)) {
+ (node.heritageClauses === undefined || extendsOneTypeWithoutTypeArguments(node.heritageClauses[0]))) {
return ctx.addFailureAtNode(node.name, node.heritageClauses !== undefined ? Rule.FAILURE_STRING_FOR_EXTENDS : Rule.FAILURE_STRING);
}
return ts.forEachChild(node, cb);
});
}
+function extendsOneTypeWithoutTypeArguments(_a) {
+ var types = _a.types;
+ switch (types.length) {
+ case 0:
+ return true; // don't crash on empty extends list
+ case 1:
+ return types[0].typeArguments === undefined; // allow interfaces that provide type arguments for the extended type
+ default:
+ return false; // allow interfaces extending more than one types
+ }
+}
diff --git a/node_modules/tslint/lib/rules/noImplicitDependenciesRule.d.ts b/node_modules/tslint/lib/rules/noImplicitDependenciesRule.d.ts
new file mode 100644
index 000000000..ac0e6994f
--- /dev/null
+++ b/node_modules/tslint/lib/rules/noImplicitDependenciesRule.d.ts
@@ -0,0 +1,7 @@
+import * as ts from "typescript";
+import * as Lint from "../index";
+export declare class Rule extends Lint.Rules.AbstractRule {
+ static metadata: Lint.IRuleMetadata;
+ static FAILURE_STRING_FACTORY(module: string): string;
+ apply(sourceFile: ts.SourceFile): Lint.RuleFailure[];
+}
diff --git a/node_modules/tslint/lib/rules/noImplicitDependenciesRule.js b/node_modules/tslint/lib/rules/noImplicitDependenciesRule.js
new file mode 100644
index 000000000..212baf8ae
--- /dev/null
+++ b/node_modules/tslint/lib/rules/noImplicitDependenciesRule.js
@@ -0,0 +1,132 @@
+"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 builtins = require("builtin-modules");
+var fs = require("fs");
+var path = require("path");
+var tsutils_1 = require("tsutils");
+var ts = require("typescript");
+var Lint = require("../index");
+var OPTION_DEV = "dev";
+var OPTION_OPTIONAL = "optional";
+var Rule = /** @class */ (function (_super) {
+ tslib_1.__extends(Rule, _super);
+ function Rule() {
+ return _super !== null && _super.apply(this, arguments) || this;
+ }
+ /* tslint:enable:object-literal-sort-keys */
+ Rule.FAILURE_STRING_FACTORY = function (module) {
+ return "Module '" + module + "' is not listed as dependency in package.json";
+ };
+ Rule.prototype.apply = function (sourceFile) {
+ return this.applyWithFunction(sourceFile, walk, {
+ dev: this.ruleArguments.indexOf(OPTION_DEV) !== -1,
+ optional: this.ruleArguments.indexOf(OPTION_OPTIONAL) !== -1,
+ });
+ };
+ /* tslint:disable:object-literal-sort-keys */
+ Rule.metadata = {
+ ruleName: "no-implicit-dependencies",
+ description: "Disallows importing modules that are not listed as dependency in the project's package.json",
+ descriptionDetails: (_a = ["\n Disallows importing transient dependencies and modules installed above your package's root directory.\n "], _a.raw = ["\n Disallows importing transient dependencies and modules installed above your package's root directory.\n "], Lint.Utils.dedent(_a)),
+ optionsDescription: (_b = ["\n By default the rule looks at `\"dependencies\"` and `\"peerDependencies\"`.\n By adding the `\"", "\"` option the rule looks at `\"devDependencies\"` instead of `\"peerDependencies\"`.\n By adding the `\"", "\"` option the rule also looks at `\"optionalDependencies\"`.\n "], _b.raw = ["\n By default the rule looks at \\`\"dependencies\"\\` and \\`\"peerDependencies\"\\`.\n By adding the \\`\"", "\"\\` option the rule looks at \\`\"devDependencies\"\\` instead of \\`\"peerDependencies\"\\`.\n By adding the \\`\"", "\"\\` option the rule also looks at \\`\"optionalDependencies\"\\`.\n "], Lint.Utils.dedent(_b, OPTION_DEV, OPTION_OPTIONAL)),
+ options: {
+ type: "array",
+ items: {
+ type: "string",
+ enum: [OPTION_DEV, OPTION_OPTIONAL],
+ },
+ minItems: 0,
+ maxItems: 2,
+ },
+ optionExamples: [true, [true, OPTION_DEV], [true, OPTION_OPTIONAL]],
+ type: "functionality",
+ typescriptOnly: false,
+ };
+ return Rule;
+}(Lint.Rules.AbstractRule));
+exports.Rule = Rule;
+function walk(ctx) {
+ var options = ctx.options;
+ var dependencies;
+ for (var _i = 0, _a = tsutils_1.findImports(ctx.sourceFile, 31 /* All */); _i < _a.length; _i++) {
+ var name = _a[_i];
+ if (!ts.isExternalModuleNameRelative(name.text)) {
+ var packageName = getPackageName(name.text);
+ if (builtins.indexOf(packageName) === -1 && !hasDependency(packageName)) {
+ ctx.addFailureAtNode(name, Rule.FAILURE_STRING_FACTORY(packageName));
+ }
+ }
+ }
+ function hasDependency(module) {
+ if (dependencies === undefined) {
+ dependencies = getDependencies(ctx.sourceFile.fileName, options);
+ }
+ return dependencies.has(module);
+ }
+}
+function getPackageName(name) {
+ var parts = name.split(/\//g);
+ if (name[0] !== "@") {
+ return parts[0];
+ }
+ return parts[0] + "/" + parts[1];
+}
+function getDependencies(fileName, options) {
+ var result = new Set();
+ var packageJsonPath = findPackageJson(path.resolve(path.dirname(fileName)));
+ if (packageJsonPath !== undefined) {
+ // don't use require here to avoid caching
+ // remove BOM from file content before parsing
+ var content = JSON.parse(fs.readFileSync(packageJsonPath, "utf8").replace(/^\uFEFF/, ""));
+ if (content.dependencies !== undefined) {
+ addDependencies(result, content.dependencies);
+ }
+ if (!options.dev && content.peerDependencies !== undefined) {
+ addDependencies(result, content.peerDependencies);
+ }
+ if (options.dev && content.devDependencies !== undefined) {
+ addDependencies(result, content.devDependencies);
+ }
+ if (options.optional && content.optionalDependencies !== undefined) {
+ addDependencies(result, content.optionalDependencies);
+ }
+ }
+ return result;
+}
+function addDependencies(result, dependencies) {
+ for (var name in dependencies) {
+ if (dependencies.hasOwnProperty(name)) {
+ result.add(name);
+ }
+ }
+}
+function findPackageJson(current) {
+ var prev;
+ do {
+ var fileName = path.join(current, "package.json");
+ if (fs.existsSync(fileName)) {
+ return fileName;
+ }
+ prev = current;
+ current = path.dirname(current);
+ } while (prev !== current);
+ return undefined;
+}
+var _a, _b;
diff --git a/node_modules/tslint/lib/rules/noInvalidThisRule.d.ts b/node_modules/tslint/lib/rules/noInvalidThisRule.d.ts
index 43c9599c8..a664f16a5 100644
--- a/node_modules/tslint/lib/rules/noInvalidThisRule.d.ts
+++ b/node_modules/tslint/lib/rules/noInvalidThisRule.d.ts
@@ -1,21 +1,5 @@
-/**
- * @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 * as Lint from "../index";
+import * as Lint from "..";
export declare class Rule extends Lint.Rules.AbstractRule {
static metadata: Lint.IRuleMetadata;
static FAILURE_STRING_OUTSIDE: string;
diff --git a/node_modules/tslint/lib/rules/noInvalidThisRule.js b/node_modules/tslint/lib/rules/noInvalidThisRule.js
index b9b04a842..49333d54f 100644
--- a/node_modules/tslint/lib/rules/noInvalidThisRule.js
+++ b/node_modules/tslint/lib/rules/noInvalidThisRule.js
@@ -17,8 +17,9 @@
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
+var tsutils_1 = require("tsutils");
var ts = require("typescript");
-var Lint = require("../index");
+var Lint = require("..");
var OPTION_FUNCTION_IN_METHOD = "check-function-in-method";
var DEPRECATED_OPTION_FUNCTION_IN_METHOD = "no-this-in-function-in-method";
var Rule = /** @class */ (function (_super) {
@@ -75,6 +76,9 @@ function walk(ctx) {
break;
case ts.SyntaxKind.FunctionDeclaration:
case ts.SyntaxKind.FunctionExpression:
+ if (node.parameters.some(tsutils_1.isThisParameter)) {
+ return;
+ }
if (inClass) {
inFunctionInClass = true;
ts.forEachChild(node, cb);
diff --git a/node_modules/tslint/lib/rules/noNonNullAssertionRule.js b/node_modules/tslint/lib/rules/noNonNullAssertionRule.js
index f0c2d20f3..dc657fc53 100644
--- a/node_modules/tslint/lib/rules/noNonNullAssertionRule.js
+++ b/node_modules/tslint/lib/rules/noNonNullAssertionRule.js
@@ -30,7 +30,7 @@ var Rule = /** @class */ (function (_super) {
/* tslint:disable:object-literal-sort-keys */
Rule.metadata = {
ruleName: "no-non-null-assertion",
- description: "Disallows non-null assertions.",
+ description: "Disallows non-null assertions using the `!` postfix operator.",
rationale: "Using non-null assertion cancels the benefits of the strict null checking mode.",
optionsDescription: "Not configurable.",
options: null,
diff --git a/node_modules/tslint/lib/rules/noRedundantJsdocRule.d.ts b/node_modules/tslint/lib/rules/noRedundantJsdocRule.d.ts
new file mode 100644
index 000000000..5d51fdd37
--- /dev/null
+++ b/node_modules/tslint/lib/rules/noRedundantJsdocRule.d.ts
@@ -0,0 +1,9 @@
+import * as ts from "typescript";
+import * as Lint from "../index";
+export declare class Rule extends Lint.Rules.AbstractRule {
+ static metadata: Lint.IRuleMetadata;
+ static FAILURE_STRING_REDUNDANT_TYPE: string;
+ static FAILURE_STRING_REDUNDANT_TAG(tagName: string): string;
+ static FAILURE_STRING_NO_COMMENT(tagName: string): string;
+ apply(sourceFile: ts.SourceFile): Lint.RuleFailure[];
+}
diff --git a/node_modules/tslint/lib/rules/noRedundantJsdocRule.js b/node_modules/tslint/lib/rules/noRedundantJsdocRule.js
new file mode 100644
index 000000000..398162132
--- /dev/null
+++ b/node_modules/tslint/lib/rules/noRedundantJsdocRule.js
@@ -0,0 +1,133 @@
+"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 tsutils_1 = require("tsutils");
+var ts = require("typescript");
+var Lint = require("../index");
+var Rule = /** @class */ (function (_super) {
+ tslib_1.__extends(Rule, _super);
+ function Rule() {
+ return _super !== null && _super.apply(this, arguments) || this;
+ }
+ Rule.FAILURE_STRING_REDUNDANT_TAG = function (tagName) {
+ return "JSDoc tag '@" + tagName + "' is redundant in TypeScript code.";
+ };
+ Rule.FAILURE_STRING_NO_COMMENT = function (tagName) {
+ return "'@" + tagName + "' is redundant in TypeScript code if it has no description.";
+ };
+ Rule.prototype.apply = function (sourceFile) {
+ return this.applyWithFunction(sourceFile, walk);
+ };
+ /* tslint:disable:object-literal-sort-keys */
+ Rule.metadata = {
+ ruleName: "no-redundant-jsdoc",
+ description: "Forbids JSDoc which duplicates TypeScript functionality.",
+ optionsDescription: "Not configurable.",
+ options: null,
+ optionExamples: [true],
+ type: "style",
+ typescriptOnly: true,
+ };
+ /* tslint:enable:object-literal-sort-keys */
+ Rule.FAILURE_STRING_REDUNDANT_TYPE = "Type annotation in JSDoc is redundant in TypeScript code.";
+ return Rule;
+}(Lint.Rules.AbstractRule));
+exports.Rule = Rule;
+function walk(ctx) {
+ var sourceFile = ctx.sourceFile;
+ // Intentionally exclude EndOfFileToken: it can have JSDoc, but it is only relevant in JavaScript files
+ return sourceFile.statements.forEach(function cb(node) {
+ if (tsutils_1.canHaveJsDoc(node)) {
+ for (var _i = 0, _a = tsutils_1.getJsDoc(node, sourceFile); _i < _a.length; _i++) {
+ var tags = _a[_i].tags;
+ if (tags !== undefined) {
+ for (var _b = 0, tags_1 = tags; _b < tags_1.length; _b++) {
+ var tag = tags_1[_b];
+ checkTag(tag);
+ }
+ }
+ }
+ }
+ return ts.forEachChild(node, cb);
+ });
+ function checkTag(tag) {
+ switch (tag.kind) {
+ case ts.SyntaxKind.JSDocTag:
+ if (redundantTags.has(tag.tagName.text)) {
+ ctx.addFailureAtNode(tag.tagName, Rule.FAILURE_STRING_REDUNDANT_TAG(tag.tagName.text));
+ }
+ break;
+ case ts.SyntaxKind.JSDocAugmentsTag:
+ // OK
+ break;
+ case ts.SyntaxKind.JSDocTemplateTag:
+ case ts.SyntaxKind.JSDocTypeTag:
+ case ts.SyntaxKind.JSDocTypedefTag:
+ case ts.SyntaxKind.JSDocPropertyTag:
+ // Always redundant
+ ctx.addFailureAtNode(tag.tagName, Rule.FAILURE_STRING_REDUNDANT_TAG(tag.tagName.text));
+ break;
+ case ts.SyntaxKind.JSDocReturnTag:
+ case ts.SyntaxKind.JSDocParameterTag: {
+ var _a = tag, typeExpression = _a.typeExpression, comment = _a.comment;
+ if (typeExpression !== undefined) {
+ ctx.addFailureAtNode(typeExpression, Rule.FAILURE_STRING_REDUNDANT_TYPE);
+ }
+ if (comment === "") {
+ // Redundant if no documentation
+ ctx.addFailureAtNode(tag.tagName, Rule.FAILURE_STRING_NO_COMMENT(tag.tagName.text));
+ }
+ break;
+ }
+ default:
+ throw new Error("Unexpected tag kind: " + ts.SyntaxKind[tag.kind]);
+ }
+ }
+}
+var redundantTags = new Set([
+ "abstract",
+ "access",
+ "class",
+ "constant",
+ "constructs",
+ "default",
+ "enum",
+ "exports",
+ "function",
+ "global",
+ "implements",
+ "interface",
+ "instance",
+ "member",
+ "memberof",
+ "mixes",
+ "mixin",
+ "module",
+ "name",
+ "namespace",
+ "override",
+ "private",
+ "property",
+ "protected",
+ "public",
+ "readonly",
+ "requires",
+ "static",
+ "this",
+]);
diff --git a/node_modules/tslint/lib/rules/noReferenceImportRule.js b/node_modules/tslint/lib/rules/noReferenceImportRule.js
index 8579b5eee..108addd75 100644
--- a/node_modules/tslint/lib/rules/noReferenceImportRule.js
+++ b/node_modules/tslint/lib/rules/noReferenceImportRule.js
@@ -18,7 +18,6 @@
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var tsutils_1 = require("tsutils");
-var ts = require("typescript");
var Lint = require("../index");
var Rule = /** @class */ (function (_super) {
tslib_1.__extends(Rule, _super);
@@ -30,7 +29,7 @@ var Rule = /** @class */ (function (_super) {
return "No need to reference \"" + moduleReference + "\", since it is imported.";
};
Rule.prototype.apply = function (sourceFile) {
- return this.applyWithWalker(new NoReferenceImportWalker(sourceFile, this.ruleName, undefined));
+ return this.applyWithFunction(sourceFile, walk);
};
/* tslint:disable:object-literal-sort-keys */
Rule.metadata = {
@@ -44,55 +43,15 @@ var Rule = /** @class */ (function (_super) {
return Rule;
}(Lint.Rules.AbstractRule));
exports.Rule = Rule;
-var NoReferenceImportWalker = /** @class */ (function (_super) {
- tslib_1.__extends(NoReferenceImportWalker, _super);
- function NoReferenceImportWalker() {
- var _this = _super !== null && _super.apply(this, arguments) || this;
- _this.imports = new Set();
- return _this;
+function walk(ctx) {
+ if (ctx.sourceFile.typeReferenceDirectives.length === 0) {
+ return;
}
- NoReferenceImportWalker.prototype.walk = function (sourceFile) {
- if (sourceFile.typeReferenceDirectives.length === 0) {
- return;
+ var imports = new Set(tsutils_1.findImports(ctx.sourceFile, 3 /* AllStaticImports */).map(function (name) { return name.text; }));
+ for (var _i = 0, _a = ctx.sourceFile.typeReferenceDirectives; _i < _a.length; _i++) {
+ var ref = _a[_i];
+ if (imports.has(ref.fileName)) {
+ ctx.addFailure(ref.pos, ref.end, Rule.FAILURE_STRING(ref.fileName));
}
- this.findImports(sourceFile.statements);
- for (var _i = 0, _a = sourceFile.typeReferenceDirectives; _i < _a.length; _i++) {
- var ref = _a[_i];
- if (this.imports.has(ref.fileName)) {
- this.addFailure(ref.pos, ref.end, Rule.FAILURE_STRING(ref.fileName));
- }
- }
- };
- NoReferenceImportWalker.prototype.findImports = function (statements) {
- for (var _i = 0, statements_1 = statements; _i < statements_1.length; _i++) {
- var statement = statements_1[_i];
- if (tsutils_1.isImportDeclaration(statement)) {
- this.addImport(statement.moduleSpecifier);
- }
- else if (tsutils_1.isImportEqualsDeclaration(statement)) {
- if (statement.moduleReference.kind === ts.SyntaxKind.ExternalModuleReference &&
- statement.moduleReference.expression !== undefined) {
- this.addImport(statement.moduleReference.expression);
- }
- }
- else if (tsutils_1.isModuleDeclaration(statement) && statement.body !== undefined && this.sourceFile.isDeclarationFile) {
- // There can't be any imports in a module augmentation or namespace
- this.findImportsInModule(statement.body);
- }
- }
- };
- NoReferenceImportWalker.prototype.findImportsInModule = function (body) {
- if (body.kind === ts.SyntaxKind.ModuleBlock) {
- return this.findImports(body.statements);
- }
- else if (body.kind === ts.SyntaxKind.ModuleDeclaration && body.body !== undefined) {
- return this.findImportsInModule(body.body);
- }
- };
- NoReferenceImportWalker.prototype.addImport = function (specifier) {
- if (tsutils_1.isStringLiteral(specifier)) {
- this.imports.add(specifier.text);
- }
- };
- return NoReferenceImportWalker;
-}(Lint.AbstractWalker));
+ }
+}
diff --git a/node_modules/tslint/lib/rules/noRequireImportsRule.js b/node_modules/tslint/lib/rules/noRequireImportsRule.js
index 77c7d155f..7fd8037f2 100644
--- a/node_modules/tslint/lib/rules/noRequireImportsRule.js
+++ b/node_modules/tslint/lib/rules/noRequireImportsRule.js
@@ -18,7 +18,6 @@
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var tsutils_1 = require("tsutils");
-var ts = require("typescript");
var Lint = require("../index");
var Rule = /** @class */ (function (_super) {
tslib_1.__extends(Rule, _super);
@@ -45,17 +44,8 @@ var Rule = /** @class */ (function (_super) {
}(Lint.Rules.AbstractRule));
exports.Rule = Rule;
function walk(ctx) {
- return ts.forEachChild(ctx.sourceFile, function cb(node) {
- if (tsutils_1.isCallExpression(node)) {
- if (node.arguments.length !== 0 &&
- tsutils_1.isIdentifier(node.expression) && node.expression.text === "require") {
- ctx.addFailureAtNode(node, Rule.FAILURE_STRING);
- }
- }
- else if (tsutils_1.isImportEqualsDeclaration(node) &&
- node.moduleReference.kind === ts.SyntaxKind.ExternalModuleReference) {
- ctx.addFailureAtNode(node.moduleReference, Rule.FAILURE_STRING);
- }
- return ts.forEachChild(node, cb);
- });
+ for (var _i = 0, _a = tsutils_1.findImports(ctx.sourceFile, 18 /* AllRequireLike */); _i < _a.length; _i++) {
+ var name = _a[_i];
+ ctx.addFailureAtNode(name.parent, Rule.FAILURE_STRING);
+ }
}
diff --git a/node_modules/tslint/lib/rules/noReturnAwaitRule.d.ts b/node_modules/tslint/lib/rules/noReturnAwaitRule.d.ts
new file mode 100644
index 000000000..cce59d100
--- /dev/null
+++ b/node_modules/tslint/lib/rules/noReturnAwaitRule.d.ts
@@ -0,0 +1,7 @@
+import * as ts from "typescript";
+import * as Lint from "../index";
+export declare class Rule extends Lint.Rules.AbstractRule {
+ static metadata: Lint.IRuleMetadata;
+ static FAILURE_STRING: string;
+ apply(sourceFile: ts.SourceFile): Lint.RuleFailure[];
+}
diff --git a/node_modules/tslint/lib/rules/noReturnAwaitRule.js b/node_modules/tslint/lib/rules/noReturnAwaitRule.js
new file mode 100644
index 000000000..67cc188ad
--- /dev/null
+++ b/node_modules/tslint/lib/rules/noReturnAwaitRule.js
@@ -0,0 +1,110 @@
+"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 tsutils_1 = require("tsutils");
+var ts = require("typescript");
+var Lint = require("../index");
+var Rule = /** @class */ (function (_super) {
+ tslib_1.__extends(Rule, _super);
+ function Rule() {
+ return _super !== null && _super.apply(this, arguments) || this;
+ }
+ Rule.prototype.apply = function (sourceFile) {
+ return this.applyWithFunction(sourceFile, walk);
+ };
+ /* tslint:disable:object-literal-sort-keys */
+ Rule.metadata = {
+ ruleName: "no-return-await",
+ description: "Disallows unnecessary `return await`.",
+ rationale: (_a = ["\n An async function always wraps the return value in a Promise.\n Using `return await` just adds extra time before the overreaching promise is resolved without changing the semantics.\n "], _a.raw = ["\n An async function always wraps the return value in a Promise.\n Using \\`return await\\` just adds extra time before the overreaching promise is resolved without changing the semantics.\n "], Lint.Utils.dedent(_a)),
+ optionsDescription: "Not configurable.",
+ options: null,
+ optionExamples: [true],
+ type: "functionality",
+ typescriptOnly: false,
+ hasFix: true,
+ };
+ /* tslint:enable:object-literal-sort-keys */
+ Rule.FAILURE_STRING = "Unnecessary 'await'.";
+ return Rule;
+}(Lint.Rules.AbstractRule));
+exports.Rule = Rule;
+function walk(ctx) {
+ return ts.forEachChild(ctx.sourceFile, function cb(node) {
+ if (node.kind === ts.SyntaxKind.AwaitExpression && isUnnecessaryAwait(node)) {
+ var expression = node.expression;
+ var keywordStart = expression.pos - "await".length;
+ ctx.addFailure(keywordStart, expression.pos, Rule.FAILURE_STRING, Lint.Replacement.deleteFromTo(keywordStart, expression.getStart(ctx.sourceFile)));
+ }
+ return ts.forEachChild(node, cb);
+ });
+}
+function isUnnecessaryAwait(node) {
+ while (true) {
+ var parent = node.parent;
+ outer: switch (parent.kind) {
+ case ts.SyntaxKind.ArrowFunction:
+ return true;
+ case ts.SyntaxKind.ReturnStatement:
+ return !isInsideTryBlock(parent.parent);
+ case ts.SyntaxKind.ParenthesizedExpression:
+ break;
+ case ts.SyntaxKind.ConditionalExpression:
+ if (parent.condition === node) {
+ return false;
+ }
+ break;
+ case ts.SyntaxKind.BinaryExpression:
+ if (parent.right === node) {
+ switch (parent.operatorToken.kind) {
+ case ts.SyntaxKind.AmpersandAmpersandToken:
+ case ts.SyntaxKind.BarBarToken:
+ case ts.SyntaxKind.CommaToken:
+ break outer;
+ }
+ }
+ return false;
+ default:
+ return false;
+ }
+ node = parent;
+ }
+}
+function isInsideTryBlock(node) {
+ while (node.parent !== undefined) {
+ if (tsutils_1.isFunctionScopeBoundary(node)) {
+ return false;
+ }
+ if (tsutils_1.isTryStatement(node.parent)) {
+ if (
+ // statements inside the try block always have an error handler, either catch or finally
+ node.parent.tryBlock === node ||
+ // statement inside the catch block only have an error handler if there is a finally block
+ node.parent.finallyBlock !== undefined && node.parent.catchClause === node) {
+ return true;
+ }
+ node = node.parent.parent;
+ }
+ else {
+ node = node.parent;
+ }
+ }
+ return false;
+}
+var _a;
diff --git a/node_modules/tslint/lib/rules/noShadowedVariableRule.js b/node_modules/tslint/lib/rules/noShadowedVariableRule.js
index 6ca830085..c2db583c6 100644
--- a/node_modules/tslint/lib/rules/noShadowedVariableRule.js
+++ b/node_modules/tslint/lib/rules/noShadowedVariableRule.js
@@ -37,7 +37,7 @@ var Rule = /** @class */ (function (_super) {
ruleName: "no-shadowed-variable",
description: "Disallows shadowing variable declarations.",
rationale: "Shadowing a variable masks access to it and obscures to what value an identifier actually refers.",
- optionsDescription: (_a = ["\n You can optionally pass an object to disable checking for certain kinds of declarations.\n Possible keys are `\"class\"`, `\"enum\"`, `\"function\"`, `\"import\"`, `\"interface\"`, `\"namespace\"`, `\"typeAlias\"`\n and `\"typeParameter\"`. Just set the value to `false` for the check you want to disable.\n All checks default to `true`, i.e. are enabled by default.\n Not that you cannot disable variables and parameters.\n "], _a.raw = ["\n You can optionally pass an object to disable checking for certain kinds of declarations.\n Possible keys are \\`\"class\"\\`, \\`\"enum\"\\`, \\`\"function\"\\`, \\`\"import\"\\`, \\`\"interface\"\\`, \\`\"namespace\"\\`, \\`\"typeAlias\"\\`\n and \\`\"typeParameter\"\\`. Just set the value to \\`false\\` for the check you want to disable.\n All checks default to \\`true\\`, i.e. are enabled by default.\n Not that you cannot disable variables and parameters.\n "], Lint.Utils.dedent(_a)),
+ optionsDescription: (_a = ["\n You can optionally pass an object to disable checking for certain kinds of declarations.\n Possible keys are `\"class\"`, `\"enum\"`, `\"function\"`, `\"import\"`, `\"interface\"`, `\"namespace\"`, `\"typeAlias\"`\n and `\"typeParameter\"`. Just set the value to `false` for the check you want to disable.\n All checks default to `true`, i.e. are enabled by default.\n Note that you cannot disable variables and parameters.\n "], _a.raw = ["\n You can optionally pass an object to disable checking for certain kinds of declarations.\n Possible keys are \\`\"class\"\\`, \\`\"enum\"\\`, \\`\"function\"\\`, \\`\"import\"\\`, \\`\"interface\"\\`, \\`\"namespace\"\\`, \\`\"typeAlias\"\\`\n and \\`\"typeParameter\"\\`. Just set the value to \\`false\\` for the check you want to disable.\n All checks default to \\`true\\`, i.e. are enabled by default.\n Note that you cannot disable variables and parameters.\n "], Lint.Utils.dedent(_a)),
options: {
type: "object",
properties: {
diff --git a/node_modules/tslint/lib/rules/noStringLiteralRule.js b/node_modules/tslint/lib/rules/noStringLiteralRule.js
index 7774cbcb2..c543aa4d8 100644
--- a/node_modules/tslint/lib/rules/noStringLiteralRule.js
+++ b/node_modules/tslint/lib/rules/noStringLiteralRule.js
@@ -50,9 +50,11 @@ function walk(ctx) {
if (tsutils_1.isElementAccessExpression(node)) {
var argument = node.argumentExpression;
if (argument !== undefined && tsutils_1.isStringLiteral(argument) && tsutils_1.isValidPropertyAccess(argument.text)) {
+ // for compatibility with typescript@<2.5.0 to avoid fixing expr['__foo'] to expr.___foo
+ var propertyName = ts.unescapeIdentifier(argument.text); // tslint:disable-line:deprecation
ctx.addFailureAtNode(argument, Rule.FAILURE_STRING,
// expr['foo'] -> expr.foo
- Lint.Replacement.replaceFromTo(node.expression.end, node.end, "." + argument.text));
+ Lint.Replacement.replaceFromTo(node.expression.end, node.end, "." + propertyName));
}
}
return ts.forEachChild(node, cb);
diff --git a/node_modules/tslint/lib/rules/noSubmoduleImportsRule.js b/node_modules/tslint/lib/rules/noSubmoduleImportsRule.js
index 37e661b1f..d0ae3c619 100644
--- a/node_modules/tslint/lib/rules/noSubmoduleImportsRule.js
+++ b/node_modules/tslint/lib/rules/noSubmoduleImportsRule.js
@@ -26,7 +26,7 @@ var Rule = /** @class */ (function (_super) {
return _super !== null && _super.apply(this, arguments) || this;
}
Rule.prototype.apply = function (sourceFile) {
- return this.applyWithWalker(new NoSubmoduleImportsWalker(sourceFile, this.ruleName, this.ruleArguments));
+ return this.applyWithFunction(sourceFile, walk, this.ruleArguments);
};
/* tslint:disable:object-literal-sort-keys */
Rule.metadata = {
@@ -48,61 +48,27 @@ var Rule = /** @class */ (function (_super) {
return Rule;
}(Lint.Rules.AbstractRule));
exports.Rule = Rule;
-var NoSubmoduleImportsWalker = /** @class */ (function (_super) {
- tslib_1.__extends(NoSubmoduleImportsWalker, _super);
- function NoSubmoduleImportsWalker() {
- return _super !== null && _super.apply(this, arguments) || this;
- }
- NoSubmoduleImportsWalker.prototype.walk = function (sourceFile) {
- var _this = this;
- var findDynamicImport = function (node) {
- if (tsutils_1.isCallExpression(node) && node.arguments.length === 1 &&
- (tsutils_1.isIdentifier(node.expression) && node.expression.text === "require" ||
- node.expression.kind === ts.SyntaxKind.ImportKeyword)) {
- _this.checkForBannedImport(node.arguments[0]);
- }
- return ts.forEachChild(node, findDynamicImport);
- };
- for (var _i = 0, _a = sourceFile.statements; _i < _a.length; _i++) {
- var statement = _a[_i];
- if (tsutils_1.isImportDeclaration(statement)) {
- this.checkForBannedImport(statement.moduleSpecifier);
- }
- else if (tsutils_1.isImportEqualsDeclaration(statement)) {
- if (tsutils_1.isExternalModuleReference(statement.moduleReference) && statement.moduleReference.expression !== undefined) {
- this.checkForBannedImport(statement.moduleReference.expression);
- }
- }
- else {
- ts.forEachChild(statement, findDynamicImport);
- }
+function walk(ctx) {
+ for (var _i = 0, _a = tsutils_1.findImports(ctx.sourceFile, 31 /* All */); _i < _a.length; _i++) {
+ var name = _a[_i];
+ // TODO remove assertion on upgrade to typescript@2.5.2
+ if (!ts.isExternalModuleNameRelative(name.text) &&
+ isSubmodulePath(name.text) &&
+ !isWhitelisted(name.text, ctx.options)) {
+ ctx.addFailureAtNode(name, Rule.FAILURE_STRING);
}
- };
- NoSubmoduleImportsWalker.prototype.checkForBannedImport = function (expression) {
- if (tsutils_1.isTextualLiteral(expression) &&
- // TODO remove assertion on upgrade to typescript@2.5.2
- !ts.isExternalModuleNameRelative(expression.text) &&
- isSubmodulePath(expression.text)) {
- /*
- * A submodule is being imported.
- * Check if its path contains any
- * of the whitelist packages.
- */
- for (var _i = 0, _a = this.options; _i < _a.length; _i++) {
- var option = _a[_i];
- if (expression.text === option || expression.text.startsWith(option + "/")) {
- return;
- }
- }
- this.addFailureAtNode(expression, Rule.FAILURE_STRING);
+ }
+}
+function isWhitelisted(path, whitelist) {
+ for (var _i = 0, whitelist_1 = whitelist; _i < whitelist_1.length; _i++) {
+ var option = whitelist_1[_i];
+ if (path === option || path.startsWith(option + "/")) {
+ return true;
}
- };
- return NoSubmoduleImportsWalker;
-}(Lint.AbstractWalker));
-function isScopedPath(path) {
- return path[0] === "@";
+ }
+ return false;
}
function isSubmodulePath(path) {
- return path.split("/").length > (isScopedPath(path) ? 2 : 1);
+ return path.split("/").length > (path[0] === "@" ? 2 : 1);
}
var _a, _b;
diff --git a/node_modules/tslint/lib/rules/noTrailingWhitespaceRule.js b/node_modules/tslint/lib/rules/noTrailingWhitespaceRule.js
index 3531bc9ae..5ad6cbe8a 100644
--- a/node_modules/tslint/lib/rules/noTrailingWhitespaceRule.js
+++ b/node_modules/tslint/lib/rules/noTrailingWhitespaceRule.js
@@ -24,6 +24,7 @@ var noConsecutiveBlankLinesRule_1 = require("./noConsecutiveBlankLinesRule");
var OPTION_IGNORE_COMMENTS = "ignore-comments";
var OPTION_IGNORE_JSDOC = "ignore-jsdoc";
var OPTION_IGNORE_TEMPLATE_STRINGS = "ignore-template-strings";
+var OPTION_IGNORE_BLANK_LINES = "ignore-blank-lines";
var Rule = /** @class */ (function (_super) {
tslib_1.__extends(Rule, _super);
function Rule() {
@@ -32,6 +33,7 @@ var Rule = /** @class */ (function (_super) {
Rule.prototype.apply = function (sourceFile) {
var ignoreComments = this.ruleArguments.indexOf(OPTION_IGNORE_COMMENTS) !== -1;
return this.applyWithFunction(sourceFile, walk, {
+ ignoreBlankLines: this.ruleArguments.indexOf(OPTION_IGNORE_BLANK_LINES) !== -1,
ignoreComments: ignoreComments,
ignoreJsDoc: ignoreComments || this.ruleArguments.indexOf(OPTION_IGNORE_JSDOC) !== -1,
ignoreTemplates: this.ruleArguments.indexOf(OPTION_IGNORE_TEMPLATE_STRINGS) !== -1,
@@ -42,13 +44,13 @@ var Rule = /** @class */ (function (_super) {
ruleName: "no-trailing-whitespace",
description: "Disallows trailing whitespace at the end of a line.",
rationale: "Keeps version control diffs clean as it prevents accidental whitespace from being committed.",
- optionsDescription: (_a = ["\n Possible settings are:\n\n * `\"", "\"`: Allows trailing whitespace in template strings.\n * `\"", "\"`: Allows trailing whitespace in comments.\n * `\"", "\"`: Allows trailing whitespace only in JSDoc comments."], _a.raw = ["\n Possible settings are:\n\n * \\`\"", "\"\\`: Allows trailing whitespace in template strings.\n * \\`\"", "\"\\`: Allows trailing whitespace in comments.\n * \\`\"", "\"\\`: Allows trailing whitespace only in JSDoc comments."], Lint.Utils.dedent(_a, OPTION_IGNORE_TEMPLATE_STRINGS, OPTION_IGNORE_COMMENTS, OPTION_IGNORE_JSDOC)),
+ optionsDescription: (_a = ["\n Possible settings are:\n\n * `\"", "\"`: Allows trailing whitespace in template strings.\n * `\"", "\"`: Allows trailing whitespace in comments.\n * `\"", "\"`: Allows trailing whitespace only in JSDoc comments.\n * `\"", "\"`: Allows trailing whitespace on empty lines."], _a.raw = ["\n Possible settings are:\n\n * \\`\"", "\"\\`: Allows trailing whitespace in template strings.\n * \\`\"", "\"\\`: Allows trailing whitespace in comments.\n * \\`\"", "\"\\`: Allows trailing whitespace only in JSDoc comments.\n * \\`\"", "\"\\`: Allows trailing whitespace on empty lines."], Lint.Utils.dedent(_a, OPTION_IGNORE_TEMPLATE_STRINGS, OPTION_IGNORE_COMMENTS, OPTION_IGNORE_JSDOC, OPTION_IGNORE_BLANK_LINES)),
hasFix: true,
options: {
type: "array",
items: {
type: "string",
- enum: [OPTION_IGNORE_COMMENTS, OPTION_IGNORE_JSDOC, OPTION_IGNORE_TEMPLATE_STRINGS],
+ enum: [OPTION_IGNORE_COMMENTS, OPTION_IGNORE_JSDOC, OPTION_IGNORE_TEMPLATE_STRINGS, OPTION_IGNORE_BLANK_LINES],
},
},
optionExamples: [
@@ -70,8 +72,9 @@ function walk(ctx) {
var text = sourceFile.text;
for (var _i = 0, _a = tsutils_1.getLineRanges(sourceFile); _i < _a.length; _i++) {
var line = _a[_i];
+ // \s matches any whitespace character (equal to [\r\n\t\f\v ])
var match = text.substr(line.pos, line.contentLength).match(/\s+$/);
- if (match !== null) {
+ if (match !== null && !(ctx.options.ignoreBlankLines && match.index === 0)) {
possibleFailures.push({
end: line.pos + line.contentLength,
pos: line.pos + match.index,
diff --git a/node_modules/tslint/lib/rules/noUnboundMethodRule.js b/node_modules/tslint/lib/rules/noUnboundMethodRule.js
index a60eb6335..153550c57 100644
--- a/node_modules/tslint/lib/rules/noUnboundMethodRule.js
+++ b/node_modules/tslint/lib/rules/noUnboundMethodRule.js
@@ -96,6 +96,7 @@ function isSafeUse(node) {
case ts.SyntaxKind.WhileStatement:
case ts.SyntaxKind.DoStatement:
case ts.SyntaxKind.ForStatement:
+ case ts.SyntaxKind.PrefixUnaryExpression:
return true;
default:
return false;
diff --git a/node_modules/tslint/lib/rules/noUnnecessaryClassRule.d.ts b/node_modules/tslint/lib/rules/noUnnecessaryClassRule.d.ts
new file mode 100644
index 000000000..afaa33e43
--- /dev/null
+++ b/node_modules/tslint/lib/rules/noUnnecessaryClassRule.d.ts
@@ -0,0 +1,25 @@
+/**
+ * @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 * as Lint from "../index";
+export declare class Rule extends Lint.Rules.AbstractRule {
+ static metadata: Lint.IRuleMetadata;
+ static FAILURE_CONSTRUCTOR_ONLY: string;
+ static FAILURE_STATIC_ONLY: string;
+ static FAILURE_EMPTY_CLASS: string;
+ apply(sourceFile: ts.SourceFile): Lint.RuleFailure[];
+}
diff --git a/node_modules/tslint/lib/rules/noUnnecessaryClassRule.js b/node_modules/tslint/lib/rules/noUnnecessaryClassRule.js
new file mode 100644
index 000000000..fff8b5ed1
--- /dev/null
+++ b/node_modules/tslint/lib/rules/noUnnecessaryClassRule.js
@@ -0,0 +1,113 @@
+"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 ts = require("typescript");
+var Lint = require("../index");
+var tsutils_1 = require("tsutils");
+var OPTION__ALLOW_CONSTRUCTOR_ONLY = "allow-constructor-only";
+var OPTION__ALLOW_EMPTY_CLASS = "allow-empty-class";
+var OPTION__ALLOW_STATIC_ONLY = "allow-static-only";
+function parseOptions(options) {
+ return {
+ allowConstructorOnly: options.indexOf(OPTION__ALLOW_CONSTRUCTOR_ONLY) !== -1,
+ allowEmptyClass: options.indexOf(OPTION__ALLOW_EMPTY_CLASS) !== -1,
+ allowStaticOnly: options.indexOf(OPTION__ALLOW_STATIC_ONLY) !== -1,
+ };
+}
+var Rule = /** @class */ (function (_super) {
+ tslib_1.__extends(Rule, _super);
+ function Rule() {
+ return _super !== null && _super.apply(this, arguments) || this;
+ }
+ Rule.prototype.apply = function (sourceFile) {
+ return this.applyWithWalker(new NoUnnecessaryClassWalker(sourceFile, this.ruleName, parseOptions(this.ruleArguments)));
+ };
+ /* tslint:disable:object-literal-sort-keys */
+ Rule.metadata = {
+ ruleName: "no-unnecessary-class",
+ description: (_a = ["\n Disallows classes that are not strictly necessary."], _a.raw = ["\n Disallows classes that are not strictly necessary."], Lint.Utils.dedent(_a)),
+ rationale: (_b = ["\n Users who come from a Java-style OO language may wrap\n their utility functions in an extra class, instead of\n putting them at the top level."], _b.raw = ["\n Users who come from a Java-style OO language may wrap\n their utility functions in an extra class, instead of\n putting them at the top level."], Lint.Utils.dedent(_b)),
+ optionsDescription: (_c = ["\n Three arguments may be optionally provided:\n\n * `\"allow-constructor-only\"` ignores classes whose members are constructors.\n * `\"allow-empty-class\"` ignores `class DemoClass {}`.\n * `\"allow-static-only\"` ignores classes whose members are static."], _c.raw = ["\n Three arguments may be optionally provided:\n\n * \\`\"allow-constructor-only\"\\` ignores classes whose members are constructors.\n * \\`\"allow-empty-class\"\\` ignores \\`class DemoClass {}\\`.\n * \\`\"allow-static-only\"\\` ignores classes whose members are static."], Lint.Utils.dedent(_c)),
+ options: {
+ type: "array",
+ items: {
+ type: "string",
+ },
+ minLength: 0,
+ maxLength: 3,
+ },
+ optionExamples: [true, ["allow-empty-class", "allow-constructor-only"]],
+ type: "functionality",
+ typescriptOnly: false,
+ };
+ /* tslint:enable:object-literal-sort-keys */
+ Rule.FAILURE_CONSTRUCTOR_ONLY = "Every member of this class is a constructor. Use functions instead.";
+ Rule.FAILURE_STATIC_ONLY = "Every member of this class is static. Use namespaces or plain objects instead.";
+ Rule.FAILURE_EMPTY_CLASS = "This class has no members.";
+ return Rule;
+}(Lint.Rules.AbstractRule));
+exports.Rule = Rule;
+var NoUnnecessaryClassWalker = /** @class */ (function (_super) {
+ tslib_1.__extends(NoUnnecessaryClassWalker, _super);
+ function NoUnnecessaryClassWalker() {
+ return _super !== null && _super.apply(this, arguments) || this;
+ }
+ NoUnnecessaryClassWalker.prototype.walk = function (sourceFile) {
+ var _this = this;
+ var checkIfUnnecessaryClass = function (node) {
+ if (tsutils_1.isClassDeclaration(node) && !hasExtendsClause(node)) {
+ _this.checkMembers(node);
+ }
+ return ts.forEachChild(node, checkIfUnnecessaryClass);
+ };
+ ts.forEachChild(sourceFile, checkIfUnnecessaryClass);
+ };
+ NoUnnecessaryClassWalker.prototype.checkMembers = function (node) {
+ if (node.members.length === 0) {
+ if (!this.options.allowEmptyClass) {
+ this.addFailureAtNode(tsutils_1.getChildOfKind(node, ts.SyntaxKind.ClassKeyword), Rule.FAILURE_EMPTY_CLASS);
+ }
+ return;
+ }
+ var allMembersAreConstructors = node.members.every(tsutils_1.isConstructorDeclaration);
+ if (allMembersAreConstructors &&
+ !this.options.allowConstructorOnly &&
+ !node.members.some(isConstructorWithShorthandProps)) {
+ this.addFailureAtNode(tsutils_1.getChildOfKind(node, ts.SyntaxKind.ClassKeyword, this.sourceFile), Rule.FAILURE_CONSTRUCTOR_ONLY);
+ }
+ if (!allMembersAreConstructors &&
+ !this.options.allowStaticOnly &&
+ !node.members.some(isNonStaticMember)) {
+ this.addFailureAtNode(tsutils_1.getChildOfKind(node, ts.SyntaxKind.ClassKeyword, this.sourceFile), Rule.FAILURE_STATIC_ONLY);
+ }
+ };
+ return NoUnnecessaryClassWalker;
+}(Lint.AbstractWalker));
+function isNonStaticMember(member) {
+ return (isConstructorWithShorthandProps(member) ||
+ (!tsutils_1.isConstructorDeclaration(member) && !tsutils_1.hasModifier(member.modifiers, ts.SyntaxKind.StaticKeyword)));
+}
+function hasExtendsClause(declaration) {
+ return (declaration.heritageClauses !== undefined &&
+ declaration.heritageClauses[0].token === ts.SyntaxKind.ExtendsKeyword);
+}
+function isConstructorWithShorthandProps(member) {
+ return tsutils_1.isConstructorDeclaration(member) && member.parameters.some(tsutils_1.isParameterProperty);
+}
+var _a, _b, _c;
diff --git a/node_modules/tslint/lib/rules/noUnnecessaryQualifierRule.js b/node_modules/tslint/lib/rules/noUnnecessaryQualifierRule.js
index ff2858c41..a9a32b362 100644
--- a/node_modules/tslint/lib/rules/noUnnecessaryQualifierRule.js
+++ b/node_modules/tslint/lib/rules/noUnnecessaryQualifierRule.js
@@ -103,7 +103,7 @@ function walk(ctx, checker) {
}
function symbolIsNamespaceInScope(symbol) {
var symbolDeclarations = symbol.getDeclarations();
- if (symbolDeclarations == null) {
+ if (symbolDeclarations === undefined) {
return false;
}
else if (symbolDeclarations.some(function (decl) { return namespacesInScope.some(function (ns) { return ns === decl; }); })) {
diff --git a/node_modules/tslint/lib/rules/noUnnecessaryTypeAssertionRule.js b/node_modules/tslint/lib/rules/noUnnecessaryTypeAssertionRule.js
index 97a06adfc..6af6a0d60 100644
--- a/node_modules/tslint/lib/rules/noUnnecessaryTypeAssertionRule.js
+++ b/node_modules/tslint/lib/rules/noUnnecessaryTypeAssertionRule.js
@@ -26,14 +26,20 @@ var Rule = /** @class */ (function (_super) {
return _super !== null && _super.apply(this, arguments) || this;
}
Rule.prototype.applyWithProgram = function (sourceFile, program) {
- return this.applyWithWalker(new Walker(sourceFile, this.ruleName, program.getTypeChecker()));
+ return this.applyWithWalker(new Walker(sourceFile, this.ruleName, this.ruleArguments, program.getTypeChecker()));
};
/* tslint:disable:object-literal-sort-keys */
Rule.metadata = {
ruleName: "no-unnecessary-type-assertion",
description: "Warns if a type assertion does not change the type of an expression.",
- options: null,
- optionsDescription: "Not configurable",
+ options: {
+ type: "list",
+ listType: {
+ type: "array",
+ items: { type: "string" },
+ },
+ },
+ optionsDescription: "A list of whitelisted assertion types to ignore",
type: "typescript",
hasFix: true,
typescriptOnly: true,
@@ -46,8 +52,8 @@ var Rule = /** @class */ (function (_super) {
exports.Rule = Rule;
var Walker = /** @class */ (function (_super) {
tslib_1.__extends(Walker, _super);
- function Walker(sourceFile, ruleName, checker) {
- var _this = _super.call(this, sourceFile, ruleName, undefined) || this;
+ function Walker(sourceFile, ruleName, options, checker) {
+ var _this = _super.call(this, sourceFile, ruleName, options) || this;
_this.checker = checker;
return _this;
}
@@ -65,6 +71,9 @@ var Walker = /** @class */ (function (_super) {
return ts.forEachChild(sourceFile, cb);
};
Walker.prototype.verifyCast = function (node) {
+ if (tsutils_1.isAssertionExpression(node) && this.options.indexOf(node.type.getText(this.sourceFile)) !== -1) {
+ return;
+ }
var castType = this.checker.getTypeAtLocation(node);
if (castType === undefined) {
return;
@@ -72,7 +81,12 @@ var Walker = /** @class */ (function (_super) {
if (node.kind !== ts.SyntaxKind.NonNullExpression &&
(tsutils_1.isTypeFlagSet(castType, ts.TypeFlags.Literal) ||
tsutils_1.isObjectType(castType) &&
- tsutils_1.isObjectFlagSet(castType, ts.ObjectFlags.Tuple))) {
+ tsutils_1.isObjectFlagSet(castType, ts.ObjectFlags.Tuple)) ||
+ // Sometimes tuple types don't have ObjectFlags.Tuple set, like when
+ // they're being matched against an inferred type. So, in addition,
+ // check if any properties are numbers, which implies that this is
+ // likely a tuple type.
+ (castType.getProperties().some(function (symbol) { return !isNaN(Number(symbol.name)); }))) {
// It's not always safe to remove a cast to a literal type or tuple
// type, as those types are sometimes widened without the cast.
return;
diff --git a/node_modules/tslint/lib/rules/noUnsafeAnyRule.js b/node_modules/tslint/lib/rules/noUnsafeAnyRule.js
index 3ff493ce9..c0a36360a 100644
--- a/node_modules/tslint/lib/rules/noUnsafeAnyRule.js
+++ b/node_modules/tslint/lib/rules/noUnsafeAnyRule.js
@@ -26,7 +26,7 @@ var Rule = /** @class */ (function (_super) {
return _super !== null && _super.apply(this, arguments) || this;
}
Rule.prototype.applyWithProgram = function (sourceFile, program) {
- return this.applyWithFunction(sourceFile, walk, undefined, program.getTypeChecker());
+ return this.applyWithWalker(new NoUnsafeAnyWalker(sourceFile, this.ruleName, program.getTypeChecker()));
};
/* tslint:disable:object-literal-sort-keys */
Rule.metadata = {
@@ -44,229 +44,319 @@ var Rule = /** @class */ (function (_super) {
return Rule;
}(Lint.Rules.TypedRule));
exports.Rule = Rule;
-function walk(ctx, checker) {
- if (ctx.sourceFile.isDeclarationFile) {
- // Not possible in a declaration file.
- return;
+var NoUnsafeAnyWalker = /** @class */ (function (_super) {
+ tslib_1.__extends(NoUnsafeAnyWalker, _super);
+ function NoUnsafeAnyWalker(sourceFile, ruleName, checker) {
+ var _this = _super.call(this, sourceFile, ruleName, undefined) || this;
+ _this.checker = checker;
+ /** Wraps `visitNode` with the correct `this` binding and discards the return value to prevent `forEachChild` from returning early */
+ _this.visitNodeCallback = function (node) { return void _this.visitNode(node); };
+ return _this;
}
- return ts.forEachChild(ctx.sourceFile, cb);
- /** @param anyOk If true, this node will be allowed to be of type *any*. (But its children might not.) */
- function cb(node, anyOk) {
+ NoUnsafeAnyWalker.prototype.walk = function (sourceFile) {
+ if (sourceFile.isDeclarationFile) {
+ return; // Not possible in a declaration file.
+ }
+ sourceFile.statements.forEach(this.visitNodeCallback);
+ };
+ NoUnsafeAnyWalker.prototype.visitNode = function (node, anyOk) {
switch (node.kind) {
case ts.SyntaxKind.ParenthesizedExpression:
// Don't warn on a parenthesized expression, warn on its contents.
- return cb(node.expression, anyOk);
- case ts.SyntaxKind.Parameter: {
- var _a = node, type = _a.type, initializer = _a.initializer;
- // TODO handle destructuring
- if (initializer !== undefined) {
- return cb(initializer, /*anyOk*/ type !== undefined && type.kind === ts.SyntaxKind.AnyKeyword);
- }
- return;
- }
+ return this.visitNode(node.expression, anyOk);
case ts.SyntaxKind.LabeledStatement:
// Ignore label
- return cb(node.statement);
- case ts.SyntaxKind.BreakStatement: // Ignore label
+ return this.visitNode(node.statement);
+ // ignore labels
+ case ts.SyntaxKind.BreakStatement:
case ts.SyntaxKind.ContinueStatement:
// Ignore types
case ts.SyntaxKind.InterfaceDeclaration:
case ts.SyntaxKind.TypeAliasDeclaration:
- case ts.SyntaxKind.QualifiedName:
- case ts.SyntaxKind.TypePredicate:
- case ts.SyntaxKind.TypeOfExpression:
+ case ts.SyntaxKind.TypeParameter:
+ case ts.SyntaxKind.IndexSignature:
// Ignore imports
case ts.SyntaxKind.ImportEqualsDeclaration:
case ts.SyntaxKind.ImportDeclaration:
case ts.SyntaxKind.ExportDeclaration:
- // These show as type "any" if in type position.
- case ts.SyntaxKind.NumericLiteral:
- case ts.SyntaxKind.StringLiteral:
- return;
+ case ts.SyntaxKind.ExportAssignment:
+ return false;
+ case ts.SyntaxKind.ThisKeyword:
+ case ts.SyntaxKind.Identifier:
+ return anyOk ? false : this.check(node);
// Recurse through these, but ignore the immediate child because it is allowed to be 'any'.
case ts.SyntaxKind.DeleteExpression:
case ts.SyntaxKind.ExpressionStatement:
case ts.SyntaxKind.TypeAssertionExpression:
case ts.SyntaxKind.AsExpression:
case ts.SyntaxKind.TemplateSpan: // Allow stringification (works on all values). Note: tagged templates handled differently.
- case ts.SyntaxKind.ThrowStatement: {
- var expression = node.expression;
- return cb(expression, /*anyOk*/ true);
- }
+ case ts.SyntaxKind.ThrowStatement:
+ case ts.SyntaxKind.TypeOfExpression:
+ case ts.SyntaxKind.VoidExpression:
+ return this.visitNode(node.expression, true);
case ts.SyntaxKind.PropertyAssignment: {
- // Only check RHS.
- var _b = node, name = _b.name, initializer = _b.initializer;
- // The LHS will be 'any' if the RHS is, so just handle the RHS.
- // Still need to check the LHS in case it is a computed key.
- cb(name, /*anyOk*/ true);
- cb(initializer);
- return;
+ var _a = node, name = _a.name, initializer = _a.initializer;
+ this.visitNode(name, /*anyOk*/ true);
+ if (tsutils_1.isReassignmentTarget(node.parent)) {
+ return this.visitNode(initializer, true);
+ }
+ return this.checkContextualType(initializer, true);
+ }
+ case ts.SyntaxKind.ShorthandPropertyAssignment: {
+ var _b = node, name = _b.name, objectAssignmentInitializer = _b.objectAssignmentInitializer;
+ if (objectAssignmentInitializer !== undefined) {
+ return this.checkContextualType(objectAssignmentInitializer);
+ }
+ return this.checkContextualType(name, true);
}
case ts.SyntaxKind.PropertyDeclaration: {
var _c = node, name = _c.name, initializer = _c.initializer;
- if (initializer !== undefined) {
- return cb(initializer, /*anyOk*/ isNodeAny(name, checker));
- }
- return;
+ this.visitNode(name, true);
+ return initializer !== undefined &&
+ this.visitNode(initializer, isPropertyAny(node, this.checker));
}
+ case ts.SyntaxKind.ComputedPropertyName:
+ return this.visitNode(node.expression, true);
case ts.SyntaxKind.TaggedTemplateExpression: {
var _d = node, tag = _d.tag, template = _d.template;
- cb(tag);
if (template.kind === ts.SyntaxKind.TemplateExpression) {
for (var _i = 0, _e = template.templateSpans; _i < _e.length; _i++) {
var expression = _e[_i].expression;
- checkContextual(expression);
+ this.checkContextualType(expression);
}
}
// Also check the template expression itself
- check();
- return;
+ if (this.visitNode(tag)) {
+ return true;
+ }
+ return anyOk ? false : this.check(node);
}
case ts.SyntaxKind.CallExpression:
case ts.SyntaxKind.NewExpression: {
var _f = node, expression = _f.expression, args = _f.arguments;
- cb(expression);
if (args !== undefined) {
for (var _g = 0, args_1 = args; _g < args_1.length; _g++) {
var arg = args_1[_g];
- checkContextual(arg);
+ this.checkContextualType(arg);
}
}
+ if (this.visitNode(expression)) {
+ return true;
+ }
// Also check the call expression itself
- check();
- return;
+ return anyOk ? false : this.check(node);
}
case ts.SyntaxKind.PropertyAccessExpression:
// Don't warn for right hand side; this is redundant if we warn for the access itself.
- cb(node.expression);
- check();
- return;
- case ts.SyntaxKind.VariableDeclaration:
- return checkVariableDeclaration(node);
- case ts.SyntaxKind.BinaryExpression:
- return checkBinaryExpression(node);
+ if (this.visitNode(node.expression)) {
+ return true;
+ }
+ return anyOk ? false : this.check(node);
+ case ts.SyntaxKind.ElementAccessExpression: {
+ var _h = node, expression = _h.expression, argumentExpression = _h.argumentExpression;
+ if (argumentExpression !== undefined) {
+ this.visitNode(argumentExpression, true);
+ }
+ if (this.visitNode(expression)) {
+ return true;
+ }
+ return anyOk ? false : this.check(node);
+ }
case ts.SyntaxKind.ReturnStatement: {
var expression = node.expression;
- if (expression !== undefined) {
- return checkContextual(expression);
- }
- return;
+ return expression !== undefined && this.checkContextualType(expression, true);
}
case ts.SyntaxKind.SwitchStatement: {
- var _h = node, expression = _h.expression, clauses = _h.caseBlock.clauses;
+ var _j = node, expression = _j.expression, clauses = _j.caseBlock.clauses;
// Allow `switch (x) {}` where `x` is any
- cb(expression, /*anyOk*/ true);
- for (var _j = 0, clauses_1 = clauses; _j < clauses_1.length; _j++) {
- var clause = clauses_1[_j];
+ this.visitNode(expression, /*anyOk*/ true);
+ for (var _k = 0, clauses_1 = clauses; _k < clauses_1.length; _k++) {
+ var clause = clauses_1[_k];
if (clause.kind === ts.SyntaxKind.CaseClause) {
// Allow `case x:` where `x` is any
- cb(clause.expression, /*anyOk*/ true);
+ this.visitNode(clause.expression, /*anyOk*/ true);
}
- for (var _k = 0, _l = clause.statements; _k < _l.length; _k++) {
- var statement = _l[_k];
- cb(statement);
+ for (var _l = 0, _m = clause.statements; _l < _m.length; _l++) {
+ var statement = _m[_l];
+ this.visitNode(statement);
}
}
- break;
+ return false;
}
case ts.SyntaxKind.ModuleDeclaration: {
// In `declare global { ... }`, don't mark `global` as unsafe any.
var body = node.body;
- if (body !== undefined) {
- cb(body);
- }
- return;
+ return body !== undefined && this.visitNode(body);
}
case ts.SyntaxKind.IfStatement: {
- var _m = node, expression = _m.expression, thenStatement = _m.thenStatement, elseStatement = _m.elseStatement;
- cb(expression, true); // allow truthyness check
- cb(thenStatement);
- if (elseStatement !== undefined) {
- cb(elseStatement);
- }
- return;
+ var _o = node, expression = _o.expression, thenStatement = _o.thenStatement, elseStatement = _o.elseStatement;
+ this.visitNode(expression, true); // allow truthyness check
+ this.visitNode(thenStatement);
+ return elseStatement !== undefined && this.visitNode(elseStatement);
}
case ts.SyntaxKind.PrefixUnaryExpression: {
- var _o = node, operator = _o.operator, operand = _o.operand;
- cb(operand, operator === ts.SyntaxKind.ExclamationToken); // allow falsyness check
- check();
- return;
+ var _p = node, operator = _p.operator, operand = _p.operand;
+ this.visitNode(operand, operator === ts.SyntaxKind.ExclamationToken); // allow falsyness check
+ return false;
}
case ts.SyntaxKind.ForStatement: {
- var _p = node, initializer = _p.initializer, condition = _p.condition, incrementor = _p.incrementor, statement = _p.statement;
+ var _q = node, initializer = _q.initializer, condition = _q.condition, incrementor = _q.incrementor, statement = _q.statement;
if (initializer !== undefined) {
- cb(initializer);
+ this.visitNode(initializer, true);
}
if (condition !== undefined) {
- cb(condition, true);
+ this.visitNode(condition, true);
} // allow truthyness check
if (incrementor !== undefined) {
- cb(incrementor);
+ this.visitNode(incrementor, true);
}
- return cb(statement);
+ return this.visitNode(statement);
}
case ts.SyntaxKind.DoStatement:
case ts.SyntaxKind.WhileStatement:
- cb(node.statement);
- return cb(node.expression, true);
- default:
- if (!(tsutils_1.isExpression(node) && check())) {
- return ts.forEachChild(node, cb);
+ this.visitNode(node.expression, true);
+ return this.visitNode(node.statement);
+ case ts.SyntaxKind.ConditionalExpression: {
+ var _r = node, condition = _r.condition, whenTrue = _r.whenTrue, whenFalse = _r.whenFalse;
+ this.visitNode(condition, true);
+ var left = this.visitNode(whenTrue, anyOk);
+ return this.visitNode(whenFalse, anyOk) || left;
+ }
+ case ts.SyntaxKind.VariableDeclaration:
+ case ts.SyntaxKind.Parameter:
+ return this.checkVariableOrParameterDeclaration(node);
+ case ts.SyntaxKind.BinaryExpression:
+ return this.checkBinaryExpression(node, anyOk);
+ case ts.SyntaxKind.AwaitExpression:
+ this.visitNode(node.expression);
+ return anyOk ? false : this.check(node);
+ case ts.SyntaxKind.YieldExpression:
+ return this.checkYieldExpression(node, anyOk);
+ case ts.SyntaxKind.ClassExpression:
+ case ts.SyntaxKind.ClassDeclaration:
+ this.checkClassLikeDeclaration(node);
+ return false;
+ case ts.SyntaxKind.ArrayLiteralExpression: {
+ for (var _s = 0, _t = node.elements; _s < _t.length; _s++) {
+ var element = _t[_s];
+ this.checkContextualType(element, true);
}
- return;
- }
- function check() {
- var isUnsafe = !anyOk && isNodeAny(node, checker);
- if (isUnsafe) {
- ctx.addFailureAtNode(node, Rule.FAILURE_STRING);
+ return false;
}
- return isUnsafe;
+ case ts.SyntaxKind.JsxExpression:
+ return node.expression !== undefined &&
+ this.checkContextualType(node.expression);
}
- }
- /** OK for this value to be 'any' if that's its contextual type. */
- function checkContextual(arg) {
- return cb(arg, /*anyOk*/ isAny(checker.getContextualType(arg)));
- }
- // Allow `const x = foo;` and `const x: any = foo`, but not `const x: Foo = foo;`.
- function checkVariableDeclaration(_a) {
- var type = _a.type, initializer = _a.initializer;
- // Always allow the LHS to be `any`. Just don't allow RHS to be `any` when LHS isn't.
- // TODO: handle destructuring
- if (initializer !== undefined) {
- return cb(initializer, /*anyOk*/ type === undefined || type.kind === ts.SyntaxKind.AnyKeyword);
+ if (tsutils_1.isTypeNodeKind(node.kind) || tsutils_1.isTokenKind(node.kind)) {
+ return false;
}
- return;
- }
- function checkBinaryExpression(node) {
- var _a = node, left = _a.left, right = _a.right, operatorToken = _a.operatorToken;
- // Allow equality since all values support equality.
- if (Lint.getEqualsKind(operatorToken) !== undefined) {
- return;
+ return ts.forEachChild(node, this.visitNodeCallback);
+ };
+ NoUnsafeAnyWalker.prototype.check = function (node) {
+ if (!isNodeAny(node, this.checker)) {
+ return false;
}
- switch (operatorToken.kind) {
- case ts.SyntaxKind.InstanceOfKeyword:// Allow test
- return cb(right);
+ this.addFailureAtNode(node, Rule.FAILURE_STRING);
+ return true;
+ };
+ NoUnsafeAnyWalker.prototype.checkContextualType = function (node, allowIfNoContextualType) {
+ var type = this.checker.getContextualType(node);
+ return this.visitNode(node, type === undefined && allowIfNoContextualType || isAny(type));
+ };
+ // Allow `const x = foo;` and `const x: any = foo`, but not `const x: Foo = foo;`.
+ NoUnsafeAnyWalker.prototype.checkVariableOrParameterDeclaration = function (_a) {
+ var name = _a.name, type = _a.type, initializer = _a.initializer;
+ this.checkBindingName(name);
+ // Always allow the LHS to be `any`. Just don't allow RHS to be `any` when LHS isn't.
+ return initializer !== undefined &&
+ this.visitNode(initializer,
+ /*anyOk*/
+ name.kind === ts.SyntaxKind.Identifier && (type === undefined || type.kind === ts.SyntaxKind.AnyKeyword) ||
+ type !== undefined && type.kind === ts.SyntaxKind.AnyKeyword);
+ };
+ NoUnsafeAnyWalker.prototype.checkBinaryExpression = function (node, anyOk) {
+ var allowAnyLeft = false;
+ var allowAnyRight = false;
+ switch (node.operatorToken.kind) {
+ case ts.SyntaxKind.ExclamationEqualsEqualsToken:
+ case ts.SyntaxKind.ExclamationEqualsToken:
+ case ts.SyntaxKind.EqualsEqualsEqualsToken:
+ case ts.SyntaxKind.EqualsEqualsToken:
case ts.SyntaxKind.CommaToken: // Allow `any, any`
case ts.SyntaxKind.BarBarToken: // Allow `any || any`
case ts.SyntaxKind.AmpersandAmpersandToken:// Allow `any && any`
- cb(left, /*anyOk*/ true);
- return cb(right, /*anyOk*/ true);
+ allowAnyLeft = allowAnyRight = true;
+ break;
+ case ts.SyntaxKind.InstanceOfKeyword:// Allow test
+ allowAnyLeft = true;
+ break;
case ts.SyntaxKind.EqualsToken:
// Allow assignment if the lhs is also *any*.
- // TODO: handle destructuring
- cb(right, /*anyOk*/ isNodeAny(left, checker));
- return;
+ allowAnyLeft = true;
+ allowAnyRight = isNodeAny(node.left, this.checker);
+ break;
case ts.SyntaxKind.PlusToken: // Allow implicit stringification
case ts.SyntaxKind.PlusEqualsToken:
- var anyOk = isStringLike(left, checker)
- || (isStringLike(right, checker) && operatorToken.kind === ts.SyntaxKind.PlusToken);
- cb(left, anyOk);
- return cb(right, anyOk);
- default:
- cb(left);
- return cb(right);
+ allowAnyLeft = allowAnyRight = isStringLike(node.left, this.checker)
+ || (isStringLike(node.right, this.checker) && node.operatorToken.kind === ts.SyntaxKind.PlusToken);
+ }
+ this.visitNode(node.left, allowAnyLeft);
+ this.visitNode(node.right, allowAnyRight);
+ return anyOk ? false : this.check(node);
+ };
+ NoUnsafeAnyWalker.prototype.checkYieldExpression = function (node, anyOk) {
+ if (node.expression !== undefined) {
+ this.checkContextualType(node.expression, true);
+ }
+ if (anyOk) {
+ return false;
+ }
+ this.addFailureAtNode(node, Rule.FAILURE_STRING);
+ return true;
+ };
+ NoUnsafeAnyWalker.prototype.checkClassLikeDeclaration = function (node) {
+ if (node.decorators !== undefined) {
+ node.decorators.forEach(this.visitNodeCallback);
+ }
+ if (node.heritageClauses !== undefined) {
+ node.heritageClauses.forEach(this.visitNodeCallback);
+ }
+ return node.members.forEach(this.visitNodeCallback);
+ };
+ NoUnsafeAnyWalker.prototype.checkBindingName = function (node) {
+ if (node.kind !== ts.SyntaxKind.Identifier) {
+ if (isNodeAny(node, this.checker)) {
+ this.addFailureAtNode(node, Rule.FAILURE_STRING);
+ }
+ for (var _i = 0, _a = node.elements; _i < _a.length; _i++) {
+ var element = _a[_i];
+ if (element.kind !== ts.SyntaxKind.OmittedExpression) {
+ if (element.propertyName !== undefined && element.propertyName.kind === ts.SyntaxKind.ComputedPropertyName) {
+ this.visitNode(element.propertyName.expression);
+ }
+ this.checkBindingName(element.name);
+ if (element.initializer !== undefined) {
+ this.checkContextualType(element.initializer);
+ }
+ }
+ }
+ }
+ };
+ return NoUnsafeAnyWalker;
+}(Lint.AbstractWalker));
+/** Check if property has no type annotation in this class and the base class */
+function isPropertyAny(node, checker) {
+ if (!isNodeAny(node.name, checker) || node.name.kind === ts.SyntaxKind.ComputedPropertyName) {
+ return false;
+ }
+ for (var _i = 0, _a = checker.getBaseTypes(checker.getTypeAtLocation(node.parent)); _i < _a.length; _i++) {
+ var base = _a[_i];
+ var prop = base.getProperty(node.name.text);
+ if (prop !== undefined && prop.declarations !== undefined) {
+ return isAny(checker.getTypeOfSymbolAtLocation(prop, prop.declarations[0]));
}
}
+ return true;
}
function isNodeAny(node, checker) {
return isAny(checker.getTypeAtLocation(node));
diff --git a/node_modules/tslint/lib/rules/noUnusedVariableRule.js b/node_modules/tslint/lib/rules/noUnusedVariableRule.js
index 02506f434..b7b9f6fe4 100644
--- a/node_modules/tslint/lib/rules/noUnusedVariableRule.js
+++ b/node_modules/tslint/lib/rules/noUnusedVariableRule.js
@@ -29,19 +29,15 @@ var Rule = /** @class */ (function (_super) {
}
/* tslint:enable:object-literal-sort-keys */
Rule.prototype.applyWithProgram = function (sourceFile, program) {
- var x = program.getCompilerOptions();
- if (x.noUnusedLocals && x.noUnusedParameters) {
- console.warn("WARNING: 'no-unused-variable' lint rule does not need to be set if " +
- "the 'no-unused-locals' and 'no-unused-parameters' compiler options are enabled.");
- }
return this.applyWithFunction(sourceFile, walk, parseOptions(this.ruleArguments), program);
};
/* tslint:disable:object-literal-sort-keys */
Rule.metadata = {
ruleName: "no-unused-variable",
description: (_a = ["Disallows unused imports, variables, functions and\n private class members. Similar to tsc's --noUnusedParameters and --noUnusedLocals\n options, but does not interrupt code compilation."], _a.raw = ["Disallows unused imports, variables, functions and\n private class members. Similar to tsc's --noUnusedParameters and --noUnusedLocals\n options, but does not interrupt code compilation."], Lint.Utils.dedent(_a)),
+ descriptionDetails: (_b = ["\n In addition to avoiding compilation errors, this rule may still be useful if you\n wish to have `tslint` automatically remove unused imports, variables, functions,\n and private class members, when using TSLint's `--fix` option."], _b.raw = ["\n In addition to avoiding compilation errors, this rule may still be useful if you\n wish to have \\`tslint\\` automatically remove unused imports, variables, functions,\n and private class members, when using TSLint's \\`--fix\\` option."], Lint.Utils.dedent(_b)),
hasFix: true,
- optionsDescription: (_b = ["\n Three optional arguments may be optionally provided:\n\n * `\"check-parameters\"` disallows unused function and constructor parameters.\n * NOTE: this option is experimental and does not work with classes\n that use abstract method declarations, among other things.\n * `{\"ignore-pattern\": \"pattern\"}` where pattern is a case-sensitive regexp.\n Variable names that match the pattern will be ignored."], _b.raw = ["\n Three optional arguments may be optionally provided:\n\n * \\`\"check-parameters\"\\` disallows unused function and constructor parameters.\n * NOTE: this option is experimental and does not work with classes\n that use abstract method declarations, among other things.\n * \\`{\"ignore-pattern\": \"pattern\"}\\` where pattern is a case-sensitive regexp.\n Variable names that match the pattern will be ignored."], Lint.Utils.dedent(_b)),
+ optionsDescription: (_c = ["\n Three optional arguments may be optionally provided:\n\n * `\"check-parameters\"` disallows unused function and constructor parameters.\n * NOTE: this option is experimental and does not work with classes\n that use abstract method declarations, among other things.\n * `{\"ignore-pattern\": \"pattern\"}` where pattern is a case-sensitive regexp.\n Variable names and imports that match the pattern will be ignored."], _c.raw = ["\n Three optional arguments may be optionally provided:\n\n * \\`\"check-parameters\"\\` disallows unused function and constructor parameters.\n * NOTE: this option is experimental and does not work with classes\n that use abstract method declarations, among other things.\n * \\`{\"ignore-pattern\": \"pattern\"}\\` where pattern is a case-sensitive regexp.\n Variable names and imports that match the pattern will be ignored."], Lint.Utils.dedent(_c)),
options: {
type: "array",
items: {
@@ -78,7 +74,7 @@ function parseOptions(options) {
if (typeof o === "object") {
// tslint:disable-next-line no-unsafe-any
var ignore = o[OPTION_IGNORE_PATTERN];
- if (ignore != null) {
+ if (ignore != undefined) {
ignorePattern = new RegExp(ignore);
break;
}
@@ -104,6 +100,12 @@ function walk(ctx, program) {
continue;
}
var failure = ts.flattenDiagnosticMessageText(diag.messageText, "\n");
+ if (ignorePattern !== undefined) {
+ var varName = /'(.*)'/.exec(failure)[1];
+ if (ignorePattern.test(varName)) {
+ continue;
+ }
+ }
if (kind === 0 /* VARIABLE_OR_PARAMETER */) {
var importName = findImport(diag.start, sourceFile);
if (importName !== undefined) {
@@ -117,12 +119,6 @@ function walk(ctx, program) {
continue;
}
}
- if (ignorePattern !== undefined) {
- var varName = /'(.*)'/.exec(failure)[1];
- if (ignorePattern.test(varName)) {
- continue;
- }
- }
ctx.addFailureAt(diag.start, diag.length, failure);
}
if (importSpecifierFailures.size !== 0) {
@@ -375,4 +371,4 @@ function makeUnusedCheckedProgram(program, checkParameters) {
return ts.sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase();
}
}
-var _a, _b;
+var _a, _b, _c;
diff --git a/node_modules/tslint/lib/rules/noVarRequiresRule.js b/node_modules/tslint/lib/rules/noVarRequiresRule.js
index 25e212b3a..9a8dfb694 100644
--- a/node_modules/tslint/lib/rules/noVarRequiresRule.js
+++ b/node_modules/tslint/lib/rules/noVarRequiresRule.js
@@ -17,8 +17,6 @@
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
-// tslint:disable deprecation
-// (https://github.com/palantir/tslint/pull/2341)
var ts = require("typescript");
var Lint = require("../index");
var Rule = /** @class */ (function (_super) {
@@ -46,6 +44,7 @@ var Rule = /** @class */ (function (_super) {
return Rule;
}(Lint.Rules.AbstractRule));
exports.Rule = Rule;
+// tslint:disable-next-line:deprecation
var NoVarRequiresWalker = /** @class */ (function (_super) {
tslib_1.__extends(NoVarRequiresWalker, _super);
function NoVarRequiresWalker() {
diff --git a/node_modules/tslint/lib/rules/objectLiteralShorthandRule.d.ts b/node_modules/tslint/lib/rules/objectLiteralShorthandRule.d.ts
index 8d990f416..94e0c80a5 100644
--- a/node_modules/tslint/lib/rules/objectLiteralShorthandRule.d.ts
+++ b/node_modules/tslint/lib/rules/objectLiteralShorthandRule.d.ts
@@ -1,8 +1,9 @@
import * as ts from "typescript";
-import * as Lint from "../index";
+import * as Lint from "..";
export declare class Rule extends Lint.Rules.AbstractRule {
static metadata: Lint.IRuleMetadata;
static LONGHAND_PROPERTY: string;
static LONGHAND_METHOD: string;
+ static SHORTHAND_ASSIGNMENT: string;
apply(sourceFile: ts.SourceFile): Lint.RuleFailure[];
}
diff --git a/node_modules/tslint/lib/rules/objectLiteralShorthandRule.js b/node_modules/tslint/lib/rules/objectLiteralShorthandRule.js
index 78d9d3bc9..59ac30d76 100644
--- a/node_modules/tslint/lib/rules/objectLiteralShorthandRule.js
+++ b/node_modules/tslint/lib/rules/objectLiteralShorthandRule.js
@@ -19,33 +19,51 @@ Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var tsutils_1 = require("tsutils");
var ts = require("typescript");
-var Lint = require("../index");
+var Lint = require("..");
+var OPTION_NEVER = "never";
var Rule = /** @class */ (function (_super) {
tslib_1.__extends(Rule, _super);
function Rule() {
return _super !== null && _super.apply(this, arguments) || this;
}
Rule.prototype.apply = function (sourceFile) {
- return this.applyWithFunction(sourceFile, walk);
+ return this.applyWithFunction(sourceFile, this.ruleArguments.indexOf(OPTION_NEVER) === -1
+ ? enforceShorthandWalker
+ : disallowShorthandWalker);
};
/* tslint:disable:object-literal-sort-keys */
Rule.metadata = {
ruleName: "object-literal-shorthand",
- description: "Enforces use of ES6 object literal shorthand when possible.",
+ description: "Enforces/disallows use of ES6 object literal shorthand.",
hasFix: true,
- optionsDescription: "Not configurable.",
- options: null,
- optionExamples: [true],
+ optionsDescription: (_a = ["\n If the 'never' option is provided, any shorthand object literal syntax will cause a failure."], _a.raw = ["\n If the \\'never\\' option is provided, any shorthand object literal syntax will cause a failure."], Lint.Utils.dedent(_a)),
+ options: {
+ type: "string",
+ enum: [OPTION_NEVER],
+ },
+ optionExamples: [true, [true, OPTION_NEVER]],
type: "style",
typescriptOnly: false,
};
/* tslint:enable:object-literal-sort-keys */
Rule.LONGHAND_PROPERTY = "Expected property shorthand in object literal ";
Rule.LONGHAND_METHOD = "Expected method shorthand in object literal ";
+ Rule.SHORTHAND_ASSIGNMENT = "Shorthand property assignments have been disallowed.";
return Rule;
}(Lint.Rules.AbstractRule));
exports.Rule = Rule;
-function walk(ctx) {
+function disallowShorthandWalker(ctx) {
+ return ts.forEachChild(ctx.sourceFile, function cb(node) {
+ if (tsutils_1.isShorthandPropertyAssignment(node)) {
+ ctx.addFailureAtNode(node.name, Rule.SHORTHAND_ASSIGNMENT, Lint.Replacement.appendText(node.getStart(ctx.sourceFile), node.name.text + ": "));
+ }
+ else if (tsutils_1.isMethodDeclaration(node) && node.parent.kind === ts.SyntaxKind.ObjectLiteralExpression) {
+ ctx.addFailureAtNode(node.name, Rule.SHORTHAND_ASSIGNMENT, fixShorthandMethodDeclaration(node, ctx.sourceFile));
+ }
+ return ts.forEachChild(node, cb);
+ });
+}
+function enforceShorthandWalker(ctx) {
return ts.forEachChild(ctx.sourceFile, function cb(node) {
if (tsutils_1.isPropertyAssignment(node)) {
if (node.name.kind === ts.SyntaxKind.Identifier &&
@@ -57,12 +75,17 @@ function walk(ctx) {
// allow named function expressions
node.initializer.name === undefined) {
var _a = handleLonghandMethod(node.name, node.initializer, ctx.sourceFile), name = _a[0], fix = _a[1];
- ctx.addFailureAtNode(node, Rule.LONGHAND_METHOD + "('{" + name + "() {...}}').", fix);
+ ctx.addFailure(node.getStart(ctx.sourceFile), tsutils_1.getChildOfKind(node.initializer, ts.SyntaxKind.OpenParenToken, ctx.sourceFile).pos, Rule.LONGHAND_METHOD + "('{" + name + "() {...}}').", fix);
}
}
return ts.forEachChild(node, cb);
});
}
+function fixShorthandMethodDeclaration(node, sourceFile) {
+ var isGenerator = node.asteriskToken !== undefined;
+ var isAsync = tsutils_1.hasModifier(node.modifiers, ts.SyntaxKind.AsyncKeyword);
+ return Lint.Replacement.replaceFromTo(node.getStart(sourceFile), node.name.end, node.name.getText(sourceFile) + ":" + (isAsync ? " async" : "") + " function" + (isGenerator ? "*" : ""));
+}
function handleLonghandMethod(name, initializer, sourceFile) {
var nameStart = name.getStart(sourceFile);
var fix = Lint.Replacement.deleteFromTo(name.end, tsutils_1.getChildOfKind(initializer, ts.SyntaxKind.OpenParenToken).pos);
@@ -78,3 +101,4 @@ function handleLonghandMethod(name, initializer, sourceFile) {
}
return [prefix + sourceFile.text.substring(nameStart, name.end), fix];
}
+var _a;
diff --git a/node_modules/tslint/lib/rules/objectLiteralSortKeysRule.js b/node_modules/tslint/lib/rules/objectLiteralSortKeysRule.js
index ab8a4c332..70d7c5e49 100644
--- a/node_modules/tslint/lib/rules/objectLiteralSortKeysRule.js
+++ b/node_modules/tslint/lib/rules/objectLiteralSortKeysRule.js
@@ -48,9 +48,9 @@ var Rule = /** @class */ (function (_super) {
/* tslint:disable:object-literal-sort-keys */
Rule.metadata = {
ruleName: "object-literal-sort-keys",
- description: "Checks ordering of keys in object literals.",
+ description: (_a = ["\n Checks ordering of keys in object literals.\n\n When using the default alphabetical ordering, additional blank lines may be used to group\n object properties together while keeping the elements within each group in alphabetical order.\n "], _a.raw = ["\n Checks ordering of keys in object literals.\n\n When using the default alphabetical ordering, additional blank lines may be used to group\n object properties together while keeping the elements within each group in alphabetical order.\n "], Lint.Utils.dedent(_a)),
rationale: "Useful in preventing merge conflicts",
- optionsDescription: (_a = ["\n By default, this rule checks that keys are in alphabetical order.\n The following may optionally be passed:\n\n * \"", "\" will to compare keys in a case insensitive way.\n * \"", " will prefer to use the key ordering of the contextual type of the object literal, as in:\n\n interface I { foo: number; bar: number; }\n const obj: I = { foo: 1, bar: 2 };\n\n If a contextual type is not found, alphabetical ordering will be used instead.\n "], _a.raw = ["\n By default, this rule checks that keys are in alphabetical order.\n The following may optionally be passed:\n\n * \"", "\" will to compare keys in a case insensitive way.\n * \"", " will prefer to use the key ordering of the contextual type of the object literal, as in:\n\n interface I { foo: number; bar: number; }\n const obj: I = { foo: 1, bar: 2 };\n\n If a contextual type is not found, alphabetical ordering will be used instead.\n "], Lint.Utils.dedent(_a, OPTION_IGNORE_CASE, OPTION_MATCH_DECLARATION_ORDER)),
+ optionsDescription: (_b = ["\n By default, this rule checks that keys are in alphabetical order.\n The following may optionally be passed:\n\n * \"", "\" will to compare keys in a case insensitive way.\n * \"", "\" will prefer to use the key ordering of the contextual type of the object literal, as in:\n\n interface I { foo: number; bar: number; }\n const obj: I = { foo: 1, bar: 2 };\n\n If a contextual type is not found, alphabetical ordering will be used instead.\n "], _b.raw = ["\n By default, this rule checks that keys are in alphabetical order.\n The following may optionally be passed:\n\n * \"", "\" will to compare keys in a case insensitive way.\n * \"", "\" will prefer to use the key ordering of the contextual type of the object literal, as in:\n\n interface I { foo: number; bar: number; }\n const obj: I = { foo: 1, bar: 2 };\n\n If a contextual type is not found, alphabetical ordering will be used instead.\n "], Lint.Utils.dedent(_b, OPTION_IGNORE_CASE, OPTION_MATCH_DECLARATION_ORDER)),
options: {
type: "string",
enum: [OPTION_IGNORE_CASE, OPTION_MATCH_DECLARATION_ORDER],
@@ -112,7 +112,7 @@ function walk(ctx, checker) {
property.name.kind === ts.SyntaxKind.StringLiteral) {
var key = ignoreCase ? property.name.text.toLowerCase() : property.name.text;
// comparison with undefined is expected
- if (lastKey > key) {
+ if (lastKey > key && !hasBlankLineBefore(ctx.sourceFile, property)) {
ctx.addFailureAtNode(property.name, Rule.FAILURE_STRING_ALPHABETICAL(property.name.text));
return; // only show warning on first out-of-order property
}
@@ -137,7 +137,7 @@ function walk(ctx, checker) {
for (; memberIndex !== members.length; memberIndex++) {
var memberName = members[memberIndex].name;
if (memberName.kind !== ts.SyntaxKind.ComputedPropertyName && propName === memberName.text) {
- continue outer; // tslint:disable-line no-unsafe-any (fixed in tslint 5.4)
+ continue outer;
}
}
// This We didn't find the member we were looking for past the previous member,
@@ -148,6 +148,22 @@ function walk(ctx, checker) {
}
}
}
+function hasBlankLineBefore(sourceFile, element) {
+ var comments = ts.getLeadingCommentRanges(sourceFile.text, element.pos);
+ if (comments === undefined) {
+ comments = []; // it will be easier to work with an empty array down below...
+ }
+ var elementStart = comments.length > 0 ? comments[comments.length - 1].end : element.getFullStart();
+ // either the element itself, or one of its leading comments must have an extra new line before them
+ return hasDoubleNewLine(sourceFile, elementStart) || comments.some(function (comment) {
+ var commentLine = ts.getLineAndCharacterOfPosition(sourceFile, comment.pos).line;
+ var commentLineStartPosition = ts.getPositionOfLineAndCharacter(sourceFile, commentLine, 0);
+ return hasDoubleNewLine(sourceFile, commentLineStartPosition - 4);
+ });
+}
+function hasDoubleNewLine(sourceFile, position) {
+ return /(\r\n|\r|\n){2}/.test(sourceFile.text.slice(position, position + 4));
+}
function getTypeName(t) {
var parent = t.parent;
return t.kind === ts.SyntaxKind.InterfaceDeclaration
@@ -168,4 +184,4 @@ function getContextualType(node, checker) {
var decl = declarations[0];
return tsutils_1.isInterfaceDeclaration(decl) || tsutils_1.isTypeLiteralNode(decl) ? decl : undefined;
}
-var _a;
+var _a, _b;
diff --git a/node_modules/tslint/lib/rules/oneLineRule.d.ts b/node_modules/tslint/lib/rules/oneLineRule.d.ts
index 435a5db6d..73a63c253 100644
--- a/node_modules/tslint/lib/rules/oneLineRule.d.ts
+++ b/node_modules/tslint/lib/rules/oneLineRule.d.ts
@@ -2,10 +2,6 @@ import * as ts from "typescript";
import * as Lint from "../index";
export declare class Rule extends Lint.Rules.AbstractRule {
static metadata: Lint.IRuleMetadata;
- static BRACE_FAILURE_STRING: string;
- static CATCH_FAILURE_STRING: string;
- static ELSE_FAILURE_STRING: string;
- static FINALLY_FAILURE_STRING: string;
static WHITESPACE_FAILURE_STRING: string;
apply(sourceFile: ts.SourceFile): Lint.RuleFailure[];
}
diff --git a/node_modules/tslint/lib/rules/oneLineRule.js b/node_modules/tslint/lib/rules/oneLineRule.js
index dcbd2169d..5d271ae91 100644
--- a/node_modules/tslint/lib/rules/oneLineRule.js
+++ b/node_modules/tslint/lib/rules/oneLineRule.js
@@ -31,8 +31,13 @@ var Rule = /** @class */ (function (_super) {
return _super !== null && _super.apply(this, arguments) || this;
}
Rule.prototype.apply = function (sourceFile) {
- var oneLineWalker = new OneLineWalker(sourceFile, this.getOptions());
- return this.applyWithWalker(oneLineWalker);
+ return this.applyWithWalker(new OneLineWalker(sourceFile, this.ruleName, {
+ brace: this.ruleArguments.indexOf(OPTION_BRACE) !== -1,
+ catch: this.ruleArguments.indexOf(OPTION_CATCH) !== -1,
+ else: this.ruleArguments.indexOf(OPTION_ELSE) !== -1,
+ finally: this.ruleArguments.indexOf(OPTION_FINALLY) !== -1,
+ whitespace: this.ruleArguments.indexOf(OPTION_WHITESPACE) !== -1,
+ }));
};
/* tslint:disable:object-literal-sort-keys */
Rule.metadata = {
@@ -51,12 +56,9 @@ var Rule = /** @class */ (function (_super) {
optionExamples: [[true, OPTION_CATCH, OPTION_FINALLY, OPTION_ELSE]],
type: "style",
typescriptOnly: false,
+ hasFix: true,
};
/* tslint:enable:object-literal-sort-keys */
- Rule.BRACE_FAILURE_STRING = "misplaced opening brace";
- Rule.CATCH_FAILURE_STRING = "misplaced 'catch'";
- Rule.ELSE_FAILURE_STRING = "misplaced 'else'";
- Rule.FINALLY_FAILURE_STRING = "misplaced 'finally'";
Rule.WHITESPACE_FAILURE_STRING = "missing whitespace";
return Rule;
}(Lint.Rules.AbstractRule));
@@ -66,204 +68,84 @@ var OneLineWalker = /** @class */ (function (_super) {
function OneLineWalker() {
return _super !== null && _super.apply(this, arguments) || this;
}
- OneLineWalker.prototype.visitIfStatement = function (node) {
- var thenStatement = node.thenStatement;
- var thenIsBlock = thenStatement.kind === ts.SyntaxKind.Block;
- if (thenIsBlock) {
- var expressionCloseParen = node.getChildAt(3);
- var thenOpeningBrace = thenStatement.getChildAt(0);
- this.handleOpeningBrace(expressionCloseParen, thenOpeningBrace);
- }
- var elseStatement = node.elseStatement;
- if (elseStatement != null) {
- // find the else keyword
- var elseKeyword = Lint.childOfKind(node, ts.SyntaxKind.ElseKeyword);
- if (elseStatement.kind === ts.SyntaxKind.Block) {
- var elseOpeningBrace = elseStatement.getChildAt(0);
- this.handleOpeningBrace(elseKeyword, elseOpeningBrace);
- }
- if (thenIsBlock && this.hasOption(OPTION_ELSE)) {
- var thenStatementEndLine = this.getLineAndCharacterOfPosition(thenStatement.getEnd()).line;
- var elseKeywordLine = this.getLineAndCharacterOfPosition(elseKeyword.getStart()).line;
- if (thenStatementEndLine !== elseKeywordLine) {
- this.addFailureAtNode(elseKeyword, Rule.ELSE_FAILURE_STRING);
+ OneLineWalker.prototype.walk = function (sourceFile) {
+ var _this = this;
+ var cb = function (node) {
+ switch (node.kind) {
+ case ts.SyntaxKind.Block:
+ if (!tsutils_1.isBlockLike(node.parent)) {
+ _this.check({ pos: node.pos, end: node.statements.pos });
+ }
+ break;
+ case ts.SyntaxKind.CaseBlock:
+ _this.check({ pos: node.pos, end: node.clauses.pos });
+ break;
+ case ts.SyntaxKind.ModuleBlock:
+ _this.check({ pos: node.pos, end: node.statements.pos });
+ break;
+ case ts.SyntaxKind.EnumDeclaration:
+ _this.check({ pos: node.name.end, end: node.members.pos });
+ break;
+ case ts.SyntaxKind.InterfaceDeclaration:
+ case ts.SyntaxKind.ClassDeclaration:
+ case ts.SyntaxKind.ClassExpression: {
+ _this.check(tsutils_1.getChildOfKind(node, ts.SyntaxKind.OpenBraceToken, sourceFile));
+ break;
}
- }
- }
- _super.prototype.visitIfStatement.call(this, node);
- };
- OneLineWalker.prototype.visitCatchClause = function (node) {
- var catchClosingParen = Lint.childOfKind(node, ts.SyntaxKind.CloseParenToken);
- var catchOpeningBrace = node.block.getChildAt(0);
- this.handleOpeningBrace(catchClosingParen, catchOpeningBrace);
- _super.prototype.visitCatchClause.call(this, node);
- };
- OneLineWalker.prototype.visitTryStatement = function (node) {
- var catchClause = node.catchClause;
- var finallyBlock = node.finallyBlock;
- var finallyKeyword = Lint.childOfKind(node, ts.SyntaxKind.FinallyKeyword);
- // "visit" try block
- var tryKeyword = node.getChildAt(0);
- var tryBlock = node.tryBlock;
- var tryOpeningBrace = tryBlock.getChildAt(0);
- this.handleOpeningBrace(tryKeyword, tryOpeningBrace);
- if (this.hasOption(OPTION_CATCH) && catchClause != null) {
- var tryClosingBrace = node.tryBlock.getChildAt(node.tryBlock.getChildCount() - 1);
- var catchKeyword = catchClause.getChildAt(0);
- var tryClosingBraceLine = this.getLineAndCharacterOfPosition(tryClosingBrace.getEnd()).line;
- var catchKeywordLine = this.getLineAndCharacterOfPosition(catchKeyword.getStart()).line;
- if (tryClosingBraceLine !== catchKeywordLine) {
- this.addFailureAtNode(catchKeyword, Rule.CATCH_FAILURE_STRING);
- }
- }
- if (finallyBlock != null && finallyKeyword != null) {
- var finallyOpeningBrace = finallyBlock.getChildAt(0);
- this.handleOpeningBrace(finallyKeyword, finallyOpeningBrace);
- if (this.hasOption(OPTION_FINALLY)) {
- var previousBlock = catchClause != null ? catchClause.block : node.tryBlock;
- var closingBrace = previousBlock.getChildAt(previousBlock.getChildCount() - 1);
- var closingBraceLine = this.getLineAndCharacterOfPosition(closingBrace.getEnd()).line;
- var finallyKeywordLine = this.getLineAndCharacterOfPosition(finallyKeyword.getStart()).line;
- if (closingBraceLine !== finallyKeywordLine) {
- this.addFailureAtNode(finallyKeyword, Rule.FINALLY_FAILURE_STRING);
+ case ts.SyntaxKind.IfStatement: {
+ var _a = node, thenStatement = _a.thenStatement, elseStatement = _a.elseStatement;
+ if (elseStatement !== undefined && thenStatement.kind === ts.SyntaxKind.Block) {
+ _this.check({ pos: thenStatement.end, end: elseStatement.pos }, "else");
+ }
+ break;
+ }
+ case ts.SyntaxKind.TryStatement: {
+ var _b = node, finallyBlock = _b.finallyBlock, catchClause = _b.catchClause, tryBlock = _b.tryBlock;
+ if (catchClause !== undefined) {
+ _this.check(catchClause.getChildAt(0, sourceFile), "catch");
+ if (finallyBlock !== undefined) {
+ _this.check({ pos: catchClause.end, end: finallyBlock.pos }, "finally");
+ }
+ }
+ else if (finallyBlock !== undefined) {
+ _this.check({ pos: tryBlock.end, end: finallyBlock.pos }, "finally");
+ }
+ break;
+ }
+ case ts.SyntaxKind.BinaryExpression: {
+ var _c = node, operatorToken = _c.operatorToken, right = _c.right;
+ if (operatorToken.kind === ts.SyntaxKind.EqualsToken && tsutils_1.isObjectLiteralExpression(right)) {
+ _this.check({ pos: right.pos, end: right.properties.pos });
+ }
+ break;
+ }
+ case ts.SyntaxKind.VariableDeclaration: {
+ var initializer = node.initializer;
+ if (initializer !== undefined && tsutils_1.isObjectLiteralExpression(initializer)) {
+ _this.check({ pos: initializer.pos, end: initializer.properties.pos });
+ }
+ break;
+ }
+ case ts.SyntaxKind.TypeAliasDeclaration: {
+ var type = node.type;
+ if (type.kind === ts.SyntaxKind.MappedType || type.kind === ts.SyntaxKind.TypeLiteral) {
+ _this.check(type.getChildAt(0, sourceFile));
+ }
}
}
+ return ts.forEachChild(node, cb);
+ };
+ return ts.forEachChild(sourceFile, cb);
+ };
+ OneLineWalker.prototype.check = function (range, kind) {
+ var tokenStart = range.end - (kind === undefined ? 1 : kind.length);
+ if (this.options[kind === undefined ? "brace" : kind] && !tsutils_1.isSameLine(this.sourceFile, range.pos, tokenStart)) {
+ this.addFailure(tokenStart, range.end, "misplaced " + (kind === undefined ? "opening brace" : "'" + kind + "'"), Lint.Replacement.replaceFromTo(range.pos, tokenStart, this.options.whitespace ? " " : ""));
}
- _super.prototype.visitTryStatement.call(this, node);
- };
- OneLineWalker.prototype.visitForStatement = function (node) {
- this.handleIterationStatement(node);
- _super.prototype.visitForStatement.call(this, node);
- };
- OneLineWalker.prototype.visitForInStatement = function (node) {
- this.handleIterationStatement(node);
- _super.prototype.visitForInStatement.call(this, node);
- };
- OneLineWalker.prototype.visitWhileStatement = function (node) {
- this.handleIterationStatement(node);
- _super.prototype.visitWhileStatement.call(this, node);
- };
- OneLineWalker.prototype.visitBinaryExpression = function (node) {
- var rightkind = node.right.kind;
- var opkind = node.operatorToken.kind;
- if (opkind === ts.SyntaxKind.EqualsToken && rightkind === ts.SyntaxKind.ObjectLiteralExpression) {
- var equalsToken = node.getChildAt(1);
- var openBraceToken = node.right.getChildAt(0);
- this.handleOpeningBrace(equalsToken, openBraceToken);
- }
- _super.prototype.visitBinaryExpression.call(this, node);
- };
- OneLineWalker.prototype.visitVariableDeclaration = function (node) {
- var initializer = node.initializer;
- if (initializer != null && initializer.kind === ts.SyntaxKind.ObjectLiteralExpression) {
- var equalsToken = Lint.childOfKind(node, ts.SyntaxKind.EqualsToken);
- var openBraceToken = initializer.getChildAt(0);
- this.handleOpeningBrace(equalsToken, openBraceToken);
- }
- _super.prototype.visitVariableDeclaration.call(this, node);
- };
- OneLineWalker.prototype.visitDoStatement = function (node) {
- var doKeyword = node.getChildAt(0);
- var statement = node.statement;
- if (statement.kind === ts.SyntaxKind.Block) {
- var openBraceToken = statement.getChildAt(0);
- this.handleOpeningBrace(doKeyword, openBraceToken);
- }
- _super.prototype.visitDoStatement.call(this, node);
- };
- OneLineWalker.prototype.visitModuleDeclaration = function (node) {
- var nameNode = node.name;
- var body = node.body;
- if (body != null && body.kind === ts.SyntaxKind.ModuleBlock) {
- var openBraceToken = body.getChildAt(0);
- this.handleOpeningBrace(nameNode, openBraceToken);
- }
- _super.prototype.visitModuleDeclaration.call(this, node);
- };
- OneLineWalker.prototype.visitEnumDeclaration = function (node) {
- var nameNode = node.name;
- var openBraceToken = Lint.childOfKind(node, ts.SyntaxKind.OpenBraceToken);
- this.handleOpeningBrace(nameNode, openBraceToken);
- _super.prototype.visitEnumDeclaration.call(this, node);
- };
- OneLineWalker.prototype.visitSwitchStatement = function (node) {
- var closeParenToken = node.getChildAt(3);
- var openBraceToken = node.caseBlock.getChildAt(0);
- this.handleOpeningBrace(closeParenToken, openBraceToken);
- _super.prototype.visitSwitchStatement.call(this, node);
- };
- OneLineWalker.prototype.visitInterfaceDeclaration = function (node) {
- this.handleClassLikeDeclaration(node);
- _super.prototype.visitInterfaceDeclaration.call(this, node);
- };
- OneLineWalker.prototype.visitClassDeclaration = function (node) {
- this.handleClassLikeDeclaration(node);
- _super.prototype.visitClassDeclaration.call(this, node);
- };
- OneLineWalker.prototype.visitFunctionDeclaration = function (node) {
- this.handleFunctionLikeDeclaration(node);
- _super.prototype.visitFunctionDeclaration.call(this, node);
- };
- OneLineWalker.prototype.visitMethodDeclaration = function (node) {
- this.handleFunctionLikeDeclaration(node);
- _super.prototype.visitMethodDeclaration.call(this, node);
- };
- OneLineWalker.prototype.visitConstructorDeclaration = function (node) {
- this.handleFunctionLikeDeclaration(node);
- _super.prototype.visitConstructorDeclaration.call(this, node);
- };
- OneLineWalker.prototype.visitArrowFunction = function (node) {
- var body = node.body;
- if (body != null && body.kind === ts.SyntaxKind.Block) {
- var arrowToken = Lint.childOfKind(node, ts.SyntaxKind.EqualsGreaterThanToken);
- var openBraceToken = body.getChildAt(0);
- this.handleOpeningBrace(arrowToken, openBraceToken);
- }
- _super.prototype.visitArrowFunction.call(this, node);
- };
- OneLineWalker.prototype.handleFunctionLikeDeclaration = function (node) {
- var body = node.body;
- if (body != null && body.kind === ts.SyntaxKind.Block) {
- var openBraceToken = body.getChildAt(0);
- if (node.type != null) {
- this.handleOpeningBrace(node.type, openBraceToken);
- }
- else {
- var closeParenToken = Lint.childOfKind(node, ts.SyntaxKind.CloseParenToken);
- this.handleOpeningBrace(closeParenToken, openBraceToken);
- }
- }
- };
- OneLineWalker.prototype.handleClassLikeDeclaration = function (node) {
- var openBraceToken = Lint.childOfKind(node, ts.SyntaxKind.OpenBraceToken);
- this.handleOpeningBrace(tsutils_1.getPreviousToken(openBraceToken), openBraceToken);
- };
- OneLineWalker.prototype.handleIterationStatement = function (node) {
- // last child is the statement, second to last child is the close paren
- var closeParenToken = node.getChildAt(node.getChildCount() - 2);
- var statement = node.statement;
- if (statement.kind === ts.SyntaxKind.Block) {
- var openBraceToken = statement.getChildAt(0);
- this.handleOpeningBrace(closeParenToken, openBraceToken);
- }
- };
- OneLineWalker.prototype.handleOpeningBrace = function (previousNode, openBraceToken) {
- if (previousNode == null || openBraceToken == null) {
- return;
- }
- var previousNodeLine = this.getLineAndCharacterOfPosition(previousNode.getEnd()).line;
- var openBraceLine = this.getLineAndCharacterOfPosition(openBraceToken.getStart()).line;
- var failure;
- if (this.hasOption(OPTION_BRACE) && previousNodeLine !== openBraceLine) {
- failure = Rule.BRACE_FAILURE_STRING;
- }
- else if (this.hasOption(OPTION_WHITESPACE) && previousNode.getEnd() === openBraceToken.getStart()) {
- failure = Rule.WHITESPACE_FAILURE_STRING;
- }
- if (failure !== undefined) {
- this.addFailureAtNode(openBraceToken, failure);
+ else if (this.options.whitespace && range.pos === tokenStart) {
+ this.addFailure(tokenStart, range.end, Rule.WHITESPACE_FAILURE_STRING, Lint.Replacement.appendText(range.pos, " "));
}
};
return OneLineWalker;
-}(Lint.RuleWalker));
+}(Lint.AbstractWalker));
var _a;
diff --git a/node_modules/tslint/lib/rules/onlyArrowFunctionsRule.js b/node_modules/tslint/lib/rules/onlyArrowFunctionsRule.js
index 36239c5b8..7af04a45b 100644
--- a/node_modules/tslint/lib/rules/onlyArrowFunctionsRule.js
+++ b/node_modules/tslint/lib/rules/onlyArrowFunctionsRule.js
@@ -84,14 +84,11 @@ function walk(ctx) {
}
/** Generator functions and functions using `this` are allowed. */
function functionIsExempt(node) {
- return node.asteriskToken !== undefined || hasThisParameter(node) || node.body !== undefined && usesThisInBody(node.body) === true;
+ return node.asteriskToken !== undefined ||
+ node.parameters.length !== 0 && utils.isThisParameter(node.parameters[0]) ||
+ node.body !== undefined && ts.forEachChild(node, usesThis) === true;
}
-function hasThisParameter(node) {
- var first = node.parameters[0];
- return first !== undefined && first.name.kind === ts.SyntaxKind.Identifier &&
- first.name.originalKeywordKind === ts.SyntaxKind.ThisKeyword;
-}
-function usesThisInBody(node) {
- return node.kind === ts.SyntaxKind.ThisKeyword || !utils.hasOwnThisReference(node) && ts.forEachChild(node, usesThisInBody);
+function usesThis(node) {
+ return node.kind === ts.SyntaxKind.ThisKeyword || !utils.hasOwnThisReference(node) && ts.forEachChild(node, usesThis);
}
var _a;
diff --git a/node_modules/tslint/lib/rules/orderedImportsRule.d.ts b/node_modules/tslint/lib/rules/orderedImportsRule.d.ts
index 3f2362e71..ab1329ea4 100644
--- a/node_modules/tslint/lib/rules/orderedImportsRule.d.ts
+++ b/node_modules/tslint/lib/rules/orderedImportsRule.d.ts
@@ -2,6 +2,7 @@ import * as ts from "typescript";
import * as Lint from "../index";
export declare class Rule extends Lint.Rules.AbstractRule {
static metadata: Lint.IRuleMetadata;
+ static IMPORT_SOURCES_NOT_GROUPED: string;
static IMPORT_SOURCES_UNORDERED: string;
static NAMED_IMPORTS_UNORDERED: string;
apply(sourceFile: ts.SourceFile): Lint.RuleFailure[];
diff --git a/node_modules/tslint/lib/rules/orderedImportsRule.js b/node_modules/tslint/lib/rules/orderedImportsRule.js
index c40d197b1..4f7c5f0da 100644
--- a/node_modules/tslint/lib/rules/orderedImportsRule.js
+++ b/node_modules/tslint/lib/rules/orderedImportsRule.js
@@ -31,13 +31,16 @@ var Rule = /** @class */ (function (_super) {
/* tslint:disable:object-literal-sort-keys */
Rule.metadata = {
ruleName: "ordered-imports",
- description: "Requires that import statements be alphabetized.",
- descriptionDetails: (_a = ["\n Enforce a consistent ordering for ES6 imports:\n - Named imports must be alphabetized (i.e. \"import {A, B, C} from \"foo\";\")\n - The exact ordering can be controlled by the named-imports-order option.\n - \"longName as name\" imports are ordered by \"longName\".\n - Import sources must be alphabetized within groups, i.e.:\n import * as foo from \"a\";\n import * as bar from \"b\";\n - Groups of imports are delineated by blank lines. You can use these to group imports\n however you like, e.g. by first- vs. third-party or thematically."], _a.raw = ["\n Enforce a consistent ordering for ES6 imports:\n - Named imports must be alphabetized (i.e. \"import {A, B, C} from \"foo\";\")\n - The exact ordering can be controlled by the named-imports-order option.\n - \"longName as name\" imports are ordered by \"longName\".\n - Import sources must be alphabetized within groups, i.e.:\n import * as foo from \"a\";\n import * as bar from \"b\";\n - Groups of imports are delineated by blank lines. You can use these to group imports\n however you like, e.g. by first- vs. third-party or thematically."], Lint.Utils.dedent(_a)),
+ description: "Requires that import statements be alphabetized and grouped.",
+ descriptionDetails: (_a = ["\n Enforce a consistent ordering for ES6 imports:\n - Named imports must be alphabetized (i.e. \"import {A, B, C} from \"foo\";\")\n - The exact ordering can be controlled by the named-imports-order option.\n - \"longName as name\" imports are ordered by \"longName\".\n - Import sources must be alphabetized within groups, i.e.:\n import * as foo from \"a\";\n import * as bar from \"b\";\n - Groups of imports are delineated by blank lines. You can use these to group imports\n however you like, e.g. by first- vs. third-party or thematically or can you can\n enforce a grouping of third-party, parent directories and the current directory."], _a.raw = ["\n Enforce a consistent ordering for ES6 imports:\n - Named imports must be alphabetized (i.e. \"import {A, B, C} from \"foo\";\")\n - The exact ordering can be controlled by the named-imports-order option.\n - \"longName as name\" imports are ordered by \"longName\".\n - Import sources must be alphabetized within groups, i.e.:\n import * as foo from \"a\";\n import * as bar from \"b\";\n - Groups of imports are delineated by blank lines. You can use these to group imports\n however you like, e.g. by first- vs. third-party or thematically or can you can\n enforce a grouping of third-party, parent directories and the current directory."], Lint.Utils.dedent(_a)),
hasFix: true,
- optionsDescription: (_b = ["\n You may set the `\"import-sources-order\"` option to control the ordering of source\n imports (the `\"foo\"` in `import {A, B, C} from \"foo\"`).\n\n Possible values for `\"import-sources-order\"` are:\n\n * `\"case-insensitive'`: Correct order is `\"Bar\"`, `\"baz\"`, `\"Foo\"`. (This is the default.)\n * `\"lowercase-first\"`: Correct order is `\"baz\"`, `\"Bar\"`, `\"Foo\"`.\n * `\"lowercase-last\"`: Correct order is `\"Bar\"`, `\"Foo\"`, `\"baz\"`.\n * `\"any\"`: Allow any order.\n\n You may set the `\"named-imports-order\"` option to control the ordering of named\n imports (the `{A, B, C}` in `import {A, B, C} from \"foo\"`).\n\n Possible values for `\"named-imports-order\"` are:\n\n * `\"case-insensitive'`: Correct order is `{A, b, C}`. (This is the default.)\n * `\"lowercase-first\"`: Correct order is `{b, A, C}`.\n * `\"lowercase-last\"`: Correct order is `{A, C, b}`.\n * `\"any\"`: Allow any order.\n\n "], _b.raw = ["\n You may set the \\`\"import-sources-order\"\\` option to control the ordering of source\n imports (the \\`\"foo\"\\` in \\`import {A, B, C} from \"foo\"\\`).\n\n Possible values for \\`\"import-sources-order\"\\` are:\n\n * \\`\"case-insensitive'\\`: Correct order is \\`\"Bar\"\\`, \\`\"baz\"\\`, \\`\"Foo\"\\`. (This is the default.)\n * \\`\"lowercase-first\"\\`: Correct order is \\`\"baz\"\\`, \\`\"Bar\"\\`, \\`\"Foo\"\\`.\n * \\`\"lowercase-last\"\\`: Correct order is \\`\"Bar\"\\`, \\`\"Foo\"\\`, \\`\"baz\"\\`.\n * \\`\"any\"\\`: Allow any order.\n\n You may set the \\`\"named-imports-order\"\\` option to control the ordering of named\n imports (the \\`{A, B, C}\\` in \\`import {A, B, C} from \"foo\"\\`).\n\n Possible values for \\`\"named-imports-order\"\\` are:\n\n * \\`\"case-insensitive'\\`: Correct order is \\`{A, b, C}\\`. (This is the default.)\n * \\`\"lowercase-first\"\\`: Correct order is \\`{b, A, C}\\`.\n * \\`\"lowercase-last\"\\`: Correct order is \\`{A, C, b}\\`.\n * \\`\"any\"\\`: Allow any order.\n\n "], Lint.Utils.dedent(_b)),
+ optionsDescription: (_b = ["\n You may set the `\"import-sources-order\"` option to control the ordering of source\n imports (the `\"foo\"` in `import {A, B, C} from \"foo\"`).\n\n Possible values for `\"import-sources-order\"` are:\n\n * `\"case-insensitive'`: Correct order is `\"Bar\"`, `\"baz\"`, `\"Foo\"`. (This is the default.)\n * `\"lowercase-first\"`: Correct order is `\"baz\"`, `\"Bar\"`, `\"Foo\"`.\n * `\"lowercase-last\"`: Correct order is `\"Bar\"`, `\"Foo\"`, `\"baz\"`.\n * `\"any\"`: Allow any order.\n\n You may set the `\"grouped-imports\"` option to control the grouping of source\n imports (the `\"foo\"` in `import {A, B, C} from \"foo\"`).\n\n Possible values for `\"grouped-imports\"` are:\n\n * `false`: Do not enforce grouping. (This is the default.)\n * `true`: Group source imports by `\"bar\"`, `\"../baz\"`, `\"./foo\"`.\n\n You may set the `\"named-imports-order\"` option to control the ordering of named\n imports (the `{A, B, C}` in `import {A, B, C} from \"foo\"`).\n\n Possible values for `\"named-imports-order\"` are:\n\n * `\"case-insensitive'`: Correct order is `{A, b, C}`. (This is the default.)\n * `\"lowercase-first\"`: Correct order is `{b, A, C}`.\n * `\"lowercase-last\"`: Correct order is `{A, C, b}`.\n * `\"any\"`: Allow any order.\n\n You may set the `\"module-source-path\"` option to control the ordering of imports based full path\n or just the module name\n\n Possible values for `\"module-source-path\"` are:\n\n * `\"full'`: Correct order is `\"./a/Foo\"`, `\"./b/baz\"`, `\"./c/Bar\"`. (This is the default.)\n * `\"basename\"`: Correct order is `\"./c/Bar\"`, `\"./b/baz\"`, `\"./a/Foo\"`.\n\n "], _b.raw = ["\n You may set the \\`\"import-sources-order\"\\` option to control the ordering of source\n imports (the \\`\"foo\"\\` in \\`import {A, B, C} from \"foo\"\\`).\n\n Possible values for \\`\"import-sources-order\"\\` are:\n\n * \\`\"case-insensitive'\\`: Correct order is \\`\"Bar\"\\`, \\`\"baz\"\\`, \\`\"Foo\"\\`. (This is the default.)\n * \\`\"lowercase-first\"\\`: Correct order is \\`\"baz\"\\`, \\`\"Bar\"\\`, \\`\"Foo\"\\`.\n * \\`\"lowercase-last\"\\`: Correct order is \\`\"Bar\"\\`, \\`\"Foo\"\\`, \\`\"baz\"\\`.\n * \\`\"any\"\\`: Allow any order.\n\n You may set the \\`\"grouped-imports\"\\` option to control the grouping of source\n imports (the \\`\"foo\"\\` in \\`import {A, B, C} from \"foo\"\\`).\n\n Possible values for \\`\"grouped-imports\"\\` are:\n\n * \\`false\\`: Do not enforce grouping. (This is the default.)\n * \\`true\\`: Group source imports by \\`\"bar\"\\`, \\`\"../baz\"\\`, \\`\"./foo\"\\`.\n\n You may set the \\`\"named-imports-order\"\\` option to control the ordering of named\n imports (the \\`{A, B, C}\\` in \\`import {A, B, C} from \"foo\"\\`).\n\n Possible values for \\`\"named-imports-order\"\\` are:\n\n * \\`\"case-insensitive'\\`: Correct order is \\`{A, b, C}\\`. (This is the default.)\n * \\`\"lowercase-first\"\\`: Correct order is \\`{b, A, C}\\`.\n * \\`\"lowercase-last\"\\`: Correct order is \\`{A, C, b}\\`.\n * \\`\"any\"\\`: Allow any order.\n\n You may set the \\`\"module-source-path\"\\` option to control the ordering of imports based full path\n or just the module name\n\n Possible values for \\`\"module-source-path\"\\` are:\n\n * \\`\"full'\\`: Correct order is \\`\"./a/Foo\"\\`, \\`\"./b/baz\"\\`, \\`\"./c/Bar\"\\`. (This is the default.)\n * \\`\"basename\"\\`: Correct order is \\`\"./c/Bar\"\\`, \\`\"./b/baz\"\\`, \\`\"./a/Foo\"\\`.\n\n "], Lint.Utils.dedent(_b)),
options: {
type: "object",
properties: {
+ "grouped-imports": {
+ type: "boolean",
+ },
"import-sources-order": {
type: "string",
enum: ["case-insensitive", "lowercase-first", "lowercase-last", "any"],
@@ -46,6 +49,10 @@ var Rule = /** @class */ (function (_super) {
type: "string",
enum: ["case-insensitive", "lowercase-first", "lowercase-last", "any"],
},
+ "module-source-path": {
+ type: "string",
+ enum: ["full", "basename"],
+ },
},
additionalProperties: false,
},
@@ -57,6 +64,7 @@ var Rule = /** @class */ (function (_super) {
typescriptOnly: false,
};
/* tslint:enable:object-literal-sort-keys */
+ Rule.IMPORT_SOURCES_NOT_GROUPED = "Import sources of different groups must be sorted by: libraries, parent directories, current directory.";
Rule.IMPORT_SOURCES_UNORDERED = "Import sources within a group must be alphabetized.";
Rule.NAMED_IMPORTS_UNORDERED = "Named imports must be alphabetized.";
return Rule;
@@ -67,12 +75,31 @@ var TRANSFORMS = new Map([
["case-insensitive", function (x) { return x.toLowerCase(); }],
["lowercase-first", flipCase],
["lowercase-last", function (x) { return x; }],
+ ["full", function (x) { return x; }],
+ ["basename", function (x) {
+ if (!ts.isExternalModuleNameRelative(x)) {
+ return x;
+ }
+ var splitIndex = x.lastIndexOf("/");
+ if (splitIndex === -1) {
+ return x;
+ }
+ return x.substr(splitIndex + 1);
+ }],
]);
+var ImportType;
+(function (ImportType) {
+ ImportType[ImportType["LIBRARY_IMPORT"] = 1] = "LIBRARY_IMPORT";
+ ImportType[ImportType["PARENT_DIRECTORY_IMPORT"] = 2] = "PARENT_DIRECTORY_IMPORT";
+ ImportType[ImportType["CURRENT_DIRECTORY_IMPORT"] = 3] = "CURRENT_DIRECTORY_IMPORT";
+})(ImportType || (ImportType = {}));
function parseOptions(ruleArguments) {
var optionSet = ruleArguments[0];
- var _a = optionSet === undefined ? {} : optionSet, _b = _a["import-sources-order"], sources = _b === void 0 ? "case-insensitive" : _b, _c = _a["named-imports-order"], named = _c === void 0 ? "case-insensitive" : _c;
+ var _a = optionSet === undefined ? {} : optionSet, _b = _a["grouped-imports"], isGrouped = _b === void 0 ? false : _b, _c = _a["import-sources-order"], sources = _c === void 0 ? "case-insensitive" : _c, _d = _a["named-imports-order"], named = _d === void 0 ? "case-insensitive" : _d, _e = _a["module-source-path"], path = _e === void 0 ? "full" : _e;
return {
+ groupedImports: isGrouped,
importSourcesOrderTransform: TRANSFORMS.get(sources),
+ moduleSourcePath: TRANSFORMS.get(path),
namedImportsOrderTransform: TRANSFORMS.get(named),
};
}
@@ -80,15 +107,26 @@ var Walker = /** @class */ (function (_super) {
tslib_1.__extends(Walker, _super);
function Walker() {
var _this = _super !== null && _super.apply(this, arguments) || this;
- _this.currentImportsBlock = new ImportsBlock();
+ _this.importsBlocks = [new ImportsBlock()];
+ _this.nextType = ImportType.LIBRARY_IMPORT;
return _this;
}
+ Object.defineProperty(Walker.prototype, "currentImportsBlock", {
+ get: function () {
+ return this.importsBlocks[this.importsBlocks.length - 1];
+ },
+ enumerable: true,
+ configurable: true
+ });
Walker.prototype.walk = function (sourceFile) {
for (var _i = 0, _a = sourceFile.statements; _i < _a.length; _i++) {
var statement = _a[_i];
this.checkStatement(statement);
}
this.endBlock();
+ if (this.options.groupedImports) {
+ this.checkBlocksGrouping();
+ }
};
Walker.prototype.checkStatement = function (statement) {
if (!(tsutils_1.isImportDeclaration(statement) || tsutils_1.isImportEqualsDeclaration(statement)) ||
@@ -138,9 +176,10 @@ var Walker = /** @class */ (function (_super) {
this.checkSource(source, node);
};
Walker.prototype.checkSource = function (source, node) {
+ var currentSource = this.options.moduleSourcePath(source);
var previousSource = this.currentImportsBlock.getLastImportSource();
- this.currentImportsBlock.addImportDeclaration(this.sourceFile, node, source);
- if (previousSource !== null && compare(source, previousSource) === -1) {
+ this.currentImportsBlock.addImportDeclaration(this.sourceFile, node, currentSource);
+ if (previousSource !== null && compare(currentSource, previousSource) === -1) {
this.lastFix = [];
this.addFailureAtNode(node, Rule.IMPORT_SOURCES_UNORDERED, this.lastFix);
}
@@ -153,7 +192,7 @@ var Walker = /** @class */ (function (_super) {
}
this.lastFix = undefined;
}
- this.currentImportsBlock = new ImportsBlock();
+ this.importsBlocks.push(new ImportsBlock());
};
Walker.prototype.checkNamedImports = function (node) {
var _this = this;
@@ -175,6 +214,79 @@ var Walker = /** @class */ (function (_super) {
this.addFailure(a.getStart(), b.getEnd(), Rule.NAMED_IMPORTS_UNORDERED, this.lastFix);
}
};
+ Walker.prototype.checkBlocksGrouping = function () {
+ this.importsBlocks.some(this.checkBlockGroups, this);
+ };
+ Walker.prototype.checkBlockGroups = function (importsBlock) {
+ var oddImportDeclaration = this.getOddImportDeclaration(importsBlock);
+ if (oddImportDeclaration !== undefined) {
+ this.addFailureAtNode(oddImportDeclaration.node, Rule.IMPORT_SOURCES_NOT_GROUPED, this.getReplacements());
+ return true;
+ }
+ return false;
+ };
+ Walker.prototype.getOddImportDeclaration = function (importsBlock) {
+ var importDeclarations = importsBlock.getImportDeclarations();
+ if (importDeclarations.length === 0) {
+ return undefined;
+ }
+ var type = importDeclarations[0].type;
+ if (type < this.nextType) {
+ return importDeclarations[0];
+ }
+ else {
+ this.nextType = type;
+ return importDeclarations.find(function (importDeclaration) { return importDeclaration.type !== type; });
+ }
+ };
+ Walker.prototype.getReplacements = function () {
+ var importDeclarationsList = this.importsBlocks
+ .map(function (block) { return block.getImportDeclarations(); })
+ .filter(function (imports) { return imports.length > 0; });
+ var allImportDeclarations = (_a = []).concat.apply(_a, importDeclarationsList);
+ var replacements = this.getReplacementsForExistingImports(importDeclarationsList);
+ var startOffset = allImportDeclarations.length === 0 ? 0 : allImportDeclarations[0].nodeStartOffset;
+ replacements.push(Lint.Replacement.appendText(startOffset, this.getGroupedImports(allImportDeclarations)));
+ return replacements;
+ var _a;
+ };
+ Walker.prototype.getReplacementsForExistingImports = function (importDeclarationsList) {
+ var _this = this;
+ return importDeclarationsList.map(function (items, index) {
+ var start = items[0].nodeStartOffset;
+ if (index > 0) {
+ var prevItems = importDeclarationsList[index - 1];
+ var last = prevItems[prevItems.length - 1];
+ if (/[\r\n]+/.test(_this.sourceFile.text.slice(last.nodeEndOffset, start))) {
+ // remove whitespace between blocks
+ start = last.nodeEndOffset;
+ }
+ }
+ return Lint.Replacement.deleteFromTo(start, items[items.length - 1].nodeEndOffset);
+ });
+ };
+ Walker.prototype.getGroupedImports = function (importDeclarations) {
+ return [ImportType.LIBRARY_IMPORT, ImportType.PARENT_DIRECTORY_IMPORT, ImportType.CURRENT_DIRECTORY_IMPORT]
+ .map(function (type) {
+ var imports = importDeclarations.filter(function (importDeclaration) { return importDeclaration.type === type; });
+ return getSortedImportDeclarationsAsText(imports);
+ })
+ .filter(function (text) { return text.length > 0; })
+ .join(this.getEolChar());
+ };
+ Walker.prototype.getEolChar = function () {
+ var lineEnd = this.sourceFile.getLineEndOfPosition(0);
+ var newLine;
+ if (lineEnd > 0) {
+ if (lineEnd > 1 && this.sourceFile.text[lineEnd - 1] === "\r") {
+ newLine = "\r\n";
+ }
+ else if (this.sourceFile.text[lineEnd] === "\n") {
+ newLine = "\n";
+ }
+ }
+ return newLine === undefined ? ts.sys.newLine : newLine;
+ };
return Walker;
}(Lint.AbstractWalker));
var ImportsBlock = /** @class */ (function () {
@@ -185,6 +297,7 @@ var ImportsBlock = /** @class */ (function () {
var start = this.getStartOffset(node);
var end = this.getEndOffset(sourceFile, node);
var text = sourceFile.text.substring(start, end);
+ var type = this.getImportType(sourcePath);
if (start > node.getStart() || end === 0) {
// skip block if any statements don't end with a newline to simplify implementation
this.importDeclarations = [];
@@ -196,12 +309,16 @@ var ImportsBlock = /** @class */ (function () {
nodeStartOffset: start,
sourcePath: sourcePath,
text: text,
+ type: type,
});
};
+ ImportsBlock.prototype.getImportDeclarations = function () {
+ return this.importDeclarations;
+ };
// replaces the named imports on the most recent import declaration
ImportsBlock.prototype.replaceNamedImports = function (fileOffset, length, replacement) {
var importDeclaration = this.getLastImportDeclaration();
- if (importDeclaration == null) {
+ if (importDeclaration === undefined) {
// nothing to replace. This can happen if the block is skipped
return;
}
@@ -223,8 +340,7 @@ var ImportsBlock = /** @class */ (function () {
if (this.importDeclarations.length === 0) {
return undefined;
}
- var sortedDeclarations = sortByKey(this.importDeclarations.slice(), function (x) { return x.sourcePath; });
- var fixedText = sortedDeclarations.map(function (x) { return x.text; }).join("");
+ var fixedText = getSortedImportDeclarationsAsText(this.importDeclarations);
var start = this.importDeclarations[0].nodeStartOffset;
var end = this.getLastImportDeclaration().nodeEndOffset;
return new Lint.Replacement(start, end - start, fixedText);
@@ -243,6 +359,19 @@ var ImportsBlock = /** @class */ (function () {
ImportsBlock.prototype.getLastImportDeclaration = function () {
return this.importDeclarations[this.importDeclarations.length - 1];
};
+ ImportsBlock.prototype.getImportType = function (sourcePath) {
+ if (sourcePath.charAt(0) === ".") {
+ if (sourcePath.charAt(1) === ".") {
+ return ImportType.PARENT_DIRECTORY_IMPORT;
+ }
+ else {
+ return ImportType.CURRENT_DIRECTORY_IMPORT;
+ }
+ }
+ else {
+ return ImportType.LIBRARY_IMPORT;
+ }
+ };
return ImportsBlock;
}());
// Convert aBcD --> AbCd
@@ -267,7 +396,6 @@ function findUnsortedPair(xs, transform) {
}
return undefined;
}
-// tslint:disable-next-line no-unsafe-any (fixed in 5.3)
function compare(a, b) {
function isLow(value) {
return value[0] === "." || value[0] === "/";
@@ -293,6 +421,10 @@ function removeQuotes(value) {
}
return value;
}
+function getSortedImportDeclarationsAsText(importDeclarations) {
+ var sortedDeclarations = sortByKey(importDeclarations.slice(), function (x) { return x.sourcePath; });
+ return sortedDeclarations.map(function (x) { return x.text; }).join("");
+}
function sortByKey(xs, getSortKey) {
return xs.slice().sort(function (a, b) { return compare(getSortKey(a), getSortKey(b)); });
}
diff --git a/node_modules/tslint/lib/rules/preferConstRule.js b/node_modules/tslint/lib/rules/preferConstRule.js
index 6bb1a3cd0..42f1e6ce4 100644
--- a/node_modules/tslint/lib/rules/preferConstRule.js
+++ b/node_modules/tslint/lib/rules/preferConstRule.js
@@ -33,7 +33,8 @@ var Rule = /** @class */ (function (_super) {
};
Rule.prototype.apply = function (sourceFile) {
var options = {
- destructuringAll: this.ruleArguments.length !== 0 && this.ruleArguments[0].destructuring === OPTION_DESTRUCTURING_ALL,
+ destructuringAll: this.ruleArguments.length !== 0 &&
+ this.ruleArguments[0].destructuring === OPTION_DESTRUCTURING_ALL,
};
var preferConstWalker = new PreferConstWalker(sourceFile, this.ruleName, options);
return this.applyWithWalker(preferConstWalker);
diff --git a/node_modules/tslint/lib/rules/restrictPlusOperandsRule.d.ts b/node_modules/tslint/lib/rules/restrictPlusOperandsRule.d.ts
index 21b50bfe4..222faaa7f 100644
--- a/node_modules/tslint/lib/rules/restrictPlusOperandsRule.d.ts
+++ b/node_modules/tslint/lib/rules/restrictPlusOperandsRule.d.ts
@@ -3,5 +3,6 @@ import * as Lint from "../index";
export declare class Rule extends Lint.Rules.TypedRule {
static metadata: Lint.IRuleMetadata;
static INVALID_TYPES_ERROR: string;
+ static SUGGEST_TEMPLATE_LITERALS: string;
applyWithProgram(sourceFile: ts.SourceFile, program: ts.Program): Lint.RuleFailure[];
}
diff --git a/node_modules/tslint/lib/rules/restrictPlusOperandsRule.js b/node_modules/tslint/lib/rules/restrictPlusOperandsRule.js
index 1974ce47a..c2b8bdb96 100644
--- a/node_modules/tslint/lib/rules/restrictPlusOperandsRule.js
+++ b/node_modules/tslint/lib/rules/restrictPlusOperandsRule.js
@@ -41,6 +41,7 @@ var Rule = /** @class */ (function (_super) {
};
/* tslint:enable:object-literal-sort-keys */
Rule.INVALID_TYPES_ERROR = "Operands of '+' operation must either be both strings or both numbers";
+ Rule.SUGGEST_TEMPLATE_LITERALS = ", consider using template literals";
return Rule;
}(Lint.Rules.TypedRule));
exports.Rule = Rule;
@@ -50,7 +51,12 @@ function walk(ctx, tc) {
var leftType = getBaseTypeOfLiteralType(tc.getTypeAtLocation(node.left));
var rightType = getBaseTypeOfLiteralType(tc.getTypeAtLocation(node.right));
if (leftType === "invalid" || rightType === "invalid" || leftType !== rightType) {
- return ctx.addFailureAtNode(node, Rule.INVALID_TYPES_ERROR);
+ if (leftType === "string" || rightType === "string") {
+ return ctx.addFailureAtNode(node, Rule.INVALID_TYPES_ERROR + Rule.SUGGEST_TEMPLATE_LITERALS);
+ }
+ else {
+ return ctx.addFailureAtNode(node, Rule.INVALID_TYPES_ERROR);
+ }
}
}
return ts.forEachChild(node, cb);
diff --git a/node_modules/tslint/lib/rules/returnUndefinedRule.js b/node_modules/tslint/lib/rules/returnUndefinedRule.js
index 7cc14c04e..e117a1b3d 100644
--- a/node_modules/tslint/lib/rules/returnUndefinedRule.js
+++ b/node_modules/tslint/lib/rules/returnUndefinedRule.js
@@ -64,7 +64,9 @@ function walk(ctx, checker) {
}
var returnKindFromType = getReturnKind(functionReturningFrom, checker);
if (returnKindFromType !== undefined && returnKindFromType !== actualReturnKind) {
- ctx.addFailureAtNode(node, returnKindFromType === ReturnKind.Void ? Rule.FAILURE_STRING_VOID_RETURN : Rule.FAILURE_STRING_VALUE_RETURN);
+ ctx.addFailureAtNode(node, returnKindFromType === ReturnKind.Void
+ ? Rule.FAILURE_STRING_VOID_RETURN
+ : Rule.FAILURE_STRING_VALUE_RETURN);
}
}
}
@@ -92,24 +94,28 @@ function getReturnKind(node, checker) {
case ts.SyntaxKind.GetAccessor:
return ReturnKind.Value;
}
- var contextual = isFunctionExpressionLike(node) ? tryGetReturnType(checker.getContextualType(node), checker) : undefined;
+ var contextual = isFunctionExpressionLike(node) && node.type === undefined
+ ? tryGetReturnType(checker.getContextualType(node), checker)
+ : undefined;
var returnType = contextual !== undefined ? contextual : tryGetReturnType(checker.getTypeAtLocation(node), checker);
- if (returnType === undefined) {
+ if (returnType === undefined || Lint.isTypeFlagSet(returnType, ts.TypeFlags.Any)) {
return undefined;
}
- else if (isEffectivelyVoid(returnType)) {
+ if ((Lint.hasModifier(node.modifiers, ts.SyntaxKind.AsyncKeyword) ? isEffectivelyVoidPromise : isEffectivelyVoid)(returnType)) {
return ReturnKind.Void;
}
- else if (Lint.hasModifier(node.modifiers, ts.SyntaxKind.AsyncKeyword)) {
- // Would need access to `checker.getPromisedTypeOfPromise` to do this properly.
- // Assume that the return type is the global Promise (since this is an async function) and get its type argument.
- var typeArguments = returnType.typeArguments;
- if (typeArguments !== undefined && typeArguments.length === 1) {
- return isEffectivelyVoid(typeArguments[0]) ? ReturnKind.Void : ReturnKind.Value;
- }
- }
return ReturnKind.Value;
}
+/** True for `void`, `undefined`, Promise<void>, or `void | undefined | Promise<void>`. */
+function isEffectivelyVoidPromise(type) {
+ // Would need access to `checker.getPromisedTypeOfPromise` to do this properly.
+ // Assume that the return type is the global Promise (since this is an async function) and get its type argument.
+ // tslint:disable-next-line no-bitwise
+ return Lint.isTypeFlagSet(type, ts.TypeFlags.Void | ts.TypeFlags.Undefined) ||
+ tsutils_1.isUnionType(type) && type.types.every(isEffectivelyVoidPromise) ||
+ tsutils_1.isTypeReference(type) && type.typeArguments !== undefined && type.typeArguments.length === 1 &&
+ isEffectivelyVoidPromise(type.typeArguments[0]);
+}
/** True for `void`, `undefined`, or `void | undefined`. */
function isEffectivelyVoid(type) {
// tslint:disable-next-line no-bitwise
@@ -124,8 +130,7 @@ function tryGetReturnType(fnType, checker) {
if (sigs.length !== 1) {
return undefined;
}
- var ret = checker.getReturnTypeOfSignature(sigs[0]);
- return Lint.isTypeFlagSet(ret, ts.TypeFlags.Any) ? undefined : ret;
+ return checker.getReturnTypeOfSignature(sigs[0]);
}
function isFunctionLike(node) {
switch (node.kind) {
diff --git a/node_modules/tslint/lib/rules/semicolonRule.js b/node_modules/tslint/lib/rules/semicolonRule.js
index a6e0dfb85..6901842f4 100644
--- a/node_modules/tslint/lib/rules/semicolonRule.js
+++ b/node_modules/tslint/lib/rules/semicolonRule.js
@@ -23,6 +23,7 @@ var Lint = require("../index");
var OPTION_ALWAYS = "always";
var OPTION_NEVER = "never";
var OPTION_IGNORE_BOUND_CLASS_METHODS = "ignore-bound-class-methods";
+var OPTION_STRICT_BOUND_CLASS_METHODS = "strict-bound-class-methods";
var OPTION_IGNORE_INTERFACES = "ignore-interfaces";
var Rule = /** @class */ (function (_super) {
tslib_1.__extends(Rule, _super);
@@ -31,7 +32,11 @@ var Rule = /** @class */ (function (_super) {
}
Rule.prototype.apply = function (sourceFile) {
var options = {
- boundClassMethods: this.ruleArguments.indexOf(OPTION_IGNORE_BOUND_CLASS_METHODS) === -1,
+ boundClassMethods: this.ruleArguments.indexOf(OPTION_STRICT_BOUND_CLASS_METHODS) !== -1
+ ? 2 /* Strict */
+ : this.ruleArguments.indexOf(OPTION_IGNORE_BOUND_CLASS_METHODS) !== -1
+ ? 1 /* Ignore */
+ : 0 /* Default */,
interfaces: this.ruleArguments.indexOf(OPTION_IGNORE_INTERFACES) === -1,
};
var Walker = this.ruleArguments.indexOf(OPTION_NEVER) === -1 ? SemicolonAlwaysWalker : SemicolonNeverWalker;
@@ -42,7 +47,7 @@ var Rule = /** @class */ (function (_super) {
ruleName: "semicolon",
description: "Enforces consistent semicolon usage at the end of every statement.",
hasFix: true,
- optionsDescription: (_a = ["\n One of the following arguments must be provided:\n\n * `\"", "\"` enforces semicolons at the end of every statement.\n * `\"", "\"` disallows semicolons at the end of every statement except for when they are necessary.\n\n The following arguments may be optionally provided:\n\n * `\"", "\"` skips checking semicolons at the end of interface members.\n * `\"", "\"` skips checking semicolons at the end of bound class methods."], _a.raw = ["\n One of the following arguments must be provided:\n\n * \\`\"", "\"\\` enforces semicolons at the end of every statement.\n * \\`\"", "\"\\` disallows semicolons at the end of every statement except for when they are necessary.\n\n The following arguments may be optionally provided:\n\n * \\`\"", "\"\\` skips checking semicolons at the end of interface members.\n * \\`\"", "\"\\` skips checking semicolons at the end of bound class methods."], Lint.Utils.dedent(_a, OPTION_ALWAYS, OPTION_NEVER, OPTION_IGNORE_INTERFACES, OPTION_IGNORE_BOUND_CLASS_METHODS)),
+ optionsDescription: (_a = ["\n One of the following arguments must be provided:\n\n * `\"", "\"` enforces semicolons at the end of every statement.\n * `\"", "\"` disallows semicolons at the end of every statement except for when they are necessary.\n\n The following arguments may be optionally provided:\n\n * `\"", "\"` skips checking semicolons at the end of interface members.\n * `\"", "\"` skips checking semicolons at the end of bound class methods.\n * `\"", "\"` disables any special handling of bound class methods and treats them as any\n other assignment. This option overrides `\"", "\"`.\n "], _a.raw = ["\n One of the following arguments must be provided:\n\n * \\`\"", "\"\\` enforces semicolons at the end of every statement.\n * \\`\"", "\"\\` disallows semicolons at the end of every statement except for when they are necessary.\n\n The following arguments may be optionally provided:\n\n * \\`\"", "\"\\` skips checking semicolons at the end of interface members.\n * \\`\"", "\"\\` skips checking semicolons at the end of bound class methods.\n * \\`\"", "\"\\` disables any special handling of bound class methods and treats them as any\n other assignment. This option overrides \\`\"", "\"\\`.\n "], Lint.Utils.dedent(_a, OPTION_ALWAYS, OPTION_NEVER, OPTION_IGNORE_INTERFACES, OPTION_IGNORE_BOUND_CLASS_METHODS, OPTION_STRICT_BOUND_CLASS_METHODS, OPTION_IGNORE_BOUND_CLASS_METHODS)),
options: {
type: "array",
items: [
@@ -160,10 +165,11 @@ var SemicolonWalker = /** @class */ (function (_super) {
};
SemicolonWalker.prototype.visitPropertyDeclaration = function (node) {
// check if this is a multi-line arrow function
- if (node.initializer !== undefined &&
+ if (this.options.boundClassMethods !== 2 /* Strict */ &&
+ node.initializer !== undefined &&
node.initializer.kind === ts.SyntaxKind.ArrowFunction &&
!utils.isSameLine(this.sourceFile, node.getStart(this.sourceFile), node.end)) {
- if (this.options.boundClassMethods) {
+ if (this.options.boundClassMethods === 0 /* Default */) {
this.checkUnnecessary(node);
}
}
diff --git a/node_modules/tslint/lib/rules/spaceBeforeFunctionParenRule.js b/node_modules/tslint/lib/rules/spaceBeforeFunctionParenRule.js
index 712868566..7e3282b8c 100644
--- a/node_modules/tslint/lib/rules/spaceBeforeFunctionParenRule.js
+++ b/node_modules/tslint/lib/rules/spaceBeforeFunctionParenRule.js
@@ -99,14 +99,18 @@ function walk(ctx) {
function getOption(node, options) {
switch (node.kind) {
case ts.SyntaxKind.ArrowFunction:
- return Lint.hasModifier(node.modifiers, ts.SyntaxKind.AsyncKeyword) ? options.asyncArrow : undefined;
+ return !hasTypeParameters(node) && Lint.hasModifier(node.modifiers, ts.SyntaxKind.AsyncKeyword)
+ ? options.asyncArrow : undefined;
case ts.SyntaxKind.Constructor:
return options.constructor;
case ts.SyntaxKind.FunctionDeclaration:
// name is optional for function declaration which is default export (TS will emit error in other cases).
// Can be handled in the same way as function expression.
- case ts.SyntaxKind.FunctionExpression:
- return node.name !== undefined ? options.named : options.anonymous;
+ case ts.SyntaxKind.FunctionExpression: {
+ var functionName = node.name;
+ var hasName = functionName !== undefined && functionName.text !== "";
+ return hasName ? options.named : !hasTypeParameters(node) ? options.anonymous : undefined;
+ }
case ts.SyntaxKind.MethodDeclaration:
case ts.SyntaxKind.MethodSignature:
case ts.SyntaxKind.GetAccessor:
@@ -116,4 +120,7 @@ function getOption(node, options) {
return undefined;
}
}
+function hasTypeParameters(node) {
+ return node.typeParameters !== undefined;
+}
var _a;
diff --git a/node_modules/tslint/lib/rules/strictBooleanExpressionsRule.js b/node_modules/tslint/lib/rules/strictBooleanExpressionsRule.js
index 5cc1e4b39..605d85929 100644
--- a/node_modules/tslint/lib/rules/strictBooleanExpressionsRule.js
+++ b/node_modules/tslint/lib/rules/strictBooleanExpressionsRule.js
@@ -25,7 +25,7 @@ var OPTION_ALLOW_STRING = "allow-string";
var OPTION_ALLOW_NUMBER = "allow-number";
var OPTION_ALLOW_MIX = "allow-mix";
var OPTION_ALLOW_BOOLEAN_OR_UNDEFINED = "allow-boolean-or-undefined";
-// tslint:disable object-literal-sort-keys switch-default
+// tslint:disable object-literal-sort-keys
var Rule = /** @class */ (function (_super) {
tslib_1.__extends(Rule, _super);
function Rule() {
diff --git a/node_modules/tslint/lib/rules/trailingCommaRule.d.ts b/node_modules/tslint/lib/rules/trailingCommaRule.d.ts
index 10b449342..ac23c5939 100644
--- a/node_modules/tslint/lib/rules/trailingCommaRule.d.ts
+++ b/node_modules/tslint/lib/rules/trailingCommaRule.d.ts
@@ -3,6 +3,7 @@ import * as Lint from "../index";
export declare class Rule extends Lint.Rules.AbstractRule {
static metadata: Lint.IRuleMetadata;
static FAILURE_STRING_NEVER: string;
+ static FAILURE_STRING_FORBIDDEN: string;
static FAILURE_STRING_ALWAYS: string;
apply(sourceFile: ts.SourceFile): Lint.RuleFailure[];
isEnabled(): boolean;
diff --git a/node_modules/tslint/lib/rules/trailingCommaRule.js b/node_modules/tslint/lib/rules/trailingCommaRule.js
index e183e4ea4..784bc9a58 100644
--- a/node_modules/tslint/lib/rules/trailingCommaRule.js
+++ b/node_modules/tslint/lib/rules/trailingCommaRule.js
@@ -20,7 +20,7 @@ var tslib_1 = require("tslib");
var tsutils_1 = require("tsutils");
var ts = require("typescript");
var Lint = require("../index");
-var defaultOptions = fillOptions("ignore"); // tslint:disable-line no-unnecessary-type-assertion
+var defaultOptions = fillOptions("ignore");
function fillOptions(value) {
return {
arrays: value,
@@ -32,10 +32,10 @@ function fillOptions(value) {
};
}
function normalizeOptions(options) {
- return { multiline: normalize(options.multiline), singleline: normalize(options.singleline) };
- function normalize(value) {
- return typeof value === "string" ? fillOptions(value) : tslib_1.__assign({}, defaultOptions, value);
- }
+ return { multiline: normalize(options.multiline), singleline: normalize(options.singleline), specCompliant: !!options.esSpecCompliant };
+}
+function normalize(value) {
+ return typeof value === "string" ? fillOptions(value) : tslib_1.__assign({}, defaultOptions, value);
}
/* tslint:disable:object-literal-sort-keys */
var metadataOptionShape = {
@@ -71,12 +71,13 @@ var Rule = /** @class */ (function (_super) {
ruleName: "trailing-comma",
description: (_a = ["\n Requires or disallows trailing commas in array and object literals, destructuring assignments, function typings,\n named imports and exports and function parameters."], _a.raw = ["\n Requires or disallows trailing commas in array and object literals, destructuring assignments, function typings,\n named imports and exports and function parameters."], Lint.Utils.dedent(_a)),
hasFix: true,
- optionsDescription: (_b = ["\n One argument which is an object with the keys `multiline` and `singleline`.\n Both can be set to a string (`\"always\"` or `\"never\"`) or an object.\n\n The object can contain any of the following keys: `\"arrays\"`, `\"objects\"`, `\"functions\"`,\n `\"imports\"`, `\"exports\"`, and `\"typeLiterals\"`; each key can have one of the following\n values: `\"always\"`, `\"never\"`, and `\"ignore\"`. Any missing keys will default to `\"ignore\"`.\n\n * `\"multiline\"` checks multi-line object literals.\n * `\"singleline\"` checks single-line object literals.\n\n An array is considered \"multiline\" if its closing bracket is on a line\n after the last array element. The same general logic is followed for\n object literals, function typings, named import statements\n and function parameters."], _b.raw = ["\n One argument which is an object with the keys \\`multiline\\` and \\`singleline\\`.\n Both can be set to a string (\\`\"always\"\\` or \\`\"never\"\\`) or an object.\n\n The object can contain any of the following keys: \\`\"arrays\"\\`, \\`\"objects\"\\`, \\`\"functions\"\\`,\n \\`\"imports\"\\`, \\`\"exports\"\\`, and \\`\"typeLiterals\"\\`; each key can have one of the following\n values: \\`\"always\"\\`, \\`\"never\"\\`, and \\`\"ignore\"\\`. Any missing keys will default to \\`\"ignore\"\\`.\n\n * \\`\"multiline\"\\` checks multi-line object literals.\n * \\`\"singleline\"\\` checks single-line object literals.\n\n An array is considered \"multiline\" if its closing bracket is on a line\n after the last array element. The same general logic is followed for\n object literals, function typings, named import statements\n and function parameters."], Lint.Utils.dedent(_b)),
+ optionsDescription: (_b = ["\n One argument which is an object with the keys `multiline` and `singleline`.\n Both can be set to a string (`\"always\"` or `\"never\"`) or an object.\n\n The object can contain any of the following keys: `\"arrays\"`, `\"objects\"`, `\"functions\"`,\n `\"imports\"`, `\"exports\"`, and `\"typeLiterals\"`; each key can have one of the following\n values: `\"always\"`, `\"never\"`, and `\"ignore\"`. Any missing keys will default to `\"ignore\"`.\n\n * `\"multiline\"` checks multi-line object literals.\n * `\"singleline\"` checks single-line object literals.\n\n An array is considered \"multiline\" if its closing bracket is on a line\n after the last array element. The same general logic is followed for\n object literals, function typings, named import statements\n and function parameters.\n\n To align this rule with the ECMAScript specification that is implemented in modern JavaScript VMs,\n there is a third option `esSpecCompliant`. Set this option to `true` to disallow trailing comma on\n object and array rest and rest parameters.\n "], _b.raw = ["\n One argument which is an object with the keys \\`multiline\\` and \\`singleline\\`.\n Both can be set to a string (\\`\"always\"\\` or \\`\"never\"\\`) or an object.\n\n The object can contain any of the following keys: \\`\"arrays\"\\`, \\`\"objects\"\\`, \\`\"functions\"\\`,\n \\`\"imports\"\\`, \\`\"exports\"\\`, and \\`\"typeLiterals\"\\`; each key can have one of the following\n values: \\`\"always\"\\`, \\`\"never\"\\`, and \\`\"ignore\"\\`. Any missing keys will default to \\`\"ignore\"\\`.\n\n * \\`\"multiline\"\\` checks multi-line object literals.\n * \\`\"singleline\"\\` checks single-line object literals.\n\n An array is considered \"multiline\" if its closing bracket is on a line\n after the last array element. The same general logic is followed for\n object literals, function typings, named import statements\n and function parameters.\n\n To align this rule with the ECMAScript specification that is implemented in modern JavaScript VMs,\n there is a third option \\`esSpecCompliant\\`. Set this option to \\`true\\` to disallow trailing comma on\n object and array rest and rest parameters.\n "], Lint.Utils.dedent(_b)),
options: {
type: "object",
properties: {
multiline: metadataOptionShape,
singleline: metadataOptionShape,
+ esSpecCompliant: { type: "boolean" },
},
additionalProperties: false,
},
@@ -91,6 +92,7 @@ var Rule = /** @class */ (function (_super) {
functions: "never",
typeLiterals: "ignore",
},
+ esSpecCompliant: true,
},
],
],
@@ -99,6 +101,7 @@ var Rule = /** @class */ (function (_super) {
};
/* tslint:enable:object-literal-sort-keys */
Rule.FAILURE_STRING_NEVER = "Unnecessary trailing comma";
+ Rule.FAILURE_STRING_FORBIDDEN = "Forbidden trailing comma";
Rule.FAILURE_STRING_ALWAYS = "Missing trailing comma";
return Rule;
}(Lint.Rules.AbstractRule));
@@ -113,23 +116,25 @@ var TrailingCommaWalker = /** @class */ (function (_super) {
var cb = function (node) {
switch (node.kind) {
case ts.SyntaxKind.ArrayLiteralExpression:
+ _this.checkList(node.elements, node.end, "arrays", isArrayRest);
+ break;
case ts.SyntaxKind.ArrayBindingPattern:
- _this.checkList(node.elements, node.end, "arrays");
+ _this.checkList(node.elements, node.end, "arrays", isDestructuringRest);
break;
case ts.SyntaxKind.ObjectBindingPattern:
- _this.checkList(node.elements, node.end, "objects");
+ _this.checkList(node.elements, node.end, "objects", isDestructuringRest);
break;
case ts.SyntaxKind.NamedImports:
- _this.checkList(node.elements, node.end, "imports");
+ _this.checkList(node.elements, node.end, "imports", noRest);
break;
case ts.SyntaxKind.NamedExports:
- _this.checkList(node.elements, node.end, "exports");
+ _this.checkList(node.elements, node.end, "exports", noRest);
break;
case ts.SyntaxKind.ObjectLiteralExpression:
- _this.checkList(node.properties, node.end, "objects");
+ _this.checkList(node.properties, node.end, "objects", isObjectRest);
break;
case ts.SyntaxKind.EnumDeclaration:
- _this.checkList(node.members, node.end, "objects");
+ _this.checkList(node.members, node.end, "objects", noRest);
break;
case ts.SyntaxKind.NewExpression:
if (node.arguments === undefined) {
@@ -137,9 +142,14 @@ var TrailingCommaWalker = /** @class */ (function (_super) {
}
// falls through
case ts.SyntaxKind.CallExpression:
- _this.checkList(node.arguments, node.end, "functions");
+ _this.checkList(node.arguments, node.end, "functions", noRest);
break;
case ts.SyntaxKind.ArrowFunction:
+ // don't check arrow functions without parens around the parameter
+ if (tsutils_1.getChildOfKind(node, ts.SyntaxKind.OpenParenToken, _this.sourceFile) === undefined) {
+ break;
+ }
+ // falls through
case ts.SyntaxKind.Constructor:
case ts.SyntaxKind.FunctionDeclaration:
case ts.SyntaxKind.FunctionExpression:
@@ -150,7 +160,7 @@ var TrailingCommaWalker = /** @class */ (function (_super) {
case ts.SyntaxKind.ConstructorType:
case ts.SyntaxKind.FunctionType:
case ts.SyntaxKind.CallSignature:
- _this.checkListWithEndToken(node, node.parameters, ts.SyntaxKind.CloseParenToken, "functions");
+ _this.checkList(node.parameters, tsutils_1.getChildOfKind(node, ts.SyntaxKind.CloseParenToken, _this.sourceFile).end, "functions", isRestParameter);
break;
case ts.SyntaxKind.TypeLiteral:
_this.checkTypeLiteral(node);
@@ -176,26 +186,24 @@ var TrailingCommaWalker = /** @class */ (function (_super) {
}
// The trailing comma is part of the last member and therefore not present as hasTrailingComma on the NodeArray
var hasTrailingComma = sourceText[members.end - 1] === ",";
- return this.checkComma(hasTrailingComma, members, node.end, "typeLiterals");
+ return this.checkComma(hasTrailingComma, members, node.end, "typeLiterals", noRest);
};
- TrailingCommaWalker.prototype.checkListWithEndToken = function (node, list, closeTokenKind, optionKey) {
+ TrailingCommaWalker.prototype.checkList = function (list, closeElementPos, optionKey, isRest) {
if (list.length === 0) {
return;
}
- var token = tsutils_1.getChildOfKind(node, closeTokenKind, this.sourceFile);
- if (token !== undefined) {
- return this.checkComma(list.hasTrailingComma, list, token.end, optionKey);
- }
+ return this.checkComma(list.hasTrailingComma, list, closeElementPos, optionKey, isRest);
};
- TrailingCommaWalker.prototype.checkList = function (list, closeElementPos, optionKey) {
- if (list.length === 0) {
+ /* Expects `list.length !== 0` */
+ TrailingCommaWalker.prototype.checkComma = function (hasTrailingComma, list, closeTokenPos, optionKey, isRest) {
+ var last = list[list.length - 1];
+ if (this.options.specCompliant && isRest(last)) {
+ if (hasTrailingComma) {
+ this.addFailureAt(list.end - 1, 1, Rule.FAILURE_STRING_FORBIDDEN, Lint.Replacement.deleteText(list.end - 1, 1));
+ }
return;
}
- return this.checkComma(list.hasTrailingComma, list, closeElementPos, optionKey);
- };
- /* Expects `list.length !== 0` */
- TrailingCommaWalker.prototype.checkComma = function (hasTrailingComma, list, closeTokenPos, optionKey) {
- var options = tsutils_1.isSameLine(this.sourceFile, list[list.length - 1].end, closeTokenPos)
+ var options = tsutils_1.isSameLine(this.sourceFile, last.end, closeTokenPos)
? this.options.singleline
: this.options.multiline;
var option = options[optionKey];
@@ -208,4 +216,19 @@ var TrailingCommaWalker = /** @class */ (function (_super) {
};
return TrailingCommaWalker;
}(Lint.AbstractWalker));
+function isRestParameter(node) {
+ return node.dotDotDotToken !== undefined;
+}
+function isDestructuringRest(node) {
+ return node.kind === ts.SyntaxKind.BindingElement && node.dotDotDotToken !== undefined;
+}
+function isObjectRest(node) {
+ return node.kind === ts.SyntaxKind.SpreadAssignment && tsutils_1.isReassignmentTarget(node.expression);
+}
+function isArrayRest(node) {
+ return node.kind === ts.SyntaxKind.SpreadElement && tsutils_1.isReassignmentTarget(node);
+}
+function noRest() {
+ return false;
+}
var _a, _b;
diff --git a/node_modules/tslint/lib/rules/typeofCompareRule.js b/node_modules/tslint/lib/rules/typeofCompareRule.js
index 7734d9afd..7668784df 100644
--- a/node_modules/tslint/lib/rules/typeofCompareRule.js
+++ b/node_modules/tslint/lib/rules/typeofCompareRule.js
@@ -38,6 +38,9 @@ var Rule = /** @class */ (function (_super) {
optionExamples: [true],
type: "functionality",
typescriptOnly: false,
+ deprecationMessage: ts.versionMajorMinor === "2.1"
+ ? "Starting from TypeScript 2.2 the compiler includes this check which makes this rule redundant."
+ : "",
};
/* tslint:enable:object-literal-sort-keys */
Rule.FAILURE_STRING = "'typeof' expression must be compared to one of: " + Array.from(LEGAL_TYPEOF_RESULTS).map(function (x) { return "\"" + x + "\""; }).join(", ");
diff --git a/node_modules/tslint/lib/rules/variableNameRule.js b/node_modules/tslint/lib/rules/variableNameRule.js
index b095c75a8..ce17c71ea 100644
--- a/node_modules/tslint/lib/rules/variableNameRule.js
+++ b/node_modules/tslint/lib/rules/variableNameRule.js
@@ -126,7 +126,7 @@ function walk(ctx) {
if (initializer !== undefined && isAlias(text, initializer)) {
return;
}
- if (!isCamelCase(text, options) && !utils_1.isUpperCase(text)) {
+ if (text.length !== 0 && !isCamelCase(text, options) && !utils_1.isUpperCase(text)) {
ctx.addFailureAtNode(name, formatFailure());
}
}
diff --git a/node_modules/tslint/lib/rules/whitespaceRule.js b/node_modules/tslint/lib/rules/whitespaceRule.js
index 67a8bdfb9..baae7ec33 100644
--- a/node_modules/tslint/lib/rules/whitespaceRule.js
+++ b/node_modules/tslint/lib/rules/whitespaceRule.js
@@ -59,6 +59,7 @@ var Rule = /** @class */ (function (_super) {
optionExamples: [[true, "check-branch", "check-operator", "check-typecast"]],
type: "style",
typescriptOnly: false,
+ hasFix: true,
};
Rule.FAILURE_STRING_MISSING = "missing whitespace";
Rule.FAILURE_STRING_INVALID = "invalid whitespace";