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.18.0 to 5.19.0

lib/rules/code-examples/noPromiseAsBoolean.examples.d.ts

4

lib/configs/all.d.ts

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

"no-empty-interface": boolean;
"no-for-in": boolean;
"no-import-side-effect": boolean;

@@ -94,2 +95,3 @@ "no-inferrable-types": {

"no-object-literal-type-assertion": boolean;
"no-promise-as-boolean": boolean;
"no-return-await": boolean;

@@ -117,2 +119,3 @@ "no-shadowed-variable": boolean;

"strict-boolean-expressions": boolean;
"strict-string-expressions": boolean;
"strict-comparisons": boolean;

@@ -130,2 +133,3 @@ "strict-type-predicates": boolean;

};
"invalid-void": boolean;
"linebreak-style": {

@@ -132,0 +136,0 @@ options: string;

11

lib/configs/all.js

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

var ruleLoader_1 = require("../ruleLoader");
var utils_1 = require("../utils");
// tslint:disable object-literal-sort-keys

@@ -53,2 +52,3 @@ // tslint:disable object-literal-key-quotes

"no-empty-interface": true,
"no-for-in": true,
"no-import-side-effect": true,

@@ -131,2 +131,3 @@ // Technically this is not the strictest setting, but don't want to conflict with "typedef"

"no-object-literal-type-assertion": true,
"no-promise-as-boolean": true,
"no-return-await": true,

@@ -153,2 +154,3 @@ "no-shadowed-variable": true,

"strict-boolean-expressions": true,
"strict-string-expressions": true,
"strict-comparisons": true,

@@ -165,2 +167,3 @@ "strict-type-predicates": true,

indent: { options: ["spaces"] },
"invalid-void": true,
"linebreak-style": { options: "LF" },

@@ -297,6 +300,4 @@ "max-classes-per-file": { options: 1 },

exports.jsRules = {};
for (var key in exports.rules) {
if (!utils_1.hasOwnProperty(exports.rules, key)) {
continue;
}
for (var _i = 0, _a = Object.keys(exports.rules); _i < _a.length; _i++) {
var key = _a[_i];
var Rule = ruleLoader_1.findRule(key, path_1.join(__dirname, "..", "rules"));

@@ -303,0 +304,0 @@ if (Rule === undefined) {

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

if (property !== undefined) {
for (var name in property) {
if (utils_1.hasOwnProperty(property, name)) {
combinedProperty[name] = property[name];
}
for (var _i = 0, _a = Object.keys(property); _i < _a.length; _i++) {
var name = _a[_i];
combinedProperty[name] = property[name];
}

@@ -435,6 +434,5 @@ }

if (config !== undefined) {
for (var ruleName in config) {
if (utils_1.hasOwnProperty(config, ruleName)) {
map.set(ruleName, parseRuleOptions(config[ruleName], defaultSeverity));
}
for (var _i = 0, _a = Object.keys(config); _i < _a.length; _i++) {
var ruleName = _a[_i];
map.set(ruleName, parseRuleOptions(config[ruleName], defaultSeverity));
}

@@ -441,0 +439,0 @@ }

@@ -19,3 +19,3 @@ /**

import { Fix, RuleFailure } from "../rule/rule";
export declare class WalkContext<T = void> {
export declare class WalkContext<T = undefined> {
readonly sourceFile: ts.SourceFile;

@@ -22,0 +22,0 @@ readonly ruleName: string;

@@ -25,3 +25,3 @@ /**

}
export declare abstract class AbstractWalker<T = void> extends WalkContext<T> implements IWalker {
export declare abstract class AbstractWalker<T = undefined> extends WalkContext<T> implements IWalker {
abstract walk(sourceFile: ts.SourceFile): void;

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

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

if (Formatter === undefined) {
throw new Error("formatter '" + formatterName + "' not found");
throw new Error("formatter '" + String(formatterName) + "' not found");
}

@@ -247,3 +247,3 @@ var formatter = new Formatter();

};
Linter.VERSION = "5.18.0";
Linter.VERSION = "5.19.0";
Linter.findConfiguration = configuration_1.findConfiguration;

@@ -250,0 +250,0 @@ Linter.findConfigurationPath = configuration_1.findConfigurationPath;

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

function isAsyncIterable(name) {
return name === "AsyncIterable" || name === "AsyncIterableIterator";
return (name === "AsyncIterable" || name === "AsyncIterableIterator" || name === "AsyncGenerator");
}
var templateObject_1, templateObject_2;

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

Object.defineProperty(exports, "__esModule", { value: true });
var utils_1 = require("../../utils");
var completedDocsRule_1 = require("../completedDocsRule");

@@ -38,6 +37,5 @@ var blockExclusion_1 = require("./blockExclusion");

}
for (var docType in descriptors) {
if (utils_1.hasOwnProperty(descriptors, docType)) {
exclusionsMap.set(docType, createRequirementsForDocType(docType, descriptors[docType]));
}
for (var _i = 0, _a = Object.keys(descriptors); _i < _a.length; _i++) {
var docType = _a[_i];
exclusionsMap.set(docType, createRequirementsForDocType(docType, descriptors[docType]));
}

@@ -44,0 +42,0 @@ };

@@ -20,4 +20,10 @@ "use strict";

var tslib_1 = require("tslib");
var _a, _b;
var tsutils_1 = require("tsutils");
var ts = require("typescript");
var Lint = require("../index");
var OPTION_LIMIT = "limit";
var OPTION_IGNORE_PATTERN = "ignore-pattern";
var OPTION_CHECK_STRINGS = "check-strings";
var OPTION_CHECK_REGEX = "check-regex";
var Rule = /** @class */ (function (_super) {

@@ -33,3 +39,3 @@ tslib_1.__extends(Rule, _super);

Rule.prototype.isEnabled = function () {
var limit = this.getRuleOptions().limit;
var limit = this.getRuleOptions()[OPTION_LIMIT];
return _super.prototype.isEnabled.call(this) && limit > 0;

@@ -42,14 +48,14 @@ };

var argument = this.ruleArguments[0];
var options = { limit: 0 };
if (typeof argument === "number") {
options.limit = argument;
return { limit: argument };
}
else {
options = argument;
var ignorePattern = argument["ignore-pattern"];
options.ignorePattern =
typeof ignorePattern === "string" ? new RegExp(ignorePattern) : undefined;
var _a = OPTION_CHECK_REGEX, checkRegex = argument[_a], _b = OPTION_CHECK_STRINGS, checkStrings = argument[_b], _c = OPTION_IGNORE_PATTERN, ignorePattern = argument[_c], _d = OPTION_LIMIT, limit = argument[_d];
return {
checkRegex: Boolean(checkRegex),
checkStrings: Boolean(checkStrings),
ignorePattern: typeof ignorePattern === "string" ? new RegExp(ignorePattern) : undefined,
limit: Number(limit),
};
}
options.limit = Number(options.limit); // user can pass a string instead of number
return options;
};

@@ -61,3 +67,3 @@ /* tslint:disable:object-literal-sort-keys */

rationale: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n Limiting the length of a line of code improves code readability.\n It also makes comparing code side-by-side easier and improves compatibility with\n various editors, IDEs, and diff viewers."], ["\n Limiting the length of a line of code improves code readability.\n It also makes comparing code side-by-side easier and improves compatibility with\n various editors, IDEs, and diff viewers."]))),
optionsDescription: Lint.Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n It can take one argument, which can be any of the following:\n * integer indicating maximum length of lines.\n * object with keys:\n * `limit` - number greater than 0 defining the max line length\n * `ignore-pattern` - string defining ignore pattern for this rule, being parsed by `new RegExp()`.\n For example:\n * `// ` pattern will ignore all in-line comments.\n * `^import ` pattern will ignore all import statements.\n * `^export {(.*?)}` pattern will ignore all multiple export statements.\n * `class [a-zA-Z]+ implements ` pattern will ignore all class declarations implementing interfaces.\n * `^import |^export {(.*?)}|class [a-zA-Z]+ implements |// ` pattern will ignore all the cases listed above.\n "], ["\n It can take one argument, which can be any of the following:\n * integer indicating maximum length of lines.\n * object with keys:\n * \\`limit\\` - number greater than 0 defining the max line length\n * \\`ignore-pattern\\` - string defining ignore pattern for this rule, being parsed by \\`new RegExp()\\`.\n For example:\n * \\`\\/\\/ \\` pattern will ignore all in-line comments.\n * \\`^import \\` pattern will ignore all import statements.\n * \\`^export \\{(.*?)\\}\\` pattern will ignore all multiple export statements.\n * \\`class [a-zA-Z]+ implements \\` pattern will ignore all class declarations implementing interfaces.\n * \\`^import |^export \\{(.*?)\\}|class [a-zA-Z]+ implements |// \\` pattern will ignore all the cases listed above.\n "]))),
optionsDescription: Lint.Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n It can take one argument, which can be any of the following:\n * integer indicating maximum length of lines.\n * object with keys:\n * `", "` - number greater than 0 defining the max line length\n * `", "` - string defining ignore pattern for this rule, being parsed by `new RegExp()`.\n For example:\n * `// ` pattern will ignore all in-line comments.\n * `^import ` pattern will ignore all import statements.\n * `^export {(.*?)}` pattern will ignore all multiple export statements.\n * `class [a-zA-Z]+ implements ` pattern will ignore all class declarations implementing interfaces.\n * `^import |^export {(.*?)}|class [a-zA-Z]+ implements |// ` pattern will ignore all the cases listed above.\n * `", "` - determines if strings should be checked, `false` by default.\n * `", "` - determines if regular expressions should be checked, `false` by default.\n "], ["\n It can take one argument, which can be any of the following:\n * integer indicating maximum length of lines.\n * object with keys:\n * \\`", "\\` - number greater than 0 defining the max line length\n * \\`", "\\` - string defining ignore pattern for this rule, being parsed by \\`new RegExp()\\`.\n For example:\n * \\`\\/\\/ \\` pattern will ignore all in-line comments.\n * \\`^import \\` pattern will ignore all import statements.\n * \\`^export \\{(.*?)\\}\\` pattern will ignore all multiple export statements.\n * \\`class [a-zA-Z]+ implements \\` pattern will ignore all class declarations implementing interfaces.\n * \\`^import |^export \\{(.*?)\\}|class [a-zA-Z]+ implements |// \\` pattern will ignore all the cases listed above.\n * \\`", "\\` - determines if strings should be checked, \\`false\\` by default.\n * \\`", "\\` - determines if regular expressions should be checked, \\`false\\` by default.\n "])), OPTION_LIMIT, OPTION_IGNORE_PATTERN, OPTION_CHECK_STRINGS, OPTION_CHECK_REGEX),
options: {

@@ -72,6 +78,8 @@ type: "array",

type: "object",
properties: {
limit: { type: "number" },
"ignore-pattern": { type: "string" },
},
properties: (_a = {},
_a[OPTION_LIMIT] = { type: "number" },
_a[OPTION_IGNORE_PATTERN] = { type: "string" },
_a[OPTION_CHECK_STRINGS] = { type: "boolean" },
_a[OPTION_CHECK_REGEX] = { type: "boolean" },
_a),
additionalProperties: false,

@@ -88,6 +96,8 @@ },

true,
{
limit: 120,
"ignore-pattern": "^import |^export {(.*?)}",
},
(_b = {},
_b[OPTION_LIMIT] = 120,
_b[OPTION_IGNORE_PATTERN] = "^import |^export {(.*?)}",
_b[OPTION_CHECK_STRINGS] = true,
_b[OPTION_CHECK_REGEX] = true,
_b),
],

@@ -103,15 +113,50 @@ ],

var limit = ctx.options.limit;
var ignorePattern = ctx.options.ignorePattern;
for (var _i = 0, _a = tsutils_1.getLineRanges(ctx.sourceFile); _i < _a.length; _i++) {
var line = _a[_i];
if (line.contentLength <= limit) {
continue;
tsutils_1.getLineRanges(ctx.sourceFile)
.filter(function (line) {
return line.contentLength > limit && !shouldIgnoreLine(line, ctx);
})
.forEach(function (_a) {
var pos = _a.pos, contentLength = _a.contentLength;
return ctx.addFailureAt(pos, contentLength, Rule.FAILURE_STRING_FACTORY(limit));
});
return;
}
function shouldIgnoreLine(_a, _b) {
var pos = _a.pos, contentLength = _a.contentLength;
var options = _b.options, sourceFile = _b.sourceFile;
var checkRegex = options.checkRegex, checkStrings = options.checkStrings, ignorePattern = options.ignorePattern, limit = options.limit;
var shouldOmitLine = false;
if (ignorePattern !== undefined) {
shouldOmitLine =
shouldOmitLine || ignorePattern.test(sourceFile.text.substr(pos, contentLength));
}
if (!checkStrings) {
var nodeAtLimit = tsutils_1.getTokenAtPosition(sourceFile, pos + limit);
if (nodeAtLimit !== undefined) {
shouldOmitLine =
shouldOmitLine ||
nodeAtLimit.kind === ts.SyntaxKind.StringLiteral ||
nodeAtLimit.kind === ts.SyntaxKind.NoSubstitutionTemplateLiteral ||
hasParentMatchingTypes(nodeAtLimit, sourceFile, [ts.SyntaxKind.TemplateExpression]);
}
var lineContent = ctx.sourceFile.text.substr(line.pos, line.contentLength);
if (ignorePattern !== undefined && ignorePattern.test(lineContent)) {
continue;
}
if (!checkRegex) {
var nodeAtLimit = tsutils_1.getTokenAtPosition(sourceFile, pos + limit);
if (nodeAtLimit !== undefined) {
shouldOmitLine =
shouldOmitLine || nodeAtLimit.kind === ts.SyntaxKind.RegularExpressionLiteral;
}
ctx.addFailureAt(line.pos, line.contentLength, Rule.FAILURE_STRING_FACTORY(limit));
}
return shouldOmitLine;
}
function hasParentMatchingTypes(node, root, parentTypes) {
var nodeReference = node;
while (nodeReference !== root) {
if (parentTypes.indexOf(nodeReference.kind) >= 0) {
return true;
}
nodeReference = nodeReference.parent;
}
return false;
}
var templateObject_1, templateObject_2;

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

var start = node.getStart(ctx.sourceFile);
var addParens = needsParens(node);
var addParens = tsutils_1.isBinaryExpression(node.parent);
var replaceText = " as " + node.type.getText(ctx.sourceFile) + (addParens ? ")" : "");

@@ -69,8 +69,2 @@ while (tsutils_1.isTypeAssertion(expression)) {

}
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 templateObject_1;

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

if (node.body === undefined) {
reportFailureIfAsyncFunction(node);
if (node.type === undefined) {
reportFailureIfAsyncFunction(node);
}
return;

@@ -62,0 +64,0 @@ }

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

function addDependencies(result, dependencies) {
for (var name in dependencies) {
if (dependencies.hasOwnProperty(name)) {
result.add(name);
}
for (var _i = 0, _a = Object.keys(dependencies); _i < _a.length; _i++) {
var name = _a[_i];
result.add(name);
}

@@ -141,0 +140,0 @@ }

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

var objectLiteralSortKeys_examples_1 = require("./code-examples/objectLiteralSortKeys.examples");
var OPTION_IGNORE_BLANK_LINES = "ignore-blank-lines";
var OPTION_IGNORE_CASE = "ignore-case";

@@ -67,8 +68,9 @@ var OPTION_LOCALE_COMPARE = "locale-compare";

ruleName: "object-literal-sort-keys",
description: Lint.Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\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 "], ["\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 "]))),
description: Lint.Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\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 To opt out of this use ", " option.\n "], ["\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 To opt out of this use ", " option.\n "])), OPTION_IGNORE_BLANK_LINES),
rationale: "Useful in preventing merge conflicts",
optionsDescription: Lint.Utils.dedent(templateObject_3 || (templateObject_3 = tslib_1.__makeTemplateObject(["\n By default, this rule checks that keys are in alphabetical order.\n The following may optionally be passed:\n\n * `", "` will compare keys in a case insensitive way.\n * `", "` will compare keys using the expected sort order of special characters, such as accents.\n * `", "` will prefer to use the key ordering of the contextual type of the object literal, as in:\n\n ```\n interface I { foo: number; bar: number; }\n const obj: I = { foo: 1, bar: 2 };\n ```\n\n If a contextual type is not found, alphabetical ordering will be used instead.\n * \"", "\" exactly like \"", "\",\n but don't fall back to alphabetical if a contextual type is not found.\n\n Note: If both ", " and ", " options are present,\n ", " will take precedence and alphabetical fallback will not occur.\n\n * `", "` will enforce shorthand properties to appear first, as in:\n\n ```\n const obj = { a, c, b: true };\n ```\n "], ["\n By default, this rule checks that keys are in alphabetical order.\n The following may optionally be passed:\n\n * \\`", "\\` will compare keys in a case insensitive way.\n * \\`", "\\` will compare keys using the expected sort order of special characters, such as accents.\n * \\`", "\\` will prefer to use the key ordering of the contextual type of the object literal, as in:\n\n \\`\\`\\`\n interface I { foo: number; bar: number; }\n const obj: I = { foo: 1, bar: 2 };\n \\`\\`\\`\n\n If a contextual type is not found, alphabetical ordering will be used instead.\n * \"", "\" exactly like \"", "\",\n but don't fall back to alphabetical if a contextual type is not found.\n\n Note: If both ", " and ", " options are present,\n ", " will take precedence and alphabetical fallback will not occur.\n\n * \\`", "\\` will enforce shorthand properties to appear first, as in:\n\n \\`\\`\\`\n const obj = { a, c, b: true };\n \\`\\`\\`\n "])), OPTION_IGNORE_CASE, OPTION_LOCALE_COMPARE, OPTION_MATCH_DECLARATION_ORDER, OPTION_MATCH_DECLARATION_ORDER_ONLY, OPTION_MATCH_DECLARATION_ORDER, OPTION_MATCH_DECLARATION_ORDER_ONLY, OPTION_MATCH_DECLARATION_ORDER, OPTION_MATCH_DECLARATION_ORDER_ONLY, OPTION_SHORTHAND_FIRST),
optionsDescription: Lint.Utils.dedent(templateObject_3 || (templateObject_3 = tslib_1.__makeTemplateObject(["\n By default, this rule checks that keys are in alphabetical order.\n The following may optionally be passed:\n\n * `", "` will enforce alphabetical ordering regardless of blank lines between each key-value pair.\n * `", "` will compare keys in a case insensitive way.\n * `", "` will compare keys using the expected sort order of special characters, such as accents.\n * `", "` will prefer to use the key ordering of the contextual type of the object literal, as in:\n\n ```\n interface I { foo: number; bar: number; }\n const obj: I = { foo: 1, bar: 2 };\n ```\n\n If a contextual type is not found, alphabetical ordering will be used instead.\n * \"", "\" exactly like \"", "\",\n but don't fall back to alphabetical if a contextual type is not found.\n\n Note: If both ", " and ", " options are present,\n ", " will take precedence and alphabetical fallback will not occur.\n\n * `", "` will enforce shorthand properties to appear first, as in:\n\n ```\n const obj = { a, c, b: true };\n ```\n "], ["\n By default, this rule checks that keys are in alphabetical order.\n The following may optionally be passed:\n\n * \\`", "\\` will enforce alphabetical ordering regardless of blank lines between each key-value pair.\n * \\`", "\\` will compare keys in a case insensitive way.\n * \\`", "\\` will compare keys using the expected sort order of special characters, such as accents.\n * \\`", "\\` will prefer to use the key ordering of the contextual type of the object literal, as in:\n\n \\`\\`\\`\n interface I { foo: number; bar: number; }\n const obj: I = { foo: 1, bar: 2 };\n \\`\\`\\`\n\n If a contextual type is not found, alphabetical ordering will be used instead.\n * \"", "\" exactly like \"", "\",\n but don't fall back to alphabetical if a contextual type is not found.\n\n Note: If both ", " and ", " options are present,\n ", " will take precedence and alphabetical fallback will not occur.\n\n * \\`", "\\` will enforce shorthand properties to appear first, as in:\n\n \\`\\`\\`\n const obj = { a, c, b: true };\n \\`\\`\\`\n "])), OPTION_IGNORE_BLANK_LINES, OPTION_IGNORE_CASE, OPTION_LOCALE_COMPARE, OPTION_MATCH_DECLARATION_ORDER, OPTION_MATCH_DECLARATION_ORDER_ONLY, OPTION_MATCH_DECLARATION_ORDER, OPTION_MATCH_DECLARATION_ORDER_ONLY, OPTION_MATCH_DECLARATION_ORDER, OPTION_MATCH_DECLARATION_ORDER_ONLY, OPTION_SHORTHAND_FIRST),
options: {
type: "string",
enum: [
OPTION_IGNORE_BLANK_LINES,
OPTION_IGNORE_CASE,

@@ -85,2 +87,3 @@ OPTION_LOCALE_COMPARE,

true,
OPTION_IGNORE_BLANK_LINES,
OPTION_IGNORE_CASE,

@@ -101,2 +104,3 @@ OPTION_LOCALE_COMPARE,

return {
ignoreBlankLines: has(OPTION_IGNORE_BLANK_LINES),
ignoreCase: has(OPTION_IGNORE_CASE),

@@ -113,3 +117,3 @@ localeCompare: has(OPTION_LOCALE_COMPARE),

function walk(ctx, checker) {
var sourceFile = ctx.sourceFile, _a = ctx.options, ignoreCase = _a.ignoreCase, localeCompare = _a.localeCompare, matchDeclarationOrder = _a.matchDeclarationOrder, matchDeclarationOrderOnly = _a.matchDeclarationOrderOnly, shorthandFirst = _a.shorthandFirst;
var sourceFile = ctx.sourceFile, _a = ctx.options, ignoreBlankLines = _a.ignoreBlankLines, ignoreCase = _a.ignoreCase, localeCompare = _a.localeCompare, matchDeclarationOrder = _a.matchDeclarationOrder, matchDeclarationOrderOnly = _a.matchDeclarationOrderOnly, shorthandFirst = _a.shorthandFirst;
ts.forEachChild(sourceFile, function cb(node) {

@@ -180,2 +184,6 @@ if (tsutils_1.isObjectLiteralExpression(node) && node.properties.length > 1) {

: lastKey > key;
if (keyOrderDescending && ignoreBlankLines) {
ctx.addFailureAtNode(property.name, Rule.FAILURE_STRING_ALPHABETICAL(property.name.text));
return;
}
if (keyOrderDescending && !hasBlankLineBefore(ctx.sourceFile, property)) {

@@ -182,0 +190,0 @@ ctx.addFailureAtNode(property.name, Rule.FAILURE_STRING_ALPHABETICAL(property.name.text));

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

var _a;
var tsutils_1 = require("tsutils");
var tsutils = require("tsutils");
var ts = require("typescript");

@@ -87,18 +87,7 @@ var Lint = require("../index");

return ts.forEachChild(sourceFile, function cb(node) {
if (options.has(node.kind)) {
var declaration = node;
switch (node.kind) {
case ts.SyntaxKind.MethodDeclaration:
case ts.SyntaxKind.FunctionDeclaration:
if (declaration.body === undefined) {
break;
}
// falls through
case ts.SyntaxKind.FunctionExpression:
case ts.SyntaxKind.ArrowFunction:
if (!tsutils_1.hasModifier(node.modifiers, ts.SyntaxKind.AsyncKeyword) &&
returnsPromise(declaration, tc) &&
!tsutils_1.isCallExpression(declaration.body)) {
ctx.addFailure(node.getStart(sourceFile), node.body.pos, Rule.FAILURE_STRING);
}
if (options.has(node.kind) && isFunctionLikeWithBody(node)) {
if (!tsutils.hasModifier(node.modifiers, ts.SyntaxKind.AsyncKeyword) &&
!isCallExpressionBody(node.body) &&
returnsPromise(node, tc)) {
ctx.addFailure(node.getStart(sourceFile), node.body.pos, Rule.FAILURE_STRING);
}

@@ -109,2 +98,18 @@ }

}
function isFunctionLikeWithBody(node) {
switch (node.kind) {
case ts.SyntaxKind.MethodDeclaration:
case ts.SyntaxKind.FunctionDeclaration:
case ts.SyntaxKind.FunctionExpression:
case ts.SyntaxKind.ArrowFunction:
return node.body !== undefined;
}
return false;
}
function isCallExpressionBody(body) {
while (tsutils.isParenthesizedExpression(body)) {
body = body.expression;
}
return tsutils.isCallExpression(body);
}
function returnsPromise(node, tc) {

@@ -111,0 +116,0 @@ var type = tc.getReturnTypeOfSignature(tc.getTypeAtLocation(node).getCallSignatures()[0]);

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

/* tslint:enable:object-literal-sort-keys */
Rule.INVALID_TYPES_ERROR = "Operands of '+' operation must either be both strings or both numbers";
Rule.INVALID_TYPES_ERROR = "Operands of '+' operation must either be both strings or both numbers or both bigints";
Rule.SUGGEST_TEMPLATE_LITERALS = ". Consider using template literals.";

@@ -89,2 +89,6 @@ return Rule;

}
else if (tsutils_1.isTypeFlagSet(type, ts.TypeFlags.BigIntLiteral) ||
tsutils_1.isTypeFlagSet(type, ts.TypeFlags.BigInt)) {
return "bigint";
}
else if (tsutils_1.isUnionType(type) && !tsutils_1.isTypeFlagSet(type, ts.TypeFlags.Enum)) {

@@ -91,0 +95,0 @@ var types = type.types.map(getBaseTypeOfLiteralType);

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

function check(node) {
var actualReturnKind = returnKindFromReturn(node);
var actualReturnKind = getReturnKindFromReturnStatement(node);
if (actualReturnKind === undefined) {

@@ -66,5 +66,5 @@ return;

}
var returnKindFromType = getReturnKind(functionReturningFrom, checker);
var returnKindFromType = getReturnKindFromFunction(functionReturningFrom, checker);
if (returnKindFromType !== undefined && returnKindFromType !== actualReturnKind) {
ctx.addFailureAtNode(node, returnKindFromType === ReturnKind.Void
ctx.addFailureAtNode(node, returnKindFromType === "void" /* Void */
? Rule.FAILURE_STRING_VOID_RETURN

@@ -75,8 +75,8 @@ : Rule.FAILURE_STRING_VALUE_RETURN);

}
function returnKindFromReturn(node) {
function getReturnKindFromReturnStatement(node) {
if (node.expression === undefined) {
return ReturnKind.Void;
return "void" /* Void */;
}
else if (tsutils_1.isIdentifier(node.expression) && node.expression.text === "undefined") {
return ReturnKind.Value;
return "value" /* Value */;
}

@@ -87,18 +87,13 @@ else {

}
var ReturnKind;
(function (ReturnKind) {
ReturnKind[ReturnKind["Void"] = 0] = "Void";
ReturnKind[ReturnKind["Value"] = 1] = "Value";
})(ReturnKind || (ReturnKind = {}));
function getReturnKind(node, checker) {
function getReturnKindFromFunction(node, checker) {
switch (node.kind) {
case ts.SyntaxKind.Constructor:
case ts.SyntaxKind.SetAccessor:
return ReturnKind.Void;
return "void" /* Void */;
case ts.SyntaxKind.GetAccessor:
return ReturnKind.Value;
return "value" /* Value */;
}
// Handle generator functions/methods:
if (node.asteriskToken !== undefined) {
return ReturnKind.Void;
return "void" /* Void */;
}

@@ -114,8 +109,9 @@ var contextual = isFunctionExpressionLike(node) && node.type === undefined

}
if ((tsutils_1.hasModifier(node.modifiers, ts.SyntaxKind.AsyncKeyword)
var effectivelyVoidChecker = tsutils_1.hasModifier(node.modifiers, ts.SyntaxKind.AsyncKeyword)
? isEffectivelyVoidPromise
: isEffectivelyVoid)(returnType)) {
return ReturnKind.Void;
: isEffectivelyVoid;
if (effectivelyVoidChecker(returnType)) {
return "void" /* Void */;
}
return ReturnKind.Value;
return "value" /* Value */;
}

@@ -122,0 +118,0 @@ /** True for `void`, `undefined`, Promise<void>, or `void | undefined | Promise<void>`. */

@@ -102,4 +102,9 @@ "use strict";

if (tsutils_1.isBinaryExpression(node) && isComparisonOperator(node)) {
var isEquality = isEqualityOperator(node);
var leftType = checker.getTypeAtLocation(node.left);
var rightType = checker.getTypeAtLocation(node.right);
if ((containsNullOrUndefined(leftType) || containsNullOrUndefined(rightType)) &&
isEquality) {
return;
}
var leftKinds = getTypes(leftType);

@@ -114,3 +119,2 @@ var rightKinds = getTypes(rightType);

var failureString = Rule.INVALID_TYPE_FOR_OPERATOR(operandKind, node.operatorToken.getText());
var isEquality = isEqualityOperator(node);
if (isEquality) {

@@ -158,2 +162,6 @@ // Check !=, ==, !==, ===

}
function containsNullOrUndefined(type) {
return (type.intrinsicName === "null" ||
type.intrinsicName === "undefined");
}
function getTypes(types) {

@@ -160,0 +168,0 @@ // Compatibility for TypeScript pre-2.4, which used EnumLiteralType instead of LiteralType

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

var OPTION_VARIABLE_DECLARATION = "variable-declaration";
var OPTION_VARIABLE_DECLARATION_IGNORE_FUNCTION = "variable-declaration-ignore-function";
var OPTION_MEMBER_VARIABLE_DECLARATION = "member-variable-declaration";

@@ -55,3 +56,3 @@ var OPTION_OBJECT_DESTRUCTURING = "object-destructuring";

description: "Requires type definitions to exist.",
optionsDescription: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n Several arguments may be optionally provided:\n\n * `\"", "\"` checks return type of functions.\n * `\"", "\"` checks return type of arrow functions.\n * `\"", "\"` checks type specifier of function parameters for non-arrow functions.\n * `\"", "\"` checks type specifier of function parameters for arrow functions.\n * `\"", "\"` checks return types of interface properties.\n * `\"", "\"` checks non-binding variable declarations.\n * `\"", "\"` checks member variable declarations.\n * `\"", "\"` checks object destructuring declarations.\n * `\"", "\"` checks array destructuring declarations."], ["\n Several arguments may be optionally provided:\n\n * \\`\"", "\"\\` checks return type of functions.\n * \\`\"", "\"\\` checks return type of arrow functions.\n * \\`\"", "\"\\` checks type specifier of function parameters for non-arrow functions.\n * \\`\"", "\"\\` checks type specifier of function parameters for arrow functions.\n * \\`\"", "\"\\` checks return types of interface properties.\n * \\`\"", "\"\\` checks non-binding variable declarations.\n * \\`\"", "\"\\` checks member variable declarations.\n * \\`\"", "\"\\` checks object destructuring declarations.\n * \\`\"", "\"\\` checks array destructuring declarations."])), OPTION_CALL_SIGNATURE, OPTION_ARROW_CALL_SIGNATURE, OPTION_PARAMETER, OPTION_ARROW_PARAMETER, OPTION_PROPERTY_DECLARATION, OPTION_VARIABLE_DECLARATION, OPTION_MEMBER_VARIABLE_DECLARATION, OPTION_OBJECT_DESTRUCTURING, OPTION_ARRAY_DESTRUCTURING),
optionsDescription: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n Several arguments may be optionally provided:\n\n * `\"", "\"` checks return type of functions.\n * `\"", "\"` checks return type of arrow functions.\n * `\"", "\"` checks type specifier of function parameters for non-arrow functions.\n * `\"", "\"` checks type specifier of function parameters for arrow functions.\n * `\"", "\"` checks return types of interface properties.\n * `\"", "\"` checks non-binding variable declarations.\n * `\"", "\"` ignore variable declarations for non-arrow and arrow functions.\n * `\"", "\"` checks member variable declarations.\n * `\"", "\"` checks object destructuring declarations.\n * `\"", "\"` checks array destructuring declarations."], ["\n Several arguments may be optionally provided:\n\n * \\`\"", "\"\\` checks return type of functions.\n * \\`\"", "\"\\` checks return type of arrow functions.\n * \\`\"", "\"\\` checks type specifier of function parameters for non-arrow functions.\n * \\`\"", "\"\\` checks type specifier of function parameters for arrow functions.\n * \\`\"", "\"\\` checks return types of interface properties.\n * \\`\"", "\"\\` checks non-binding variable declarations.\n * \\`\"", "\"\\` ignore variable declarations for non-arrow and arrow functions.\n * \\`\"", "\"\\` checks member variable declarations.\n * \\`\"", "\"\\` checks object destructuring declarations.\n * \\`\"", "\"\\` checks array destructuring declarations."])), OPTION_CALL_SIGNATURE, OPTION_ARROW_CALL_SIGNATURE, OPTION_PARAMETER, OPTION_ARROW_PARAMETER, OPTION_PROPERTY_DECLARATION, OPTION_VARIABLE_DECLARATION, OPTION_VARIABLE_DECLARATION_IGNORE_FUNCTION, OPTION_MEMBER_VARIABLE_DECLARATION, OPTION_OBJECT_DESTRUCTURING, OPTION_ARRAY_DESTRUCTURING),
options: {

@@ -68,2 +69,3 @@ type: "array",

OPTION_VARIABLE_DECLARATION,
OPTION_VARIABLE_DECLARATION_IGNORE_FUNCTION,
OPTION_MEMBER_VARIABLE_DECLARATION,

@@ -75,3 +77,3 @@ OPTION_OBJECT_DESTRUCTURING,

minLength: 0,
maxLength: 7,
maxLength: 10,
},

@@ -133,4 +135,4 @@ optionExamples: [

};
TypedefWalker.prototype.checkParameter = function (_a) {
var parent = _a.parent, name = _a.name, type = _a.type;
TypedefWalker.prototype.checkParameter = function (node) {
var _a = node, parent = _a.parent, name = _a.name, type = _a.type;
var isArrowFunction = parent.kind === ts.SyntaxKind.ArrowFunction;

@@ -160,7 +162,12 @@ var option = (function () {

if (initializer === undefined || initializer.kind !== ts.SyntaxKind.ArrowFunction) {
if (this.options[OPTION_VARIABLE_DECLARATION_IGNORE_FUNCTION] === true &&
initializer !== undefined &&
initializer.kind === ts.SyntaxKind.FunctionExpression) {
return;
}
this.checkTypeAnnotation("member-variable-declaration", name, type, name);
}
};
TypedefWalker.prototype.checkVariableDeclaration = function (_a) {
var parent = _a.parent, name = _a.name, type = _a.type;
TypedefWalker.prototype.checkVariableDeclaration = function (node) {
var _a = node, parent = _a.parent, name = _a.name, type = _a.type;
// variable declarations should always have a grandparent, but check that to be on the safe side.

@@ -174,14 +181,24 @@ // catch statements will be the parent of the variable declaration

}
var option = (function () {
switch (name.kind) {
case ts.SyntaxKind.ObjectBindingPattern:
return "object-destructuring";
case ts.SyntaxKind.ArrayBindingPattern:
return "array-destructuring";
default:
return "variable-declaration";
}
})();
var option;
switch (name.kind) {
case ts.SyntaxKind.ObjectBindingPattern:
option = OPTION_OBJECT_DESTRUCTURING;
break;
case ts.SyntaxKind.ArrayBindingPattern:
option = OPTION_ARRAY_DESTRUCTURING;
break;
default:
option = OPTION_VARIABLE_DECLARATION;
}
if (this.shouldIgnoreVariableDeclaration(node)) {
return;
}
this.checkTypeAnnotation(option, name, type, name);
};
TypedefWalker.prototype.shouldIgnoreVariableDeclaration = function (node) {
var ignoreFunctions = this.options[OPTION_VARIABLE_DECLARATION_IGNORE_FUNCTION] === true;
return (ignoreFunctions &&
(utils.getChildOfKind(node, ts.SyntaxKind.ArrowFunction) !== undefined ||
utils.getChildOfKind(node, ts.SyntaxKind.FunctionExpression) !== undefined));
};
TypedefWalker.prototype.checkTypeAnnotation = function (option, location, typeAnnotation, name) {

@@ -188,0 +205,0 @@ if (this.options[option] === true && typeAnnotation === undefined) {

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

@@ -5,0 +5,0 @@ "bin": {

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

:warning: __TSLint will be deprecated some time in 2019__. See this issue for more details: [Roadmap: TSLint &rarr; ESLint](https://github.com/palantir/tslint/issues/4534).
:warning: __TSLint will be deprecated some time in 2019__. See this issue for more details: [Roadmap: TSLint &rarr; ESLint](https://github.com/palantir/tslint/issues/4534). If you're interested in helping with the TSLint/ESLint migration, please check out our [OSS Fellowship](https://medium.com/palantir/fellowships-for-open-source-developers-3892e6b75ee1) program.

@@ -15,0 +15,0 @@ TSLint currently supports:

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