Socket
Socket
Sign inDemoInstall

tslint

Package Overview
Dependencies
Maintainers
1
Versions
182
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tslint - npm Package Compare versions

Comparing version 5.5.0 to 5.6.0

lib/rules/noDuplicateImportsRule.d.ts

3

lib/configs/all.d.ts

@@ -59,2 +59,3 @@ export declare const rules: {

"no-sparse-arrays": boolean;
"no-submodule-imports": boolean;
"no-unbound-method": boolean;

@@ -85,2 +86,3 @@ "no-unsafe-any": boolean;

"no-default-export": boolean;
"no-duplicate-imports": boolean;
"no-irregular-whitespace": boolean;

@@ -147,2 +149,3 @@ "no-mergeable-namespace": boolean;

})[];
"space-within-parens": (number | boolean)[];
"switch-final-break": boolean;

@@ -149,0 +152,0 @@ "type-literal-delimiter": boolean;

@@ -117,2 +117,3 @@ "use strict";

"no-sparse-arrays": true,
"no-submodule-imports": true,
"no-unbound-method": true,

@@ -144,2 +145,3 @@ "no-unsafe-any": true,

"no-default-export": true,
"no-duplicate-imports": true,
"no-irregular-whitespace": true,

@@ -231,2 +233,3 @@ "no-mergeable-namespace": true,

}],
"space-within-parens": [true, 0],
"switch-final-break": true,

@@ -233,0 +236,0 @@ "type-literal-delimiter": true,

@@ -28,4 +28,6 @@ /**

"no-this-assignment": boolean;
"no-duplicate-imports": boolean;
"space-within-parens": (number | boolean)[];
};
declare const xtends = "tslint:recommended";
export { xtends as extends };

@@ -42,3 +42,7 @@ "use strict";

],
// added in v5.5
"no-this-assignment": true,
// added in v5.6
"no-duplicate-imports": true,
"space-within-parens": [true, 0],
};

@@ -45,0 +49,0 @@ // tslint:enable object-literal-sort-keys

4

lib/formatters/checkstyleFormatter.js

@@ -31,5 +31,3 @@ "use strict";

if (failures.length !== 0) {
var failuresSorted = failures.sort(function (a, b) {
return a.getFileName().localeCompare(b.getFileName());
});
var failuresSorted = failures.sort(function (a, b) { return a.getFileName().localeCompare(b.getFileName()); });
var previousFilename = null;

@@ -36,0 +34,0 @@ for (var _i = 0, failuresSorted_1 = failuresSorted; _i < failuresSorted_1.length; _i++) {

@@ -29,3 +29,3 @@ "use strict";

// if no program is given to the linter, show an error
error_1.showWarningOnce("Warning: The '" + this.ruleName + "' rule requires type infomation.");
error_1.showWarningOnce("Warning: The '" + this.ruleName + "' rule requires type information.");
return [];

@@ -32,0 +32,0 @@ };

@@ -61,2 +61,6 @@ import * as ts from "typescript";

export declare function isLoop(node: ts.Node): node is ts.IterationStatement;
/**
* @returns Whether node is a numeric expression.
*/
export declare function isNumeric(node: ts.Expression): boolean;
export interface TokenPosition {

@@ -63,0 +67,0 @@ /** The start of the token including all trivia before it */

@@ -47,5 +47,3 @@ "use strict";

}
return modifiers.some(function (m) {
return modifierKinds.some(function (k) { return m.kind === k; });
});
return modifiers.some(function (m) { return modifierKinds.some(function (k) { return m.kind === k; }); });
}

@@ -227,2 +225,14 @@ exports.hasModifier = hasModifier;

