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.13.1 to 5.14.0

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

3

lib/configs/all.d.ts

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

"no-submodule-imports": boolean;
"no-tautology-expression": boolean;
"no-unbound-method": boolean;

@@ -111,2 +112,3 @@ "no-unnecessary-class": {

"restrict-plus-operands": boolean;
"static-this": boolean;
"strict-boolean-expressions": boolean;

@@ -246,2 +248,3 @@ "strict-type-predicates": boolean;

"unnecessary-bind": boolean;
"unnecessary-else": boolean;
"variable-name": {

@@ -248,0 +251,0 @@ options: string[];

5

lib/configs/all.js

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

"no-submodule-imports": true,
"no-tautology-expression": true,
"no-unbound-method": true,

@@ -146,2 +147,3 @@ "no-unnecessary-class": { options: ["allow-empty-class"] },

"restrict-plus-operands": true,
"static-this": true,
"strict-boolean-expressions": true,

@@ -261,3 +263,4 @@ "strict-type-predicates": true,

"unnecessary-bind": true,
"variable-name": { options: ["ban-keywords", "check-format"] },
"unnecessary-else": true,
"variable-name": { options: ["ban-keywords", "check-format", "require-const-for-all-caps"] },
whitespace: {

@@ -264,0 +267,0 @@ options: [

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

exclude: utils_1.arrayify(raw.exclude).map(function (pattern) {
return dir === undefined
? path.resolve(pattern)
: path.resolve(dir, pattern);
return dir === undefined ? path.resolve(pattern) : path.resolve(dir, pattern);
}),

@@ -467,0 +465,0 @@ }

@@ -22,4 +22,4 @@ /**

static metadata: IFormatterMetadata;
format(failures: RuleFailure[]): string;
format(failures: RuleFailure[], _fixes?: RuleFailure[], fileNames?: string[]): string;
private escapeXml;
}

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

/* tslint:enable:object-literal-sort-keys */
Formatter.prototype.format = function (failures) {
Formatter.prototype.format = function (failures, _fixes, fileNames) {
var output = '<?xml version="1.0" encoding="utf-8"?><testsuites package="tslint">';
var failureFileNames = new Set(failures.map(function (f) { return f.getFileName(); }).slice());
if (failures.length !== 0) {

@@ -61,2 +62,12 @@ var failuresSorted = failures.sort(function (a, b) {

}
if (fileNames !== undefined && fileNames.length !== 0) {
// Filter out files which have had a failure associated with them.
var filteredFileNames = fileNames.filter(function (fileName) { return !failureFileNames.has(fileName); });
for (var _a = 0, filteredFileNames_1 = filteredFileNames; _a < filteredFileNames_1.length; _a++) {
var fileName = filteredFileNames_1[_a];
output += "<testsuite name=\"" + this.escapeXml(fileName) + "\" errors=\"0\">";
output += "<testcase name=\"" + this.escapeXml(fileName) + "\" />";
output += "</testsuite>";
}
}
output += "</testsuites>";

@@ -63,0 +74,0 @@ return output;

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

Replacement.applyFixes = function (content, fixes) {
return this.applyAll(content, utils_1.flatMap(fixes, utils_1.arrayify));
return Replacement.applyAll(content, utils_1.flatMap(fixes, utils_1.arrayify));
};

@@ -40,3 +40,3 @@ Replacement.applyAll = function (content, replacements) {

Replacement.replaceNode = function (node, text, sourceFile) {
return this.replaceFromTo(node.getStart(sourceFile), node.getEnd(), text);
return Replacement.replaceFromTo(node.getStart(sourceFile), node.getEnd(), text);
};

@@ -43,0 +43,0 @@ Replacement.replaceFromTo = function (start, end, text) {

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

};
Linter.VERSION = "5.13.1";
Linter.VERSION = "5.14.0";
Linter.findConfiguration = configuration_1.findConfiguration;

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

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

addFailures(getMisplacedOverloads(members, function (member) {
return utils.isSignatureDeclaration(member)
? getOverloadKey(member)
: undefined;
return utils.isSignatureDeclaration(member) ? getOverloadKey(member) : undefined;
}));

@@ -67,0 +65,0 @@ }

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

export declare const DESCRIPTOR_LOCATIONS = "locations";
export declare const DESCRIPTOR_OVERLOADS = "overloads";
export declare const DESCRIPTOR_PRIVACIES = "privacies";

@@ -107,6 +108,65 @@ export declare const DESCRIPTOR_VISIBILITIES = "visibilities";

};
static ARGUMENT_DESCRIPTOR_FUNCTION: {
properties: {
[DESCRIPTOR_OVERLOADS]: {
type: string;
};
[DESCRIPTOR_TAGS]: {
properties: {
[TAGS_FOR_CONTENT]: {
items: {
type: string;
};
type: string;
};
[TAGS_FOR_EXISTENCE]: {
items: {
type: string;
};
type: string;
};
};
};
[DESCRIPTOR_VISIBILITIES]: {
enum: string[];
type: string;
};
};
type: string;
};
static ARGUMENT_DESCRIPTOR_METHOD: {
properties: {
[DESCRIPTOR_OVERLOADS]: {
type: string;
};
[DESCRIPTOR_TAGS]: {
properties: {
[TAGS_FOR_CONTENT]: {
items: {
type: string;
};
type: string;
};
[TAGS_FOR_EXISTENCE]: {
items: {
type: string;
};
type: string;
};
};
};
[DESCRIPTOR_LOCATIONS]: {
enum: string[];
type: string;
};
[DESCRIPTOR_PRIVACIES]: {
enum: string[];
type: string;
};
};
type: string;
};
static metadata: Lint.IRuleMetadata;
private readonly exclusionFactory;
apply(sourceFile: ts.SourceFile): Lint.RuleFailure[];
private getExclusionsMap;
}

@@ -20,7 +20,7 @@ "use strict";

var tslib_1 = require("tslib");
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
var tsutils = require("tsutils");
var ts = require("typescript");
var Lint = require("../index");
var exclusionFactory_1 = require("./completed-docs/exclusionFactory");
var exclusions_1 = require("./completed-docs/exclusions");
exports.ALL = "all";

@@ -39,2 +39,3 @@ exports.ARGUMENT_CLASSES = "classes";

exports.DESCRIPTOR_LOCATIONS = "locations";
exports.DESCRIPTOR_OVERLOADS = "overloads";
exports.DESCRIPTOR_PRIVACIES = "privacies";

@@ -54,7 +55,5 @@ exports.DESCRIPTOR_VISIBILITIES = "visibilities";

function Rule() {
var _this = _super !== null && _super.apply(this, arguments) || this;
/* tslint:enable:object-literal-sort-keys */
_this.exclusionFactory = new exclusionFactory_1.ExclusionFactory();
return _this;
return _super !== null && _super.apply(this, arguments) || this;
}
/* tslint:enable:object-literal-sort-keys */
Rule.prototype.apply = function (sourceFile) {

@@ -69,3 +68,3 @@ var options = this.getOptions();

}
return this.exclusionFactory.constructExclusionsMap(ruleArguments);
return exclusions_1.constructExclusionsMap(ruleArguments);
};

@@ -147,2 +146,14 @@ Rule.FAILURE_STRING_EXIST = "Documentation must exist for ";

};
Rule.ARGUMENT_DESCRIPTOR_FUNCTION = {
properties: tslib_1.__assign({}, Rule.ARGUMENT_DESCRIPTOR_BLOCK.properties, (_k = {}, _k[exports.DESCRIPTOR_OVERLOADS] = {
type: "boolean",
}, _k)),
type: "object",
};
Rule.ARGUMENT_DESCRIPTOR_METHOD = {
properties: tslib_1.__assign({}, Rule.ARGUMENT_DESCRIPTOR_CLASS.properties, (_l = {}, _l[exports.DESCRIPTOR_OVERLOADS] = {
type: "boolean",
}, _l)),
type: "object",
};
/* tslint:disable:object-literal-sort-keys */

@@ -152,3 +163,3 @@ Rule.metadata = {

description: "Enforces JSDoc comments for important items be filled out.",
optionsDescription: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\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 * `\"", "\"`"], ["\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 * \\`\"", "\"\\`"])), 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),
optionsDescription: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\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 * `\"", "\"` `\"", "\"` may also specify `\"", "\"`\n to indicate that each overload should have its own documentation, which is `false` by default.\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 * `\"", "\"`"], ["\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 * \\`\"", "\"\\` \\`\"", "\"\\` may also specify \\`\"", "\"\\`\n to indicate that each overload should have its own documentation, which is \\`false\\` by default.\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 * \\`\"", "\"\\`"])), 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.ARGUMENT_FUNCTIONS, exports.ARGUMENT_METHODS, exports.DESCRIPTOR_OVERLOADS, 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: {

@@ -174,14 +185,14 @@ type: "array",

type: "object",
properties: (_k = {},
_k[exports.ARGUMENT_CLASSES] = Rule.ARGUMENT_DESCRIPTOR_BLOCK,
_k[exports.ARGUMENT_ENUMS] = Rule.ARGUMENT_DESCRIPTOR_BLOCK,
_k[exports.ARGUMENT_ENUM_MEMBERS] = Rule.ARGUMENT_DESCRIPTOR_BLOCK,
_k[exports.ARGUMENT_FUNCTIONS] = Rule.ARGUMENT_DESCRIPTOR_BLOCK,
_k[exports.ARGUMENT_INTERFACES] = Rule.ARGUMENT_DESCRIPTOR_BLOCK,
_k[exports.ARGUMENT_METHODS] = Rule.ARGUMENT_DESCRIPTOR_CLASS,
_k[exports.ARGUMENT_NAMESPACES] = Rule.ARGUMENT_DESCRIPTOR_BLOCK,
_k[exports.ARGUMENT_PROPERTIES] = Rule.ARGUMENT_DESCRIPTOR_CLASS,
_k[exports.ARGUMENT_TYPES] = Rule.ARGUMENT_DESCRIPTOR_BLOCK,
_k[exports.ARGUMENT_VARIABLES] = Rule.ARGUMENT_DESCRIPTOR_BLOCK,
_k),
properties: (_m = {},
_m[exports.ARGUMENT_CLASSES] = Rule.ARGUMENT_DESCRIPTOR_BLOCK,
_m[exports.ARGUMENT_ENUMS] = Rule.ARGUMENT_DESCRIPTOR_BLOCK,
_m[exports.ARGUMENT_ENUM_MEMBERS] = Rule.ARGUMENT_DESCRIPTOR_BLOCK,
_m[exports.ARGUMENT_FUNCTIONS] = Rule.ARGUMENT_DESCRIPTOR_FUNCTION,
_m[exports.ARGUMENT_INTERFACES] = Rule.ARGUMENT_DESCRIPTOR_BLOCK,
_m[exports.ARGUMENT_METHODS] = Rule.ARGUMENT_DESCRIPTOR_METHOD,
_m[exports.ARGUMENT_NAMESPACES] = Rule.ARGUMENT_DESCRIPTOR_BLOCK,
_m[exports.ARGUMENT_PROPERTIES] = Rule.ARGUMENT_DESCRIPTOR_CLASS,
_m[exports.ARGUMENT_TYPES] = Rule.ARGUMENT_DESCRIPTOR_BLOCK,
_m[exports.ARGUMENT_VARIABLES] = Rule.ARGUMENT_DESCRIPTOR_BLOCK,
_m),
},

@@ -196,23 +207,23 @@ ],

true,
(_l = {},
_l[exports.ARGUMENT_ENUMS] = true,
_l[exports.ARGUMENT_FUNCTIONS] = (_m = {},
_m[exports.DESCRIPTOR_VISIBILITIES] = [exports.VISIBILITY_EXPORTED],
_m),
_l[exports.ARGUMENT_METHODS] = (_o = {},
_o[exports.DESCRIPTOR_LOCATIONS] = exports.LOCATION_INSTANCE,
_o[exports.DESCRIPTOR_PRIVACIES] = [exports.PRIVACY_PUBLIC, exports.PRIVACY_PROTECTED],
_o),
_l[exports.ARGUMENT_PROPERTIES] = (_p = {},
_p[exports.DESCRIPTOR_TAGS] = (_q = {},
_q[exports.TAGS_FOR_CONTENT] = {
(_o = {},
_o[exports.ARGUMENT_ENUMS] = true,
_o[exports.ARGUMENT_FUNCTIONS] = (_p = {},
_p[exports.DESCRIPTOR_VISIBILITIES] = [exports.VISIBILITY_EXPORTED],
_p),
_o[exports.ARGUMENT_METHODS] = (_q = {},
_q[exports.DESCRIPTOR_LOCATIONS] = exports.LOCATION_INSTANCE,
_q[exports.DESCRIPTOR_PRIVACIES] = [exports.PRIVACY_PUBLIC, exports.PRIVACY_PROTECTED],
_q),
_o[exports.ARGUMENT_PROPERTIES] = (_r = {},
_r[exports.DESCRIPTOR_TAGS] = (_s = {},
_s[exports.TAGS_FOR_CONTENT] = {
see: ["#.*"],
},
_q[exports.TAGS_FOR_EXISTENCE] = ["inheritdoc"],
_q),
_p),
_l),
_s[exports.TAGS_FOR_EXISTENCE] = ["inheritdoc"],
_s),
_r),
_o),
],
],
rationale: Lint.Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n Helps ensure important components are documented.\n\n Note: use this rule sparingly. It's better to have self-documenting names on components with single, consice responsibilities.\n Comments that only restate the names of variables add nothing to code, and can easily become outdated.\n "], ["\n Helps ensure important components are documented.\n\n Note: use this rule sparingly. It's better to have self-documenting names on components with single, consice responsibilities.\n Comments that only restate the names of variables add nothing to code, and can easily become outdated.\n "]))),
rationale: Lint.Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n Helps ensure important components are documented.\n\n Note: use this rule sparingly. It's better to have self-documenting names on components with single, concise responsibilities.\n Comments that only restate the names of variables add nothing to code, and can easily become outdated.\n "], ["\n Helps ensure important components are documented.\n\n Note: use this rule sparingly. It's better to have self-documenting names on components with single, concise responsibilities.\n Comments that only restate the names of variables add nothing to code, and can easily become outdated.\n "]))),
type: "style",

@@ -285,3 +296,3 @@ typescriptOnly: false,

if (node.parent.kind !== ts.SyntaxKind.ObjectLiteralExpression) {
checkAccessorNode(node);
checkAccessorNode(node, exports.ARGUMENT_PROPERTIES);
}

@@ -291,18 +302,18 @@ }

}
function checkNode(node, nodeType, requirementNode) {
function checkNode(node, docType, requirementNode) {
if (requirementNode === void 0) { requirementNode = node; }
if (!nodeIsExcluded(node, nodeType, requirementNode) && !nodeHasDocs(node)) {
addDocumentationFailure(node, describeNode(nodeType), requirementNode);
if (!nodeIsExcluded(node, docType, requirementNode) && !nodeHasDocs(node, docType)) {
addDocumentationFailure(node, describeDocType(docType), requirementNode);
}
}
function checkAccessorNode(node) {
if (nodeIsExcluded(node, exports.ARGUMENT_PROPERTIES, node) || nodeHasDocs(node)) {
function checkAccessorNode(node, docType) {
if (nodeIsExcluded(node, exports.ARGUMENT_PROPERTIES, node) || nodeHasDocs(node, docType)) {
return;
}
var correspondingAccessor = getCorrespondingAccessor(node);
if (correspondingAccessor === undefined || !nodeHasDocs(correspondingAccessor)) {
if (correspondingAccessor === undefined || !nodeHasDocs(correspondingAccessor, docType)) {
addDocumentationFailure(node, exports.ARGUMENT_PROPERTIES, node);
}
}
function nodeIsExcluded(node, nodeType, requirementNode) {
function nodeIsExcluded(node, docType, requirementNode) {
var name = node.name;

@@ -312,9 +323,9 @@ if (name === undefined) {

}
var exclusions = context.options.get(nodeType);
var exclusions = context.options.get(docType);
if (exclusions === undefined) {
return true;
}
for (var _i = 0, exclusions_1 = exclusions; _i < exclusions_1.length; _i++) {
var exclusion = exclusions_1[_i];
if (exclusion.excludes(requirementNode)) {
for (var _i = 0, _a = exclusions.requirements; _i < _a.length; _i++) {
var requirement = _a[_i];
if (requirement.excludes(requirementNode)) {
return true;

@@ -325,4 +336,4 @@ }

}
function nodeHasDocs(node) {
var docs = getApparentJsDoc(node);
function nodeHasDocs(node, docType) {
var docs = getApparentJsDoc(node, docType, context.sourceFile);
if (docs === undefined) {

@@ -336,6 +347,53 @@ return false;

}
function addDocumentationFailure(node, nodeType, requirementNode) {
/**
* @see https://github.com/ajafff/tsutils/issues/16
*/
function getApparentJsDoc(node, docType, sourceFile) {
if (ts.isVariableDeclaration(node)) {
if (variableIsAfterFirstInDeclarationList(node)) {
return undefined;
}
node = node.parent;
}
if (ts.isVariableDeclarationList(node)) {
node = node.parent;
}
var equivalentNodesForDocs = getEquivalentNodesForDocs(node, docType);
return equivalentNodesForDocs
.map(function (docsNode) { return tsutils.getJsDoc(docsNode, sourceFile); })
.filter(function (nodeDocs) { return nodeDocs !== undefined; })
.reduce(function (docs, moreDocs) { return docs.concat(moreDocs); }, []);
}
/**
* @see https://github.com/palantir/tslint/issues/4416
*/
function getEquivalentNodesForDocs(node, docType) {
var exclusions = context.options.get(docType);
if (exclusions === undefined || exclusions.overloadsSeparateDocs) {
return [node];
}
if (tsutils.isFunctionDeclaration(node) && node.name !== undefined) {
var functionName_1 = node.name.text;
return getSiblings(node).filter(function (child) {
return tsutils.isFunctionDeclaration(child) &&
child.name !== undefined &&
child.name.text === functionName_1;
});
}
if (tsutils.isMethodDeclaration(node) &&
tsutils.isIdentifier(node.name) &&
tsutils.isClassDeclaration(node.parent)) {
var methodName_1 = node.name.text;
return node.parent.members.filter(function (member) {
return tsutils.isMethodDeclaration(member) &&
tsutils.isIdentifier(member.name) &&
member.name.text === methodName_1;
});
}
return [node];
}
function addDocumentationFailure(node, docType, requirementNode) {
var start = node.getStart();
var width = node.getText().split(/\r|\n/g)[0].length;
var description = describeDocumentationFailure(requirementNode, nodeType);
var description = describeDocumentationFailure(requirementNode, docType);
context.addFailureAt(start, width, description);

@@ -362,17 +420,2 @@ }

}
/**
* @remarks See https://github.com/ajafff/tsutils/issues/16
*/
function getApparentJsDoc(node) {
if (ts.isVariableDeclaration(node)) {
if (variableIsAfterFirstInDeclarationList(node)) {
return undefined;
}
node = node.parent;
}
if (ts.isVariableDeclarationList(node)) {
node = node.parent;
}
return tsutils.getJsDoc(node);
}
function variableIsAfterFirstInDeclarationList(node) {

@@ -385,3 +428,3 @@ var parent = node.parent;

}
function describeDocumentationFailure(node, nodeType) {
function describeDocumentationFailure(node, docType) {
var description = Rule.FAILURE_STRING_EXIST;

@@ -393,3 +436,3 @@ if (node.modifiers !== undefined) {

}
return "" + description + nodeType + ".";
return "" + description + docType + ".";
}

@@ -401,5 +444,13 @@ function describeModifier(kind) {

}
function describeNode(nodeType) {
return nodeType.replace("-", " ");
function describeDocType(docType) {
return docType.replace("-", " ");
}
function getSiblings(node) {
var parent = node.parent;
// Source files nest their statements within a node for getChildren()
if (ts.isSourceFile(parent)) {
return parent.statements.slice();
}
return parent.getChildren();
}
function isGetAccessor(node) {

@@ -406,0 +457,0 @@ return node.kind === ts.SyntaxKind.GetAccessor;

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

if (failureExists) {
var sortedMemberIndexes = members.map(function (_, i) { return i; }).sort(function (ai, bi) {
var sortedMemberIndexes = members
.map(function (_, i) { return i; })
.sort(function (ai, bi) {
var a = members[ai];

@@ -293,0 +295,0 @@ var b = members[bi];

@@ -22,3 +22,4 @@ /**

static FAILURE_STRING(module: string): string;
static NAMESPACE_FAILURE_STRING(module: string): string;
apply(sourceFile: ts.SourceFile): Lint.RuleFailure[];
}

@@ -20,5 +20,7 @@ "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_ALLOW_SEPARATE_NAMESPACE_IMPORTS = "allow-namespace-imports";
var Rule = /** @class */ (function (_super) {

@@ -32,4 +34,12 @@ tslib_1.__extends(Rule, _super);

};
Rule.NAMESPACE_FAILURE_STRING = function (module) {
return "Multiple wildcard imports from the same module, '" + module + "', are prohibited.";
};
Rule.prototype.apply = function (sourceFile) {
return this.applyWithFunction(sourceFile, walk);
var _a;
return this.applyWithFunction(sourceFile, walk, (_a = {},
_a[OPTION_ALLOW_SEPARATE_NAMESPACE_IMPORTS] = !!(this.ruleArguments.length > 0 &&
this.ruleArguments[0] !== null &&
this.ruleArguments[0][OPTION_ALLOW_SEPARATE_NAMESPACE_IMPORTS]),
_a));
};

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

rationale: Lint.Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n Using a single import statement per module will make the code clearer because you can see everything being imported\n from that module on one line."], ["\n Using a single import statement per module will make the code clearer because you can see everything being imported\n from that module on one line."]))),
optionsDescription: "Not configurable",
options: null,
optionExamples: [true],
optionsDescription: Lint.Utils.dedent(templateObject_3 || (templateObject_3 = tslib_1.__makeTemplateObject(["\n \"", "\" allows you to import namespaces on separate lines."], ["\n \"", "\" allows you to import namespaces on separate lines."])), OPTION_ALLOW_SEPARATE_NAMESPACE_IMPORTS),
options: {
type: "object",
properties: (_a = {},
_a[OPTION_ALLOW_SEPARATE_NAMESPACE_IMPORTS] = {
type: "boolean",
},
_a),
},
optionExamples: [[true, (_b = {}, _b[OPTION_ALLOW_SEPARATE_NAMESPACE_IMPORTS] = true, _b)]],
type: "maintainability",

@@ -52,14 +69,35 @@ typescriptOnly: false,

function walk(ctx) {
walkWorker(ctx, ctx.sourceFile.statements, new Set());
walkWorker(ctx, ctx.sourceFile.statements, {
imports: new Set(),
namespaceImports: new Set(),
});
}
function statementIsNamespaceImport(statement) {
return !!(statement.importClause !== undefined &&
statement.importClause.namedBindings !== undefined &&
tsutils_1.isNamespaceImport(statement.importClause.namedBindings));
}
function walkWorker(ctx, statements, seen) {
for (var _i = 0, statements_1 = statements; _i < statements_1.length; _i++) {
var statement = statements_1[_i];
if (tsutils_1.isImportDeclaration(statement) && tsutils_1.isLiteralExpression(statement.moduleSpecifier)) {
if (tsutils_1.isImportDeclaration(statement) &&
tsutils_1.isLiteralExpression(statement.moduleSpecifier) &&
(!statementIsNamespaceImport(statement) ||
!ctx.options[OPTION_ALLOW_SEPARATE_NAMESPACE_IMPORTS])) {
var text = statement.moduleSpecifier.text;
if (seen.has(text)) {
if (seen.imports.has(text)) {
ctx.addFailureAtNode(statement, Rule.FAILURE_STRING(text));
}
seen.add(text);
seen.imports.add(text);
}
else if (tsutils_1.isImportDeclaration(statement) &&
tsutils_1.isLiteralExpression(statement.moduleSpecifier) &&
statementIsNamespaceImport(statement) &&
ctx.options[OPTION_ALLOW_SEPARATE_NAMESPACE_IMPORTS]) {
var text = statement.moduleSpecifier.text;
if (seen.namespaceImports.has(text)) {
ctx.addFailureAtNode(statement, Rule.NAMESPACE_FAILURE_STRING(text));
}
seen.namespaceImports.add(text);
}
if (tsutils_1.isModuleDeclaration(statement) &&

@@ -71,6 +109,11 @@ statement.body !== undefined &&

// because they should have separate imports to avoid becoming augmentations.
walkWorker(ctx, statement.body.statements, ts.isExternalModule(ctx.sourceFile) ? seen : new Set());
walkWorker(ctx, statement.body.statements, ts.isExternalModule(ctx.sourceFile)
? seen
: {
imports: new Set(),
namespaceImports: new Set(),
});
}
}
}
var templateObject_1, templateObject_2;
var templateObject_1, templateObject_2, templateObject_3;

@@ -20,5 +20,11 @@ "use strict";

var tslib_1 = require("tslib");
var _a, _b, _c;
var tsutils_1 = require("tsutils");
var ts = require("typescript");
var Lint = require("../index");
var noObjectLiteralTypeAssertion_examples_1 = require("./code-examples/noObjectLiteralTypeAssertion.examples");
var OPTION_ALLOW_ARGUMENTS = "allow-arguments";
var DEFAULT_OPTIONS = (_a = {},
_a[OPTION_ALLOW_ARGUMENTS] = false,
_a);
var Rule = /** @class */ (function (_super) {

@@ -30,3 +36,3 @@ tslib_1.__extends(Rule, _super);

Rule.prototype.apply = function (sourceFile) {
return this.applyWithFunction(sourceFile, walk);
return this.applyWithFunction(sourceFile, walk, parseOptions(this.ruleArguments[0]));
};

@@ -38,7 +44,16 @@ /* tslint:disable:object-literal-sort-keys */

rationale: Lint.Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n Always prefer `const x: T = { ... };` to `const x = { ... } as T;`.\n The type assertion in the latter case is either unnecessary or hides an error.\n The compiler will warn for excess properties with this syntax, but not missing required fields.\n For example: `const x: { foo: number } = {}` will fail to compile, but\n `const x = {} as { foo: number }` will succeed."], ["\n Always prefer \\`const x: T = { ... };\\` to \\`const x = { ... } as T;\\`.\n The type assertion in the latter case is either unnecessary or hides an error.\n The compiler will warn for excess properties with this syntax, but not missing required fields.\n For example: \\`const x: { foo: number } = {}\\` will fail to compile, but\n \\`const x = {} as { foo: number }\\` will succeed."]))),
optionsDescription: "Not configurable.",
options: null,
optionExamples: [true],
optionsDescription: Lint.Utils.dedent(templateObject_3 || (templateObject_3 = tslib_1.__makeTemplateObject(["\n One option may be configured:\n\n * `", "` allows type assertions to be used on object literals inside call expressions."], ["\n One option may be configured:\n\n * \\`", "\\` allows type assertions to be used on object literals inside call expressions."])), OPTION_ALLOW_ARGUMENTS),
options: {
type: "object",
properties: (_b = {},
_b[OPTION_ALLOW_ARGUMENTS] = {
type: "boolean",
},
_b),
additionalProperties: false,
},
optionExamples: [true, [true, (_c = {}, _c[OPTION_ALLOW_ARGUMENTS] = true, _c)]],
type: "functionality",
typescriptOnly: true,
codeExamples: noObjectLiteralTypeAssertion_examples_1.codeExamples,
};

@@ -60,3 +75,4 @@ /* tslint:enable:object-literal-sort-keys */

? node.expression.expression
: node.expression)) {
: node.expression) &&
!(ctx.options[OPTION_ALLOW_ARGUMENTS] && isArgument(node))) {
ctx.addFailureAtNode(node, Rule.FAILURE_STRING);

@@ -67,2 +83,8 @@ }

}
var templateObject_1, templateObject_2;
function isArgument(node) {
return ts.isCallLikeExpression(node.parent);
}
function parseOptions(options) {
return tslib_1.__assign({}, DEFAULT_OPTIONS, options);
}
var templateObject_1, templateObject_2, templateObject_3;

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

rationale: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n When a variable in a local scope and a variable in the containing scope have the same name, shadowing occurs.\n Shadowing makes it impossible to access the variable in the containing scope and\n obscures to what value an identifier actually refers. Compare the following snippets:\n\n ```\n const a = 'no shadow';\n function print() {\n console.log(a);\n }\n print(); // logs 'no shadow'.\n ```\n\n ```\n const a = 'no shadow';\n function print() {\n const a = 'shadow'; // TSLint will complain here.\n console.log(a);\n }\n print(); // logs 'shadow'.\n ```\n\n ESLint has [an equivalent rule](https://eslint.org/docs/rules/no-shadow).\n For more background information, refer to\n [this MDN closure doc](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures#Lexical_scoping).\n "], ["\n When a variable in a local scope and a variable in the containing scope have the same name, shadowing occurs.\n Shadowing makes it impossible to access the variable in the containing scope and\n obscures to what value an identifier actually refers. Compare the following snippets:\n\n \\`\\`\\`\n const a = 'no shadow';\n function print() {\n console.log(a);\n }\n print(); // logs 'no shadow'.\n \\`\\`\\`\n\n \\`\\`\\`\n const a = 'no shadow';\n function print() {\n const a = 'shadow'; // TSLint will complain here.\n console.log(a);\n }\n print(); // logs 'shadow'.\n \\`\\`\\`\n\n ESLint has [an equivalent rule](https://eslint.org/docs/rules/no-shadow).\n For more background information, refer to\n [this MDN closure doc](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures#Lexical_scoping).\n "]))),
optionsDescription: Lint.Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\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\n The option `\"temporalDeadZone\"` defaults to `true` which shows errors when shadowing block scoped declarations in their\n temporal dead zone. When set to `false` parameters, classes, enums and variables declared\n with `let` or `const` are not considered shadowed if the shadowing occurs within their\n [temporal dead zone](http://jsrocks.org/2015/01/temporal-dead-zone-tdz-demystified).\n\n The following example shows how the `\"temporalDeadZone\"` option changes the linting result:\n\n ```ts\n function fn(value) {\n if (value) {\n const tmp = value; // no error on this line if \"temporalDeadZone\" is false\n return tmp;\n }\n let tmp = undefined;\n if (!value) {\n const tmp = value; // this line always contains an error\n return tmp;\n }\n }\n ```\n "], ["\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\n The option \\`\"temporalDeadZone\"\\` defaults to \\`true\\` which shows errors when shadowing block scoped declarations in their\n temporal dead zone. When set to \\`false\\` parameters, classes, enums and variables declared\n with \\`let\\` or \\`const\\` are not considered shadowed if the shadowing occurs within their\n [temporal dead zone](http://jsrocks.org/2015/01/temporal-dead-zone-tdz-demystified).\n\n The following example shows how the \\`\"temporalDeadZone\"\\` option changes the linting result:\n\n \\`\\`\\`ts\n function fn(value) {\n if (value) {\n const tmp = value; // no error on this line if \"temporalDeadZone\" is false\n return tmp;\n }\n let tmp = undefined;\n if (!value) {\n const tmp = value; // this line always contains an error\n return tmp;\n }\n }\n \\`\\`\\`\n "]))),
optionsDescription: Lint.Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\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\"`. You can also pass `\"underscore`\" to ignore variable names that begin with `_`.\n 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\n The option `\"temporalDeadZone\"` defaults to `true` which shows errors when shadowing block scoped declarations in their\n temporal dead zone. When set to `false` parameters, classes, enums and variables declared\n with `let` or `const` are not considered shadowed if the shadowing occurs within their\n [temporal dead zone](http://jsrocks.org/2015/01/temporal-dead-zone-tdz-demystified).\n\n The following example shows how the `\"temporalDeadZone\"` option changes the linting result:\n\n ```ts\n function fn(value) {\n if (value) {\n const tmp = value; // no error on this line if \"temporalDeadZone\" is false\n return tmp;\n }\n let tmp = undefined;\n if (!value) {\n const tmp = value; // this line always contains an error\n return tmp;\n }\n }\n ```\n "], ["\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\"\\`. You can also pass \\`\"underscore\\`\" to ignore variable names that begin with \\`_\\`.\n 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\n The option \\`\"temporalDeadZone\"\\` defaults to \\`true\\` which shows errors when shadowing block scoped declarations in their\n temporal dead zone. When set to \\`false\\` parameters, classes, enums and variables declared\n with \\`let\\` or \\`const\\` are not considered shadowed if the shadowing occurs within their\n [temporal dead zone](http://jsrocks.org/2015/01/temporal-dead-zone-tdz-demystified).\n\n The following example shows how the \\`\"temporalDeadZone\"\\` option changes the linting result:\n\n \\`\\`\\`ts\n function fn(value) {\n if (value) {\n const tmp = value; // no error on this line if \"temporalDeadZone\" is false\n return tmp;\n }\n let tmp = undefined;\n if (!value) {\n const tmp = value; // this line always contains an error\n return tmp;\n }\n }\n \\`\\`\\`\n "]))),
options: {

@@ -54,2 +54,3 @@ type: "object",

temporalDeadZone: { type: "boolean" },
underscore: { type: "boolean" },
},

@@ -69,2 +70,3 @@ },

typeParameter: false,
underscore: false,
},

@@ -80,3 +82,3 @@ ],

function parseOptions(option) {
return tslib_1.__assign({ class: true, enum: true, function: true, import: true, interface: true, namespace: true, temporalDeadZone: true, typeAlias: true, typeParameter: true }, option);
return tslib_1.__assign({ class: true, enum: true, function: true, import: true, interface: true, namespace: true, temporalDeadZone: true, typeAlias: true, typeParameter: true, underscore: true }, option);
}

@@ -300,3 +302,4 @@ var Scope = /** @class */ (function () {

return !declaration.tdz || declaration.identifier.pos < identifier.pos;
}))) {
})) &&
(_this.options.underscore || !identifier.getText().startsWith("_"))) {
_this.addFailureAtNode(identifier, Rule.FAILURE_STRING_FACTORY(name));

@@ -303,0 +306,0 @@ }

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

var noConsecutiveBlankLinesRule_1 = require("./noConsecutiveBlankLinesRule");
var ZERO_WIDTH_NO_BREAK_SPACE = 0xfeff;
var OPTION_IGNORE_COMMENTS = "ignore-comments";

@@ -79,3 +80,5 @@ var OPTION_IGNORE_JSDOC = "ignore-jsdoc";

var match = text.substr(line.pos, line.contentLength).match(/\s+$/);
if (match !== null && !(ctx.options.ignoreBlankLines && match.index === 0)) {
if (match !== null &&
!(ctx.options.ignoreBlankLines && match.index === 0) &&
match[0] !== String.fromCharCode(ZERO_WIDTH_NO_BREAK_SPACE)) {
possibleFailures.push({

@@ -82,0 +85,0 @@ end: line.pos + line.contentLength,

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

var OPTION_ALLOW_TYPEOF = "allow-typeof";
var OPTION_ALLOW_DELETE = "allow-delete";
var OPTION_WHITELIST_EXAMPLE = [

@@ -48,3 +49,3 @@ true,

description: "Warns when a method is used outside of a method call.",
optionsDescription: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n You may additionally pass \"", "\" to ignore static methods, or an options object.\n \n The object may have three properties:\n \n * \"", "\" - to ignore static methods.\n * \"", "\" - ignore methods referenced in a typeof expression.\n * \"", "\" - ignore method references in parameters of specifed function calls.\n \n "], ["\n You may additionally pass \"", "\" to ignore static methods, or an options object.\n \n The object may have three properties:\n \n * \"", "\" - to ignore static methods.\n * \"", "\" - ignore methods referenced in a typeof expression.\n * \"", "\" - ignore method references in parameters of specifed function calls.\n \n "])), OPTION_IGNORE_STATIC, OPTION_IGNORE_STATIC, OPTION_ALLOW_TYPEOF, OPTION_WHITELIST),
optionsDescription: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n You may additionally pass \"", "\" to ignore static methods, or an options object.\n \n The object may have the following properties:\n \n * \"", "\" - to ignore static methods.\n * \"", "\" - ignore methods referenced in a delete expression.\n * \"", "\" - ignore methods referenced in a typeof expression.\n * \"", "\" - ignore method references in parameters of specifed function calls.\n \n "], ["\n You may additionally pass \"", "\" to ignore static methods, or an options object.\n \n The object may have the following properties:\n \n * \"", "\" - to ignore static methods.\n * \"", "\" - ignore methods referenced in a delete expression.\n * \"", "\" - ignore methods referenced in a typeof expression.\n * \"", "\" - ignore method references in parameters of specifed function calls.\n \n "])), OPTION_IGNORE_STATIC, OPTION_IGNORE_STATIC, OPTION_ALLOW_DELETE, OPTION_ALLOW_TYPEOF, OPTION_WHITELIST),
options: {

@@ -59,2 +60,3 @@ anyOf: [

properties: (_b = {},
_b[OPTION_ALLOW_DELETE] = { type: "boolean" },
_b[OPTION_ALLOW_TYPEOF] = { type: "boolean" },

@@ -84,2 +86,3 @@ _b[OPTION_IGNORE_STATIC] = { type: "boolean" },

var options = {
allowDelete: false,
allowTypeof: false,

@@ -97,2 +100,3 @@ ignoreStatic: false,

else {
options.allowDelete = arg[OPTION_ALLOW_DELETE] || false;
options.allowTypeof = arg[OPTION_ALLOW_TYPEOF] || false;

@@ -111,4 +115,3 @@ options.ignoreStatic = arg[OPTION_IGNORE_STATIC] || false;

var isMethodAccess = declaration !== undefined && isMethod(declaration, ctx.options.ignoreStatic);
var shouldBeReported = isMethodAccess &&
!isWhitelisted(node, ctx.options.whitelist, ctx.options.allowTypeof);
var shouldBeReported = isMethodAccess && !isWhitelisted(node, ctx.options);
if (shouldBeReported) {

@@ -162,3 +165,7 @@ ctx.addFailureAtNode(node, Rule.FAILURE_STRING);

}
function isWhitelisted(node, whitelist, allowTypeof) {
function isWhitelisted(node, options) {
var whitelist = options.whitelist, allowTypeof = options.allowTypeof, allowDelete = options.allowDelete;
if (tsutils_1.isDeleteExpression(node.parent)) {
return allowDelete;
}
if (tsutils_1.isTypeOfExpression(node.parent)) {

@@ -165,0 +172,0 @@ return allowTypeof;

@@ -87,6 +87,7 @@ "use strict";

if (options.has(node.kind)) {
var declaration = node;
switch (node.kind) {
case ts.SyntaxKind.MethodDeclaration:
case ts.SyntaxKind.FunctionDeclaration:
if (node.body === undefined) {
if (declaration.body === undefined) {
break;

@@ -98,3 +99,4 @@ }

if (!tsutils_1.hasModifier(node.modifiers, ts.SyntaxKind.AsyncKeyword) &&
returnsPromise(node, tc)) {
returnsPromise(declaration, tc) &&
!tsutils_1.isCallExpression(declaration.body)) {
ctx.addFailure(node.getStart(sourceFile), node.body.pos, Rule.FAILURE_STRING);

@@ -101,0 +103,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";

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
/**

@@ -18,4 +20,2 @@ * @license

*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var tsutils_1 = require("tsutils");

@@ -99,2 +99,7 @@ var ts = require("typescript");

var actualQuotemark = sourceFile.text[node.end - 1];
// Don't use backticks instead of single/double quotes when it breaks TypeScript syntax.
if (expectedQuotemark === "`" &&
(tsutils_1.isImportDeclaration(node.parent) || tsutils_1.isPropertyAssignment(node.parent))) {
return;
}
if (actualQuotemark === expectedQuotemark) {

@@ -101,0 +106,0 @@ return;

@@ -32,9 +32,9 @@ "use strict";

Rule.FAILURE_STRING_OMITTING_SINGLE_PARAMETER = function (otherLine) {
return this.FAILURE_STRING_START(otherLine) + " with an optional parameter.";
return Rule.FAILURE_STRING_START(otherLine) + " with an optional parameter.";
};
Rule.FAILURE_STRING_OMITTING_REST_PARAMETER = function (otherLine) {
return this.FAILURE_STRING_START(otherLine) + " with a rest parameter.";
return Rule.FAILURE_STRING_START(otherLine) + " with a rest parameter.";
};
Rule.FAILURE_STRING_SINGLE_PARAMETER_DIFFERENCE = function (otherLine, type1, type2) {
return this.FAILURE_STRING_START(otherLine) + " taking `" + type1 + " | " + type2 + "`.";
return Rule.FAILURE_STRING_START(otherLine) + " taking `" + type1 + " | " + type2 + "`.";
};

@@ -41,0 +41,0 @@ Rule.FAILURE_STRING_START = function (otherLine) {

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

return utils_1.find(sym.declarations, function (decl) {
return tsutils_1.isClassLikeDeclaration(decl) ||
tsutils_1.isTypeAliasDeclaration(decl) ||
tsutils_1.isInterfaceDeclaration(decl)
return tsutils_1.isClassLikeDeclaration(decl) || tsutils_1.isTypeAliasDeclaration(decl) || tsutils_1.isInterfaceDeclaration(decl)
? decl.typeParameters

@@ -118,0 +116,0 @@ : undefined;

@@ -22,3 +22,4 @@ /**

static KEYWORD_FAILURE: string;
static FAILURE_STRING_CONST: string;
apply(sourceFile: ts.SourceFile): Lint.RuleFailure[];
}

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

// tslint:disable object-literal-sort-keys
var tsutils_1 = require("tsutils");
var tsutils = require("tsutils");
var ts = require("typescript");

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

var OPTION_CHECK_FORMAT = "check-format";
var OPTION_REQUIRE_CONT_FOR_ALL_CAPS = "require-const-for-all-caps";
var OPTION_ALLOW_PASCAL_CASE = "allow-pascal-case";

@@ -57,3 +58,3 @@ var OPTION_ALLOW_SNAKE_CASE = "allow-snake-case";

description: "Checks variable names for various errors.",
optionsDescription: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n Five arguments may be optionally provided:\n\n * `\"", "\"`: allows only lowerCamelCased or UPPER_CASED variable names\n * `\"", "\"` allows underscores at the beginning (only has an effect if \"check-format\" specified)\n * `\"", "\"` allows underscores at the end. (only has an effect if \"check-format\" specified)\n * `\"", "\"` allows PascalCase in addition to lowerCamelCase.\n * `\"", "\"` allows snake_case in addition to lowerCamelCase.\n * `\"", "\"`: disallows the use of certain TypeScript keywords as variable or parameter names.\n * These are: ", ""], ["\n Five arguments may be optionally provided:\n\n * \\`\"", "\"\\`: allows only lowerCamelCased or UPPER_CASED variable names\n * \\`\"", "\"\\` allows underscores at the beginning (only has an effect if \"check-format\" specified)\n * \\`\"", "\"\\` allows underscores at the end. (only has an effect if \"check-format\" specified)\n * \\`\"", "\"\\` allows PascalCase in addition to lowerCamelCase.\n * \\`\"", "\"\\` allows snake_case in addition to lowerCamelCase.\n * \\`\"", "\"\\`: disallows the use of certain TypeScript keywords as variable or parameter names.\n * These are: ", ""])), OPTION_CHECK_FORMAT, OPTION_LEADING_UNDERSCORE, OPTION_TRAILING_UNDERSCORE, OPTION_ALLOW_PASCAL_CASE, OPTION_ALLOW_SNAKE_CASE, OPTION_BAN_KEYWORDS, bannedKeywordsStr),
optionsDescription: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n Six arguments may be optionally provided:\n\n * `\"", "\"`: allows only lowerCamelCased or UPPER_CASED variable names\n * `\"", "\"` allows underscores at the beginning (only has an effect if \"check-format\" specified)\n * `\"", "\"` allows underscores at the end. (only has an effect if \"check-format\" specified)\n * `\"", "\"`: enforces that all variables with UPPER_CASED names should be `const`.\n * `\"", "\"` allows PascalCase in addition to lowerCamelCase.\n * `\"", "\"` allows snake_case in addition to lowerCamelCase.\n * `\"", "\"`: disallows the use of certain TypeScript keywords as variable or parameter names.\n * These are: ", ""], ["\n Six arguments may be optionally provided:\n\n * \\`\"", "\"\\`: allows only lowerCamelCased or UPPER_CASED variable names\n * \\`\"", "\"\\` allows underscores at the beginning (only has an effect if \"check-format\" specified)\n * \\`\"", "\"\\` allows underscores at the end. (only has an effect if \"check-format\" specified)\n * \\`\"", "\"\\`: enforces that all variables with UPPER_CASED names should be \\`const\\`.\n * \\`\"", "\"\\` allows PascalCase in addition to lowerCamelCase.\n * \\`\"", "\"\\` allows snake_case in addition to lowerCamelCase.\n * \\`\"", "\"\\`: disallows the use of certain TypeScript keywords as variable or parameter names.\n * These are: ", ""])), OPTION_CHECK_FORMAT, OPTION_LEADING_UNDERSCORE, OPTION_TRAILING_UNDERSCORE, OPTION_REQUIRE_CONT_FOR_ALL_CAPS, OPTION_ALLOW_PASCAL_CASE, OPTION_ALLOW_SNAKE_CASE, OPTION_BAN_KEYWORDS, bannedKeywordsStr),
options: {

@@ -73,3 +74,3 @@ type: "array",

minLength: 0,
maxLength: 5,
maxLength: 6,
},

@@ -81,2 +82,3 @@ optionExamples: [[true, "ban-keywords", "check-format", "allow-leading-underscore"]],

Rule.KEYWORD_FAILURE = "variable name clashes with keyword/type";
Rule.FAILURE_STRING_CONST = "Only `const` variables may be UPPER_CASE.";
return Rule;

@@ -93,2 +95,3 @@ }(Lint.Rules.AbstractRule));

trailingUnderscore: hasOption(OPTION_TRAILING_UNDERSCORE),
allCapsForConst: hasOption(OPTION_REQUIRE_CONT_FOR_ALL_CAPS),
allowPascalCase: hasOption(OPTION_ALLOW_PASCAL_CASE),

@@ -120,3 +123,3 @@ allowSnakeCase: hasOption(OPTION_ALLOW_SNAKE_CASE),

// skip 'declare' keywords
if (tsutils_1.hasModifier(node.modifiers, ts.SyntaxKind.DeclareKeyword)) {
if (tsutils.hasModifier(node.modifiers, ts.SyntaxKind.DeclareKeyword)) {
return;

@@ -127,15 +130,19 @@ }

case ts.SyntaxKind.PropertyDeclaration:
case ts.SyntaxKind.VariableDeclaration: {
var _b = node, name = _b.name, initializer = _b.initializer;
if (name.kind === ts.SyntaxKind.Identifier) {
handleVariableNameFormat(name, initializer);
// do not check property declarations for keywords, they are allowed to be keywords
if (node.kind !== ts.SyntaxKind.PropertyDeclaration) {
handleVariableNameKeyword(name);
}
}
}
handleDeclaredVariable(node);
break;
case ts.SyntaxKind.VariableDeclaration:
handleVariableDeclaration(node);
}
return ts.forEachChild(node, cb);
});
function handleDeclaredVariable(node) {
var name = node.name, initializer = node.initializer;
if (name.kind === ts.SyntaxKind.Identifier) {
handleVariableNameFormat(name, initializer);
// do not check property declarations for keywords, they are allowed to be keywords
if (node.kind !== ts.SyntaxKind.PropertyDeclaration) {
handleVariableNameKeyword(name);
}
}
}
function handleVariableNameFormat(name, initializer) {

@@ -158,2 +165,13 @@ if (!options.checkFormat) {

}
function handleVariableDeclaration(node) {
handleDeclaredVariable(node);
if (!ctx.options.allCapsForConst || tsutils.isBindingPattern(node.name)) {
return;
}
var declarationList = node.parent;
var text = node.name.text;
if (utils_1.isUpperCase(text) && !tsutils.isNodeFlagSet(declarationList, ts.NodeFlags.Const)) {
ctx.addFailureAtNode(node, Rule.FAILURE_STRING_CONST);
}
}
function formatFailure() {

@@ -160,0 +178,0 @@ var failureMessage = "variable name must be in lowerCamelCase";

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

rationale: "Helps maintain a readable, consistent style in your codebase.",
optionsDescription: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n Ten arguments may be optionally provided:\n\n * `\"check-branch\"` checks branching statements (`if`/`else`/`for`/`while`) are followed by whitespace.\n * `\"check-decl\"`checks that variable declarations have whitespace around the equals token.\n * `\"check-operator\"` checks for whitespace around operator tokens.\n * `\"check-module\"` checks for whitespace in import & export statements.\n * `\"check-separator\"` checks for whitespace after separator tokens (`,`/`;`).\n * `\"check-rest-spread\"` checks that there is no whitespace after rest/spread operator (`...`).\n * `\"check-type\"` checks for whitespace before a variable type specification.\n * `\"check-typecast\"` checks for whitespace between a typecast and its target.\n * `\"check-type-operator\"` checks for whitespace between type operators `|` and `&`.\n * `\"check-preblock\"` checks for whitespace before the opening brace of a block.\n * `\"check-postbrace\"` checks for whitespace after an opening brace."], ["\n Ten arguments may be optionally provided:\n\n * \\`\"check-branch\"\\` checks branching statements (\\`if\\`/\\`else\\`/\\`for\\`/\\`while\\`) are followed by whitespace.\n * \\`\"check-decl\"\\`checks that variable declarations have whitespace around the equals token.\n * \\`\"check-operator\"\\` checks for whitespace around operator tokens.\n * \\`\"check-module\"\\` checks for whitespace in import & export statements.\n * \\`\"check-separator\"\\` checks for whitespace after separator tokens (\\`,\\`/\\`;\\`).\n * \\`\"check-rest-spread\"\\` checks that there is no whitespace after rest/spread operator (\\`...\\`).\n * \\`\"check-type\"\\` checks for whitespace before a variable type specification.\n * \\`\"check-typecast\"\\` checks for whitespace between a typecast and its target.\n * \\`\"check-type-operator\"\\` checks for whitespace between type operators \\`|\\` and \\`&\\`.\n * \\`\"check-preblock\"\\` checks for whitespace before the opening brace of a block.\n * \\`\"check-postbrace\"\\` checks for whitespace after an opening brace."]))),
optionsDescription: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n Several arguments may be optionally provided:\n\n * `\"check-branch\"` checks branching statements (`if`/`else`/`for`/`while`) are followed by whitespace.\n * `\"check-decl\"`checks that variable declarations have whitespace around the equals token.\n * `\"check-operator\"` checks for whitespace around operator tokens.\n * `\"check-module\"` checks for whitespace in import & export statements.\n * `\"check-separator\"` checks for whitespace after separator tokens (`,`/`;`).\n * `\"check-rest-spread\"` checks that there is no whitespace after rest/spread operator (`...`).\n * `\"check-type\"` checks for whitespace before a variable type specification.\n * `\"check-typecast\"` checks for whitespace between a typecast and its target.\n * `\"check-type-operator\"` checks for whitespace between type operators `|` and `&`.\n * `\"check-preblock\"` checks for whitespace before the opening brace of a block.\n * `\"check-postbrace\"` checks for whitespace after an opening brace."], ["\n Several arguments may be optionally provided:\n\n * \\`\"check-branch\"\\` checks branching statements (\\`if\\`/\\`else\\`/\\`for\\`/\\`while\\`) are followed by whitespace.\n * \\`\"check-decl\"\\`checks that variable declarations have whitespace around the equals token.\n * \\`\"check-operator\"\\` checks for whitespace around operator tokens.\n * \\`\"check-module\"\\` checks for whitespace in import & export statements.\n * \\`\"check-separator\"\\` checks for whitespace after separator tokens (\\`,\\`/\\`;\\`).\n * \\`\"check-rest-spread\"\\` checks that there is no whitespace after rest/spread operator (\\`...\\`).\n * \\`\"check-type\"\\` checks for whitespace before a variable type specification.\n * \\`\"check-typecast\"\\` checks for whitespace between a typecast and its target.\n * \\`\"check-type-operator\"\\` checks for whitespace between type operators \\`|\\` and \\`&\\`.\n * \\`\"check-preblock\"\\` checks for whitespace before the opening brace of a block.\n * \\`\"check-postbrace\"\\` checks for whitespace after an opening brace."]))),
options: {

@@ -138,2 +138,17 @@ type: "array",

break;
case ts.SyntaxKind.ExportDeclaration:
var exportClause_1 = node.exportClause;
if (options.module && exportClause_1 !== undefined) {
exportClause_1.elements.forEach(function (element, idx, arr) {
if (idx === arr.length - 1) {
var token = exportClause_1.getLastToken();
checkForTrailingWhitespace(token.getFullStart());
}
if (idx === 0) {
var startPos = element.getStart() - 1;
checkForTrailingWhitespace(startPos, startPos + 1);
}
});
}
break;
case ts.SyntaxKind.FunctionType:

@@ -140,0 +155,0 @@ checkEqualsGreaterThanTokenInNode(node);

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

var cwd = process.cwd();
return results.map(function (file) { return (outputAbsolutePaths ? path.resolve(cwd, file) : path.relative(cwd, file)); });
return results.map(function (file) {
return outputAbsolutePaths ? path.resolve(cwd, file) : path.relative(cwd, file);
});
}

@@ -166,0 +168,0 @@ function doLinting(options, files, program, logger) {

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

@@ -19,5 +19,6 @@ "bin": {

"compile:test": "tsc -p test",
"lint": "npm-run-all -p lint:global lint:from-bin",
"lint:global": "tslint --project test/tsconfig.json --format codeFrame",
"lint": "npm-run-all -p lint:from-installed lint:from-bin",
"lint:from-bin": "node bin/tslint --project test/tsconfig.json --format codeFrame",
"lint:from-installed": "tslint --project test/tsconfig.json --format codeFrame",
"lint-fix": "yarn lint:from-installed --fix",
"publish:local": "./scripts/npmPublish.sh",

@@ -44,3 +45,3 @@ "test": "npm-run-all test:pre -p test:mocha test:rules",

"tslib": "^1.8.0",
"tsutils": "^2.27.2"
"tsutils": "^2.29.0"
},

@@ -70,7 +71,7 @@ "peerDependencies": {

"nyc": "^10.2.0",
"prettier": "1.14.3",
"prettier": "~1.16.4",
"rimraf": "^2.5.4",
"ts-node": "^3.3.0",
"tslint": "~5.12.0",
"tslint-config-prettier": "^1.15.0",
"tslint": "~5.13.0",
"tslint-config-prettier": "^1.18.0",
"tslint-plugin-prettier": "^2.0.1",

@@ -77,0 +78,0 @@ "tslint-test-config-non-relative": "file:test/external/tslint-test-config-non-relative",

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