/**
* @returns Whether node is a numeric expression.
*/
function isNumeric(node) {
while (tsutils_1.isPrefixUnaryExpression(node) &&
(node.operator === ts.SyntaxKind.PlusToken || node.operator === ts.SyntaxKind.MinusToken)) {
node = node.operand;
}
return node.kind === ts.SyntaxKind.NumericLiteral ||
tsutils_1.isIdentifier(node) && (node.text === "NaN" || node.text === "Infinity");
}
exports.isNumeric = isNumeric;
/**
* Iterate over all tokens of `node`

@@ -229,0 +239,0 @@ *

@@ -20,3 +20,2 @@ /**

import { WalkContext } from "./walkContext";
import { IWalker } from "./walker";
export interface IWalker {

@@ -23,0 +22,0 @@ getSourceFile(): ts.SourceFile;

@@ -84,6 +84,5 @@ "use strict";

// add rule severity to failures
var ruleSeverityMap = new Map(enabledRules.map(function (rule) {
// tslint:disable-next-line no-unnecessary-type-assertion
return [rule.getOptions().ruleName, rule.getOptions().ruleSeverity];
}));
var ruleSeverityMap = new Map(enabledRules.map(
// tslint:disable-next-line no-unnecessary-type-assertion
function (rule) { return [rule.getOptions().ruleName, rule.getOptions().ruleSeverity]; }));
for (var _i = 0, fileFailures_1 = fileFailures; _i < fileFailures_1.length; _i++) {

@@ -215,3 +214,3 @@ var failure = fileFailures_1[_i];

};
Linter.VERSION = "5.5.0";
Linter.VERSION = "5.6.0";
Linter.findConfiguration = configuration_1.findConfiguration;

@@ -218,0 +217,0 @@ Linter.findConfigurationPath = configuration_1.findConfigurationPath;

@@ -134,2 +134,3 @@ "use strict";

case ts.SyntaxKind.NeverKeyword:
case ts.SyntaxKind.ThisType:
return true;

@@ -136,0 +137,0 @@ case ts.SyntaxKind.TypeReference:

@@ -67,3 +67,3 @@ "use strict";

}
if (isUnionType(type)) {
if (tsutils_1.isUnionOrIntersectionType(type)) {
return type.types.some(couldBePromise);

@@ -79,5 +79,2 @@ }

}
function isUnionType(type) {
return Lint.isTypeFlagSet(type, ts.TypeFlags.Union);
}
var _a;

@@ -59,3 +59,6 @@ "use strict";

var suggestion = renderSuggestion(member, node, ctx.sourceFile);
ctx.addFailureAtNode(member, Rule.FAILURE_STRING_FACTORY(node.kind === ts.SyntaxKind.TypeLiteral ? "Type literal" : "Interface", suggestion), Lint.Replacement.replaceNode(node, suggestion));
var fixStart = node.kind === ts.SyntaxKind.TypeLiteral
? node.getStart(ctx.sourceFile)
: tsutils_1.getChildOfKind(node, ts.SyntaxKind.InterfaceKeyword).getStart(ctx.sourceFile);
ctx.addFailureAtNode(member, Rule.FAILURE_STRING_FACTORY(node.kind === ts.SyntaxKind.TypeLiteral ? "Type literal" : "Interface", suggestion), Lint.Replacement.replaceFromTo(fixStart, node.end, suggestion));
}

@@ -62,0 +65,0 @@ }

@@ -1,17 +0,1 @@

/**
* @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";

@@ -18,0 +2,0 @@ import * as Lint from "../index";

@@ -20,2 +20,3 @@ "use strict";

var tslib_1 = require("tslib");
var tsutils_1 = require("tsutils");
var ts = require("typescript");

@@ -293,5 +294,24 @@ var Lint = require("../index");

CompletedDocsWalker.prototype.visitVariableDeclaration = function (node) {
this.checkNode(node, exports.ARGUMENT_VARIABLES);
this.checkVariable(node);
_super.prototype.visitVariableDeclaration.call(this, node);
};
CompletedDocsWalker.prototype.checkVariable = function (node) {
// Only check variables in variable declaration lists
// and not variables in catch clauses and for loops.
var list = node.parent;
if (!tsutils_1.isVariableDeclarationList(list)) {
return;
}
var statement = list.parent;
if (!tsutils_1.isVariableStatement(statement)) {
return;
}
// Only check variables at the namespace/module-level or file-level
// and not variables declared inside functions and other things.
switch (statement.parent.kind) {
case ts.SyntaxKind.SourceFile:
case ts.SyntaxKind.ModuleBlock:
this.checkNode(node, exports.ARGUMENT_VARIABLES, statement);
}
};
CompletedDocsWalker.prototype.checkNode = function (node, nodeType, requirementNode) {

@@ -298,0 +318,0 @@ if (requirementNode === void 0) { requirementNode = node; }

@@ -57,8 +57,8 @@ "use strict";

description: "Enforces a threshold of cyclomatic complexity.",
descriptionDetails: (_a = ["\n Cyclomatic complexity is assessed for each function of any type. A starting value of 20\n is assigned and this value is then incremented for every statement which can branch the\n control flow within the function. The following statements and expressions contribute\n to cyclomatic complexity:\n * `catch`\n * `if` and `? :`\n * `||` and `&&` due to short-circuit evaluation\n * `for`, `for in` and `for of` loops\n * `while` and `do while` loops"], _a.raw = ["\n Cyclomatic complexity is assessed for each function of any type. A starting value of 20\n is assigned and this value is then incremented for every statement which can branch the\n control flow within the function. The following statements and expressions contribute\n to cyclomatic complexity:\n * \\`catch\\`\n * \\`if\\` and \\`? :\\`\n * \\`||\\` and \\`&&\\` due to short-circuit evaluation\n * \\`for\\`, \\`for in\\` and \\`for of\\` loops\n * \\`while\\` and \\`do while\\` loops"], Lint.Utils.dedent(_a)),
descriptionDetails: (_a = ["\n Cyclomatic complexity is assessed for each function of any type. A starting value of 0\n is assigned and this value is then incremented for every statement which can branch the\n control flow within the function. The following statements and expressions contribute\n to cyclomatic complexity:\n * `catch`\n * `if` and `? :`\n * `||` and `&&` due to short-circuit evaluation\n * `for`, `for in` and `for of` loops\n * `while` and `do while` loops\n * `case` clauses that contain statements"], _a.raw = ["\n Cyclomatic complexity is assessed for each function of any type. A starting value of 0\n is assigned and this value is then incremented for every statement which can branch the\n control flow within the function. The following statements and expressions contribute\n to cyclomatic complexity:\n * \\`catch\\`\n * \\`if\\` and \\`? :\\`\n * \\`||\\` and \\`&&\\` due to short-circuit evaluation\n * \\`for\\`, \\`for in\\` and \\`for of\\` loops\n * \\`while\\` and \\`do while\\` loops\n * \\`case\\` clauses that contain statements"], Lint.Utils.dedent(_a)),
rationale: (_b = ["\n Cyclomatic complexity is a code metric which indicates the level of complexity in a\n function. High cyclomatic complexity indicates confusing code which may be prone to\n errors or difficult to modify."], _b.raw = ["\n Cyclomatic complexity is a code metric which indicates the level of complexity in a\n function. High cyclomatic complexity indicates confusing code which may be prone to\n errors or difficult to modify."], Lint.Utils.dedent(_b)),
optionsDescription: (_c = ["\n An optional upper limit for cyclomatic complexity can be specified. If no limit option\n is provided a default value of $(Rule.DEFAULT_THRESHOLD) will be used."], _c.raw = ["\n An optional upper limit for cyclomatic complexity can be specified. If no limit option\n is provided a default value of $(Rule.DEFAULT_THRESHOLD) will be used."], Lint.Utils.dedent(_c)),
optionsDescription: (_c = ["\n An optional upper limit for cyclomatic complexity can be specified. If no limit option\n is provided a default value of ", " will be used."], _c.raw = ["\n An optional upper limit for cyclomatic complexity can be specified. If no limit option\n is provided a default value of ", " will be used."], Lint.Utils.dedent(_c, Rule.DEFAULT_THRESHOLD)),
options: {
type: "number",
minimum: "$(Rule.MINIMUM_THRESHOLD)",
minimum: Rule.MINIMUM_THRESHOLD,
},

@@ -65,0 +65,0 @@ optionExamples: [true, [true, 20]],

@@ -32,5 +32,3 @@ "use strict";

// returns the text of the first comment or undefined
var commentText = ts.forEachLeadingCommentRange(text, offset, function (pos, end, kind) {
return text.substring(pos + 2, kind === ts.SyntaxKind.SingleLineCommentTrivia ? end : end - 2);
});
var commentText = ts.forEachLeadingCommentRange(text, offset, function (pos, end, kind) { return text.substring(pos + 2, kind === ts.SyntaxKind.SingleLineCommentTrivia ? end : end - 2); });
if (commentText === undefined || !new RegExp(this.ruleArguments[0]).test(commentText)) {

@@ -37,0 +35,0 @@ if (offset !== 0) {

@@ -72,2 +72,3 @@ "use strict";

typescriptOnly: true,
hasFix: true,
};

@@ -110,8 +111,8 @@ /* tslint:enable:object-literal-sort-keys */

}
var isPublic = Lint.hasModifier(node.modifiers, ts.SyntaxKind.PublicKeyword);
if (noPublic && isPublic) {
var publicKeyword = node.modifiers.find(function (m) { return m.kind === ts.SyntaxKind.PublicKeyword; });
ctx.addFailureAtNode(publicKeyword, Rule.FAILURE_STRING_NO_PUBLIC);
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)));
}
if (!noPublic && !isPublic) {
if (!noPublic && publicKeyword === undefined) {
var nameNode = node.kind === ts.SyntaxKind.Constructor

@@ -121,3 +122,3 @@ ? tsutils_1.getChildOfKind(node, ts.SyntaxKind.ConstructorKeyword, ctx.sourceFile)

var memberName = node.name !== undefined && node.name.kind === ts.SyntaxKind.Identifier ? node.name.text : undefined;
ctx.addFailureAtNode(nameNode, Rule.FAILURE_STRING_FACTORY(typeToString(node), memberName));
ctx.addFailureAtNode(nameNode, Rule.FAILURE_STRING_FACTORY(typeToString(node), memberName), Lint.Replacement.appendText(node.getStart(ctx.sourceFile), "public "));
}

@@ -124,0 +125,0 @@ }

@@ -59,3 +59,5 @@ "use strict";

var expression = node.expression;
if (tsutils_1.isCallExpression(expression) && !isPromiseCatchCall(expression)) {
if (tsutils_1.isCallExpression(expression) &&
!isPromiseCatchCall(expression) &&
!isPromiseThenCallWithRejectionHandler(expression)) {
var symbol = tc.getTypeAtLocation(expression).symbol;

@@ -73,2 +75,7 @@ if (symbol !== undefined && ctx.options.indexOf(symbol.name) !== -1) {

}
function isPromiseThenCallWithRejectionHandler(expression) {
return tsutils_1.isPropertyAccessExpression(expression.expression) &&
expression.expression.name.text === "then" &&
expression.arguments.length >= 2;
}
var _a;

@@ -77,3 +77,4 @@ "use strict";

var name = node.name, type = node.type, initializer = node.initializer;
if (type !== undefined && initializer !== undefined && typeIsInferrable(type.kind, initializer.kind)) {
if (type !== undefined && initializer !== undefined
&& typeIsInferrable(type.kind, initializer)) {
var fix = Lint.Replacement.deleteFromTo(name.end, type.end);

@@ -108,7 +109,7 @@ _this.addFailureAtNode(type, Rule.FAILURE_STRING_FACTORY(ts.tokenToString(type.kind)), fix);

case ts.SyntaxKind.BooleanKeyword:
return initializer === ts.SyntaxKind.TrueKeyword || initializer === ts.SyntaxKind.FalseKeyword;
return initializer.kind === ts.SyntaxKind.TrueKeyword || initializer.kind === ts.SyntaxKind.FalseKeyword;
case ts.SyntaxKind.NumberKeyword:
return initializer === ts.SyntaxKind.NumericLiteral;
return Lint.isNumeric(initializer);
case ts.SyntaxKind.StringKeyword:
switch (initializer) {
switch (initializer.kind) {
case ts.SyntaxKind.StringLiteral:

@@ -115,0 +116,0 @@ case ts.SyntaxKind.NoSubstitutionTemplateLiteral:

@@ -1,17 +0,1 @@

/**
* @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";

@@ -18,0 +2,0 @@ import * as Lint from "../index";

@@ -21,2 +21,3 @@ "use strict";

// with due reference to https://github.com/Microsoft/TypeScript/blob/7813121c4d77e50aad0eed3152ef1f1156c7b574/scripts/tslint/noNullRule.ts
var tsutils_1 = require("tsutils");
var ts = require("typescript");

@@ -42,2 +43,3 @@ var Lint = require("../index");

typescriptOnly: false,
hasFix: true,
};

@@ -52,11 +54,21 @@ /* tslint:enable:object-literal-sort-keys */

function cb(node) {
if (node.kind >= ts.SyntaxKind.FirstTypeNode && node.kind <= ts.SyntaxKind.LastTypeNode) {
if (tsutils_1.isTypeNodeKind(node.kind)) {
return; // skip type nodes
}
if (node.kind === ts.SyntaxKind.NullKeyword) {
return ctx.addFailureAtNode(node, Rule.FAILURE_STRING);
if (node.kind !== ts.SyntaxKind.NullKeyword) {
return ts.forEachChild(node, cb);
}
return ts.forEachChild(node, cb);
var parent = node.parent;
var eq;
if (tsutils_1.isBinaryExpression(parent)) {
eq = Lint.getEqualsKind(parent.operatorToken);
}
if (eq === undefined) {
ctx.addFailureAtNode(node, Rule.FAILURE_STRING);
}
else if (!eq.isStrict) {
ctx.addFailureAtNode(node, Rule.FAILURE_STRING, Lint.Replacement.replaceNode(node, "undefined", ctx.sourceFile));
}
}
}
var _a;

@@ -38,3 +38,3 @@ "use strict";

ruleName: "no-reference-import",
description: 'Don\'t <reference types="foo" /> if you import "foo" anyway.',
description: 'Don\'t `<reference types="foo" />` if you import `foo` anyway.',
optionsDescription: "Not configurable.",

@@ -41,0 +41,0 @@ options: null,

@@ -33,3 +33,3 @@ "use strict";

Rule.prototype.apply = function (sourceFile) {
return this.applyWithWalker(new NoShadowedVariableWalker(sourceFile, this.ruleName, undefined));
return this.applyWithWalker(new NoShadowedVariableWalker(sourceFile, this.ruleName, parseOptions(this.ruleArguments[0])));
};

@@ -41,5 +41,20 @@ /* tslint:disable:object-literal-sort-keys */

rationale: "Shadowing a variable masks access to it and obscures to what value an identifier actually refers.",
optionsDescription: "Not configurable.",
options: null,
optionExamples: [true],
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)),
options: {
type: "object",
properties: {
class: { type: "boolean" },
enum: { type: "boolean" },
function: { type: "boolean" },
import: { type: "boolean" },
interface: { type: "boolean" },
namespace: { type: "boolean" },
typeAlias: { type: "boolean" },
typeParameter: { type: "boolean" },
},
},
optionExamples: [
true,
[true, { class: true, enum: true, function: true, interface: false, namespace: true, typeAlias: false, typeParameter: false }],
],
type: "functionality",

@@ -51,2 +66,5 @@ typescriptOnly: false,

exports.Rule = Rule;
function parseOptions(option) {
return tslib_1.__assign({ class: true, enum: true, function: true, import: true, interface: true, namespace: true, typeAlias: true, typeParameter: true }, option);
}
var Scope = (function () {

@@ -84,4 +102,5 @@ function Scope(functionScope) {

var parentScope = _this.scope;
if (tsutils_1.isFunctionExpression(node) && node.name !== undefined) {
/* special handling for named function expressions:
if ((_this.options.function && tsutils_1.isFunctionExpression(node) || _this.options.class && tsutils_1.isClassExpression(node)) &&
node.name !== undefined) {
/* special handling for named function and class expressions:
technically the name of the function is only visible inside of it,

@@ -93,3 +112,8 @@ but variables with the same name declared inside don't cause compiler errors.

_this.scope = new Scope();
ts.forEachChild(node, cb);
if (tsutils_1.isClassExpression(node)) {
_this.visitClassLikeDeclaration(node, functionScope, cb);
}
else {
ts.forEachChild(node, cb);
}
_this.onScopeEnd(functionScope);

@@ -101,2 +125,13 @@ _this.scope = functionScope;

}
/* Visit decorators before entering a function scope.
In the AST decorators are children of the declaration they decorate, but we don't want to warn for the following code:
@decorator((param) => param)
function foo(param) {}
*/
if (node.decorators !== undefined) {
for (var _i = 0, _a = node.decorators; _i < _a.length; _i++) {
var decorator = _a[_i];
ts.forEachChild(decorator, cb);
}
}
var boundary = tsutils_1.isScopeBoundary(node);

@@ -110,26 +145,46 @@ if (boundary === 2 /* Block */) {

switch (node.kind) {
case ts.SyntaxKind.Decorator:
return; // handled above
case ts.SyntaxKind.VariableDeclarationList:
_this.handleVariableDeclarationList(node);
break;
case ts.SyntaxKind.ClassExpression:
if (node.name !== undefined) {
case ts.SyntaxKind.TypeParameter:
if (_this.options.typeParameter) {
_this.scope.addVariable(node.name);
}
break;
case ts.SyntaxKind.TypeParameter:
_this.scope.addVariable(node.name);
case ts.SyntaxKind.FunctionDeclaration:
if (_this.options.function && node.name !== undefined) {
parentScope.addVariable(node.name, false);
}
break;
case ts.SyntaxKind.FunctionDeclaration:
case ts.SyntaxKind.ClassDeclaration:
if (node.name !== undefined) {
parentScope.addVariable(node.name, node.kind !== ts.SyntaxKind.FunctionDeclaration);
if (_this.options.class && node.name !== undefined) {
parentScope.addVariable(node.name);
}
// falls through
case ts.SyntaxKind.ClassExpression:
_this.visitClassLikeDeclaration(node, parentScope, cb);
_this.onScopeEnd(parentScope);
_this.scope = parentScope;
return;
case ts.SyntaxKind.TypeAliasDeclaration:
if (_this.options.typeAlias) {
parentScope.addVariable(node.name);
}
break;
case ts.SyntaxKind.TypeAliasDeclaration:
case ts.SyntaxKind.EnumDeclaration:
if (_this.options.enum) {
parentScope.addVariable(node.name);
}
break;
case ts.SyntaxKind.InterfaceDeclaration:
parentScope.addVariable(node.name);
if (_this.options.interface) {
parentScope.addVariable(node.name);
}
break;
case ts.SyntaxKind.Parameter:
if (!tsutils_1.isThisParameter(node) && tsutils_1.isFunctionWithBody(node.parent)) {
if (node.parent.kind !== ts.SyntaxKind.IndexSignature &&
!tsutils_1.isThisParameter(node) &&
tsutils_1.isFunctionWithBody(node.parent)) {
_this.handleBindingName(node.name, false);

@@ -139,3 +194,4 @@ }

case ts.SyntaxKind.ModuleDeclaration:
if (node.parent.kind !== ts.SyntaxKind.ModuleDeclaration &&
if (_this.options.namespace &&
node.parent.kind !== ts.SyntaxKind.ModuleDeclaration &&
node.name.kind === ts.SyntaxKind.Identifier) {

@@ -146,3 +202,3 @@ parentScope.addVariable(node.name, false);

case ts.SyntaxKind.ImportClause:
if (node.name !== undefined) {
if (_this.options.import && node.name !== undefined) {
_this.scope.addVariable(node.name, false);

@@ -154,3 +210,5 @@ }

case ts.SyntaxKind.ImportEqualsDeclaration:
_this.scope.addVariable(node.name, false);
if (_this.options.import) {
_this.scope.addVariable(node.name, false);
}
}

@@ -169,2 +227,19 @@ if (boundary !== 0 /* None */) {

};
NoShadowedVariableWalker.prototype.visitClassLikeDeclaration = function (declaration, parentScope, cb) {
var _this = this;
var currentScope = this.scope;
ts.forEachChild(declaration, function (node) {
if (!tsutils_1.hasModifier(node.modifiers, ts.SyntaxKind.StaticKeyword)) {
return cb(node);
}
/* Don't treat static members as children of the class' scope. That avoid shadowed type parameter warnings on static members.
class C<T> {
static method<T>() {}
}
*/
_this.scope = parentScope;
cb(node);
_this.scope = currentScope;
});
};
NoShadowedVariableWalker.prototype.handleVariableDeclarationList = function (node) {

@@ -221,1 +296,2 @@ var blockScoped = tsutils_1.isBlockScopedVariableDeclarationList(node);

}
var _a;

@@ -81,3 +81,4 @@ "use strict";

var comments = ts.getLeadingCommentRanges(this.sourceFile.text, clause.end);
return comments !== undefined && comments.some(function (comment) { return commentText(comment, _this.sourceFile).trim() === "falls through"; });
return comments !== undefined &&
comments.some(function (comment) { return /^\s*falls through\b/i.test(_this.sourceFile.text.slice(comment.pos + 2, comment.end)); });
};

@@ -87,6 +88,2 @@ return NoSwitchCaseFallThroughWalker;

exports.NoSwitchCaseFallThroughWalker = NoSwitchCaseFallThroughWalker;
function commentText(_a, sourceFile) {
var pos = _a.pos, end = _a.end, kind = _a.kind;
return sourceFile.text.slice(pos + 2, kind === ts.SyntaxKind.MultiLineCommentTrivia ? end - 2 : end);
}
var _a;

@@ -75,3 +75,3 @@ "use strict";

optionsDescription: (_c = ["\n Two options may be provided on an object:\n\n * `", "` allows using destructuring to access members of `this` (e.g. `{ foo, bar } = this;`).\n * `", "` may be specified as a list of regular expressions to match allowed variable names."], _c.raw = ["\n Two options may be provided on an object:\n\n * \\`", "\\` allows using destructuring to access members of \\`this\\` (e.g. \\`{ foo, bar } = this;\\`).\n * \\`", "\\` may be specified as a list of regular expressions to match allowed variable names."], Lint.Utils.dedent(_c, ALLOW_THIS_DESTRUCTURING, ALLOWED_THIS_NAMES)),
rationale: "Assigning a variable to `this` instead of properly using arrow lambdas"
rationale: "Assigning a variable to `this` instead of properly using arrow lambdas "
+ "may be a symptom of pre-ES6 practices or not manging scope well.",

@@ -78,0 +78,0 @@ ruleName: "no-this-assignment",

@@ -97,3 +97,3 @@ "use strict";

var fromScope = getSymbolInScope(qualifier, accessedSymbol.flags, name.text);
return fromScope === undefined || fromScope === accessedSymbol;
return fromScope === undefined || Lint.Utils.arraysAreEqual(fromScope.declarations, accessedSymbol.declarations, function (a, b) { return a === b; });
}

@@ -100,0 +100,0 @@ function getSymbolInScope(node, flags, name) {

@@ -61,2 +61,3 @@ "use strict";

var _a = node, type = _a.type, initializer = _a.initializer;
// TODO handle destructuring
if (initializer !== undefined) {

@@ -180,2 +181,34 @@ return cb(initializer, /*anyOk*/ type !== undefined && type.kind === ts.SyntaxKind.AnyKeyword);

}
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;
}
case ts.SyntaxKind.PrefixUnaryExpression: {
var _o = node, operator = _o.operator, operand = _o.operand;
cb(operand, operator === ts.SyntaxKind.ExclamationToken); // allow falsyness check
check();
return;
}
case ts.SyntaxKind.ForStatement: {
var _p = node, initializer = _p.initializer, condition = _p.condition, incrementor = _p.incrementor, statement = _p.statement;
if (initializer !== undefined) {
cb(initializer);
}
if (condition !== undefined) {
cb(condition, true);
} // allow truthyness check
if (incrementor !== undefined) {
cb(incrementor);
}
return cb(statement);
}
case ts.SyntaxKind.DoStatement:
case ts.SyntaxKind.WhileStatement:
cb(node.statement);
return cb(node.expression, true);
default:

@@ -218,3 +251,5 @@ if (!(tsutils_1.isExpression(node) && check())) {

return cb(right);
case ts.SyntaxKind.CommaToken:// Allow `any, any`
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);

@@ -221,0 +256,0 @@ return cb(right, /*anyOk*/ true);

@@ -96,2 +96,3 @@ "use strict";

var checker = unusedCheckedProgram.getTypeChecker(); // Doesn't matter which program is used for this.
var declaration = program.getCompilerOptions().declaration;
// If all specifiers in an import are unused, we elide the entire import.

@@ -112,3 +113,3 @@ var importSpecifierFailures = new Map();

if (importName !== undefined) {
if (isImportUsed(importName, sourceFile, checker)) {
if (declaration && isImportUsed(importName, sourceFile, checker)) {
continue;

@@ -270,3 +271,5 @@ }

function getImplicitType(node, checker) {
if ((utils.isPropertyDeclaration(node) || utils.isVariableDeclaration(node)) && node.type === undefined) {
if ((utils.isPropertyDeclaration(node) || utils.isVariableDeclaration(node)) &&
node.type === undefined && node.name.kind === ts.SyntaxKind.Identifier ||
utils.isBindingElement(node) && node.name.kind === ts.SyntaxKind.Identifier) {
return checker.getTypeAtLocation(node);

@@ -273,0 +276,0 @@ }

@@ -1,17 +0,1 @@

/**
* @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";

@@ -18,0 +2,0 @@ import * as Lint from "../index";

@@ -20,2 +20,3 @@ "use strict";

var tslib_1 = require("tslib");
var tsutils_1 = require("tsutils");
var ts = require("typescript");

@@ -238,11 +239,4 @@ var Lint = require("../index");

OneLineWalker.prototype.handleClassLikeDeclaration = function (node) {
var lastNodeOfDeclaration = node.name;
var openBraceToken = Lint.childOfKind(node, ts.SyntaxKind.OpenBraceToken);
if (node.heritageClauses != null) {
lastNodeOfDeclaration = node.heritageClauses[node.heritageClauses.length - 1];
}
else if (node.typeParameters != null) {
lastNodeOfDeclaration = node.typeParameters[node.typeParameters.length - 1];
}
this.handleOpeningBrace(lastNodeOfDeclaration, openBraceToken);
this.handleOpeningBrace(tsutils_1.getPreviousToken(openBraceToken), openBraceToken);
};

@@ -249,0 +243,0 @@ OneLineWalker.prototype.handleIterationStatement = function (node) {

@@ -94,3 +94,3 @@ "use strict";

Walker.prototype.checkStatement = function (statement) {
if (!tsutils_1.isImportDeclaration(statement) ||
if (!(tsutils_1.isImportDeclaration(statement) || tsutils_1.isImportEqualsDeclaration(statement)) ||
/\r?\n\r?\n/.test(this.sourceFile.text.slice(statement.getFullStart(), statement.getStart(this.sourceFile)))) {

@@ -100,18 +100,7 @@ this.endBlock();

if (tsutils_1.isImportDeclaration(statement)) {
if (!tsutils_1.isStringLiteral(statement.moduleSpecifier)) {
// Ignore grammar error
return;
}
var source = this.options.importSourcesOrderTransform(removeQuotes(statement.moduleSpecifier.text));
var previousSource = this.currentImportsBlock.getLastImportSource();
this.currentImportsBlock.addImportDeclaration(this.sourceFile, statement, source);
if (previousSource !== null && compare(source, previousSource) === -1) {
this.lastFix = [];
this.addFailureAtNode(statement, Rule.IMPORT_SOURCES_UNORDERED, this.lastFix);
}
var importClause = statement.importClause;
if (importClause !== undefined && importClause.namedBindings !== undefined && tsutils_1.isNamedImports(importClause.namedBindings)) {
this.checkNamedImports(importClause.namedBindings);
}
this.checkImportDeclaration(statement);
}
else if (tsutils_1.isImportEqualsDeclaration(statement)) {
this.checkImportEqualsDeclaration(statement);
}
else if (tsutils_1.isModuleDeclaration(statement)) {

@@ -128,2 +117,35 @@ var body = moduleDeclarationBody(statement);

};
Walker.prototype.checkImportDeclaration = function (node) {
if (!tsutils_1.isStringLiteral(node.moduleSpecifier)) {
// Ignore grammar error
return;
}
var source = this.options.importSourcesOrderTransform(removeQuotes(node.moduleSpecifier.text));
this.checkSource(source, node);
var importClause = node.importClause;
if (importClause !== undefined && importClause.namedBindings !== undefined && tsutils_1.isNamedImports(importClause.namedBindings)) {
this.checkNamedImports(importClause.namedBindings);
}
};
Walker.prototype.checkImportEqualsDeclaration = function (node) {
// only allowed `import x = require('y');`
var moduleReference = node.moduleReference;
if (!tsutils_1.isExternalModuleReference(moduleReference)) {
return;
}
var expression = moduleReference.expression;
if (expression === undefined || !tsutils_1.isStringLiteral(expression)) {
return;
}
var source = this.options.importSourcesOrderTransform(removeQuotes(expression.text));
this.checkSource(source, node);
};
Walker.prototype.checkSource = function (source, node) {
var previousSource = this.currentImportsBlock.getLastImportSource();
this.currentImportsBlock.addImportDeclaration(this.sourceFile, node, source);
if (previousSource !== null && compare(source, previousSource) === -1) {
this.lastFix = [];
this.addFailureAtNode(node, Rule.IMPORT_SOURCES_UNORDERED, this.lastFix);
}
};
Walker.prototype.endBlock = function () {

@@ -130,0 +152,0 @@ if (this.lastFix !== undefined) {

@@ -23,2 +23,3 @@ "use strict";

var Lint = require("../index");
var OPTION_CHECK_ELSE_IF = "check-else-if";
var Rule = (function (_super) {

@@ -34,3 +35,5 @@ tslib_1.__extends(Rule, _super);

Rule.prototype.apply = function (sourceFile) {
return this.applyWithFunction(sourceFile, walk);
return this.applyWithFunction(sourceFile, walk, {
checkElseIf: this.ruleArguments.indexOf(OPTION_CHECK_ELSE_IF) !== -1,
});
};

@@ -42,5 +45,8 @@ /* tslint:disable:object-literal-sort-keys */

rationale: (_b = ["\n This reduces duplication and can eliminate an unnecessary variable declaration."], _b.raw = ["\n This reduces duplication and can eliminate an unnecessary variable declaration."], Lint.Utils.dedent(_b)),
optionsDescription: "Not configurable.",
options: null,
optionExamples: [true],
optionsDescription: "If `" + OPTION_CHECK_ELSE_IF + "` is specified, the rule also checks nested if-else-if statements.",
options: {
type: "string",
enum: [OPTION_CHECK_ELSE_IF],
},
optionExamples: [true, [true, OPTION_CHECK_ELSE_IF]],
type: "functionality",

@@ -53,8 +59,10 @@ typescriptOnly: false,

function walk(ctx) {
var sourceFile = ctx.sourceFile;
var sourceFile = ctx.sourceFile, checkElseIf = ctx.options.checkElseIf;
return ts.forEachChild(sourceFile, function cb(node) {
if (tsutils_1.isIfStatement(node)) {
var assigned = detect(node, sourceFile);
var assigned = detect(node, sourceFile, checkElseIf);
if (assigned !== undefined) {
ctx.addFailureAtNode(Lint.childOfKind(node, ts.SyntaxKind.IfKeyword), Rule.FAILURE_STRING(assigned.getText(sourceFile)));
ctx.addFailureAtNode(node.getChildAt(0, sourceFile), Rule.FAILURE_STRING(assigned.getText(sourceFile)));
}
if (assigned !== undefined || !checkElseIf) {
// Be careful not to fail again for the "else if"

@@ -72,8 +80,8 @@ ts.forEachChild(node.expression, cb);

}
function detect(_a, sourceFile) {
function detect(_a, sourceFile, elseIf) {
var thenStatement = _a.thenStatement, elseStatement = _a.elseStatement;
if (elseStatement === undefined) {
if (elseStatement === undefined || !elseIf && elseStatement.kind === ts.SyntaxKind.IfStatement) {
return undefined;
}
var elze = tsutils_1.isIfStatement(elseStatement) ? detect(elseStatement, sourceFile) : getAssigned(elseStatement, sourceFile);
var elze = tsutils_1.isIfStatement(elseStatement) ? detect(elseStatement, sourceFile, elseIf) : getAssigned(elseStatement, sourceFile);
if (elze === undefined) {

@@ -80,0 +88,0 @@ return undefined;

@@ -79,8 +79,6 @@ "use strict";

// check if iterator is used for something other than reading data from array
var elementAccess = node.parent;
var accessParent = elementAccess.parent;
return !utils.isElementAccessExpression(elementAccess)
|| utils_1.isAssignment(accessParent)
|| accessParent.kind === ts.SyntaxKind.DeleteExpression
|| !nodeEquals(arrayExpr, utils_1.unwrapParentheses(elementAccess.expression), sourceFile);
var parent = node.parent;
return !utils.isElementAccessExpression(parent)
|| utils.isReassignmentTarget(parent)
|| !nodeEquals(arrayExpr, utils_1.unwrapParentheses(parent.expression), sourceFile);
}

@@ -87,0 +85,0 @@ function nodeEquals(a, b, sourceFile) {

@@ -54,2 +54,3 @@ "use strict";

tsutils_1.isIdentifier(node.expression.expression) && node.expression.expression.text === "Object" &&
!ts.isFunctionLike(node.arguments[0]) &&
// Object.assign(...someArray) cannot be written as object spread

@@ -69,5 +70,6 @@ !node.arguments.some(tsutils_1.isSpreadElement)) {

var args = node.arguments;
var objectNeedsParens = node.parent.kind === ts.SyntaxKind.ArrowFunction;
var fix = [
Lint.Replacement.replaceFromTo(node.getStart(sourceFile), args[0].getStart(sourceFile), "{"),
new Lint.Replacement(node.end - 1, 1, "}"),
Lint.Replacement.replaceFromTo(node.getStart(sourceFile), args[0].getStart(sourceFile), (objectNeedsParens ? "(" : "") + "{"),
new Lint.Replacement(node.end - 1, 1, "}" + (objectNeedsParens ? ")" : "")),
];

@@ -74,0 +76,0 @@ for (var i = 0; i < args.length; ++i) {

@@ -106,3 +106,4 @@ "use strict";

case ts.SyntaxKind.FunctionDeclaration:
return options.named;
// 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:

@@ -109,0 +110,0 @@ return node.name !== undefined ? options.named : options.anonymous;

@@ -1,2 +0,2 @@

import { LintError } from "./test/lintError";
import { LintError } from "./verify/lintError";
export interface TestOutput {

@@ -3,0 +3,0 @@ skipped: false;

@@ -28,4 +28,4 @@ "use strict";

var Linter = require("./linter");
var parse = require("./test/parse");
var utils_1 = require("./utils");
var parse = require("./verify/parse");
var MARKUP_FILE_EXTENSION = ".lint";

@@ -32,0 +32,0 @@ var FIXES_FILE_EXTENSION = ".fix";

@@ -155,3 +155,3 @@ "use strict";

if (!(argv.init || argv.test !== undefined || argv.project !== undefined || commander.args.length > 0)) {
console.error("Missing files");
console.error("No files specified. Use --project to lint a project folder.");
process.exit(1);

@@ -158,0 +158,0 @@ }

@@ -49,7 +49,7 @@ /// <reference types="node" />

export declare type Equal<T> = (a: T, b: T) => boolean;
export declare function arraysAreEqual<T>(a: T[] | undefined, b: T[] | undefined, eq: Equal<T>): boolean;
export declare function arraysAreEqual<T>(a: ReadonlyArray<T> | undefined, b: ReadonlyArray<T> | undefined, eq: Equal<T>): boolean;
/** Returns the first non-`undefined` result. */
export declare function find<T, U>(inputs: T[], getResult: (t: T) => U | undefined): U | undefined;
/** Returns an array that is the concatenation of all output arrays. */
export declare function flatMap<T, U>(inputs: T[], getOutputs: (input: T, index: number) => U[]): U[];
export declare function flatMap<T, U>(inputs: ReadonlyArray<T>, getOutputs: (input: T, index: number) => ReadonlyArray<U>): U[];
/** Returns an array of all outputs that are not `undefined`. */

@@ -56,0 +56,0 @@ export declare function mapDefined<T, U>(inputs: T[], getOutput: (input: T) => U | undefined): U[];

@@ -75,5 +75,3 @@ "use strict";

}
var fullString = strings.reduce(function (accumulator, str, i) {
return "" + accumulator + values[i - 1] + str;
});
var fullString = strings.reduce(function (accumulator, str, i) { return "" + accumulator + values[i - 1] + str; });
// match all leading spaces/tabs at the start of each line

@@ -80,0 +78,0 @@ var match = fullString.match(/^[ \t]*(?=\S)/gm);

{
"name": "tslint",
"version": "5.5.0",
"version": "5.6.0",
"description": "An extensible static analysis linter for the TypeScript language",

@@ -31,2 +31,3 @@ "bin": {

"lint:from-bin": "node bin/tslint --project test/tsconfig.json --format stylish",
"publish:local": "./scripts/npmPublish.sh",
"test": "npm-run-all test:pre -p test:mocha test:rules",

@@ -49,3 +50,3 @@ "test:pre": "cd ./test/config && npm install --no-save",

"tslib": "^1.7.1",
"tsutils": "^2.5.1"
"tsutils": "^2.7.1"
},

@@ -76,5 +77,5 @@ "peerDependencies": {

"rimraf": "^2.5.4",
"tslint": "^5.4.2",
"tslint": "^5.5.0",
"tslint-test-config-non-relative": "file:test/external/tslint-test-config-non-relative",
"typescript": "2.1"
"typescript": "~2.4.1"
},

@@ -81,0 +82,0 @@ "license": "Apache-2.0",

@@ -18,3 +18,3 @@ [![NPM version](https://badge.fury.io/js/tslint.svg)](http://badge.fury.io/js/tslint)

- automatic fixing of formatting & style violations
- integration with [msbuild](https://github.com/joshuakgoldberg/tslint.msbuild), [grunt](https://github.com/palantir/grunt-tslint), [gulp](https://github.com/panuhorsmalahti/gulp-tslint), [atom](https://github.com/AtomLinter/linter-tslint), [eclipse](https://github.com/palantir/eclipse-tslint), [emacs](http://flycheck.org), [sublime](https://packagecontrol.io/packages/SublimeLinter-contrib-tslint), [vim](https://github.com/scrooloose/syntastic), [visual studio 2015](https://marketplace.visualstudio.com/items?itemName=MadsKristensen.WebAnalyzer), [visual studio 2017](https://marketplace.visualstudio.com/items?itemName=RichNewman.TypeScriptAnalyzer) [vscode](https://marketplace.visualstudio.com/items?itemName=eg2.tslint), [webstorm](https://www.jetbrains.com/webstorm/help/tslint.html), and more
- integration with [MSBuild](https://github.com/joshuakgoldberg/tslint.msbuild), [Grunt](https://github.com/palantir/grunt-tslint), [Gulp](https://github.com/panuhorsmalahti/gulp-tslint), [Atom](https://github.com/AtomLinter/linter-tslint), [Eclipse](https://github.com/palantir/eclipse-tslint), [Emacs](http://flycheck.org), [Sublime](https://packagecontrol.io/packages/SublimeLinter-contrib-tslint), [Vim](https://github.com/scrooloose/syntastic), [Visual Studio 2015](https://marketplace.visualstudio.com/items?itemName=MadsKristensen.WebAnalyzer), [Visual Studio 2017](https://marketplace.visualstudio.com/items?itemName=RichNewman.TypeScriptAnalyzer) [Visual Studio code](https://marketplace.visualstudio.com/items?itemName=eg2.tslint), [WebStorm](https://www.jetbrains.com/webstorm/help/tslint.html) and [more](https://palantir.github.io/tslint/usage/third-party-tools/)

@@ -72,5 +72,8 @@ Installation & Usage

2. Add release notes in `CHANGELOG.md`
3. `yarn verify` to build the latest sources from a clean state
- Use `./scripts/generate-changelog.js` (after building it with `tsc -p scripts`) to generate the changelog diff. This script expects a Github.com personal access token to exist at `~/github_token.txt` with "repo" permissions.
4. Commit with message `Prepare release <version>`
5. Run `npm publish`
6. Create a git tag for the new release and push it ([see existing tags here](https://github.com/palantir/tslint/tags))
5. Push your branch to GitHub and make a PR
6. Once your PR is merged, wait for the tests to pass on CircleCI for develop
7. Create a "Release" on GitHub with the proper tag version and notes from the changelog.
- The tag should be identical to the version in `package.json`
8. Run `yarn run publish:local`

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc