Initial commit (from f5274cbdce4ae7c9e4b937dcdf95ac70ae436d5f)

This commit is contained in:
anaarmas 2020-04-28 16:46:47 +02:00
commit 28ccc3db2d
13974 changed files with 2618436 additions and 0 deletions

View file

@ -0,0 +1,24 @@
/**
* @license
* Copyright 2013 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as ts from "typescript";
import * as Lint from "../index";
export declare class Rule extends Lint.Rules.AbstractRule {
static metadata: Lint.IRuleMetadata;
static FAILURE_STRING(name: string): string;
apply(sourceFile: ts.SourceFile): Lint.RuleFailure[];
}
export declare function getOverloadKey(node: ts.SignatureDeclaration): string | undefined;

View file

@ -0,0 +1,166 @@
"use strict";
/**
* @license
* Copyright 2013 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var _a;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var utils = require("tsutils");
var ts = require("typescript");
var Lint = require("../index");
var OPTION_IGNORE_ACCESSORS = "ignore-accessors";
var Rule = /** @class */ (function (_super) {
tslib_1.__extends(Rule, _super);
function Rule() {
return _super !== null && _super.apply(this, arguments) || this;
}
/* tslint:enable:object-literal-sort-keys */
Rule.FAILURE_STRING = function (name) {
return "All '" + name + "' signatures should be adjacent";
};
Rule.prototype.apply = function (sourceFile) {
// tslint:disable-next-line: no-object-literal-type-assertion
var rawOptions = tslib_1.__assign({}, this.ruleArguments[0]);
return this.applyWithFunction(sourceFile, walk, {
ignoreAccessors: !!rawOptions[OPTION_IGNORE_ACCESSORS],
});
};
/* tslint:disable:object-literal-sort-keys */
Rule.metadata = {
ruleName: "adjacent-overload-signatures",
description: "Enforces function overloads to be consecutive.",
optionsDescription: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n If `", "` is specified, then getters and setters are not considered to be overloads\n of function with the same signature."], ["\n If \\`", "\\` is specified, then getters and setters are not considered to be overloads\n of function with the same signature."])), OPTION_IGNORE_ACCESSORS),
options: {
type: "object",
properties: (_a = {},
_a[OPTION_IGNORE_ACCESSORS] = {
type: "boolean",
},
_a),
additionalProperties: false,
},
optionExamples: [true, [true, { OPTION_IGNORE_ACCESSORS: true }]],
rationale: "Improves readability and organization by grouping naturally related items together.",
type: "typescript",
typescriptOnly: true,
};
return Rule;
}(Lint.Rules.AbstractRule));
exports.Rule = Rule;
function walk(ctx) {
var sourceFile = ctx.sourceFile;
visitStatements(sourceFile.statements);
return ts.forEachChild(sourceFile, function cb(node) {
switch (node.kind) {
case ts.SyntaxKind.ModuleBlock:
visitStatements(node.statements);
break;
case ts.SyntaxKind.InterfaceDeclaration:
case ts.SyntaxKind.ClassDeclaration:
case ts.SyntaxKind.TypeLiteral: {
var members = node.members;
addFailures(getMisplacedOverloads(members, function (member) {
return utils.isSignatureDeclaration(member)
? getOverloadKey(member)
: undefined;
}, ctx.options.ignoreAccessors));
}
}
return ts.forEachChild(node, cb);
});
function visitStatements(statements) {
addFailures(getMisplacedOverloads(statements, function (statement) {
return utils.isFunctionDeclaration(statement) && statement.name !== undefined
? statement.name.text
: undefined;
}, ctx.options.ignoreAccessors));
}
function addFailures(misplacedOverloads) {
for (var _i = 0, misplacedOverloads_1 = misplacedOverloads; _i < misplacedOverloads_1.length; _i++) {
var node = misplacedOverloads_1[_i];
ctx.addFailureAtNode(node, Rule.FAILURE_STRING(printOverload(node)));
}
}
}
/** 'getOverloadName' may return undefined for nodes that cannot be overloads, e.g. a `const` declaration. */
function getMisplacedOverloads(overloads, getKey, ignoreAccessors) {
var result = [];
var lastKey;
var seen = new Set();
for (var _i = 0, overloads_1 = overloads; _i < overloads_1.length; _i++) {
var node = overloads_1[_i];
if (node.kind === ts.SyntaxKind.SemicolonClassElement ||
(ignoreAccessors && isAccessor(node))) {
continue;
}
var key = getKey(node);
if (key !== undefined) {
if (seen.has(key) && lastKey !== key) {
result.push(node);
}
seen.add(key);
lastKey = key;
}
else {
lastKey = undefined;
}
}
return result;
}
function isAccessor(member) {
return member.kind === ts.SyntaxKind.GetAccessor || member.kind === ts.SyntaxKind.SetAccessor;
}
function printOverload(node) {
var info = getOverloadInfo(node);
return typeof info === "string" ? info : info === undefined ? "<unknown>" : info.name;
}
function getOverloadKey(node) {
var info = getOverloadInfo(node);
if (info === undefined) {
return undefined;
}
var _a = typeof info === "string" ? [false, info] : [info.computed, info.name], computed = _a[0], name = _a[1];
var isStatic = utils.hasModifier(node.modifiers, ts.SyntaxKind.StaticKeyword);
return (computed ? "0" : "1") + (isStatic ? "0" : "1") + name;
}
exports.getOverloadKey = getOverloadKey;
function getOverloadInfo(node) {
switch (node.kind) {
case ts.SyntaxKind.ConstructSignature:
case ts.SyntaxKind.Constructor:
return "constructor";
case ts.SyntaxKind.CallSignature:
return "()";
default: {
var name = node.name;
if (name === undefined) {
return undefined;
}
switch (name.kind) {
case ts.SyntaxKind.Identifier:
return name.text;
case ts.SyntaxKind.ComputedPropertyName:
var expression = name.expression;
return utils.isLiteralExpression(expression)
? expression.text
: { name: expression.getText(), computed: true };
default:
return utils.isLiteralExpression(name) ? name.text : undefined;
}
}
}
}
var templateObject_1;

23
node_modules/tslint/lib/rules/alignRule.d.ts generated vendored Normal file
View file

@ -0,0 +1,23 @@
/**
* @license
* Copyright 2013 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as ts from "typescript";
import * as Lint from "../index";
export declare class Rule extends Lint.Rules.AbstractRule {
static metadata: Lint.IRuleMetadata;
static FAILURE_STRING_SUFFIX: string;
apply(sourceFile: ts.SourceFile): Lint.RuleFailure[];
}

192
node_modules/tslint/lib/rules/alignRule.js generated vendored Normal file
View file

@ -0,0 +1,192 @@
"use strict";
/**
* @license
* Copyright 2013 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var tsutils_1 = require("tsutils");
var ts = require("typescript");
var Lint = require("../index");
var OPTION_STATEMENTS = "statements";
var OPTION_MEMBERS = "members";
var OPTION_ELEMENTS = "elements";
var OPTION_PARAMETERS = "parameters";
var OPTION_ARGUMENTS = "arguments";
var Rule = /** @class */ (function (_super) {
tslib_1.__extends(Rule, _super);
function Rule() {
return _super !== null && _super.apply(this, arguments) || this;
}
Rule.prototype.apply = function (sourceFile) {
return this.applyWithWalker(new AlignWalker(sourceFile, this.ruleName, {
arguments: this.ruleArguments.indexOf(OPTION_ARGUMENTS) !== -1,
elements: this.ruleArguments.indexOf(OPTION_ELEMENTS) !== -1,
members: this.ruleArguments.indexOf(OPTION_MEMBERS) !== -1,
parameters: this.ruleArguments.indexOf(OPTION_PARAMETERS) !== -1,
statements: this.ruleArguments.indexOf(OPTION_STATEMENTS) !== -1,
}));
};
/* tslint:disable:object-literal-sort-keys */
Rule.metadata = {
ruleName: "align",
description: "Enforces vertical alignment.",
hasFix: true,
rationale: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n Helps maintain a readable, consistent style in your codebase.\n\n Consistent alignment for code statements helps keep code readable and clear.\n Statements misaligned from the standard can be harder to read and understand."], ["\n Helps maintain a readable, consistent style in your codebase.\n\n Consistent alignment for code statements helps keep code readable and clear.\n Statements misaligned from the standard can be harder to read and understand."]))),
optionsDescription: Lint.Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n Five arguments may be optionally provided:\n\n * `\"", "\"` checks alignment of function parameters.\n * `\"", "\"` checks alignment of function call arguments.\n * `\"", "\"` checks alignment of statements.\n * `\"", "\"` checks alignment of members of classes, interfaces, type literal, object literals and\n object destructuring.\n * `\"", "\"` checks alignment of elements of array literals, array destructuring and tuple types."], ["\n Five arguments may be optionally provided:\n\n * \\`\"", "\"\\` checks alignment of function parameters.\n * \\`\"", "\"\\` checks alignment of function call arguments.\n * \\`\"", "\"\\` checks alignment of statements.\n * \\`\"", "\"\\` checks alignment of members of classes, interfaces, type literal, object literals and\n object destructuring.\n * \\`\"", "\"\\` checks alignment of elements of array literals, array destructuring and tuple types."])), OPTION_PARAMETERS, OPTION_ARGUMENTS, OPTION_STATEMENTS, OPTION_MEMBERS, OPTION_ELEMENTS),
options: {
type: "array",
items: {
type: "string",
enum: [
OPTION_ARGUMENTS,
OPTION_ELEMENTS,
OPTION_MEMBERS,
OPTION_PARAMETERS,
OPTION_STATEMENTS,
],
},
minLength: 1,
maxLength: 5,
},
optionExamples: [[true, "parameters", "statements"]],
type: "formatting",
typescriptOnly: false,
};
/* tslint:enable:object-literal-sort-keys */
Rule.FAILURE_STRING_SUFFIX = " are not aligned";
return Rule;
}(Lint.Rules.AbstractRule));
exports.Rule = Rule;
var AlignWalker = /** @class */ (function (_super) {
tslib_1.__extends(AlignWalker, _super);
function AlignWalker() {
return _super !== null && _super.apply(this, arguments) || this;
}
AlignWalker.prototype.walk = function (sourceFile) {
var _this = this;
var cb = function (node) {
if (_this.options.statements && tsutils_1.isBlockLike(node)) {
_this.checkAlignment(node.statements.filter(function (s) { return s.kind !== ts.SyntaxKind.EmptyStatement; }), OPTION_STATEMENTS);
}
else {
switch (node.kind) {
case ts.SyntaxKind.NewExpression:
if (node.arguments === undefined) {
break;
}
// falls through
case ts.SyntaxKind.CallExpression:
if (_this.options.arguments) {
_this.checkAlignment(node.arguments, OPTION_ARGUMENTS);
}
break;
case ts.SyntaxKind.FunctionDeclaration:
case ts.SyntaxKind.FunctionExpression:
case ts.SyntaxKind.Constructor:
case ts.SyntaxKind.MethodDeclaration:
case ts.SyntaxKind.ArrowFunction:
case ts.SyntaxKind.CallSignature:
case ts.SyntaxKind.ConstructSignature:
case ts.SyntaxKind.MethodSignature:
case ts.SyntaxKind.FunctionType:
case ts.SyntaxKind.ConstructorType:
if (_this.options.parameters) {
_this.checkAlignment(node.parameters, OPTION_PARAMETERS);
}
break;
case ts.SyntaxKind.ArrayLiteralExpression:
case ts.SyntaxKind.ArrayBindingPattern:
if (_this.options.elements) {
_this.checkAlignment(node.elements, OPTION_ELEMENTS);
}
break;
case ts.SyntaxKind.TupleType:
if (_this.options.elements) {
_this.checkAlignment(node.elementTypes, OPTION_ELEMENTS);
}
break;
case ts.SyntaxKind.ObjectLiteralExpression:
if (_this.options.members) {
_this.checkAlignment(node.properties, OPTION_MEMBERS);
}
break;
case ts.SyntaxKind.ObjectBindingPattern:
if (_this.options.members) {
_this.checkAlignment(node.elements, OPTION_MEMBERS);
}
break;
case ts.SyntaxKind.ClassDeclaration:
case ts.SyntaxKind.ClassExpression:
if (_this.options.members) {
_this.checkAlignment(node.members.filter(function (m) { return m.kind !== ts.SyntaxKind.SemicolonClassElement; }), OPTION_MEMBERS);
}
break;
case ts.SyntaxKind.InterfaceDeclaration:
case ts.SyntaxKind.TypeLiteral:
if (_this.options.members) {
_this.checkAlignment(node.members, OPTION_MEMBERS);
}
}
}
return ts.forEachChild(node, cb);
};
return cb(sourceFile);
};
AlignWalker.prototype.checkAlignment = function (nodes, kind) {
if (nodes.length <= 1) {
return;
}
var sourceFile = this.sourceFile;
var pos = getLineAndCharacterWithoutBom(sourceFile, this.getStart(nodes[0]));
var alignToColumn = pos.character;
var line = pos.line;
// skip first node in list
for (var i = 1; i < nodes.length; ++i) {
var node = nodes[i];
var start = this.getStart(node);
pos = ts.getLineAndCharacterOfPosition(sourceFile, start);
if (line !== pos.line && pos.character !== alignToColumn) {
var diff = alignToColumn - pos.character;
var fix = void 0;
if (diff >= 0) {
fix = Lint.Replacement.appendText(start, " ".repeat(diff));
}
else if (node.pos <= start + diff &&
/^\s+$/.test(sourceFile.text.substring(start + diff, start))) {
// only delete text if there is only whitespace
fix = Lint.Replacement.deleteText(start + diff, -diff);
}
this.addFailure(start, Math.max(node.end, start), kind + Rule.FAILURE_STRING_SUFFIX, fix);
}
line = pos.line;
}
};
AlignWalker.prototype.getStart = function (node) {
return node.kind !== ts.SyntaxKind.OmittedExpression
? node.getStart(this.sourceFile)
: // find the comma token following the OmmitedExpression
tsutils_1.getNextToken(node, this.sourceFile).getStart(this.sourceFile);
};
return AlignWalker;
}(Lint.AbstractWalker));
function getLineAndCharacterWithoutBom(sourceFile, pos) {
var result = ts.getLineAndCharacterOfPosition(sourceFile, pos);
if (result.line === 0 && sourceFile.text[0] === "\uFEFF") {
result.character -= 1;
}
return result;
}
var templateObject_1, templateObject_2;

26
node_modules/tslint/lib/rules/arrayTypeRule.d.ts generated vendored Normal file
View file

@ -0,0 +1,26 @@
/**
* @license
* Copyright 2018 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as ts from "typescript";
import * as Lint from "../index";
export declare class Rule extends Lint.Rules.AbstractRule {
static metadata: Lint.IRuleMetadata;
static FAILURE_STRING_ARRAY: string;
static FAILURE_STRING_GENERIC: string;
static FAILURE_STRING_ARRAY_SIMPLE: string;
static FAILURE_STRING_GENERIC_SIMPLE: string;
apply(sourceFile: ts.SourceFile): Lint.RuleFailure[];
}

162
node_modules/tslint/lib/rules/arrayTypeRule.js generated vendored Normal file
View file

@ -0,0 +1,162 @@
"use strict";
/**
* @license
* Copyright 2018 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var ts = require("typescript");
var Lint = require("../index");
var OPTION_ARRAY = "array";
var OPTION_GENERIC = "generic";
var OPTION_ARRAY_SIMPLE = "array-simple";
var Rule = /** @class */ (function (_super) {
tslib_1.__extends(Rule, _super);
function Rule() {
return _super !== null && _super.apply(this, arguments) || this;
}
Rule.prototype.apply = function (sourceFile) {
return this.applyWithFunction(sourceFile, walk, this.ruleArguments[0]);
};
/* tslint:disable:object-literal-sort-keys */
Rule.metadata = {
ruleName: "array-type",
description: "Requires using either 'T[]' or 'Array<T>' for arrays.",
hasFix: true,
optionsDescription: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n One of the following arguments must be provided:\n\n * `\"", "\"` enforces use of `T[]` for all types T.\n * `\"", "\"` enforces use of `Array<T>` for all types T.\n * `\"", "\"` enforces use of `T[]` if `T` is a simple type (primitive or type reference)."], ["\n One of the following arguments must be provided:\n\n * \\`\"", "\"\\` enforces use of \\`T[]\\` for all types T.\n * \\`\"", "\"\\` enforces use of \\`Array<T>\\` for all types T.\n * \\`\"", "\"\\` enforces use of \\`T[]\\` if \\`T\\` is a simple type (primitive or type reference)."])), OPTION_ARRAY, OPTION_GENERIC, OPTION_ARRAY_SIMPLE),
options: {
type: "string",
enum: [OPTION_ARRAY, OPTION_GENERIC, OPTION_ARRAY_SIMPLE],
},
optionExamples: [[true, OPTION_ARRAY], [true, OPTION_GENERIC], [true, OPTION_ARRAY_SIMPLE]],
type: "style",
typescriptOnly: true,
};
/* tslint:enable:object-literal-sort-keys */
Rule.FAILURE_STRING_ARRAY = "Array type using 'Array<T>' is forbidden. Use 'T[]' instead.";
Rule.FAILURE_STRING_GENERIC = "Array type using 'T[]' is forbidden. Use 'Array<T>' instead.";
Rule.FAILURE_STRING_ARRAY_SIMPLE = "Array type using 'Array<T>' is forbidden for simple types. Use 'T[]' instead.";
Rule.FAILURE_STRING_GENERIC_SIMPLE = "Array type using 'T[]' is forbidden for non-simple types. Use 'Array<T>' instead.";
return Rule;
}(Lint.Rules.AbstractRule));
exports.Rule = Rule;
function walk(ctx) {
var sourceFile = ctx.sourceFile, option = ctx.options;
return ts.forEachChild(sourceFile, function cb(node) {
switch (node.kind) {
case ts.SyntaxKind.ArrayType:
checkArrayType(node);
break;
case ts.SyntaxKind.TypeReference:
checkTypeReference(node);
}
return ts.forEachChild(node, cb);
});
function checkArrayType(node) {
var elementType = node.elementType, parent = node.parent;
if (option === "array" || (option === "array-simple" && isSimpleType(elementType))) {
return;
}
var failureString = option === "generic" ? Rule.FAILURE_STRING_GENERIC : Rule.FAILURE_STRING_GENERIC_SIMPLE;
var parens = elementType.kind === ts.SyntaxKind.ParenthesizedType ? 1 : 0;
// Add a space if the type is preceded by 'as' and the node has no leading whitespace
var space = parens === 0 &&
parent.kind === ts.SyntaxKind.AsExpression &&
node.getStart() === node.getFullStart();
var fix = [
new Lint.Replacement(elementType.getStart(), parens, (space ? " " : "") + "Array<"),
// Delete the square brackets and replace with an angle bracket
Lint.Replacement.replaceFromTo(elementType.getEnd() - parens, node.getEnd(), ">"),
];
ctx.addFailureAtNode(node, failureString, fix);
}
function checkTypeReference(node) {
var typeName = node.typeName, typeArguments = node.typeArguments;
if (option === "generic" || !isArrayIdentifier(typeName)) {
return;
}
var failureString = option === "array" ? Rule.FAILURE_STRING_ARRAY : Rule.FAILURE_STRING_ARRAY_SIMPLE;
if (typeArguments === undefined || typeArguments.length === 0) {
// Create an 'any' array
ctx.addFailureAtNode(node, failureString, Lint.Replacement.replaceFromTo(node.getStart(), node.getEnd(), "any[]"));
return;
}
if (typeArguments.length !== 1 ||
(option === "array-simple" && !isSimpleType(typeArguments[0]))) {
return;
}
var type = typeArguments[0];
var parens = typeNeedsParentheses(type);
ctx.addFailureAtNode(node, failureString, [
// Delete 'Array<'
Lint.Replacement.replaceFromTo(node.getStart(), type.getStart(), parens ? "(" : ""),
// Delete '>' and replace with '[]
Lint.Replacement.replaceFromTo(type.getEnd(), node.getEnd(), parens ? ")[]" : "[]"),
]);
}
}
function typeNeedsParentheses(type) {
switch (type.kind) {
case ts.SyntaxKind.UnionType:
case ts.SyntaxKind.FunctionType:
case ts.SyntaxKind.IntersectionType:
case ts.SyntaxKind.TypeOperator:
return true;
default:
return false;
}
}
function isArrayIdentifier(name) {
return name.kind === ts.SyntaxKind.Identifier && name.text === "Array";
}
function isSimpleType(nodeType) {
switch (nodeType.kind) {
case ts.SyntaxKind.AnyKeyword:
case ts.SyntaxKind.ArrayType:
case ts.SyntaxKind.BooleanKeyword:
case ts.SyntaxKind.NullKeyword:
case ts.SyntaxKind.ObjectKeyword:
case ts.SyntaxKind.UndefinedKeyword:
case ts.SyntaxKind.NumberKeyword:
case ts.SyntaxKind.StringKeyword:
case ts.SyntaxKind.SymbolKeyword:
case ts.SyntaxKind.VoidKeyword:
case ts.SyntaxKind.NeverKeyword:
case ts.SyntaxKind.ThisType:
case ts.SyntaxKind.UnknownKeyword:
return true;
case ts.SyntaxKind.ParenthesizedType:
return isSimpleType(nodeType.type);
case ts.SyntaxKind.TypeReference:
// TypeReferences must be non-generic or be another Array with a simple type
var _a = nodeType, typeName = _a.typeName, typeArguments = _a.typeArguments;
if (typeArguments === undefined) {
return true;
}
switch (typeArguments.length) {
case 0:
return true;
case 1:
return (typeName.kind === ts.SyntaxKind.Identifier &&
typeName.text === "Array" &&
isSimpleType(typeArguments[0]));
default:
return false;
}
default:
return false;
}
}
var templateObject_1;

24
node_modules/tslint/lib/rules/arrowParensRule.d.ts generated vendored Normal file
View file

@ -0,0 +1,24 @@
/**
* @license
* Copyright 2018 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as ts from "typescript";
import * as Lint from "../index";
export declare class Rule extends Lint.Rules.AbstractRule {
static metadata: Lint.IRuleMetadata;
static FAILURE_STRING_MISSING: string;
static FAILURE_STRING_EXISTS: string;
apply(sourceFile: ts.SourceFile): Lint.RuleFailure[];
}

97
node_modules/tslint/lib/rules/arrowParensRule.js generated vendored Normal file
View file

@ -0,0 +1,97 @@
"use strict";
/**
* @license
* Copyright 2018 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var tsutils_1 = require("tsutils");
var ts = require("typescript");
var Lint = require("../index");
var BAN_SINGLE_ARG_PARENS = "ban-single-arg-parens";
var Rule = /** @class */ (function (_super) {
tslib_1.__extends(Rule, _super);
function Rule() {
return _super !== null && _super.apply(this, arguments) || this;
}
Rule.prototype.apply = function (sourceFile) {
return this.applyWithFunction(sourceFile, walk, {
banSingleArgParens: this.ruleArguments.indexOf(BAN_SINGLE_ARG_PARENS) !== -1,
});
};
/* tslint:disable:object-literal-sort-keys */
Rule.metadata = {
ruleName: "arrow-parens",
description: "Requires parentheses around the parameters of arrow function definitions.",
hasFix: true,
rationale: "Maintains stylistic consistency with other arrow function definitions.",
optionsDescription: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n If `", "` is specified, then arrow functions with one parameter\n must not have parentheses if removing them is allowed by TypeScript."], ["\n If \\`", "\\` is specified, then arrow functions with one parameter\n must not have parentheses if removing them is allowed by TypeScript."])), BAN_SINGLE_ARG_PARENS),
options: {
type: "string",
enum: [BAN_SINGLE_ARG_PARENS],
},
optionExamples: [true, [true, BAN_SINGLE_ARG_PARENS]],
type: "formatting",
typescriptOnly: false,
};
/* tslint:enable:object-literal-sort-keys */
Rule.FAILURE_STRING_MISSING = "Parentheses are required around the parameters of an arrow function definition";
Rule.FAILURE_STRING_EXISTS = "Parentheses are prohibited around the parameter in this single parameter arrow function";
return Rule;
}(Lint.Rules.AbstractRule));
exports.Rule = Rule;
function walk(ctx) {
function cb(node) {
if (tsutils_1.isArrowFunction(node) && parensAreOptional(node)) {
var openParen = tsutils_1.getChildOfKind(node, ts.SyntaxKind.OpenParenToken);
if (openParen === undefined) {
if (!ctx.options.banSingleArgParens) {
var parameter = node.parameters[0];
var start = parameter.getStart(ctx.sourceFile);
var end = parameter.end;
ctx.addFailure(start, end, Rule.FAILURE_STRING_MISSING, [
Lint.Replacement.appendText(start, "("),
Lint.Replacement.appendText(end, ")"),
]);
}
}
else if (ctx.options.banSingleArgParens) {
var closeParen = tsutils_1.getChildOfKind(node, ts.SyntaxKind.CloseParenToken);
var charBeforeOpenParen = ctx.sourceFile.text.substring(openParen.pos - 1, openParen.pos);
var replaceValue = charBeforeOpenParen.match(/[a-z]/i) !== null ? " " : "";
ctx.addFailureAtNode(node.parameters[0], Rule.FAILURE_STRING_EXISTS, [
Lint.Replacement.replaceFromTo(openParen.pos, node.parameters[0].getStart(ctx.sourceFile), replaceValue),
Lint.Replacement.deleteFromTo(node.parameters[0].end, closeParen.end),
]);
}
}
return ts.forEachChild(node, cb);
}
return ts.forEachChild(ctx.sourceFile, cb);
}
function parensAreOptional(node) {
return (node.parameters.length === 1 &&
node.typeParameters === undefined &&
node.type === undefined &&
isSimpleParameter(node.parameters[0]));
}
function isSimpleParameter(parameter) {
return (parameter.name.kind === ts.SyntaxKind.Identifier &&
parameter.dotDotDotToken === undefined &&
parameter.initializer === undefined &&
parameter.questionToken === undefined &&
parameter.type === undefined);
}
var templateObject_1;

View file

@ -0,0 +1,23 @@
/**
* @license
* Copyright 2017 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as ts from "typescript";
import * as Lint from "../index";
export declare class Rule extends Lint.Rules.AbstractRule {
static metadata: Lint.IRuleMetadata;
static FAILURE_STRING(isObjectLiteral: boolean): string;
apply(sourceFile: ts.SourceFile): Lint.RuleFailure[];
}

View file

@ -0,0 +1,115 @@
"use strict";
/**
* @license
* Copyright 2017 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var utils = require("tsutils");
var ts = require("typescript");
var Lint = require("../index");
var utils_1 = require("../language/utils");
var arrowReturnShorthand_examples_1 = require("./code-examples/arrowReturnShorthand.examples");
var OPTION_MULTILINE = "multiline";
var Rule = /** @class */ (function (_super) {
tslib_1.__extends(Rule, _super);
function Rule() {
return _super !== null && _super.apply(this, arguments) || this;
}
/* tslint:enable:object-literal-sort-keys */
Rule.FAILURE_STRING = function (isObjectLiteral) {
var start = "This arrow function body can be simplified by omitting the curly braces and the keyword 'return'";
return (start + (isObjectLiteral ? ", and wrapping the object literal in parentheses." : "."));
};
Rule.prototype.apply = function (sourceFile) {
return this.applyWithFunction(sourceFile, walk, {
multiline: this.ruleArguments.indexOf(OPTION_MULTILINE) !== -1,
});
};
/* tslint:disable:object-literal-sort-keys */
Rule.metadata = {
ruleName: "arrow-return-shorthand",
description: "Suggests to convert `() => { return x; }` to `() => x`.",
hasFix: true,
optionsDescription: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n If `", "` is specified, then this will warn even if the function spans multiple lines."], ["\n If \\`", "\\` is specified, then this will warn even if the function spans multiple lines."])), OPTION_MULTILINE),
options: {
type: "string",
enum: [OPTION_MULTILINE],
},
optionExamples: [true, [true, OPTION_MULTILINE]],
rationale: Lint.Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n It's unnecessary to include `return` and `{}` brackets in arrow lambdas.\n Leaving them out results in simpler and easier to read code.\n "], ["\n It's unnecessary to include \\`return\\` and \\`{}\\` brackets in arrow lambdas.\n Leaving them out results in simpler and easier to read code.\n "]))),
type: "style",
typescriptOnly: false,
codeExamples: arrowReturnShorthand_examples_1.codeExamples,
};
return Rule;
}(Lint.Rules.AbstractRule));
exports.Rule = Rule;
function walk(ctx) {
var sourceFile = ctx.sourceFile, multiline = ctx.options.multiline;
return ts.forEachChild(sourceFile, function cb(node) {
if (utils.isArrowFunction(node) && utils.isBlock(node.body)) {
var expr = getSimpleReturnExpression(node.body);
if (expr !== undefined &&
(multiline ||
utils.isSameLine(sourceFile, node.body.getStart(sourceFile), node.body.end))) {
var isObjectLiteral = expr.kind === ts.SyntaxKind.ObjectLiteralExpression;
ctx.addFailureAtNode(node.body, Rule.FAILURE_STRING(isObjectLiteral), createFix(node, node.body, expr, sourceFile.text));
}
}
return ts.forEachChild(node, cb);
});
}
function createFix(arrowFunction, body, expr, text) {
var statement = expr.parent;
var returnKeyword = utils.getChildOfKind(statement, ts.SyntaxKind.ReturnKeyword);
var arrow = utils.getChildOfKind(arrowFunction, ts.SyntaxKind.EqualsGreaterThanToken);
var openBrace = utils.getChildOfKind(body, ts.SyntaxKind.OpenBraceToken);
var closeBrace = utils.getChildOfKind(body, ts.SyntaxKind.CloseBraceToken);
var semicolon = utils.getChildOfKind(statement, ts.SyntaxKind.SemicolonToken);
var anyComments = hasComments(arrow) ||
hasComments(openBrace) ||
hasComments(statement) ||
hasComments(returnKeyword) ||
hasComments(expr) ||
(semicolon !== undefined && hasComments(semicolon)) ||
hasComments(closeBrace);
return anyComments
? undefined
: tslib_1.__spreadArrays((expr.kind === ts.SyntaxKind.ObjectLiteralExpression
? [
Lint.Replacement.appendText(expr.getStart(), "("),
Lint.Replacement.appendText(expr.getEnd(), ")"),
]
: []), [
// " {"
Lint.Replacement.deleteFromTo(arrow.end, openBrace.end),
// "return "
Lint.Replacement.deleteFromTo(statement.getStart(), expr.getStart()),
// " }" (may include semicolon)
Lint.Replacement.deleteFromTo(expr.end, closeBrace.end),
]);
function hasComments(node) {
return utils_1.hasCommentAfterPosition(text, node.getEnd());
}
}
/** Given `{ return x; }`, return `x`. */
function getSimpleReturnExpression(block) {
return block.statements.length === 1 &&
block.statements[0].kind === ts.SyntaxKind.ReturnStatement
? block.statements[0].expression
: undefined;
}
var templateObject_1, templateObject_2;

24
node_modules/tslint/lib/rules/awaitPromiseRule.d.ts generated vendored Normal file
View file

@ -0,0 +1,24 @@
/**
* @license
* Copyright 2017 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as ts from "typescript";
import * as Lint from "../index";
export declare class Rule extends Lint.Rules.TypedRule {
static metadata: Lint.IRuleMetadata;
static FAILURE_STRING: string;
static FAILURE_FOR_AWAIT_OF: string;
applyWithProgram(sourceFile: ts.SourceFile, program: ts.Program): Lint.RuleFailure[];
}

94
node_modules/tslint/lib/rules/awaitPromiseRule.js generated vendored Normal file
View file

@ -0,0 +1,94 @@
"use strict";
/**
* @license
* Copyright 2017 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var tsutils_1 = require("tsutils");
var ts = require("typescript");
var Lint = require("../index");
var Rule = /** @class */ (function (_super) {
tslib_1.__extends(Rule, _super);
function Rule() {
return _super !== null && _super.apply(this, arguments) || this;
}
Rule.prototype.applyWithProgram = function (sourceFile, program) {
var promiseTypes = new Set(tslib_1.__spreadArrays(["Promise"], this.ruleArguments));
return this.applyWithFunction(sourceFile, walk, promiseTypes, program.getTypeChecker());
};
/* tslint:disable:object-literal-sort-keys */
Rule.metadata = {
ruleName: "await-promise",
description: "Warns for an awaited value that is not a Promise.",
optionsDescription: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n A list of 'string' names of any additional classes that should also be treated as Promises.\n For example, if you are using a class called 'Future' that implements the Thenable interface,\n you might tell the rule to consider type references with the name 'Future' as valid Promise-like\n types. Note that this rule doesn't check for type assignability or compatibility; it just checks\n type reference names.\n "], ["\n A list of 'string' names of any additional classes that should also be treated as Promises.\n For example, if you are using a class called 'Future' that implements the Thenable interface,\n you might tell the rule to consider type references with the name 'Future' as valid Promise-like\n types. Note that this rule doesn't check for type assignability or compatibility; it just checks\n type reference names.\n "]))),
options: {
type: "list",
listType: {
type: "array",
items: { type: "string" },
},
},
optionExamples: [true, [true, "Thenable"]],
rationale: Lint.Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n While it is valid JavaScript to await a non-Promise-like value (it will resolve immediately),\n this pattern is often a programmer error and the resulting semantics can be unintuitive.\n\n Awaiting non-Promise-like values often is an indication of programmer error, such as\n forgetting to add parenthesis to call a function that returns a Promise.\n "], ["\n While it is valid JavaScript to await a non-Promise-like value (it will resolve immediately),\n this pattern is often a programmer error and the resulting semantics can be unintuitive.\n\n Awaiting non-Promise-like values often is an indication of programmer error, such as\n forgetting to add parenthesis to call a function that returns a Promise.\n "]))),
type: "functionality",
typescriptOnly: true,
requiresTypeInfo: true,
};
/* tslint:enable:object-literal-sort-keys */
Rule.FAILURE_STRING = "Invalid 'await' of a non-Promise value.";
Rule.FAILURE_FOR_AWAIT_OF = "Invalid 'for-await-of' of a non-AsyncIterable value.";
return Rule;
}(Lint.Rules.TypedRule));
exports.Rule = Rule;
function walk(ctx, tc) {
var promiseTypes = ctx.options;
return ts.forEachChild(ctx.sourceFile, cb);
function cb(node) {
if (tsutils_1.isAwaitExpression(node) &&
!containsType(tc.getTypeAtLocation(node.expression), isPromiseType)) {
ctx.addFailureAtNode(node, Rule.FAILURE_STRING);
}
else if (tsutils_1.isForOfStatement(node) &&
node.awaitModifier !== undefined &&
!containsType(tc.getTypeAtLocation(node.expression), isAsyncIterable)) {
ctx.addFailureAtNode(node.expression, Rule.FAILURE_FOR_AWAIT_OF);
}
return ts.forEachChild(node, cb);
}
function isPromiseType(name) {
return promiseTypes.has(name);
}
}
function containsType(type, predicate) {
if (tsutils_1.isTypeFlagSet(type, ts.TypeFlags.Any)) {
return true;
}
if (tsutils_1.isTypeReference(type)) {
type = type.target;
}
if (type.symbol !== undefined && predicate(type.symbol.name)) {
return true;
}
if (tsutils_1.isUnionOrIntersectionType(type)) {
return type.types.some(function (t) { return containsType(t, predicate); });
}
var bases = type.getBaseTypes();
return bases !== undefined && bases.some(function (t) { return containsType(t, predicate); });
}
function isAsyncIterable(name) {
return (name === "AsyncIterable" || name === "AsyncIterableIterator" || name === "AsyncGenerator");
}
var templateObject_1, templateObject_2;

View file

@ -0,0 +1,23 @@
/**
* @license
* Copyright 2017 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as ts from "typescript";
import * as Lint from "../index";
export declare class Rule extends Lint.Rules.AbstractRule {
static metadata: Lint.IRuleMetadata;
static FAILURE_STRING: string;
apply(sourceFile: ts.SourceFile): Lint.RuleFailure[];
}

63
node_modules/tslint/lib/rules/banCommaOperatorRule.js generated vendored Normal file
View file

@ -0,0 +1,63 @@
"use strict";
/**
* @license
* Copyright 2017 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var tsutils_1 = require("tsutils");
var ts = require("typescript");
var Lint = require("../index");
var Rule = /** @class */ (function (_super) {
tslib_1.__extends(Rule, _super);
function Rule() {
return _super !== null && _super.apply(this, arguments) || this;
}
Rule.prototype.apply = function (sourceFile) {
return this.applyWithFunction(sourceFile, walk);
};
/* tslint:disable:object-literal-sort-keys max-line-length */
Rule.metadata = {
ruleName: "ban-comma-operator",
description: "Disallows the comma operator to be used.",
descriptionDetails: "[Read more about the comma operator here](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comma_Operator).",
rationale: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n Using the comma operator can create a potential for many non-obvious bugs or lead to misunderstanding of code.\n\n ### Examples\n ```\n foo((bar, baz)); // evaluates to 'foo(baz)' because of the extra parens - confusing and not obvious\n ```\n\n ```\n switch (foo) {\n case 1, 2: // equals 'case 2' - probably intended 'case 1: case2:'\n return true;\n case 3:\n return false;\n }\n ```\n\n ```\n let x = (y = 1, z = 2); // x is equal to 2 - this may not be immediately obvious.\n ```\n "], ["\n Using the comma operator can create a potential for many non-obvious bugs or lead to misunderstanding of code.\n\n ### Examples\n \\`\\`\\`\n foo((bar, baz)); // evaluates to 'foo(baz)' because of the extra parens - confusing and not obvious\n \\`\\`\\`\n\n \\`\\`\\`\n switch (foo) {\n case 1, 2: // equals 'case 2' - probably intended 'case 1: case2:'\n return true;\n case 3:\n return false;\n }\n \\`\\`\\`\n\n \\`\\`\\`\n let x = (y = 1, z = 2); // x is equal to 2 - this may not be immediately obvious.\n \\`\\`\\`\n "]))),
options: null,
optionsDescription: "",
optionExamples: [true],
type: "functionality",
typescriptOnly: false,
};
/* tslint:enable:object-literal-sort-keys max-line-length */
Rule.FAILURE_STRING = "Do not use comma operator here because it can be easily misunderstood or lead to unintended bugs.";
return Rule;
}(Lint.Rules.AbstractRule));
exports.Rule = Rule;
function walk(ctx) {
return ts.forEachChild(ctx.sourceFile, function cb(node) {
if (tsutils_1.isBinaryExpression(node) &&
node.operatorToken.kind === ts.SyntaxKind.CommaToken &&
!isForLoopIncrementor(node)) {
ctx.addFailureAtNode(node, Rule.FAILURE_STRING);
}
return ts.forEachChild(node, cb);
});
}
function isForLoopIncrementor(node) {
var parent = node.parent;
return (parent.kind === ts.SyntaxKind.ForStatement &&
parent.incrementor === node);
}
var templateObject_1;

7
node_modules/tslint/lib/rules/banRule.d.ts generated vendored Normal file
View file

@ -0,0 +1,7 @@
import * as ts from "typescript";
import * as Lint from "../index";
export declare class Rule extends Lint.Rules.AbstractRule {
static metadata: Lint.IRuleMetadata;
static FAILURE_STRING_FACTORY(expression: string, messageAddition?: string): string;
apply(sourceFile: ts.SourceFile): Lint.RuleFailure[];
}

179
node_modules/tslint/lib/rules/banRule.js generated vendored Normal file
View file

@ -0,0 +1,179 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
/**
* @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.
*/
var tsutils_1 = require("tsutils");
var ts = require("typescript");
var Lint = require("../index");
var Rule = /** @class */ (function (_super) {
tslib_1.__extends(Rule, _super);
function Rule() {
return _super !== null && _super.apply(this, arguments) || this;
}
/* tslint:enable:object-literal-sort-keys */
Rule.FAILURE_STRING_FACTORY = function (expression, messageAddition) {
return "Calls to '" + expression + "' are not allowed." + (messageAddition !== undefined ? " " + messageAddition : "");
};
Rule.prototype.apply = function (sourceFile) {
return this.applyWithWalker(new BanFunctionWalker(sourceFile, this.ruleName, parseOptions(this.ruleArguments)));
};
/* tslint:disable:object-literal-sort-keys */
Rule.metadata = {
ruleName: "ban",
description: "Bans the use of specific functions or global methods.",
optionsDescription: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n A list of banned functions or methods in the following format:\n\n * banning functions:\n * just the name of the function: `\"functionName\"`\n * the name of the function in an array with one element: `[\"functionName\"]`\n * an object in the following format: `{\"name\": \"functionName\", \"message\": \"optional explanation message\"}`\n * banning methods:\n * an array with the object name, method name and optional message: `[\"objectName\", \"methodName\", \"optional message\"]`\n * an object in the following format: `{\"name\": [\"objectName\", \"methodName\"], \"message\": \"optional message\"}`\n * you can also ban deeply nested methods: `{\"name\": [\"foo\", \"bar\", \"baz\"]}` bans `foo.bar.baz()`\n * the first element can contain a wildcard (`*`) that matches everything. `{\"name\": [\"*\", \"forEach\"]}` bans `[].forEach(...)`, `$(...).forEach(...)`, `arr.forEach(...)`, etc.\n "], ["\n A list of banned functions or methods in the following format:\n\n * banning functions:\n * just the name of the function: \\`\"functionName\"\\`\n * the name of the function in an array with one element: \\`[\"functionName\"]\\`\n * an object in the following format: \\`{\"name\": \"functionName\", \"message\": \"optional explanation message\"}\\`\n * banning methods:\n * an array with the object name, method name and optional message: \\`[\"objectName\", \"methodName\", \"optional message\"]\\`\n * an object in the following format: \\`{\"name\": [\"objectName\", \"methodName\"], \"message\": \"optional message\"}\\`\n * you can also ban deeply nested methods: \\`{\"name\": [\"foo\", \"bar\", \"baz\"]}\\` bans \\`foo.bar.baz()\\`\n * the first element can contain a wildcard (\\`*\\`) that matches everything. \\`{\"name\": [\"*\", \"forEach\"]}\\` bans\\\n \\`[].forEach(...)\\`, \\`$(...).forEach(...)\\`, \\`arr.forEach(...)\\`, etc.\n "]))),
options: {
type: "list",
listType: {
anyOf: [
{
type: "string",
},
{
type: "array",
items: { type: "string" },
minLength: 1,
maxLength: 3,
},
{
type: "object",
properties: {
name: {
anyOf: [
{ type: "string" },
{ type: "array", items: { type: "string" }, minLength: 1 },
],
},
message: { type: "string" },
},
required: ["name"],
},
],
},
},
optionExamples: [
[
true,
"eval",
{ name: "$", message: "please don't" },
["describe", "only"],
{ name: ["it", "only"], message: "don't focus tests" },
{ name: ["chai", "assert", "equal"], message: "Use 'strictEqual' instead." },
{ name: ["*", "forEach"], message: "Use a regular for loop instead." },
{ name: ["*", "_id", "toString"], message: "Use 'toHexString' instead." },
],
],
type: "functionality",
typescriptOnly: false,
};
return Rule;
}(Lint.Rules.AbstractRule));
exports.Rule = Rule;
function parseOptions(args) {
var functions = [];
var methods = [];
for (var _i = 0, args_1 = args; _i < args_1.length; _i++) {
var arg = args_1[_i];
if (typeof arg === "string") {
functions.push({ name: arg });
}
else if (Array.isArray(arg)) {
switch (arg.length) {
case 0:
break;
case 1:
functions.push({ name: arg[0] });
break;
default:
methods.push({ object: [arg[0]], name: arg[1], message: arg[2] });
}
}
else if (!Array.isArray(arg.name)) {
functions.push(arg);
}
else {
switch (arg.name.length) {
case 0:
break;
case 1:
functions.push({ name: arg.name[0], message: arg.message });
break;
default:
methods.push({
message: arg.message,
name: arg.name[arg.name.length - 1],
object: arg.name.slice(0, -1),
});
}
}
}
return { functions: functions, methods: methods };
}
var BanFunctionWalker = /** @class */ (function (_super) {
tslib_1.__extends(BanFunctionWalker, _super);
function BanFunctionWalker() {
return _super !== null && _super.apply(this, arguments) || this;
}
BanFunctionWalker.prototype.walk = function (sourceFile) {
var _this = this;
var cb = function (node) {
if (tsutils_1.isCallExpression(node)) {
if (tsutils_1.isIdentifier(node.expression)) {
_this.checkFunctionBan(node.expression);
}
else if (tsutils_1.isPropertyAccessExpression(node.expression)) {
_this.checkForObjectMethodBan(node.expression);
}
}
return ts.forEachChild(node, cb);
};
return ts.forEachChild(sourceFile, cb);
};
BanFunctionWalker.prototype.checkForObjectMethodBan = function (expression) {
outer: for (var _i = 0, _a = this.options.methods; _i < _a.length; _i++) {
var ban = _a[_i];
if (expression.name.text !== ban.name) {
continue;
}
var current = expression.expression;
for (var i = ban.object.length - 1; i > 0; --i) {
if (!tsutils_1.isPropertyAccessExpression(current) || current.name.text !== ban.object[i]) {
continue outer;
}
current = current.expression;
}
if (ban.object[0] === "*" ||
(tsutils_1.isIdentifier(current) && current.text === ban.object[0])) {
this.addFailureAtNode(expression, Rule.FAILURE_STRING_FACTORY(ban.object.join(".") + "." + ban.name, ban.message));
break;
}
}
};
BanFunctionWalker.prototype.checkFunctionBan = function (name) {
var text = name.text;
for (var _i = 0, _a = this.options.functions; _i < _a.length; _i++) {
var ban = _a[_i];
if (ban.name === text) {
this.addFailureAtNode(name, Rule.FAILURE_STRING_FACTORY(text, ban.message));
break;
}
}
};
return BanFunctionWalker;
}(Lint.AbstractWalker));
var templateObject_1;

23
node_modules/tslint/lib/rules/banTsIgnoreRule.d.ts generated vendored Normal file
View file

@ -0,0 +1,23 @@
/**
* @license
* Copyright 2018 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as ts from "typescript";
import * as Lint from "../index";
export declare class Rule extends Lint.Rules.AbstractRule {
static metadata: Lint.IRuleMetadata;
static FAILURE_STRING: string;
apply(sourceFile: ts.SourceFile): Lint.RuleFailure[];
}

55
node_modules/tslint/lib/rules/banTsIgnoreRule.js generated vendored Normal file
View file

@ -0,0 +1,55 @@
"use strict";
/**
* @license
* Copyright 2018 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var tsutils_1 = require("tsutils");
var Lint = require("../index");
var banTsIgnore_examples_1 = require("./code-examples/banTsIgnore.examples");
var Rule = /** @class */ (function (_super) {
tslib_1.__extends(Rule, _super);
function Rule() {
return _super !== null && _super.apply(this, arguments) || this;
}
Rule.prototype.apply = function (sourceFile) {
return this.applyWithFunction(sourceFile, walk);
};
/* tslint:disable:object-literal-sort-keys */
Rule.metadata = {
ruleName: "ban-ts-ignore",
description: 'Bans "// @ts-ignore" comments from being used.',
optionsDescription: "Not configurable.",
options: null,
optionExamples: [true],
type: "typescript",
typescriptOnly: true,
codeExamples: banTsIgnore_examples_1.codeExamples,
};
/* tslint:disable:object-literal-sort-keys */
Rule.FAILURE_STRING = 'Do not use "// @ts-ignore" comments because they suppress compilation errors.';
return Rule;
}(Lint.Rules.AbstractRule));
exports.Rule = Rule;
function walk(ctx) {
var ignoreDiagnosticCommentRegEx = /^\s*\/\/\/?\s*@ts-ignore/;
tsutils_1.forEachComment(ctx.sourceFile, function (fullText, comment) {
var commentText = fullText.slice(comment.pos, comment.end);
if (Boolean(commentText.match(ignoreDiagnosticCommentRegEx))) {
ctx.addFailure(comment.pos, comment.end, Rule.FAILURE_STRING);
}
});
}

23
node_modules/tslint/lib/rules/banTypesRule.d.ts generated vendored Normal file
View file

@ -0,0 +1,23 @@
/**
* @license
* Copyright 2017 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as ts from "typescript";
import * as Lint from "../index";
export declare class Rule extends Lint.Rules.AbstractRule {
static metadata: Lint.IRuleMetadata;
static FAILURE_STRING_FACTORY(typeName: string, messageAddition?: string): string;
apply(sourceFile: ts.SourceFile): Lint.RuleFailure[];
}

75
node_modules/tslint/lib/rules/banTypesRule.js generated vendored Normal file
View file

@ -0,0 +1,75 @@
"use strict";
/**
* @license
* Copyright 2017 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var tsutils_1 = require("tsutils");
var ts = require("typescript");
var Lint = require("../index");
var Rule = /** @class */ (function (_super) {
tslib_1.__extends(Rule, _super);
function Rule() {
return _super !== null && _super.apply(this, arguments) || this;
}
/* tslint:enable:object-literal-sort-keys */
Rule.FAILURE_STRING_FACTORY = function (typeName, messageAddition) {
return "Don't use '" + typeName + "' as a type." + (messageAddition !== undefined ? " " + messageAddition : "");
};
Rule.prototype.apply = function (sourceFile) {
return this.applyWithFunction(sourceFile, walk, this.ruleArguments.map(parseOption));
};
/* tslint:disable:object-literal-sort-keys */
Rule.metadata = {
ruleName: "ban-types",
description: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n Bans specific types from being used. Does not ban the\n corresponding runtime objects from being used."], ["\n Bans specific types from being used. Does not ban the\n corresponding runtime objects from being used."]))),
options: {
type: "list",
listType: {
type: "array",
items: { type: "string" },
minLength: 1,
maxLength: 2,
},
},
optionsDescription: Lint.Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n A list of `[\"regex\", \"optional explanation here\"]`, which bans\n types that match `regex`"], ["\n A list of \\`[\"regex\", \"optional explanation here\"]\\`, which bans\n types that match \\`regex\\`"]))),
optionExamples: [[true, ["Object", "Use {} instead."], ["String"]]],
type: "typescript",
typescriptOnly: true,
};
return Rule;
}(Lint.Rules.AbstractRule));
exports.Rule = Rule;
function parseOption(_a) {
var pattern = _a[0], message = _a[1];
return { message: message, pattern: new RegExp("^" + pattern + "$") };
}
function walk(ctx) {
return ts.forEachChild(ctx.sourceFile, function cb(node) {
if (tsutils_1.isTypeReferenceNode(node)) {
var typeName = node.getText(ctx.sourceFile);
for (var _i = 0, _a = ctx.options; _i < _a.length; _i++) {
var ban = _a[_i];
if (ban.pattern.test(typeName)) {
ctx.addFailureAtNode(node, Rule.FAILURE_STRING_FACTORY(typeName, ban.message));
break;
}
}
}
return ts.forEachChild(node, cb);
});
}
var templateObject_1, templateObject_2;

View file

@ -0,0 +1,23 @@
/**
* @license
* Copyright 2017 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as ts from "typescript";
import * as Lint from "../index";
export declare class Rule extends Lint.Rules.AbstractRule {
static metadata: Lint.IRuleMetadata;
static FAILURE_STRING: string;
apply(sourceFile: ts.SourceFile): Lint.RuleFailure[];
}

View file

@ -0,0 +1,97 @@
"use strict";
/**
* @license
* Copyright 2017 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var tsutils_1 = require("tsutils");
var ts = require("typescript");
var Lint = require("../index");
var utils_1 = require("../language/utils");
var Rule = /** @class */ (function (_super) {
tslib_1.__extends(Rule, _super);
function Rule() {
return _super !== null && _super.apply(this, arguments) || this;
}
Rule.prototype.apply = function (sourceFile) {
return this.applyWithFunction(sourceFile, walk);
};
/* tslint:disable:object-literal-sort-keys */
Rule.metadata = {
ruleName: "binary-expression-operand-order",
description: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n In a binary expression, a literal should always be on the right-hand side if possible.\n For example, prefer 'x + 1' over '1 + x'."], ["\n In a binary expression, a literal should always be on the right-hand side if possible.\n For example, prefer 'x + 1' over '1 + x'."]))),
optionsDescription: "Not configurable.",
options: null,
optionExamples: [true],
rationale: Lint.Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n Expressions like `1 + x` are sometimes referred to as \"Yoda\" expressions because they read\n opposite to how we would normally speak the expression.\n\n Sticking to a consistent grammar for conditions helps keep code readable and understandable.\n "], ["\n Expressions like \\`1 + x\\` are sometimes referred to as \"Yoda\" expressions because they read\n opposite to how we would normally speak the expression.\n\n Sticking to a consistent grammar for conditions helps keep code readable and understandable.\n "]))),
type: "style",
typescriptOnly: false,
};
/* tslint:enable:object-literal-sort-keys */
Rule.FAILURE_STRING = "Literal expression should be on the right-hand side of a binary expression.";
return Rule;
}(Lint.Rules.AbstractRule));
exports.Rule = Rule;
function walk(ctx) {
ts.forEachChild(ctx.sourceFile, function cb(node) {
if (tsutils_1.isBinaryExpression(node) &&
isLiteral(node.left) &&
!isLiteral(node.right) &&
!isAllowedOrderedOperator(node)) {
ctx.addFailureAtNode(node, Rule.FAILURE_STRING);
}
ts.forEachChild(node, cb);
});
}
/** Allows certain inherently ordered operators that can't easily be written with the literal on the right. */
function isAllowedOrderedOperator(node) {
switch (node.operatorToken.kind) {
case ts.SyntaxKind.PlusToken:
// Allow `"foo" + x` but not `1 + x`.
return node.left.kind === ts.SyntaxKind.StringLiteral;
case ts.SyntaxKind.MinusToken:
case ts.SyntaxKind.SlashToken:
case ts.SyntaxKind.PercentToken:
case ts.SyntaxKind.LessThanLessThanToken:
case ts.SyntaxKind.GreaterThanGreaterThanToken:
case ts.SyntaxKind.GreaterThanGreaterThanGreaterThanToken:
case ts.SyntaxKind.AsteriskAsteriskToken:
case ts.SyntaxKind.InKeyword:
case ts.SyntaxKind.CommaToken:
return true;
default:
return false;
}
}
function isLiteral(node) {
switch (node.kind) {
case ts.SyntaxKind.StringLiteral:
case ts.SyntaxKind.NumericLiteral:
case ts.SyntaxKind.TrueKeyword:
case ts.SyntaxKind.FalseKeyword:
case ts.SyntaxKind.NullKeyword:
return true;
case ts.SyntaxKind.Identifier:
return node.originalKeywordKind === ts.SyntaxKind.UndefinedKeyword;
case ts.SyntaxKind.PrefixUnaryExpression:
return utils_1.isNegativeNumberLiteral(node);
case ts.SyntaxKind.ParenthesizedExpression:
return isLiteral(node.expression);
default:
return false;
}
}
var templateObject_1, templateObject_2;

23
node_modules/tslint/lib/rules/callableTypesRule.d.ts generated vendored Normal file
View file

@ -0,0 +1,23 @@
/**
* @license
* Copyright 2013 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as ts from "typescript";
import * as Lint from "../index";
export declare class Rule extends Lint.Rules.AbstractRule {
static metadata: Lint.IRuleMetadata;
static FAILURE_STRING_FACTORY(type: string, sigSuggestion: string): string;
apply(sourceFile: ts.SourceFile): Lint.RuleFailure[];
}

105
node_modules/tslint/lib/rules/callableTypesRule.js generated vendored Normal file
View file

@ -0,0 +1,105 @@
"use strict";
/**
* @license
* Copyright 2013 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var tsutils_1 = require("tsutils");
var ts = require("typescript");
var Lint = require("../index");
var Rule = /** @class */ (function (_super) {
tslib_1.__extends(Rule, _super);
function Rule() {
return _super !== null && _super.apply(this, arguments) || this;
}
/* tslint:enable:object-literal-sort-keys */
Rule.FAILURE_STRING_FACTORY = function (type, sigSuggestion) {
return type + " has only a call signature \u2014 use `" + sigSuggestion + "` instead.";
};
Rule.prototype.apply = function (sourceFile) {
return this.applyWithFunction(sourceFile, walk);
};
/* tslint:disable:object-literal-sort-keys */
Rule.metadata = {
ruleName: "callable-types",
description: "An interface or literal type with just a call signature can be written as a function type.",
rationale: "style",
optionsDescription: "Not configurable.",
options: null,
type: "style",
typescriptOnly: true,
hasFix: true,
};
return Rule;
}(Lint.Rules.AbstractRule));
exports.Rule = Rule;
function walk(ctx) {
return ts.forEachChild(ctx.sourceFile, function cb(node) {
if (((tsutils_1.isInterfaceDeclaration(node) && noSupertype(node)) || tsutils_1.isTypeLiteralNode(node)) &&
node.members.length === 1) {
var member = node.members[0];
if ((tsutils_1.isConstructSignatureDeclaration(member) || tsutils_1.isCallSignatureDeclaration(member)) &&
// avoid bad parse
member.type !== undefined) {
var suggestion = renderSuggestion(member, node, ctx.sourceFile);
var fixStart = node.kind === ts.SyntaxKind.TypeLiteral
? node.getStart(ctx.sourceFile)
: tsutils_1.getChildOfKind(node, ts.SyntaxKind.InterfaceKeyword).getStart(ctx.sourceFile);
ctx.addFailureAtNode(member, Rule.FAILURE_STRING_FACTORY(node.kind === ts.SyntaxKind.TypeLiteral ? "Type literal" : "Interface", suggestion), Lint.Replacement.replaceFromTo(fixStart, node.end, suggestion));
}
}
return ts.forEachChild(node, cb);
});
}
/** True if there is no supertype or if the supertype is `Function`. */
function noSupertype(node) {
if (node.heritageClauses === undefined) {
return true;
}
if (node.heritageClauses.length !== 1) {
return false;
}
var expr = node.heritageClauses[0].types[0].expression;
return tsutils_1.isIdentifier(expr) && expr.text === "Function";
}
function renderSuggestion(call, parent, sourceFile) {
var start = call.getStart(sourceFile);
var colonPos = call.type.pos - 1 - start;
var text = sourceFile.text.substring(start, call.end);
var suggestion = text.substr(0, colonPos) + " =>" + text.substr(colonPos + 1);
if (shouldWrapSuggestion(parent.parent)) {
suggestion = "(" + suggestion + ")";
}
if (parent.kind === ts.SyntaxKind.InterfaceDeclaration) {
if (parent.typeParameters !== undefined) {
return "type" + sourceFile.text.substring(parent.name.pos, parent.typeParameters.end + 1) + " = " + suggestion;
}
else {
return "type " + parent.name.text + " = " + suggestion;
}
}
return suggestion.endsWith(";") ? suggestion.slice(0, -1) : suggestion;
}
function shouldWrapSuggestion(parent) {
switch (parent.kind) {
case ts.SyntaxKind.UnionType:
case ts.SyntaxKind.IntersectionType:
case ts.SyntaxKind.ArrayType:
return true;
default:
return false;
}
}

23
node_modules/tslint/lib/rules/classNameRule.d.ts generated vendored Normal file
View file

@ -0,0 +1,23 @@
/**
* @license
* Copyright 2013 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as ts from "typescript";
import * as Lint from "../index";
export declare class Rule extends Lint.Rules.AbstractRule {
static metadata: Lint.IRuleMetadata;
static FAILURE_STRING: string;
apply(sourceFile: ts.SourceFile): Lint.RuleFailure[];
}

61
node_modules/tslint/lib/rules/classNameRule.js generated vendored Normal file
View file

@ -0,0 +1,61 @@
"use strict";
/**
* @license
* Copyright 2013 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var tsutils_1 = require("tsutils");
var ts = require("typescript");
var Lint = require("../index");
var utils_1 = require("../utils");
var className_examples_1 = require("./code-examples/className.examples");
var Rule = /** @class */ (function (_super) {
tslib_1.__extends(Rule, _super);
function Rule() {
return _super !== null && _super.apply(this, arguments) || this;
}
Rule.prototype.apply = function (sourceFile) {
return this.applyWithFunction(sourceFile, walk);
};
/* tslint:disable:object-literal-sort-keys */
Rule.metadata = {
ruleName: "class-name",
description: "Enforces PascalCased class and interface names.",
rationale: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n Makes it easy to differentiate classes from regular variables at a glance.\n\n JavaScript and general programming convention is to refer to classes in PascalCase.\n It's confusing to use camelCase or other conventions for class names.\n "], ["\n Makes it easy to differentiate classes from regular variables at a glance.\n\n JavaScript and general programming convention is to refer to classes in PascalCase.\n It's confusing to use camelCase or other conventions for class names.\n "]))),
optionsDescription: "Not configurable.",
options: null,
optionExamples: [true],
type: "style",
typescriptOnly: false,
codeExamples: className_examples_1.codeExamples,
};
/* tslint:enable:object-literal-sort-keys */
Rule.FAILURE_STRING = "Class name must be in pascal case";
return Rule;
}(Lint.Rules.AbstractRule));
exports.Rule = Rule;
function walk(ctx) {
return ts.forEachChild(ctx.sourceFile, function cb(node) {
if ((tsutils_1.isClassLikeDeclaration(node) && node.name !== undefined) ||
tsutils_1.isInterfaceDeclaration(node)) {
if (!utils_1.isPascalCased(node.name.text)) {
ctx.addFailureAtNode(node.name, Rule.FAILURE_STRING);
}
}
return ts.forEachChild(node, cb);
});
}
var templateObject_1;

View file

@ -0,0 +1,22 @@
/**
* @license
* Copyright 2018 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export declare const codeExamples: {
description: string;
config: string;
pass: string;
fail: string;
}[];

View file

@ -0,0 +1,36 @@
"use strict";
/**
* @license
* Copyright 2018 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var Lint = require("../../index");
// tslint:disable: object-literal-sort-keys
exports.codeExamples = [
{
description: "Enforces usage of the shorthand return syntax when an arrow function's body does not span multiple lines.",
config: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n \"rules\": { \"arrow-return-shorthand\": true }\n "], ["\n \"rules\": { \"arrow-return-shorthand\": true }\n "]))),
pass: Lint.Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n const calc = (x: number, y: number) => ({ add: x + y, sub: x - y, mul: x * y });\n const calc2 = (x: number, y: number) => {\n return { add: x + y, sub: x - y, mul: x * y }\n };\n "], ["\n const calc = (x: number, y: number) => ({ add: x + y, sub: x - y, mul: x * y });\n const calc2 = (x: number, y: number) => {\n return { add: x + y, sub: x - y, mul: x * y }\n };\n "]))),
fail: Lint.Utils.dedent(templateObject_3 || (templateObject_3 = tslib_1.__makeTemplateObject(["\n const calc = (x: number, y: number) => { return { add: x + y, sub: x - y, mul: x * y } };\n const calc2 = (x: number, y: number) => {\n return { add: x + y, sub: x - y, mul: x * y }\n };\n "], ["\n const calc = (x: number, y: number) => { return { add: x + y, sub: x - y, mul: x * y } };\n const calc2 = (x: number, y: number) => {\n return { add: x + y, sub: x - y, mul: x * y }\n };\n "]))),
},
{
description: "Enforces usage of the shorthand return syntax even when an arrow function's body spans multiple lines.",
config: Lint.Utils.dedent(templateObject_4 || (templateObject_4 = tslib_1.__makeTemplateObject(["\n \"rules\": { \"arrow-return-shorthand\": [true, \"multiline\"] }\n "], ["\n \"rules\": { \"arrow-return-shorthand\": [true, \"multiline\"] }\n "]))),
pass: Lint.Utils.dedent(templateObject_5 || (templateObject_5 = tslib_1.__makeTemplateObject(["\n const calc = (x: number, y: number) => ({ add: x + y, sub: x - y, mul: x * y });\n const calc2 = (x: number, y: number) =>\n ({ add: x + y, sub: x - y, mul: x * y });\n "], ["\n const calc = (x: number, y: number) => ({ add: x + y, sub: x - y, mul: x * y });\n const calc2 = (x: number, y: number) =>\n ({ add: x + y, sub: x - y, mul: x * y });\n "]))),
fail: Lint.Utils.dedent(templateObject_6 || (templateObject_6 = tslib_1.__makeTemplateObject(["\n const calc = (x: number, y: number) => { return { add: x + y, sub: x - y, mul: x * y } };\n const calc2 = (x: number, y: number) => {\n return { add: x + y, sub: x - y, mul: x * y }\n };\n "], ["\n const calc = (x: number, y: number) => { return { add: x + y, sub: x - y, mul: x * y } };\n const calc2 = (x: number, y: number) => {\n return { add: x + y, sub: x - y, mul: x * y }\n };\n "]))),
},
];
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6;

View file

@ -0,0 +1,22 @@
/**
* @license
* Copyright 2018 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export declare const codeExamples: {
description: string;
config: string;
pass: string;
fail: string;
}[];

View file

@ -0,0 +1,30 @@
"use strict";
/**
* @license
* Copyright 2018 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var Lint = require("../../index");
// tslint:disable: object-literal-sort-keys
exports.codeExamples = [
{
description: 'Disallows the use of "@ts-ignore"',
config: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n \"rules\": { \"ban-ts-ignore\": true }\n "], ["\n \"rules\": { \"ban-ts-ignore\": true }\n "]))),
pass: Lint.Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n if (false) {\n // Compiler warns about unreachable code error\n console.log(\"hello\");\n }\n "], ["\n if (false) {\n // Compiler warns about unreachable code error\n console.log(\"hello\");\n }\n "]))),
fail: Lint.Utils.dedent(templateObject_3 || (templateObject_3 = tslib_1.__makeTemplateObject(["\n if (false) {\n // @ts-ignore: Unreachable code error\n console.log(\"hello\");\n }\n "], ["\n if (false) {\n // @ts-ignore: Unreachable code error\n console.log(\"hello\");\n }\n "]))),
},
];
var templateObject_1, templateObject_2, templateObject_3;

View file

@ -0,0 +1,22 @@
/**
* @license
* Copyright 2018 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export declare const codeExamples: {
description: string;
config: string;
pass: string;
fail: string;
}[];

View file

@ -0,0 +1,30 @@
"use strict";
/**
* @license
* Copyright 2018 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var Lint = require("../../index");
// tslint:disable: object-literal-sort-keys
exports.codeExamples = [
{
description: "Enforces PascalCased class and interface names.",
config: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n \"rules\": { \"class-name\": true }\n "], ["\n \"rules\": { \"class-name\": true }\n "]))),
pass: Lint.Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n class MyClass { }\n interface MyInterface { }\n "], ["\n class MyClass { }\n interface MyInterface { }\n "]))),
fail: Lint.Utils.dedent(templateObject_3 || (templateObject_3 = tslib_1.__makeTemplateObject(["\n class myClass { }\n interface myInterface { }\n "], ["\n class myClass { }\n interface myInterface { }\n "]))),
},
];
var templateObject_1, templateObject_2, templateObject_3;

View file

@ -0,0 +1,22 @@
/**
* @license
* Copyright 2013 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export declare const codeExamples: {
description: string;
config: string;
pass: string;
fail: string;
}[];

View file

@ -0,0 +1,42 @@
"use strict";
/**
* @license
* Copyright 2013 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var Lint = require("../../index");
// tslint:disable: object-literal-sort-keys
exports.codeExamples = [
{
description: "Require curly braces whenever possible (default)",
config: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n \"rules\": { \"curly\": true }\n "], ["\n \"rules\": { \"curly\": true }\n "]))),
pass: Lint.Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n if (x > 0) {\n doStuff();\n }\n "], ["\n if (x > 0) {\n doStuff();\n }\n "]))),
fail: Lint.Utils.dedent(templateObject_3 || (templateObject_3 = tslib_1.__makeTemplateObject(["\n if (x > 0)\n doStuff();\n\n if (x > 0) doStuff();\n "], ["\n if (x > 0)\n doStuff();\n\n if (x > 0) doStuff();\n "]))),
},
{
description: "Make an exception for single-line instances",
config: Lint.Utils.dedent(templateObject_4 || (templateObject_4 = tslib_1.__makeTemplateObject(["\n \"rules\": { \"curly\": [true, \"ignore-same-line\"] }\n "], ["\n \"rules\": { \"curly\": [true, \"ignore-same-line\"] }\n "]))),
pass: Lint.Utils.dedent(templateObject_5 || (templateObject_5 = tslib_1.__makeTemplateObject(["\n if (x > 0) doStuff();\n "], ["\n if (x > 0) doStuff();\n "]))),
fail: Lint.Utils.dedent(templateObject_6 || (templateObject_6 = tslib_1.__makeTemplateObject(["\n if (x > 0)\n doStuff()\n "], ["\n if (x > 0)\n doStuff()\n "]))),
},
{
description: "Error on unnecessary curly braces",
config: Lint.Utils.dedent(templateObject_7 || (templateObject_7 = tslib_1.__makeTemplateObject(["\n \"rules\": { \"curly\": [true, \"as-needed\"] }\n "], ["\n \"rules\": { \"curly\": [true, \"as-needed\"] }\n "]))),
pass: Lint.Utils.dedent(templateObject_8 || (templateObject_8 = tslib_1.__makeTemplateObject(["\n if (x > 0)\n doStuff();\n\n if (x > 0) {\n customerUpdates.push(getInfo(customerId));\n return customerUpdates;\n }\n "], ["\n if (x > 0)\n doStuff();\n\n if (x > 0) {\n customerUpdates.push(getInfo(customerId));\n return customerUpdates;\n }\n "]))),
fail: Lint.Utils.dedent(templateObject_9 || (templateObject_9 = tslib_1.__makeTemplateObject(["\n if (x > 0) {\n doStuff();\n }\n "], ["\n if (x > 0) {\n doStuff();\n }\n "]))),
},
];
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8, templateObject_9;

View file

@ -0,0 +1,22 @@
/**
* @license
* Copyright 2013 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export declare const codeExamples: {
config: string;
description: string;
fail: string;
pass: string;
}[];

View file

@ -0,0 +1,35 @@
"use strict";
/**
* @license
* Copyright 2013 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var Lint = require("../../index");
exports.codeExamples = [
{
config: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n \"rules\": { \"function-constructor\": true }\n "], ["\n \"rules\": { \"function-constructor\": true }\n "]))),
description: "Use inline lambdas instead of calling Function",
fail: Lint.Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n let doesNothing = new Function();\n "], ["\n let doesNothing = new Function();\n "]))),
pass: Lint.Utils.dedent(templateObject_3 || (templateObject_3 = tslib_1.__makeTemplateObject(["\n let doesNothing = () => {};\n "], ["\n let doesNothing = () => {};\n "]))),
},
{
config: Lint.Utils.dedent(templateObject_4 || (templateObject_4 = tslib_1.__makeTemplateObject(["\n \"rules\": { \"function-constructor\": true }\n "], ["\n \"rules\": { \"function-constructor\": true }\n "]))),
description: "Use parameters instead of constructor strings",
fail: Lint.Utils.dedent(templateObject_5 || (templateObject_5 = tslib_1.__makeTemplateObject(["\n let addNumbers = new Function(\"a\", \"b\", \"return a + b\");\n "], ["\n let addNumbers = new Function(\"a\", \"b\", \"return a + b\");\n "]))),
pass: Lint.Utils.dedent(templateObject_6 || (templateObject_6 = tslib_1.__makeTemplateObject(["\n let addNumbers = (a, b) => a + b;\n "], ["\n let addNumbers = (a, b) => a + b;\n "]))),
},
];
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6;

View file

@ -0,0 +1,27 @@
/**
* @license
* Copyright 2018 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export declare const codeExamples: ({
description: string;
config: string;
pass: string;
fail: string;
} | {
description: string;
config: string;
pass: string;
fail?: undefined;
})[];

View file

@ -0,0 +1,35 @@
"use strict";
/**
* @license
* Copyright 2018 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var Lint = require("../../index");
// tslint:disable: object-literal-sort-keys
exports.codeExamples = [
{
description: "Disallows usages of `any` as a type declaration.",
config: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n \"rules\": { \"no-any\": true }\n "], ["\n \"rules\": { \"no-any\": true }\n "]))),
pass: Lint.Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n let foo: object;\n "], ["\n let foo: object;\n "]))),
fail: Lint.Utils.dedent(templateObject_3 || (templateObject_3 = tslib_1.__makeTemplateObject(["\n let foo: any;\n "], ["\n let foo: any;\n "]))),
},
{
description: "Disallows usages of `any` as a type declaration except rest spread parameters.",
config: Lint.Utils.dedent(templateObject_4 || (templateObject_4 = tslib_1.__makeTemplateObject(["\n \"rules\": { \"no-any\": [true, { \"ignore-rest-args\": true }] }\n "], ["\n \"rules\": { \"no-any\": [true, { \"ignore-rest-args\": true }] }\n "]))),
pass: Lint.Utils.dedent(templateObject_5 || (templateObject_5 = tslib_1.__makeTemplateObject(["\n function foo(a: number, ...rest: any[]): void {\n return;\n }\n "], ["\n function foo(a: number, ...rest: any[]): void {\n return;\n }\n "]))),
},
];
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5;

View file

@ -0,0 +1,22 @@
/**
* @license
* Copyright 2018 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export declare const codeExamples: {
config: string;
description: string;
fail: string;
pass: string;
}[];

View file

@ -0,0 +1,29 @@
"use strict";
/**
* @license
* Copyright 2018 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var Lint = require("../../index");
exports.codeExamples = [
{
config: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n \"rules\": { \"no-async-without-await\": true }\n "], ["\n \"rules\": { \"no-async-without-await\": true }\n "]))),
description: "Do not use the async keyword if it is not needed",
fail: Lint.Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n async function f() {\n fetch();\n }\n\n async function f() {\n async function g() {\n await h();\n }\n }\n "], ["\n async function f() {\n fetch();\n }\n\n async function f() {\n async function g() {\n await h();\n }\n }\n "]))),
pass: Lint.Utils.dedent(templateObject_3 || (templateObject_3 = tslib_1.__makeTemplateObject(["\n async function f() {\n await fetch();\n }\n\n const f = async () => {\n await fetch();\n };\n\n const f = async () => {\n return 'value';\n };\n "], ["\n async function f() {\n await fetch();\n }\n\n const f = async () => {\n await fetch();\n };\n\n const f = async () => {\n return 'value';\n };\n "]))),
},
];
var templateObject_1, templateObject_2, templateObject_3;

View file

@ -0,0 +1,22 @@
/**
* @license
* Copyright 2018 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export declare const codeExamples: {
description: string;
config: string;
pass: string;
fail: string;
}[];

View file

@ -0,0 +1,30 @@
"use strict";
/**
* @license
* Copyright 2018 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var Lint = require("../../index");
// tslint:disable: object-literal-sort-keys
exports.codeExamples = [
{
description: "Disallows empty interfaces.",
config: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n \"rules\": { \"no-empty-interface\": true }\n "], ["\n \"rules\": { \"no-empty-interface\": true }\n "]))),
pass: Lint.Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n interface I {\n foo: string;\n }\n "], ["\n interface I {\n foo: string;\n }\n "]))),
fail: Lint.Utils.dedent(templateObject_3 || (templateObject_3 = tslib_1.__makeTemplateObject(["\n interface I { }\n "], ["\n interface I { }\n "]))),
},
];
var templateObject_1, templateObject_2, templateObject_3;

View file

@ -0,0 +1,18 @@
/**
* @license
* Copyright 2019 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 { ICodeExample } from "../../language/rule/rule";
export declare const codeExamples: ICodeExample[];

View file

@ -0,0 +1,35 @@
"use strict";
/**
* @license
* Copyright 2019 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var Lint = require("../../index");
// tslint:disable: object-literal-sort-keys
exports.codeExamples = [
{
description: "Disallow object literals to appear in type assertion expressions (default). Casting to `any` and `unknown` is allowed.",
config: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n \"rules\": { \"no-object-literal-type-assertion\": true }\n "], ["\n \"rules\": { \"no-object-literal-type-assertion\": true }\n "]))),
pass: Lint.Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n let foo = {} as any;\n let foo = {} as unknown;\n\n let foo = {} as any as Foo;\n let foo = {} as unknown as Foo;\n "], ["\n let foo = {} as any;\n let foo = {} as unknown;\n\n let foo = {} as any as Foo;\n let foo = {} as unknown as Foo;\n "]))),
fail: Lint.Utils.dedent(templateObject_3 || (templateObject_3 = tslib_1.__makeTemplateObject(["\n let foo = {} as Foo;\n let foo = <Foo>{};\n "], ["\n let foo = {} as Foo;\n let foo = <Foo>{};\n "]))),
},
{
description: "Allow using a type assertion when the object literal is used as an argument.",
config: Lint.Utils.dedent(templateObject_4 || (templateObject_4 = tslib_1.__makeTemplateObject(["\n \"rules\": { \"no-object-literal-type-assertion\": [true, { \"allow-arguments\": true }] }\n "], ["\n \"rules\": { \"no-object-literal-type-assertion\": [true, { \"allow-arguments\": true }] }\n "]))),
pass: Lint.Utils.dedent(templateObject_5 || (templateObject_5 = tslib_1.__makeTemplateObject(["\n bar({} as Foo)\n "], ["\n bar({} as Foo)\n "]))),
},
];
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5;

View file

@ -0,0 +1,22 @@
/**
* @license
* Copyright 2019 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export declare const codeExamples: {
description: string;
config: string;
pass: string;
fail: string;
}[];

View file

@ -0,0 +1,36 @@
"use strict";
/**
* @license
* Copyright 2019 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var Lint = require("../../index");
// tslint:disable: object-literal-sort-keys
exports.codeExamples = [
{
description: "Disallows usages of a non-awaited Promise as boolean.",
config: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n \"rules\": { \"no-promise-as-boolean\": true }\n "], ["\n \"rules\": { \"no-promise-as-boolean\": true }\n "]))),
pass: Lint.Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n async function waiter(custumerDecisionPromise: Promise<any>) {\n if (await custumerDecisionPromise) {\n console.log(\"Customer ready to take an order.\")\n }\n }\n "], ["\n async function waiter(custumerDecisionPromise: Promise<any>) {\n if (await custumerDecisionPromise) {\n console.log(\"Customer ready to take an order.\")\n }\n }\n "]))),
fail: Lint.Utils.dedent(templateObject_3 || (templateObject_3 = tslib_1.__makeTemplateObject(["\n async function waiter(custumerDecisionPromise: Promise<any>) {\n if (custumerDecisionPromise) {\n console.log(\"Customer ready to take an order.\")\n }\n }\n "], ["\n async function waiter(custumerDecisionPromise: Promise<any>) {\n if (custumerDecisionPromise) {\n console.log(\"Customer ready to take an order.\")\n }\n }\n "]))),
},
{
description: "Disallows usages of a non-awaited third-party promise as boolean.",
config: Lint.Utils.dedent(templateObject_4 || (templateObject_4 = tslib_1.__makeTemplateObject(["\n \"rules\": { \"no-promise-as-boolean\": [true, { \"promise-classes\": [\"CustomPromise\"] }] }\n "], ["\n \"rules\": { \"no-promise-as-boolean\": [true, { \"promise-classes\": [\"CustomPromise\"] }] }\n "]))),
pass: Lint.Utils.dedent(templateObject_5 || (templateObject_5 = tslib_1.__makeTemplateObject(["\n function printOrdersPerLine(orderId: number, orderedFoodPromise: CustomPromise<string[]>) {\n orderedFoodPromise.then(orderedFood => {\n console.log(`${orderId} contains the following items:`);\n\n for (let index = 0; orderedFood; index++) {\n console.log(\"orderedFood[index]\");\n }\n\n console.log(\"Done.\");\n })\n }\n "], ["\n function printOrdersPerLine(orderId: number, orderedFoodPromise: CustomPromise<string[]>) {\n orderedFoodPromise.then(orderedFood => {\n console.log(\\`\\${orderId} contains the following items:\\`);\n\n for (let index = 0; orderedFood; index++) {\n console.log(\"orderedFood[index]\");\n }\n\n console.log(\"Done.\");\n })\n }\n "]))),
fail: Lint.Utils.dedent(templateObject_6 || (templateObject_6 = tslib_1.__makeTemplateObject(["\n function printOrdersPerLine(orderId: number, orderedFoodPromise: CustomPromise<string[]>) {\n console.log(`${orderId} contains the following items:`);\n\n for (let index = 0; orderedFoodPromise; index++) {\n console.log(\"orderedFoodPromise[index]\");\n }\n\n console.log(\"Done.\");\n }\n "], ["\n function printOrdersPerLine(orderId: number, orderedFoodPromise: CustomPromise<string[]>) {\n console.log(\\`\\${orderId} contains the following items:\\`);\n\n for (let index = 0; orderedFoodPromise; index++) {\n console.log(\"orderedFoodPromise[index]\");\n }\n\n console.log(\"Done.\");\n }\n "]))),
},
];
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6;

View file

@ -0,0 +1,22 @@
/**
* @license
* Copyright 2018 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export declare const codeExamples: {
description: string;
config: string;
pass: string;
fail: string;
}[];

View file

@ -0,0 +1,30 @@
"use strict";
/**
* @license
* Copyright 2018 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var Lint = require("../../index");
// tslint:disable: object-literal-sort-keys
exports.codeExamples = [
{
description: "Disallows sparse arrays",
config: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n \"rules\": { \"no-sparse-arrays\": true }\n "], ["\n \"rules\": { \"no-sparse-arrays\": true }\n "]))),
pass: Lint.Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n const arr: string[] = ['elemenet1', 'element2'];\n "], ["\n const arr: string[] = ['elemenet1', 'element2'];\n "]))),
fail: Lint.Utils.dedent(templateObject_3 || (templateObject_3 = tslib_1.__makeTemplateObject(["\n const arr: string[] = ['elemenet1',, 'element2'];\n "], ["\n const arr: string[] = ['elemenet1',, 'element2'];\n "]))),
},
];
var templateObject_1, templateObject_2, templateObject_3;

View file

@ -0,0 +1,22 @@
/**
* @license
* Copyright 2018 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export declare const codeExamples: {
description: string;
config: string;
pass: string;
fail: string;
}[];

View file

@ -0,0 +1,30 @@
"use strict";
/**
* @license
* Copyright 2018 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var Lint = require("../../index");
// tslint:disable: object-literal-sort-keys
exports.codeExamples = [
{
description: "Flags throwing plain strings or concatenations of strings.",
config: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n \"rules\": { \"no-string-throw\": true }\n "], ["\n \"rules\": { \"no-string-throw\": true }\n "]))),
pass: Lint.Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n try {\n // ...\n } catch (e) {\n throw e;\n }\n "], ["\n try {\n // ...\n } catch (e) {\n throw e;\n }\n "]))),
fail: Lint.Utils.dedent(templateObject_3 || (templateObject_3 = tslib_1.__makeTemplateObject(["\n try {\n // ...\n } catch {\n throw 'There was a problem.';\n }\n "], ["\n try {\n // ...\n } catch {\n throw 'There was a problem.';\n }\n "]))),
},
];
var templateObject_1, templateObject_2, templateObject_3;

View file

@ -0,0 +1,22 @@
/**
* @license
* Copyright 2018 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export declare const codeExamples: {
description: string;
config: string;
pass: string;
fail: string;
}[];

View file

@ -0,0 +1,30 @@
"use strict";
/**
* @license
* Copyright 2018 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var Lint = require("../../index");
// tslint:disable: object-literal-sort-keys
exports.codeExamples = [
{
description: "Disallows unnecessary callback wrappers",
config: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n \"rules\": { \"no-unnecessary-callback-wrapper\": true }\n "], ["\n \"rules\": { \"no-unnecessary-callback-wrapper\": true }\n "]))),
pass: Lint.Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n const handleContent = (content) => console.log('Handle content:', content);\n const handleError = (error) => console.log('Handle error:', error);\n promise.then(handleContent).catch(handleError);\n "], ["\n const handleContent = (content) => console.log('Handle content:', content);\n const handleError = (error) => console.log('Handle error:', error);\n promise.then(handleContent).catch(handleError);\n "]))),
fail: Lint.Utils.dedent(templateObject_3 || (templateObject_3 = tslib_1.__makeTemplateObject(["\n const handleContent = (content) => console.log('Handle content:', content);\n const handleError = (error) => console.log('Handle error:', error);\n promise.then((content) => handleContent(content)).catch((error) => handleError(error));\n "], ["\n const handleContent = (content) => console.log('Handle content:', content);\n const handleError = (error) => console.log('Handle error:', error);\n promise.then((content) => handleContent(content)).catch((error) => handleError(error));\n "]))),
},
];
var templateObject_1, templateObject_2, templateObject_3;

View file

@ -0,0 +1,22 @@
/**
* @license
* Copyright 2013 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export declare const codeExamples: {
description: string;
config: string;
pass: string;
fail: string;
}[];

View file

@ -0,0 +1,30 @@
"use strict";
/**
* @license
* Copyright 2013 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var Lint = require("../../index");
// tslint:disable: object-literal-sort-keys
exports.codeExamples = [
{
description: "Check that referenced variables are declared beforehand (default)",
config: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n \"rules\": { \"no-use-before-declare\": true }\n "], ["\n \"rules\": { \"no-use-before-declare\": true }\n "]))),
pass: Lint.Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n var hello = 'world';\n var foo;\n\n console.log(hello, foo, capitalize(hello));\n // 'world', undefined, 'WORLD'\n\n function capitalize(val) {\n return val.toUpperCase();\n }\n\n import { default as foo1 } from \"./lib\";\n import foo2 from \"./lib\";\n import _, { map, foldl } from \"./underscore\";\n import * as foo3 from \"./lib\";\n import \"./lib\";\n\n function declaredImports() {\n console.log(foo1);\n console.log(foo2);\n console.log(foo3);\n map([], (x) => x);\n }\n "], ["\n var hello = 'world';\n var foo;\n\n console.log(hello, foo, capitalize(hello));\n // 'world', undefined, 'WORLD'\n\n function capitalize(val) {\n return val.toUpperCase();\n }\n\n import { default as foo1 } from \"./lib\";\n import foo2 from \"./lib\";\n import _, { map, foldl } from \"./underscore\";\n import * as foo3 from \"./lib\";\n import \"./lib\";\n\n function declaredImports() {\n console.log(foo1);\n console.log(foo2);\n console.log(foo3);\n map([], (x) => x);\n }\n "]))),
fail: Lint.Utils.dedent(templateObject_3 || (templateObject_3 = tslib_1.__makeTemplateObject(["\n console.log(hello, foo);\n\n var hello = 'world';\n var foo;\n\n function undeclaredImports() {\n console.log(foo1);\n console.log(foo2);\n console.log(foo3);\n map([], (x) => x);\n }\n\n import { default as foo1 } from \"./lib\";\n import foo2 from \"./lib\";\n import _, { map, foldl } from \"./underscore\";\n import * as foo3 from \"./lib\";\n import \"./lib\";\n "], ["\n console.log(hello, foo);\n\n var hello = 'world';\n var foo;\n\n function undeclaredImports() {\n console.log(foo1);\n console.log(foo2);\n console.log(foo3);\n map([], (x) => x);\n }\n\n import { default as foo1 } from \"./lib\";\n import foo2 from \"./lib\";\n import _, { map, foldl } from \"./underscore\";\n import * as foo3 from \"./lib\";\n import \"./lib\";\n "]))),
},
];
var templateObject_1, templateObject_2, templateObject_3;

View file

@ -0,0 +1,22 @@
/**
* @license
* Copyright 2018 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export declare const codeExamples: {
description: string;
config: string;
pass: string;
fail: string;
}[];

View file

@ -0,0 +1,37 @@
"use strict";
/**
* @license
* Copyright 2018 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var Lint = require("../../index");
// tslint:disable: object-literal-sort-keys
exports.codeExamples = [
{
description: "Requires that an object literal's keys be sorted alphabetically.",
config: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n \"rules\": { \"object-literal-sort-keys\": true }\n "], ["\n \"rules\": { \"object-literal-sort-keys\": true }\n "]))),
pass: Lint.Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n let o = {\n bar: 2,\n foo: 1\n };\n "], ["\n let o = {\n bar: 2,\n foo: 1\n };\n "]))),
fail: Lint.Utils.dedent(templateObject_3 || (templateObject_3 = tslib_1.__makeTemplateObject(["\n let o = {\n foo: 1,\n bar: 2\n };\n "], ["\n let o = {\n foo: 1,\n bar: 2\n };\n "]))),
},
{
description: Lint.Utils
.dedent(templateObject_4 || (templateObject_4 = tslib_1.__makeTemplateObject(["Requires that an object literal's keys be sorted by interface-definition.\n If there is no interface fallback to alphabetically."], ["Requires that an object literal's keys be sorted by interface-definition.\n If there is no interface fallback to alphabetically."]))),
config: Lint.Utils.dedent(templateObject_5 || (templateObject_5 = tslib_1.__makeTemplateObject(["\n \"rules\": {\n \"object-literal-sort-keys\": {\n \"options\": \"match-declaration-order\"\n }\n }\n "], ["\n \"rules\": {\n \"object-literal-sort-keys\": {\n \"options\": \"match-declaration-order\"\n }\n }\n "]))),
pass: Lint.Utils.dedent(templateObject_6 || (templateObject_6 = tslib_1.__makeTemplateObject(["\n interface I {\n foo: number;\n bar: number;\n }\n\n let o: I = {\n foo: 1,\n bar: 2\n };\n "], ["\n interface I {\n foo: number;\n bar: number;\n }\n\n let o: I = {\n foo: 1,\n bar: 2\n };\n "]))),
fail: Lint.Utils.dedent(templateObject_7 || (templateObject_7 = tslib_1.__makeTemplateObject(["\n interface I {\n foo: number;\n bar: number;\n }\n\n let o: I = {\n bar: 2,\n foo: 1\n };\n "], ["\n interface I {\n foo: number;\n bar: number;\n }\n\n let o: I = {\n bar: 2,\n foo: 1\n };\n "]))),
},
];
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7;

View file

@ -0,0 +1,27 @@
/**
* @license
* Copyright 2018 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export declare const codeExamples: ({
description: string;
config: string;
pass: string;
fail: string;
} | {
description: string;
config: string;
pass: string;
fail?: undefined;
})[];

View file

@ -0,0 +1,35 @@
"use strict";
/**
* @license
* Copyright 2018 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var Lint = require("../../index");
// tslint:disable: object-literal-sort-keys
exports.codeExamples = [
{
description: "Disallows multiple variable definitions in the same declaration statement.",
config: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n \"rules\": { \"one-variable-per-declaration\": true }\n "], ["\n \"rules\": { \"one-variable-per-declaration\": true }\n "]))),
pass: Lint.Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n const foo = 1;\n const bar = '2';\n "], ["\n const foo = 1;\n const bar = '2';\n "]))),
fail: Lint.Utils.dedent(templateObject_3 || (templateObject_3 = tslib_1.__makeTemplateObject(["\n const foo = 1, bar = '2';\n "], ["\n const foo = 1, bar = '2';\n "]))),
},
{
description: "Disallows multiple variable definitions in the same declaration statement but allows them in for-loops.",
config: Lint.Utils.dedent(templateObject_4 || (templateObject_4 = tslib_1.__makeTemplateObject(["\n \"rules\": { \"one-variable-per-declaration\": [true, \"ignore-for-loop\"] }\n "], ["\n \"rules\": { \"one-variable-per-declaration\": [true, \"ignore-for-loop\"] }\n "]))),
pass: Lint.Utils.dedent(templateObject_5 || (templateObject_5 = tslib_1.__makeTemplateObject(["\n for (let i = 0, j = 10; i < 10; i++) {\n doSomething(j, i);\n }\n "], ["\n for (let i = 0, j = 10; i < 10; i++) {\n doSomething(j, i);\n }\n "]))),
},
];
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5;

View file

@ -0,0 +1,22 @@
/**
* @license
* Copyright 2018 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export declare const codeExamples: {
description: string;
config: string;
pass: string;
fail: string;
}[];

View file

@ -0,0 +1,30 @@
"use strict";
/**
* @license
* Copyright 2018 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var Lint = require("../../index");
// tslint:disable: object-literal-sort-keys
exports.codeExamples = [
{
description: "Disallows functions with the function keyword",
config: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n \"rules\": { \"only-arrow-functions\": true }\n "], ["\n \"rules\": { \"only-arrow-functions\": true }\n "]))),
pass: Lint.Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n const myFunc = () => {\n // do something ...\n };\n\n const myFunc = function() {\n this.doSomething();\n };\n "], ["\n const myFunc = () => {\n // do something ...\n };\n\n const myFunc = function() {\n this.doSomething();\n };\n "]))),
fail: Lint.Utils.dedent(templateObject_3 || (templateObject_3 = tslib_1.__makeTemplateObject(["\n function myFunc() {\n // do something ...\n };\n\n const myFunc = function() {\n // do something ...\n };\n "], ["\n function myFunc() {\n // do something ...\n };\n\n const myFunc = function() {\n // do something ...\n };\n "]))),
},
];
var templateObject_1, templateObject_2, templateObject_3;

View file

@ -0,0 +1,22 @@
/**
* @license
* Copyright 2018 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export declare const codeExamples: {
description: string;
config: string;
pass: string;
fail: string;
}[];

View file

@ -0,0 +1,36 @@
"use strict";
/**
* @license
* Copyright 2018 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var Lint = require("../../index");
// tslint:disable: object-literal-sort-keys
exports.codeExamples = [
{
description: "Enforces the use of template strings whenever possible.",
config: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n \"rules\": { \"prefer-template\": true }\n "], ["\n \"rules\": { \"prefer-template\": true }\n "]))),
pass: Lint.Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n const x: number = 1;\n const y: number = 1;\n const myString: string = `${x} is equals ${y}`;\n "], ["\n const x: number = 1;\n const y: number = 1;\n const myString: string = \\`\\${x} is equals \\${y}\\`;\n "]))),
fail: Lint.Utils.dedent(templateObject_3 || (templateObject_3 = tslib_1.__makeTemplateObject(["\n const x: number = 1;\n const y: number = 1;\n const myString: string = x + ' is equals ' + y;\n "], ["\n const x: number = 1;\n const y: number = 1;\n const myString: string = x + ' is equals ' + y;\n "]))),
},
{
description: "Enforces the use of template strings, but allows up to one concatenation.",
config: Lint.Utils.dedent(templateObject_4 || (templateObject_4 = tslib_1.__makeTemplateObject(["\n \"rules\": { \"prefer-template\": [true, \"allow-single-concat\"] }\n "], ["\n \"rules\": { \"prefer-template\": [true, \"allow-single-concat\"] }\n "]))),
pass: Lint.Utils.dedent(templateObject_5 || (templateObject_5 = tslib_1.__makeTemplateObject(["\n const x: number = 1;\n const y: number = 1;\n const myString: string = x + ' is equals 1';\n const myString: string = `${x} is equals ${y}`;\n "], ["\n const x: number = 1;\n const y: number = 1;\n const myString: string = x + ' is equals 1';\n const myString: string = \\`\\${x} is equals \\${y}\\`;\n "]))),
fail: Lint.Utils.dedent(templateObject_6 || (templateObject_6 = tslib_1.__makeTemplateObject(["\n const x: number = 1;\n const y: number = 1;\n const myString: string = x + ' is equals ' + y;\n "], ["\n const x: number = 1;\n const y: number = 1;\n const myString: string = x + ' is equals ' + y;\n "]))),
},
];
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6;

View file

@ -0,0 +1,22 @@
/**
* @license
* Copyright 2018 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export declare const codeExamples: {
description: string;
config: string;
pass: string;
fail: string;
}[];

View file

@ -0,0 +1,30 @@
"use strict";
/**
* @license
* Copyright 2018 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var Lint = require("../../index");
// tslint:disable: object-literal-sort-keys
exports.codeExamples = [
{
description: "Prefer `while` loops instead of `for` loops without an initializer and incrementor.",
config: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n \"rules\": { \"prefer-while\": true }\n "], ["\n \"rules\": { \"prefer-while\": true }\n "]))),
pass: Lint.Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n for(let i = 1; i < 10; i++) {\n console.log(i);\n }\n\n for (let i = 0; i < 10; i+=1) {\n console.log(i);\n }\n\n for (let i = 0; i < 10;) {\n i += 1;\n }\n "], ["\n for(let i = 1; i < 10; i++) {\n console.log(i);\n }\n\n for (let i = 0; i < 10; i+=1) {\n console.log(i);\n }\n\n for (let i = 0; i < 10;) {\n i += 1;\n }\n "]))),
fail: Lint.Utils.dedent(templateObject_3 || (templateObject_3 = tslib_1.__makeTemplateObject(["\n for(;;) {\n console.log('Hello World');\n }\n\n for(;true===true;) {\n console.log('Hello World');\n }\n "], ["\n for(;;) {\n console.log('Hello World');\n }\n\n for(;true===true;) {\n console.log('Hello World');\n }\n "]))),
},
];
var templateObject_1, templateObject_2, templateObject_3;

View file

@ -0,0 +1,22 @@
/**
* @license
* Copyright 2018 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export declare const codeExamples: {
description: string;
config: string;
pass: string;
fail: string;
}[];

View file

@ -0,0 +1,30 @@
"use strict";
/**
* @license
* Copyright 2018 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var Lint = require("../../index");
// tslint:disable: object-literal-sort-keys
exports.codeExamples = [
{
description: "Requires the inclusion of the radix parameter when calling `parseInt`.",
config: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n \"rules\": { \"radix\": true }\n "], ["\n \"rules\": { \"radix\": true }\n "]))),
pass: Lint.Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n const x: string = '11';\n const dec: number = parseInt(x, 10);\n const bin: number = parseInt(x, 2);\n const hex: number = parseInt(x, 16);\n "], ["\n const x: string = '11';\n const dec: number = parseInt(x, 10);\n const bin: number = parseInt(x, 2);\n const hex: number = parseInt(x, 16);\n "]))),
fail: Lint.Utils.dedent(templateObject_3 || (templateObject_3 = tslib_1.__makeTemplateObject(["\n const x: string = '11';\n const dec: number = parseInt(x);\n "], ["\n const x: string = '11';\n const dec: number = parseInt(x);\n "]))),
},
];
var templateObject_1, templateObject_2, templateObject_3;

View file

@ -0,0 +1,22 @@
/**
* @license
* Copyright 2019 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export declare const codeExamples: {
description: string;
config: string;
pass: string;
fail: string;
}[];

View file

@ -0,0 +1,30 @@
"use strict";
/**
* @license
* Copyright 2019 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var Lint = require("../../index");
// tslint:disable: object-literal-sort-keys
exports.codeExamples = [
{
description: "Disallows the `this` keyword usage in static context.",
config: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n \"rules\": { \"static-this\": true }\n "], ["\n \"rules\": { \"static-this\": true }\n "]))),
pass: Lint.Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n class Pass {\n static getName() {\n return 'name'\n }\n\n static getFullname() {\n return `full ${Pass.getName()}`\n }\n }\n "], ["\n class Pass {\n static getName() {\n return 'name'\n }\n\n static getFullname() {\n return \\`full \\${Pass.getName()}\\`\n }\n }\n "]))),
fail: Lint.Utils.dedent(templateObject_3 || (templateObject_3 = tslib_1.__makeTemplateObject(["\n class Fail {\n static getName() {\n return 'name'\n }\n\n static getFullname() {\n return `full ${this.getName()}`\n }\n }\n "], ["\n class Fail {\n static getName() {\n return 'name'\n }\n\n static getFullname() {\n return \\`full \\${this.getName()}\\`\n }\n }\n "]))),
},
];
var templateObject_1, templateObject_2, templateObject_3;

View file

@ -0,0 +1,22 @@
/**
* @license
* Copyright 2019 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export declare const codeExamples: {
description: string;
config: string;
pass: string;
fail: string;
}[];

View file

@ -0,0 +1,42 @@
"use strict";
/**
* @license
* Copyright 2019 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var Lint = require("../../index");
// tslint:disable: object-literal-sort-keys
exports.codeExamples = [
{
description: "Disallows usage of comparison operators with non-primitive types.",
config: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n \"rules\": { \"strict-comparisons\": true }\n "], ["\n \"rules\": { \"strict-comparisons\": true }\n "]))),
pass: Lint.Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n const object1 = {};\n const object2 = {};\n if (isEqual(object1, object2)) {}\n "], ["\n const object1 = {};\n const object2 = {};\n if (isEqual(object1, object2)) {}\n "]))),
fail: Lint.Utils.dedent(templateObject_3 || (templateObject_3 = tslib_1.__makeTemplateObject(["\n const object1 = {};\n const object2 = {};\n if (object1 === object2) {}\n "], ["\n const object1 = {};\n const object2 = {};\n if (object1 === object2) {}\n "]))),
},
{
description: "Allows equality operators to be used with non-primitive types, while still disallowing the use of greater than and less than.",
config: Lint.Utils.dedent(templateObject_4 || (templateObject_4 = tslib_1.__makeTemplateObject(["\n \"rules\": { \"strict-comparisons\": [true, { \"allow-object-equal-comparison\": true }] }\n "], ["\n \"rules\": { \"strict-comparisons\": [true, { \"allow-object-equal-comparison\": true }] }\n "]))),
pass: Lint.Utils.dedent(templateObject_5 || (templateObject_5 = tslib_1.__makeTemplateObject(["\n const object1 = {};\n const object2 = {};\n if (object1 === object2) {}\n "], ["\n const object1 = {};\n const object2 = {};\n if (object1 === object2) {}\n "]))),
fail: Lint.Utils.dedent(templateObject_6 || (templateObject_6 = tslib_1.__makeTemplateObject(["\n const object1 = {};\n const object2 = {};\n if (object1 < object2) {}\n "], ["\n const object1 = {};\n const object2 = {};\n if (object1 < object2) {}\n "]))),
},
{
description: "Allows ordering operators to be used with string types.",
config: Lint.Utils.dedent(templateObject_7 || (templateObject_7 = tslib_1.__makeTemplateObject(["\n \"rules\": { \"strict-comparisons\": [true, { \"allow-string-order-comparison\": true }] }\n "], ["\n \"rules\": { \"strict-comparisons\": [true, { \"allow-string-order-comparison\": true }] }\n "]))),
pass: Lint.Utils.dedent(templateObject_8 || (templateObject_8 = tslib_1.__makeTemplateObject(["\n const string1 = \"\";\n const string2 = \"\";\n if (string1 < string2) {}\n "], ["\n const string1 = \"\";\n const string2 = \"\";\n if (string1 < string2) {}\n "]))),
fail: Lint.Utils.dedent(templateObject_9 || (templateObject_9 = tslib_1.__makeTemplateObject(["\n const object1 = {};\n const object2 = {};\n if (object1 < object2) {}\n "], ["\n const object1 = {};\n const object2 = {};\n if (object1 < object2) {}\n "]))),
},
];
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8, templateObject_9;

View file

@ -0,0 +1,22 @@
/**
* @license
* Copyright 2018 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export declare const codeExamples: {
description: string;
config: string;
pass: string;
fail: string;
}[];

View file

@ -0,0 +1,30 @@
"use strict";
/**
* @license
* Copyright 2018 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var Lint = require("../../index");
// tslint:disable: object-literal-sort-keys
exports.codeExamples = [
{
description: "Requires a `default` case in `switch` statements.",
config: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n \"rules\": { \"switch-default\": true }\n "], ["\n \"rules\": { \"switch-default\": true }\n "]))),
pass: Lint.Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n let foo: number = 1;\n switch (foo) {\n case 1:\n doSomething();\n break;\n case 2:\n doSomething2();\n break;\n default:\n console.log('default');\n }\n "], ["\n let foo: number = 1;\n switch (foo) {\n case 1:\n doSomething();\n break;\n case 2:\n doSomething2();\n break;\n default:\n console.log('default');\n }\n "]))),
fail: Lint.Utils.dedent(templateObject_3 || (templateObject_3 = tslib_1.__makeTemplateObject(["\n let foo: number = 1;\n switch (foo) {\n case 1:\n doSomething();\n break;\n case 2:\n doSomething2();\n }\n "], ["\n let foo: number = 1;\n switch (foo) {\n case 1:\n doSomething();\n break;\n case 2:\n doSomething2();\n }\n "]))),
},
];
var templateObject_1, templateObject_2, templateObject_3;

View file

@ -0,0 +1,22 @@
/**
* @license
* Copyright 2018 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export declare const codeExamples: {
description: string;
config: string;
pass: string;
fail: string;
}[];

View file

@ -0,0 +1,78 @@
"use strict";
/**
* @license
* Copyright 2018 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var Lint = require("../../index");
// tslint:disable: object-literal-sort-keys
exports.codeExamples = [
{
description: "Requires type definitions for call signatures",
config: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n \"rules\": { \"typedef\": [true, \"call-signature\"] }\n "], ["\n \"rules\": { \"typedef\": [true, \"call-signature\"] }\n "]))),
pass: Lint.Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n function add(x, y): number {\n return x + y;\n }\n "], ["\n function add(x, y): number {\n return x + y;\n }\n "]))),
fail: Lint.Utils.dedent(templateObject_3 || (templateObject_3 = tslib_1.__makeTemplateObject(["\n function add(x, y) {\n return x + y;\n }\n "], ["\n function add(x, y) {\n return x + y;\n }\n "]))),
},
{
description: "Requires type definitions for arrow call signatures",
config: Lint.Utils.dedent(templateObject_4 || (templateObject_4 = tslib_1.__makeTemplateObject(["\n \"rules\": { \"typedef\": [true, \"arrow-call-signature\"] }\n "], ["\n \"rules\": { \"typedef\": [true, \"arrow-call-signature\"] }\n "]))),
pass: Lint.Utils.dedent(templateObject_5 || (templateObject_5 = tslib_1.__makeTemplateObject(["\n const add = (x, y): number => x + y;\n "], ["\n const add = (x, y): number => x + y;\n "]))),
fail: Lint.Utils.dedent(templateObject_6 || (templateObject_6 = tslib_1.__makeTemplateObject(["\n const add = (x, y) => x + y;\n "], ["\n const add = (x, y) => x + y;\n "]))),
},
{
description: "Requires type definitions for parameters",
config: Lint.Utils.dedent(templateObject_7 || (templateObject_7 = tslib_1.__makeTemplateObject(["\n \"rules\": { \"typedef\": [true, \"parameter\"] }\n "], ["\n \"rules\": { \"typedef\": [true, \"parameter\"] }\n "]))),
pass: Lint.Utils.dedent(templateObject_8 || (templateObject_8 = tslib_1.__makeTemplateObject(["\n function add(x: number, y: number) {\n return x + y;\n }\n "], ["\n function add(x: number, y: number) {\n return x + y;\n }\n "]))),
fail: Lint.Utils.dedent(templateObject_9 || (templateObject_9 = tslib_1.__makeTemplateObject(["\n function add(x, y) {\n return x + y;\n }\n "], ["\n function add(x, y) {\n return x + y;\n }\n "]))),
},
{
description: "Requires type definitions for arrow function parameters",
config: Lint.Utils.dedent(templateObject_10 || (templateObject_10 = tslib_1.__makeTemplateObject(["\n \"rules\": { \"typedef\": [true, \"arrow-parameter\"] }\n "], ["\n \"rules\": { \"typedef\": [true, \"arrow-parameter\"] }\n "]))),
pass: Lint.Utils.dedent(templateObject_11 || (templateObject_11 = tslib_1.__makeTemplateObject(["\n const add = (x: number, y: number) => x + y;\n "], ["\n const add = (x: number, y: number) => x + y;\n "]))),
fail: Lint.Utils.dedent(templateObject_12 || (templateObject_12 = tslib_1.__makeTemplateObject(["\n const add = (x, y) => x + y;\n "], ["\n const add = (x, y) => x + y;\n "]))),
},
{
description: "Requires type definitions for property declarations",
config: Lint.Utils.dedent(templateObject_13 || (templateObject_13 = tslib_1.__makeTemplateObject(["\n \"rules\": { \"typedef\": [true, \"property-declaration\"] }\n "], ["\n \"rules\": { \"typedef\": [true, \"property-declaration\"] }\n "]))),
pass: Lint.Utils.dedent(templateObject_14 || (templateObject_14 = tslib_1.__makeTemplateObject(["\n interface I {\n foo: number;\n bar: string;\n }\n "], ["\n interface I {\n foo: number;\n bar: string;\n }\n "]))),
fail: Lint.Utils.dedent(templateObject_15 || (templateObject_15 = tslib_1.__makeTemplateObject(["\n interface I {\n foo;\n bar;\n }\n "], ["\n interface I {\n foo;\n bar;\n }\n "]))),
},
{
description: "Requires type definitions for variable declarations",
config: Lint.Utils.dedent(templateObject_16 || (templateObject_16 = tslib_1.__makeTemplateObject(["\n \"rules\": { \"typedef\": [true, \"variable-declaration\"] }\n "], ["\n \"rules\": { \"typedef\": [true, \"variable-declaration\"] }\n "]))),
pass: Lint.Utils.dedent(templateObject_17 || (templateObject_17 = tslib_1.__makeTemplateObject(["\n let x: number;\n "], ["\n let x: number;\n "]))),
fail: Lint.Utils.dedent(templateObject_18 || (templateObject_18 = tslib_1.__makeTemplateObject(["\n let x;\n "], ["\n let x;\n "]))),
},
{
description: "Requires type definitions for member variable declarations",
config: Lint.Utils.dedent(templateObject_19 || (templateObject_19 = tslib_1.__makeTemplateObject(["\n \"rules\": { \"typedef\": [true, \"member-variable-declaration\"] }\n "], ["\n \"rules\": { \"typedef\": [true, \"member-variable-declaration\"] }\n "]))),
pass: Lint.Utils.dedent(templateObject_20 || (templateObject_20 = tslib_1.__makeTemplateObject(["\n class MyClass {\n x: number;\n }\n "], ["\n class MyClass {\n x: number;\n }\n "]))),
fail: Lint.Utils.dedent(templateObject_21 || (templateObject_21 = tslib_1.__makeTemplateObject(["\n class MyClass {\n x;\n }\n "], ["\n class MyClass {\n x;\n }\n "]))),
},
{
description: "Requires type definitions when destructuring objects.",
config: Lint.Utils.dedent(templateObject_22 || (templateObject_22 = tslib_1.__makeTemplateObject(["\n \"rules\": { \"typedef\": [true, \"object-destructuring\"] }\n "], ["\n \"rules\": { \"typedef\": [true, \"object-destructuring\"] }\n "]))),
pass: Lint.Utils.dedent(templateObject_23 || (templateObject_23 = tslib_1.__makeTemplateObject(["\n interface FooBar {\n foo: number;\n bar: string;\n }\n const foobar = { foo: 1, bar: '2' };\n const { foo, bar }: FooBar = foobar;\n "], ["\n interface FooBar {\n foo: number;\n bar: string;\n }\n const foobar = { foo: 1, bar: '2' };\n const { foo, bar }: FooBar = foobar;\n "]))),
fail: Lint.Utils.dedent(templateObject_24 || (templateObject_24 = tslib_1.__makeTemplateObject(["\n interface FooBar {\n foo: number;\n bar: string;\n }\n const foobar = { foo: 1, bar: '2' };\n const { foo, bar } = foobar;\n "], ["\n interface FooBar {\n foo: number;\n bar: string;\n }\n const foobar = { foo: 1, bar: '2' };\n const { foo, bar } = foobar;\n "]))),
},
{
description: "Requires type definitions when destructuring arrays.",
config: Lint.Utils.dedent(templateObject_25 || (templateObject_25 = tslib_1.__makeTemplateObject(["\n \"rules\": { \"typedef\": [true, \"array-destructuring\"] }\n "], ["\n \"rules\": { \"typedef\": [true, \"array-destructuring\"] }\n "]))),
pass: Lint.Utils.dedent(templateObject_26 || (templateObject_26 = tslib_1.__makeTemplateObject(["\n const foobar = [1, '2'];\n const [foo, bar]: Array<number | string> = foobar;\n "], ["\n const foobar = [1, '2'];\n const [foo, bar]: Array<number | string> = foobar;\n "]))),
fail: Lint.Utils.dedent(templateObject_27 || (templateObject_27 = tslib_1.__makeTemplateObject(["\n const foobar = [1, '2'];\n const [foo, bar] = foobar;\n "], ["\n const foobar = [1, '2'];\n const [foo, bar] = foobar;\n "]))),
},
];
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8, templateObject_9, templateObject_10, templateObject_11, templateObject_12, templateObject_13, templateObject_14, templateObject_15, templateObject_16, templateObject_17, templateObject_18, templateObject_19, templateObject_20, templateObject_21, templateObject_22, templateObject_23, templateObject_24, templateObject_25, templateObject_26, templateObject_27;

View file

@ -0,0 +1,22 @@
/**
* @license
* Copyright 2019 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export declare const codeExamples: {
description: string;
config: string;
pass: string;
fail: string;
}[];

View file

@ -0,0 +1,30 @@
"use strict";
/**
* @license
* Copyright 2019 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var Lint = require("../../index");
// tslint:disable: object-literal-sort-keys
exports.codeExamples = [
{
description: 'Disallows "else" following "if" blocks ending with "return", "break", "continue" or "throw" statement. ',
config: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n \"rules\": { \"unnecessary-else\": true }\n "], ["\n \"rules\": { \"unnecessary-else\": true }\n "]))),
pass: Lint.Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n if (someCondition()) {\n return;\n }\n // some code here\n\n if (someCondition()) {\n continue;\n }\n // some code here\n\n if (someCondition()) {\n throw;\n }\n // some code here\n\n if (someCondition()) {\n break;\n }\n // some code here\n\n "], ["\n if (someCondition()) {\n return;\n }\n // some code here\n\n if (someCondition()) {\n continue;\n }\n // some code here\n\n if (someCondition()) {\n throw;\n }\n // some code here\n\n if (someCondition()) {\n break;\n }\n // some code here\n\n "]))),
fail: Lint.Utils.dedent(templateObject_3 || (templateObject_3 = tslib_1.__makeTemplateObject(["\n if (someCondition()) {\n return;\n } else {\n // some code here\n }\n\n if (someCondition()) {\n break;\n } else {\n // some code here\n }\n\n if (someCondition()) {\n throw;\n } else {\n // some code here\n }\n\n if (someCondition()) {\n continue;\n } else {\n // some code here\n }\n "], ["\n if (someCondition()) {\n return;\n } else {\n // some code here\n }\n\n if (someCondition()) {\n break;\n } else {\n // some code here\n }\n\n if (someCondition()) {\n throw;\n } else {\n // some code here\n }\n\n if (someCondition()) {\n continue;\n } else {\n // some code here\n }\n "]))),
},
];
var templateObject_1, templateObject_2, templateObject_3;

View file

@ -0,0 +1,22 @@
/**
* @license
* Copyright 2018 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export declare const codeExamples: {
description: string;
config: string;
pass: string;
fail: string;
}[];

View file

@ -0,0 +1,30 @@
"use strict";
/**
* @license
* Copyright 2018 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var Lint = require("../../index");
// tslint:disable: object-literal-sort-keys
exports.codeExamples = [
{
description: "Enforces usage of `isNan()`.",
config: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n \"rules\": { \"use-isnan\": true }\n "], ["\n \"rules\": { \"use-isnan\": true }\n "]))),
pass: Lint.Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n if (isNaN(parseInt('_4711'))) {\n doSomething();\n }\n "], ["\n if (isNaN(parseInt('_4711'))) {\n doSomething();\n }\n "]))),
fail: Lint.Utils.dedent(templateObject_3 || (templateObject_3 = tslib_1.__makeTemplateObject(["\n if (parseInt('_4711') === NaN) {\n doSomething();\n }\n "], ["\n if (parseInt('_4711') === NaN) {\n doSomething();\n }\n "]))),
},
];
var templateObject_1, templateObject_2, templateObject_3;

29
node_modules/tslint/lib/rules/commentFormatRule.d.ts generated vendored Normal file
View file

@ -0,0 +1,29 @@
/**
* @license
* Copyright 2013 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as ts from "typescript";
import * as Lint from "../index";
export declare class Rule extends Lint.Rules.AbstractRule {
static metadata: Lint.IRuleMetadata;
static LOWERCASE_FAILURE: string;
static SPACE_LOWERCASE_FAILURE: string;
static UPPERCASE_FAILURE: string;
static SPACE_UPPERCASE_FAILURE: string;
static LEADING_SPACE_FAILURE: string;
static IGNORE_WORDS_FAILURE_FACTORY: (words: string[]) => string;
static IGNORE_PATTERN_FAILURE_FACTORY: (pattern: string) => string;
apply(sourceFile: ts.SourceFile): Lint.RuleFailure[];
}

238
node_modules/tslint/lib/rules/commentFormatRule.js generated vendored Normal file
View file

@ -0,0 +1,238 @@
"use strict";
/**
* @license
* Copyright 2013 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var utils = require("tsutils");
var ts = require("typescript");
var enableDisableRules_1 = require("../enableDisableRules");
var Lint = require("../index");
var utils_1 = require("../utils");
var OPTION_SPACE = "check-space";
var OPTION_LOWERCASE = "check-lowercase";
var OPTION_UPPERCASE = "check-uppercase";
var OPTION_ALLOW_TRAILING_LOWERCASE = "allow-trailing-lowercase";
var Rule = /** @class */ (function (_super) {
tslib_1.__extends(Rule, _super);
function Rule() {
return _super !== null && _super.apply(this, arguments) || this;
}
Rule.prototype.apply = function (sourceFile) {
var commentFormatWalker = new CommentFormatWalker(sourceFile, this.ruleName, parseOptions(this.ruleArguments));
return this.applyWithWalker(commentFormatWalker);
};
/* tslint:disable:object-literal-sort-keys */
Rule.metadata = {
ruleName: "comment-format",
description: "Enforces formatting rules for single-line comments.",
rationale: "Helps maintain a consistent, readable style in your codebase.",
optionsDescription: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n Four arguments may be optionally provided:\n\n * `\"", "\"` requires that all single-line comments must begin with a space, as in `// comment`\n * note that for comments starting with multiple slashes, e.g. `///`, leading slashes are ignored\n * TypeScript reference comments are ignored completely\n * `\"", "\"` requires that the first non-whitespace character of a comment must be lowercase, if applicable.\n * `\"", "\"` requires that the first non-whitespace character of a comment must be uppercase, if applicable.\n * `\"", "\"` allows that only the first comment of a series of comments needs to be uppercase.\n * requires `\"", "\"`\n * comments must start at the same position\n\n Exceptions to `\"", "\"` or `\"", "\"` can be managed with object that may be passed as last\n argument.\n\n One of two options can be provided in this object:\n\n * `\"ignore-words\"` - array of strings - words that will be ignored at the beginning of the comment.\n * `\"ignore-pattern\"` - string - RegExp pattern that will be ignored at the beginning of the comment.\n "], ["\n Four arguments may be optionally provided:\n\n * \\`\"", "\"\\` requires that all single-line comments must begin with a space, as in \\`// comment\\`\n * note that for comments starting with multiple slashes, e.g. \\`///\\`, leading slashes are ignored\n * TypeScript reference comments are ignored completely\n * \\`\"", "\"\\` requires that the first non-whitespace character of a comment must be lowercase, if applicable.\n * \\`\"", "\"\\` requires that the first non-whitespace character of a comment must be uppercase, if applicable.\n * \\`\"", "\"\\` allows that only the first comment of a series of comments needs to be uppercase.\n * requires \\`\"", "\"\\`\n * comments must start at the same position\n\n Exceptions to \\`\"", "\"\\` or \\`\"", "\"\\` can be managed with object that may be passed as last\n argument.\n\n One of two options can be provided in this object:\n\n * \\`\"ignore-words\"\\` - array of strings - words that will be ignored at the beginning of the comment.\n * \\`\"ignore-pattern\"\\` - string - RegExp pattern that will be ignored at the beginning of the comment.\n "])), OPTION_SPACE, OPTION_LOWERCASE, OPTION_UPPERCASE, OPTION_ALLOW_TRAILING_LOWERCASE, OPTION_UPPERCASE, OPTION_LOWERCASE, OPTION_UPPERCASE),
options: {
type: "array",
items: {
anyOf: [
{
type: "string",
enum: [
OPTION_SPACE,
OPTION_LOWERCASE,
OPTION_UPPERCASE,
OPTION_ALLOW_TRAILING_LOWERCASE,
],
},
{
type: "object",
properties: {
"ignore-words": {
type: "array",
items: {
type: "string",
},
},
"ignore-pattern": {
type: "string",
},
},
minProperties: 1,
maxProperties: 1,
},
],
},
minLength: 1,
maxLength: 5,
},
optionExamples: [
[true, OPTION_SPACE, OPTION_UPPERCASE, OPTION_ALLOW_TRAILING_LOWERCASE],
[true, OPTION_LOWERCASE, { "ignore-words": ["TODO", "HACK"] }],
[true, OPTION_LOWERCASE, { "ignore-pattern": "STD\\w{2,3}\\b" }],
],
type: "style",
typescriptOnly: false,
hasFix: true,
};
/* tslint:enable:object-literal-sort-keys */
Rule.LOWERCASE_FAILURE = "comment must start with lowercase letter";
Rule.SPACE_LOWERCASE_FAILURE = "comment must start with a space and lowercase letter";
Rule.UPPERCASE_FAILURE = "comment must start with uppercase letter";
Rule.SPACE_UPPERCASE_FAILURE = "comment must start with a space and uppercase letter";
Rule.LEADING_SPACE_FAILURE = "comment must start with a space";
Rule.IGNORE_WORDS_FAILURE_FACTORY = function (words) {
return " or the word(s): " + words.join(", ");
};
Rule.IGNORE_PATTERN_FAILURE_FACTORY = function (pattern) {
return " or its start must match the regex pattern \"" + pattern + "\"";
};
return Rule;
}(Lint.Rules.AbstractRule));
exports.Rule = Rule;
function parseOptions(options) {
return tslib_1.__assign({ allowTrailingLowercase: has(OPTION_ALLOW_TRAILING_LOWERCASE), case: options.indexOf(OPTION_LOWERCASE) !== -1
? 1 /* Lower */
: options.indexOf(OPTION_UPPERCASE) !== -1
? 2 /* Upper */
: 0 /* None */, failureSuffix: "", space: has(OPTION_SPACE) }, composeExceptions(options[options.length - 1]));
function has(option) {
return options.indexOf(option) !== -1;
}
}
function composeExceptions(option) {
if (typeof option !== "object") {
return undefined;
}
var ignorePattern = option["ignore-pattern"];
if (ignorePattern !== undefined) {
return {
exceptions: new RegExp("^\\s*(" + ignorePattern + ")"),
failureSuffix: Rule.IGNORE_PATTERN_FAILURE_FACTORY(ignorePattern),
};
}
var ignoreWords = option["ignore-words"];
if (ignoreWords !== undefined && ignoreWords.length !== 0) {
return {
exceptions: new RegExp("^\\s*(?:" + ignoreWords.map(function (word) { return utils_1.escapeRegExp(word.trim()); }).join("|") + ")\\b"),
failureSuffix: Rule.IGNORE_WORDS_FAILURE_FACTORY(ignoreWords),
};
}
return undefined;
}
var CommentFormatWalker = /** @class */ (function (_super) {
tslib_1.__extends(CommentFormatWalker, _super);
function CommentFormatWalker() {
return _super !== null && _super.apply(this, arguments) || this;
}
CommentFormatWalker.prototype.walk = function (sourceFile) {
var _this = this;
utils.forEachComment(sourceFile, function (fullText, comment) {
var commentStatus = _this.checkComment(fullText, comment);
_this.handleFailure(commentStatus, comment.end);
// cache position of last comment
_this.prevComment = ts.getLineAndCharacterOfPosition(sourceFile, comment.pos);
_this.prevCommentIsValid = commentStatus.validForTrailingLowercase;
});
};
CommentFormatWalker.prototype.checkComment = function (fullText, _a) {
var kind = _a.kind, pos = _a.pos, end = _a.end;
var status = {
firstLetterPos: -1,
leadingSpaceError: false,
lowercaseError: false,
start: pos + 2,
text: "",
uppercaseError: false,
validForTrailingLowercase: false,
};
if (kind !== ts.SyntaxKind.SingleLineCommentTrivia ||
// exclude empty comments
status.start === end ||
// exclude /// <reference path="...">
(fullText[status.start] === "/" &&
this.sourceFile.referencedFiles.some(function (ref) { return ref.pos >= pos && ref.end <= end; }))) {
return status;
}
// skip all leading slashes
while (fullText[status.start] === "/") {
++status.start;
}
if (status.start === end) {
return status;
}
status.text = fullText.slice(status.start, end);
// whitelist //#region and //#endregion and JetBrains IDEs' "//noinspection ...", "//region", "//endregion"
if (/^(?:#?(?:end)?region|noinspection\s)/.test(status.text)) {
return status;
}
if (this.options.space && status.text[0] !== " ") {
status.leadingSpaceError = true;
}
if (this.options.case === 0 /* None */ ||
(this.options.exceptions !== undefined && this.options.exceptions.test(status.text)) ||
enableDisableRules_1.ENABLE_DISABLE_REGEX.test(status.text)) {
return status;
}
// search for first non-space character to check if lower or upper
var charPos = status.text.search(/\S/);
if (charPos === -1) {
return status;
}
// All non-empty and not whitelisted comments are valid for the trailing lowercase rule
status.validForTrailingLowercase = true;
status.firstLetterPos = charPos;
if (this.options.case === 1 /* Lower */ && !utils_1.isLowerCase(status.text[charPos])) {
status.lowercaseError = true;
}
else if (this.options.case === 2 /* Upper */ && !utils_1.isUpperCase(status.text[charPos])) {
status.uppercaseError = true;
if (this.options.allowTrailingLowercase &&
this.prevComment !== undefined &&
this.prevCommentIsValid) {
var currentComment = ts.getLineAndCharacterOfPosition(this.sourceFile, pos);
if (this.prevComment.line + 1 === currentComment.line &&
this.prevComment.character === currentComment.character) {
status.uppercaseError = false;
}
}
}
return status;
};
CommentFormatWalker.prototype.handleFailure = function (status, end) {
// No failure detected
if (!status.leadingSpaceError && !status.lowercaseError && !status.uppercaseError) {
return;
}
// Only whitespace failure
if (status.leadingSpaceError && !status.lowercaseError && !status.uppercaseError) {
this.addFailure(status.start, end, Rule.LEADING_SPACE_FAILURE, Lint.Replacement.appendText(status.start, " "));
return;
}
var msg;
var firstLetterFix;
if (status.lowercaseError) {
msg = status.leadingSpaceError ? Rule.SPACE_LOWERCASE_FAILURE : Rule.LOWERCASE_FAILURE;
firstLetterFix = status.text[status.firstLetterPos].toLowerCase();
}
else {
msg = status.leadingSpaceError ? Rule.SPACE_UPPERCASE_FAILURE : Rule.UPPERCASE_FAILURE;
firstLetterFix = status.text[status.firstLetterPos].toUpperCase();
}
var fix = status.leadingSpaceError
? new Lint.Replacement(status.start, 1, " " + firstLetterFix)
: new Lint.Replacement(status.start + status.firstLetterPos, 1, firstLetterFix);
this.addFailure(status.start, end, msg + this.options.failureSuffix, fix);
};
return CommentFormatWalker;
}(Lint.AbstractWalker));
var templateObject_1;

22
node_modules/tslint/lib/rules/commentTypeRule.d.ts generated vendored Normal file
View file

@ -0,0 +1,22 @@
/**
* @license
* Copyright 2018 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as ts from "typescript";
import * as Lint from "../index";
export declare class Rule extends Lint.Rules.AbstractRule {
static metadata: Lint.IRuleMetadata;
apply(sourceFile: ts.SourceFile): Lint.RuleFailure[];
}

86
node_modules/tslint/lib/rules/commentTypeRule.js generated vendored Normal file
View file

@ -0,0 +1,86 @@
"use strict";
/**
* @license
* Copyright 2018 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var utils = require("tsutils");
var ts = require("typescript");
var Lint = require("../index");
function parseOptions(opts) {
return new Set(opts);
}
// Constant Messages
var MULTILINE_FAILURE = "multiline comments are not allowed";
var SINGLE_LINE_FAILURE = "singleline comments are not allowed";
var DOC_FAILURE = "doc comments are not allowed";
var DIRECTIVE_FAILURE = "triple-slash directives are not allowed";
// Logic
var Rule = /** @class */ (function (_super) {
tslib_1.__extends(Rule, _super);
function Rule() {
return _super !== null && _super.apply(this, arguments) || this;
}
Rule.prototype.apply = function (sourceFile) {
return this.applyWithFunction(sourceFile, walk, parseOptions(this.ruleArguments));
};
// tslint:disable:object-literal-sort-keys
Rule.metadata = {
ruleName: "comment-type",
description: "Allows a limited set of comment types",
optionsDescription: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n One or more of the following mutually exclusive comment types may be provided:\n\n * `singleline`: Comments starting with `//`\n * `multiline`: Comments between `/*` and `*/` but are not doc comments\n * `doc`: Multiline comments that start with `/**`\n * 'directive': Triple-slash directives that are singleline comments starting with `///`"], ["\n One or more of the following mutually exclusive comment types may be provided:\n\n * \\`singleline\\`: Comments starting with \\`//\\`\n * \\`multiline\\`: Comments between \\`/*\\` and \\`*/\\` but are not doc comments\n * \\`doc\\`: Multiline comments that start with \\`/**\\`\n * \\'directive\\': Triple-slash directives that are singleline comments starting with \\`///\\`"]))),
options: {
type: "array",
items: {
type: "string",
enum: ["singleline", "multiline", "doc", "directive"],
},
uniqueItems: true,
},
optionExamples: [[true, "doc", "singleline"], [true, "singleline"], [true, "multiline"]],
hasFix: false,
type: "style",
typescriptOnly: false,
};
return Rule;
}(Lint.Rules.AbstractRule));
exports.Rule = Rule;
function walk(ctx) {
utils.forEachComment(ctx.sourceFile, function (fullText, _a) {
var kind = _a.kind, pos = _a.pos, end = _a.end;
if (kind === ts.SyntaxKind.SingleLineCommentTrivia) {
// directive
if (fullText.slice(pos, pos + 3) === "///" && !ctx.options.has("directive")) {
ctx.addFailure(pos, end, DIRECTIVE_FAILURE);
// singleline
}
else if (fullText.slice(pos, pos + 3) !== "///" && !ctx.options.has("singleline")) {
ctx.addFailure(pos, end, SINGLE_LINE_FAILURE);
}
}
else if (kind === ts.SyntaxKind.MultiLineCommentTrivia) {
// doc
if (fullText.slice(pos, pos + 3) === "/**" && !ctx.options.has("doc")) {
ctx.addFailure(pos, end, DOC_FAILURE);
// multiline
}
else if (fullText.slice(pos, pos + 3) !== "/**" && !ctx.options.has("multiline")) {
ctx.addFailure(pos, end, MULTILINE_FAILURE);
}
}
});
}
var templateObject_1;

View file

@ -0,0 +1,26 @@
/**
* @license
* Copyright 2017 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as ts from "typescript";
import { Visibility } from "../completedDocsRule";
import { Exclusion } from "./exclusion";
export interface IBlockExclusionDescriptor {
visibilities?: Visibility[];
}
export declare class BlockExclusion extends Exclusion<IBlockExclusionDescriptor> {
readonly visibilities: Set<Visibility>;
excludes(node: ts.Node): boolean;
}

View file

@ -0,0 +1,42 @@
"use strict";
/**
* @license
* Copyright 2017 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var tsutils_1 = require("tsutils");
var ts = require("typescript");
var completedDocsRule_1 = require("../completedDocsRule");
var exclusion_1 = require("./exclusion");
var BlockExclusion = /** @class */ (function (_super) {
tslib_1.__extends(BlockExclusion, _super);
function BlockExclusion() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.visibilities = _this.createSet(_this.descriptor.visibilities);
return _this;
}
BlockExclusion.prototype.excludes = function (node) {
if (this.visibilities.has(completedDocsRule_1.ALL)) {
return false;
}
if (tsutils_1.hasModifier(node.modifiers, ts.SyntaxKind.ExportKeyword)) {
return !this.visibilities.has(completedDocsRule_1.VISIBILITY_EXPORTED);
}
return !this.visibilities.has(completedDocsRule_1.VISIBILITY_INTERNAL);
};
return BlockExclusion;
}(exclusion_1.Exclusion));
exports.BlockExclusion = BlockExclusion;

View file

@ -0,0 +1,30 @@
/**
* @license
* Copyright 2013 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as ts from "typescript";
import { Location, Privacy } from "../completedDocsRule";
import { Exclusion } from "./exclusion";
export interface IClassExclusionDescriptor {
locations?: Location[];
privacies?: Privacy[];
}
export declare class ClassExclusion extends Exclusion<IClassExclusionDescriptor> {
readonly locations: Set<Location>;
readonly privacies: Set<Privacy>;
excludes(node: ts.Node): boolean;
private shouldLocationBeDocumented;
private shouldPrivacyBeDocumented;
}

View file

@ -0,0 +1,58 @@
"use strict";
/**
* @license
* Copyright 2013 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var tsutils_1 = require("tsutils");
var ts = require("typescript");
var completedDocsRule_1 = require("../completedDocsRule");
var exclusion_1 = require("./exclusion");
var ClassExclusion = /** @class */ (function (_super) {
tslib_1.__extends(ClassExclusion, _super);
function ClassExclusion() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.locations = _this.createSet(_this.descriptor.locations);
_this.privacies = _this.createSet(_this.descriptor.privacies);
return _this;
}
ClassExclusion.prototype.excludes = function (node) {
return !(this.shouldLocationBeDocumented(node) && this.shouldPrivacyBeDocumented(node));
};
ClassExclusion.prototype.shouldLocationBeDocumented = function (node) {
if (this.locations.has(completedDocsRule_1.ALL)) {
return true;
}
if (tsutils_1.hasModifier(node.modifiers, ts.SyntaxKind.StaticKeyword)) {
return this.locations.has(completedDocsRule_1.LOCATION_STATIC);
}
return this.locations.has(completedDocsRule_1.LOCATION_INSTANCE);
};
ClassExclusion.prototype.shouldPrivacyBeDocumented = function (node) {
if (this.privacies.has(completedDocsRule_1.ALL)) {
return true;
}
if (tsutils_1.hasModifier(node.modifiers, ts.SyntaxKind.PrivateKeyword)) {
return this.privacies.has(completedDocsRule_1.PRIVACY_PRIVATE);
}
if (tsutils_1.hasModifier(node.modifiers, ts.SyntaxKind.ProtectedKeyword)) {
return this.privacies.has(completedDocsRule_1.PRIVACY_PROTECTED);
}
return this.privacies.has(completedDocsRule_1.PRIVACY_PUBLIC);
};
return ClassExclusion;
}(exclusion_1.Exclusion));
exports.ClassExclusion = ClassExclusion;

View file

@ -0,0 +1,26 @@
/**
* @license
* Copyright 2019 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as ts from "typescript";
import { Privacy } from "../completedDocsRule";
import { Exclusion } from "./exclusion";
export interface IConstructorExclusionDescriptor {
privacies?: Privacy[];
}
export declare class ConstructorExclusion extends Exclusion<IConstructorExclusionDescriptor> {
readonly privacies: Set<Privacy>;
excludes(node: ts.Node): boolean;
}

View file

@ -0,0 +1,45 @@
"use strict";
/**
* @license
* Copyright 2019 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var tsutils_1 = require("tsutils");
var ts = require("typescript");
var completedDocsRule_1 = require("../completedDocsRule");
var exclusion_1 = require("./exclusion");
var ConstructorExclusion = /** @class */ (function (_super) {
tslib_1.__extends(ConstructorExclusion, _super);
function ConstructorExclusion() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.privacies = _this.createSet(_this.descriptor.privacies);
return _this;
}
ConstructorExclusion.prototype.excludes = function (node) {
if (this.privacies.has(completedDocsRule_1.ALL)) {
return false;
}
if (tsutils_1.hasModifier(node.modifiers, ts.SyntaxKind.PrivateKeyword)) {
return !this.privacies.has(completedDocsRule_1.PRIVACY_PRIVATE);
}
if (tsutils_1.hasModifier(node.modifiers, ts.SyntaxKind.ProtectedKeyword)) {
return !this.privacies.has(completedDocsRule_1.PRIVACY_PROTECTED);
}
return !this.privacies.has(completedDocsRule_1.PRIVACY_PUBLIC);
};
return ConstructorExclusion;
}(exclusion_1.Exclusion));
exports.ConstructorExclusion = ConstructorExclusion;

View file

@ -0,0 +1,25 @@
/**
* @license
* Copyright 2013 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as ts from "typescript";
import { All } from "../completedDocsRule";
import { ExclusionDescriptor } from "./exclusionDescriptors";
export declare abstract class Exclusion<TDescriptor extends ExclusionDescriptor> {
protected readonly descriptor: Partial<TDescriptor>;
constructor(descriptor?: Partial<TDescriptor>);
abstract excludes(node: ts.Node): boolean;
protected createSet<T extends All | string>(values?: T[]): Set<T>;
}

View file

@ -0,0 +1,33 @@
"use strict";
/**
* @license
* Copyright 2013 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
var completedDocsRule_1 = require("../completedDocsRule");
var Exclusion = /** @class */ (function () {
function Exclusion(descriptor) {
if (descriptor === void 0) { descriptor = {}; }
this.descriptor = descriptor;
}
Exclusion.prototype.createSet = function (values) {
if (values === undefined || values.length === 0) {
values = [completedDocsRule_1.ALL];
}
return new Set(values);
};
return Exclusion;
}());
exports.Exclusion = Exclusion;

View file

@ -0,0 +1,28 @@
/**
* @license
* Copyright 2013 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { DocType } from "../completedDocsRule";
import { IBlockExclusionDescriptor } from "./blockExclusion";
import { IClassExclusionDescriptor } from "./classExclusion";
import { ITagExclusionDescriptor } from "./tagExclusion";
export declare type ExclusionDescriptor = IBlockExclusionDescriptor | IClassExclusionDescriptor | ITagExclusionDescriptor;
export declare type InputExclusionDescriptor = boolean | ExclusionDescriptor;
export interface IExclusionDescriptors {
[type: string]: ExclusionDescriptor;
}
export declare type IInputExclusionDescriptors = DocType | {
[type: string]: InputExclusionDescriptor;
};

View file

@ -0,0 +1,18 @@
"use strict";
/**
* @license
* Copyright 2013 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });

View file

@ -0,0 +1,25 @@
/**
* @license
* Copyright 2013 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { DocType } from "../completedDocsRule";
import { Exclusion } from "./exclusion";
import { IInputExclusionDescriptors } from "./exclusionDescriptors";
export declare type ExclusionsMap = Map<DocType, DocTypeExclusions>;
export interface DocTypeExclusions {
overloadsSeparateDocs?: boolean;
requirements: Array<Exclusion<any>>;
}
export declare const constructExclusionsMap: (ruleArguments: IInputExclusionDescriptors[]) => ExclusionsMap;

View file

@ -0,0 +1,66 @@
"use strict";
/**
* @license
* Copyright 2013 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
var completedDocsRule_1 = require("../completedDocsRule");
var blockExclusion_1 = require("./blockExclusion");
var classExclusion_1 = require("./classExclusion");
var constructorExclusion_1 = require("./constructorExclusion");
var tagExclusion_1 = require("./tagExclusion");
exports.constructExclusionsMap = function (ruleArguments) {
var exclusions = new Map();
for (var _i = 0, ruleArguments_1 = ruleArguments; _i < ruleArguments_1.length; _i++) {
var ruleArgument = ruleArguments_1[_i];
addRequirements(exclusions, ruleArgument);
}
return exclusions;
};
var addRequirements = function (exclusionsMap, descriptors) {
if (typeof descriptors === "string") {
exclusionsMap.set(descriptors, createRequirementsForDocType(descriptors, {}));
return;
}
for (var _i = 0, _a = Object.keys(descriptors); _i < _a.length; _i++) {
var docType = _a[_i];
exclusionsMap.set(docType, createRequirementsForDocType(docType, descriptors[docType]));
}
};
var createRequirementsForDocType = function (docType, descriptor) {
var requirements = [];
var overloadsSeparateDocs = false;
if (typeof descriptor === "object" && completedDocsRule_1.DESCRIPTOR_OVERLOADS in descriptor) {
overloadsSeparateDocs = !!descriptor[completedDocsRule_1.DESCRIPTOR_OVERLOADS];
}
switch (docType) {
case "constructors":
requirements.push(new constructorExclusion_1.ConstructorExclusion(descriptor));
break;
case "methods":
case "properties":
requirements.push(new classExclusion_1.ClassExclusion(descriptor));
break;
default:
requirements.push(new blockExclusion_1.BlockExclusion(descriptor));
}
if (descriptor.tags !== undefined) {
requirements.push(new tagExclusion_1.TagExclusion(descriptor));
}
return {
overloadsSeparateDocs: overloadsSeparateDocs,
requirements: requirements,
};
};

View file

@ -0,0 +1,34 @@
/**
* @license
* Copyright 2013 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as ts from "typescript";
import { Exclusion } from "./exclusion";
export interface ITagExclusionDescriptor {
tags?: {
content: IContentTags;
existence: string[];
};
}
export interface IContentTags {
[i: string]: string;
}
export declare class TagExclusion extends Exclusion<ITagExclusionDescriptor> {
private readonly contentTags;
private readonly existenceTags;
excludes(node: ts.Node): boolean;
private getDocumentationNode;
private parseTagsWithContents;
}

View file

@ -0,0 +1,79 @@
"use strict";
/**
* @license
* Copyright 2013 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var ts = require("typescript");
var exclusion_1 = require("./exclusion");
var TagExclusion = /** @class */ (function (_super) {
tslib_1.__extends(TagExclusion, _super);
function TagExclusion() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.contentTags = _this.descriptor.tags === undefined ? {} : _this.descriptor.tags.content;
_this.existenceTags = new Set(_this.descriptor.tags !== undefined && _this.descriptor.tags.existence !== undefined
? _this.descriptor.tags.existence
: undefined);
return _this;
}
TagExclusion.prototype.excludes = function (node) {
var documentationNode = this.getDocumentationNode(node);
var tagsWithContents = this.parseTagsWithContents(documentationNode.getFullText());
for (var _i = 0, tagsWithContents_1 = tagsWithContents; _i < tagsWithContents_1.length; _i++) {
var tagWithContent = tagsWithContents_1[_i];
if (this.existenceTags.has(tagWithContent[0])) {
return true;
}
if (this.contentTags === undefined) {
return false;
}
var matcherBody = this.contentTags[tagWithContent[0]];
if (matcherBody === undefined) {
continue;
}
if (new RegExp(matcherBody).test(tagWithContent[1])) {
return true;
}
}
return false;
};
TagExclusion.prototype.getDocumentationNode = function (node) {
if (node.kind === ts.SyntaxKind.VariableDeclaration) {
return node.parent;
}
return node;
};
TagExclusion.prototype.parseTagsWithContents = function (nodeText) {
if (nodeText === undefined) {
return [];
}
var docMatches = nodeText.match(/\/\*\*\s*\n?([^\*]*(\*[^\/])?)*\*\//);
if (docMatches === null || docMatches.length === 0) {
return [];
}
var lines = docMatches[0].match(/[\r\n\s]*\*\s*@.*[\r\n\s]/g);
if (lines === null) {
return [];
}
return lines.map(function (line) {
var body = line.substring(line.indexOf("@"));
var firstSpaceIndex = body.search(/\s/);
return [body.substring(1, firstSpaceIndex), body.substring(firstSpaceIndex).trim()];
});
};
return TagExclusion;
}(exclusion_1.Exclusion));
exports.TagExclusion = TagExclusion;

199
node_modules/tslint/lib/rules/completedDocsRule.d.ts generated vendored Normal file
View file

@ -0,0 +1,199 @@
/**
* @license
* Copyright 2013 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as ts from "typescript";
import * as Lint from "../index";
import { IInputExclusionDescriptors } from "./completed-docs/exclusionDescriptors";
export declare const ALL = "all";
export declare const ARGUMENT_CLASSES = "classes";
export declare const ARGUMENT_CONSTRUCTORS = "constructors";
export declare const ARGUMENT_ENUMS = "enums";
export declare const ARGUMENT_ENUM_MEMBERS = "enum-members";
export declare const ARGUMENT_FUNCTIONS = "functions";
export declare const ARGUMENT_INTERFACES = "interfaces";
export declare const ARGUMENT_METHODS = "methods";
export declare const ARGUMENT_NAMESPACES = "namespaces";
export declare const ARGUMENT_PROPERTIES = "properties";
export declare const ARGUMENT_TYPES = "types";
export declare const ARGUMENT_VARIABLES = "variables";
export declare const DESCRIPTOR_TAGS = "tags";
export declare const DESCRIPTOR_LOCATIONS = "locations";
export declare const DESCRIPTOR_OVERLOADS = "overloads";
export declare const DESCRIPTOR_PRIVACIES = "privacies";
export declare const DESCRIPTOR_VISIBILITIES = "visibilities";
export declare const LOCATION_INSTANCE = "instance";
export declare const LOCATION_STATIC = "static";
export declare const PRIVACY_PRIVATE = "private";
export declare const PRIVACY_PROTECTED = "protected";
export declare const PRIVACY_PUBLIC = "public";
export declare const TAGS_FOR_CONTENT = "content";
export declare const TAGS_FOR_EXISTENCE = "existence";
export declare const VISIBILITY_EXPORTED = "exported";
export declare const VISIBILITY_INTERNAL = "internal";
export declare type All = typeof ALL;
export declare type DocType = All | typeof ARGUMENT_CLASSES | typeof ARGUMENT_CONSTRUCTORS | typeof ARGUMENT_ENUMS | typeof ARGUMENT_ENUM_MEMBERS | typeof ARGUMENT_FUNCTIONS | typeof ARGUMENT_INTERFACES | typeof ARGUMENT_METHODS | typeof ARGUMENT_NAMESPACES | typeof ARGUMENT_PROPERTIES | typeof ARGUMENT_TYPES | typeof ARGUMENT_VARIABLES;
export declare type Location = All | typeof LOCATION_INSTANCE | typeof LOCATION_STATIC;
export declare type Privacy = All | typeof PRIVACY_PRIVATE | typeof PRIVACY_PROTECTED | typeof PRIVACY_PUBLIC;
export declare type Visibility = All | typeof VISIBILITY_EXPORTED | typeof VISIBILITY_INTERNAL;
export declare class Rule extends Lint.Rules.AbstractRule {
static FAILURE_STRING_EXIST: string;
static defaultArguments: IInputExclusionDescriptors;
static ARGUMENT_DESCRIPTOR_BLOCK: {
properties: {
tags: {
properties: {
content: {
items: {
type: string;
};
type: string;
};
existence: {
items: {
type: string;
};
type: string;
};
};
};
visibilities: {
enum: string[];
type: string;
};
};
type: string;
};
static ARGUMENT_DESCRIPTOR_CLASS: {
properties: {
tags: {
properties: {
content: {
items: {
type: string;
};
type: string;
};
existence: {
items: {
type: string;
};
type: string;
};
};
};
locations: {
enum: string[];
type: string;
};
privacies: {
enum: string[];
type: string;
};
};
type: string;
};
static ARGUMENT_DESCRIPTOR_CONSTRUCTOR: {
properties: {
tags: {
properties: {
content: {
items: {
type: string;
};
type: string;
};
existence: {
items: {
type: string;
};
type: string;
};
};
};
privacies: {
enum: string[];
type: string;
};
overloads: {
type: string;
};
};
type: string;
};
static ARGUMENT_DESCRIPTOR_FUNCTION: {
properties: {
overloads: {
type: string;
};
tags: {
properties: {
content: {
items: {
type: string;
};
type: string;
};
existence: {
items: {
type: string;
};
type: string;
};
};
};
visibilities: {
enum: string[];
type: string;
};
};
type: string;
};
static ARGUMENT_DESCRIPTOR_METHOD: {
properties: {
overloads: {
type: string;
};
tags: {
properties: {
content: {
items: {
type: string;
};
type: string;
};
existence: {
items: {
type: string;
};
type: string;
};
};
};
locations: {
enum: string[];
type: string;
};
privacies: {
enum: string[];
type: string;
};
};
type: string;
};
static metadata: Lint.IRuleMetadata;
apply(sourceFile: ts.SourceFile): Lint.RuleFailure[];
private getExclusionsMap;
}

484
node_modules/tslint/lib/rules/completedDocsRule.js generated vendored Normal file
View file

@ -0,0 +1,484 @@
"use strict";
/**
* @license
* Copyright 2013 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var tsutils = require("tsutils");
var ts = require("typescript");
var Lint = require("../index");
var exclusions_1 = require("./completed-docs/exclusions");
exports.ALL = "all";
exports.ARGUMENT_CLASSES = "classes";
exports.ARGUMENT_CONSTRUCTORS = "constructors";
exports.ARGUMENT_ENUMS = "enums";
exports.ARGUMENT_ENUM_MEMBERS = "enum-members";
exports.ARGUMENT_FUNCTIONS = "functions";
exports.ARGUMENT_INTERFACES = "interfaces";
exports.ARGUMENT_METHODS = "methods";
exports.ARGUMENT_NAMESPACES = "namespaces";
exports.ARGUMENT_PROPERTIES = "properties";
exports.ARGUMENT_TYPES = "types";
exports.ARGUMENT_VARIABLES = "variables";
exports.DESCRIPTOR_TAGS = "tags";
exports.DESCRIPTOR_LOCATIONS = "locations";
exports.DESCRIPTOR_OVERLOADS = "overloads";
exports.DESCRIPTOR_PRIVACIES = "privacies";
exports.DESCRIPTOR_VISIBILITIES = "visibilities";
exports.LOCATION_INSTANCE = "instance";
exports.LOCATION_STATIC = "static";
exports.PRIVACY_PRIVATE = "private";
exports.PRIVACY_PROTECTED = "protected";
exports.PRIVACY_PUBLIC = "public";
exports.TAGS_FOR_CONTENT = "content";
exports.TAGS_FOR_EXISTENCE = "existence";
exports.VISIBILITY_EXPORTED = "exported";
exports.VISIBILITY_INTERNAL = "internal";
var Rule = /** @class */ (function (_super) {
tslib_1.__extends(Rule, _super);
function Rule() {
return _super !== null && _super.apply(this, arguments) || this;
}
/* tslint:enable:object-literal-sort-keys */
Rule.prototype.apply = function (sourceFile) {
var options = this.getOptions();
var exclusionsMap = this.getExclusionsMap(options.ruleArguments);
return this.applyWithFunction(sourceFile, walk, exclusionsMap);
};
Rule.prototype.getExclusionsMap = function (ruleArguments) {
if (ruleArguments.length === 0) {
ruleArguments = [Rule.defaultArguments];
}
return exclusions_1.constructExclusionsMap(ruleArguments);
};
Rule.FAILURE_STRING_EXIST = "Documentation must exist for ";
Rule.defaultArguments = (_a = {},
_a[exports.ARGUMENT_CLASSES] = true,
_a[exports.ARGUMENT_FUNCTIONS] = true,
_a[exports.ARGUMENT_METHODS] = (_b = {},
_b[exports.DESCRIPTOR_TAGS] = (_c = {},
_c[exports.TAGS_FOR_CONTENT] = {
see: ".*",
},
_c[exports.TAGS_FOR_EXISTENCE] = ["deprecated", "inheritdoc"],
_c),
_b),
_a[exports.ARGUMENT_PROPERTIES] = (_d = {},
_d[exports.DESCRIPTOR_TAGS] = (_e = {},
_e[exports.TAGS_FOR_CONTENT] = {
see: ".*",
},
_e[exports.TAGS_FOR_EXISTENCE] = ["deprecated", "inheritdoc"],
_e),
_d),
_a);
Rule.ARGUMENT_DESCRIPTOR_BLOCK = {
properties: (_f = {},
_f[exports.DESCRIPTOR_TAGS] = {
properties: (_g = {},
_g[exports.TAGS_FOR_CONTENT] = {
items: {
type: "string",
},
type: "object",
},
_g[exports.TAGS_FOR_EXISTENCE] = {
items: {
type: "string",
},
type: "array",
},
_g),
},
_f[exports.DESCRIPTOR_VISIBILITIES] = {
enum: [exports.ALL, exports.VISIBILITY_EXPORTED, exports.VISIBILITY_INTERNAL],
type: "string",
},
_f),
type: "object",
};
Rule.ARGUMENT_DESCRIPTOR_CLASS = {
properties: (_h = {},
_h[exports.DESCRIPTOR_TAGS] = {
properties: (_j = {},
_j[exports.TAGS_FOR_CONTENT] = {
items: {
type: "string",
},
type: "object",
},
_j[exports.TAGS_FOR_EXISTENCE] = {
items: {
type: "string",
},
type: "array",
},
_j),
},
_h[exports.DESCRIPTOR_LOCATIONS] = {
enum: [exports.ALL, exports.LOCATION_INSTANCE, exports.LOCATION_STATIC],
type: "string",
},
_h[exports.DESCRIPTOR_PRIVACIES] = {
enum: [exports.ALL, exports.PRIVACY_PRIVATE, exports.PRIVACY_PROTECTED, exports.PRIVACY_PUBLIC],
type: "string",
},
_h),
type: "object",
};
Rule.ARGUMENT_DESCRIPTOR_CONSTRUCTOR = {
properties: (_k = {},
_k[exports.DESCRIPTOR_TAGS] = {
properties: (_l = {},
_l[exports.TAGS_FOR_CONTENT] = {
items: {
type: "string",
},
type: "object",
},
_l[exports.TAGS_FOR_EXISTENCE] = {
items: {
type: "string",
},
type: "array",
},
_l),
},
_k[exports.DESCRIPTOR_PRIVACIES] = {
enum: [exports.ALL, exports.PRIVACY_PRIVATE, exports.PRIVACY_PROTECTED, exports.PRIVACY_PUBLIC],
type: "string",
},
_k[exports.DESCRIPTOR_OVERLOADS] = {
type: "boolean",
},
_k),
type: "object",
};
Rule.ARGUMENT_DESCRIPTOR_FUNCTION = {
properties: tslib_1.__assign(tslib_1.__assign({}, Rule.ARGUMENT_DESCRIPTOR_BLOCK.properties), (_m = {}, _m[exports.DESCRIPTOR_OVERLOADS] = {
type: "boolean",
}, _m)),
type: "object",
};
Rule.ARGUMENT_DESCRIPTOR_METHOD = {
properties: tslib_1.__assign(tslib_1.__assign({}, Rule.ARGUMENT_DESCRIPTOR_CLASS.properties), (_o = {}, _o[exports.DESCRIPTOR_OVERLOADS] = {
type: "boolean",
}, _o)),
type: "object",
};
/* tslint:disable:object-literal-sort-keys */
Rule.metadata = {
ruleName: "completed-docs",
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 * `\"", "\"` `\"", "\"` 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 * `\"", "\"`"], ["\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 * \\`\"", "\"\\`"])), 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_CONSTRUCTORS, exports.ARGUMENT_ENUMS, exports.ARGUMENT_ENUM_MEMBERS, exports.ARGUMENT_FUNCTIONS, exports.ARGUMENT_INTERFACES, exports.ARGUMENT_METHODS, exports.ARGUMENT_NAMESPACES, exports.ARGUMENT_PROPERTIES, exports.ARGUMENT_TYPES, exports.ARGUMENT_VARIABLES),
options: {
type: "array",
items: {
anyOf: [
{
options: [
exports.ARGUMENT_CLASSES,
exports.ARGUMENT_ENUMS,
exports.ARGUMENT_FUNCTIONS,
exports.ARGUMENT_INTERFACES,
exports.ARGUMENT_METHODS,
exports.ARGUMENT_NAMESPACES,
exports.ARGUMENT_PROPERTIES,
exports.ARGUMENT_TYPES,
exports.ARGUMENT_VARIABLES,
],
type: "string",
},
{
type: "object",
properties: (_p = {},
_p[exports.ARGUMENT_CLASSES] = Rule.ARGUMENT_DESCRIPTOR_BLOCK,
_p[exports.ARGUMENT_CONSTRUCTORS] = Rule.ARGUMENT_DESCRIPTOR_CONSTRUCTOR,
_p[exports.ARGUMENT_ENUMS] = Rule.ARGUMENT_DESCRIPTOR_BLOCK,
_p[exports.ARGUMENT_ENUM_MEMBERS] = Rule.ARGUMENT_DESCRIPTOR_BLOCK,
_p[exports.ARGUMENT_FUNCTIONS] = Rule.ARGUMENT_DESCRIPTOR_FUNCTION,
_p[exports.ARGUMENT_INTERFACES] = Rule.ARGUMENT_DESCRIPTOR_BLOCK,
_p[exports.ARGUMENT_METHODS] = Rule.ARGUMENT_DESCRIPTOR_METHOD,
_p[exports.ARGUMENT_NAMESPACES] = Rule.ARGUMENT_DESCRIPTOR_BLOCK,
_p[exports.ARGUMENT_PROPERTIES] = Rule.ARGUMENT_DESCRIPTOR_CLASS,
_p[exports.ARGUMENT_TYPES] = Rule.ARGUMENT_DESCRIPTOR_BLOCK,
_p[exports.ARGUMENT_VARIABLES] = Rule.ARGUMENT_DESCRIPTOR_BLOCK,
_p),
},
],
},
},
optionExamples: [
true,
[true, exports.ARGUMENT_ENUMS, exports.ARGUMENT_FUNCTIONS, exports.ARGUMENT_METHODS],
[
true,
(_q = {},
_q[exports.ARGUMENT_ENUMS] = true,
_q[exports.ARGUMENT_FUNCTIONS] = (_r = {},
_r[exports.DESCRIPTOR_VISIBILITIES] = [exports.VISIBILITY_EXPORTED],
_r),
_q[exports.ARGUMENT_METHODS] = (_s = {},
_s[exports.DESCRIPTOR_LOCATIONS] = exports.LOCATION_INSTANCE,
_s[exports.DESCRIPTOR_PRIVACIES] = [exports.PRIVACY_PUBLIC, exports.PRIVACY_PROTECTED],
_s),
_q[exports.ARGUMENT_PROPERTIES] = (_t = {},
_t[exports.DESCRIPTOR_TAGS] = (_u = {},
_u[exports.TAGS_FOR_CONTENT] = {
see: ["#.*"],
},
_u[exports.TAGS_FOR_EXISTENCE] = ["inheritdoc"],
_u),
_t),
_q),
],
],
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",
typescriptOnly: false,
};
return Rule;
}(Lint.Rules.AbstractRule));
exports.Rule = Rule;
var modifierAliases = {
export: "exported",
};
function walk(context) {
return ts.forEachChild(context.sourceFile, cb);
function cb(node) {
switch (node.kind) {
case ts.SyntaxKind.ClassDeclaration:
checkNode(node, exports.ARGUMENT_CLASSES);
break;
case ts.SyntaxKind.Constructor:
checkNode(node, exports.ARGUMENT_CONSTRUCTORS);
break;
case ts.SyntaxKind.EnumDeclaration:
checkNode(node, exports.ARGUMENT_ENUMS);
for (var _i = 0, _a = node.members; _i < _a.length; _i++) {
var member = _a[_i];
// Enum members don't have modifiers, so use the parent
// enum declaration when checking the requirements.
checkNode(member, exports.ARGUMENT_ENUM_MEMBERS, node);
}
break;
case ts.SyntaxKind.FunctionDeclaration:
checkNode(node, exports.ARGUMENT_FUNCTIONS);
break;
case ts.SyntaxKind.InterfaceDeclaration:
checkNode(node, exports.ARGUMENT_INTERFACES);
break;
case ts.SyntaxKind.MethodSignature:
checkNode(node, exports.ARGUMENT_METHODS);
break;
case ts.SyntaxKind.MethodDeclaration:
if (node.parent.kind !== ts.SyntaxKind.ObjectLiteralExpression) {
checkNode(node, exports.ARGUMENT_METHODS);
}
break;
case ts.SyntaxKind.ModuleDeclaration:
checkNode(node, exports.ARGUMENT_NAMESPACES);
break;
case ts.SyntaxKind.PropertySignature:
checkNode(node, exports.ARGUMENT_PROPERTIES);
break;
case ts.SyntaxKind.PropertyDeclaration:
checkNode(node, exports.ARGUMENT_PROPERTIES);
break;
case ts.SyntaxKind.TypeAliasDeclaration:
checkNode(node, exports.ARGUMENT_TYPES);
break;
case ts.SyntaxKind.VariableStatement:
// Only check variables at the namespace/module-level or file-level
// and not variables declared inside functions and other things.
switch (node.parent.kind) {
case ts.SyntaxKind.SourceFile:
case ts.SyntaxKind.ModuleBlock:
for (var _b = 0, _c = node.declarationList
.declarations; _b < _c.length; _b++) {
var declaration = _c[_b];
checkNode(declaration, exports.ARGUMENT_VARIABLES, node);
}
}
break;
case ts.SyntaxKind.GetAccessor:
case ts.SyntaxKind.SetAccessor:
if (node.parent.kind !== ts.SyntaxKind.ObjectLiteralExpression) {
checkAccessorNode(node, exports.ARGUMENT_PROPERTIES);
}
}
return ts.forEachChild(node, cb);
}
function checkNode(node, docType, requirementNode) {
if (requirementNode === void 0) { requirementNode = node; }
if (!nodeIsExcluded(node, docType, requirementNode) && !nodeHasDocs(node, docType)) {
addDocumentationFailure(node, describeDocType(docType), requirementNode);
}
}
function checkAccessorNode(node, docType) {
if (nodeIsExcluded(node, exports.ARGUMENT_PROPERTIES, node) || nodeHasDocs(node, docType)) {
return;
}
var correspondingAccessor = getCorrespondingAccessor(node);
if (correspondingAccessor === undefined || !nodeHasDocs(correspondingAccessor, docType)) {
addDocumentationFailure(node, exports.ARGUMENT_PROPERTIES, node);
}
}
function nodeIsExcluded(node, docType, requirementNode) {
if (docType !== exports.ARGUMENT_CONSTRUCTORS) {
var name = node.name;
if (name === undefined) {
return true;
}
}
var exclusions = context.options.get(docType);
if (exclusions === undefined) {
return true;
}
for (var _i = 0, _a = exclusions.requirements; _i < _a.length; _i++) {
var requirement = _a[_i];
if (requirement.excludes(requirementNode)) {
return true;
}
}
return false;
}
function nodeHasDocs(node, docType) {
var docs = getApparentJsDoc(node, docType, context.sourceFile);
if (docs === undefined) {
return false;
}
var comments = docs
.map(function (doc) { return doc.comment; })
.filter(function (comment) { return comment !== undefined && comment.trim() !== ""; });
return comments.length !== 0;
}
/**
* @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 tslib_1.__spreadArrays(docs, 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.isConstructorDeclaration(node)) {
var members = node.parent.members;
return members.filter(function (child) { return tsutils.isConstructorDeclaration(child); });
}
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, docType);
context.addFailureAt(start, width, description);
}
}
function getCorrespondingAccessor(node) {
var propertyName = tsutils.getPropertyName(node.name);
if (propertyName === undefined) {
return undefined;
}
var parent = node.parent;
var correspondingKindCheck = node.kind === ts.SyntaxKind.GetAccessor ? isSetAccessor : isGetAccessor;
for (var _i = 0, _a = parent.members; _i < _a.length; _i++) {
var member = _a[_i];
if (!correspondingKindCheck(member)) {
continue;
}
if (tsutils.getPropertyName(member.name) === propertyName) {
return member;
}
}
return undefined;
}
function variableIsAfterFirstInDeclarationList(node) {
var parent = node.parent;
if (parent === undefined) {
return false;
}
return ts.isVariableDeclarationList(parent) && node !== parent.declarations[0];
}
function describeDocumentationFailure(node, docType) {
var description = Rule.FAILURE_STRING_EXIST;
if (node.modifiers !== undefined) {
description += node.modifiers
.map(function (modifier) { return describeModifier(modifier.kind); })
.join(" ") + " ";
}
return "" + description + docType + ".";
}
function describeModifier(kind) {
var description = ts.SyntaxKind[kind].toLowerCase().split("keyword")[0];
var alias = modifierAliases[description];
return alias !== undefined ? alias : description;
}
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 tslib_1.__spreadArrays(parent.statements);
}
return parent.getChildren();
}
function isGetAccessor(node) {
return node.kind === ts.SyntaxKind.GetAccessor;
}
function isSetAccessor(node) {
return node.kind === ts.SyntaxKind.SetAccessor;
}
var templateObject_1, templateObject_2;

24
node_modules/tslint/lib/rules/curlyRule.d.ts generated vendored Normal file
View file

@ -0,0 +1,24 @@
/**
* @license
* Copyright 2013 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as ts from "typescript";
import * as Lint from "../index";
export declare class Rule extends Lint.Rules.AbstractRule {
static metadata: Lint.IRuleMetadata;
static FAILURE_STRING_AS_NEEDED: string;
static FAILURE_STRING_FACTORY(kind: string): string;
apply(sourceFile: ts.SourceFile): Lint.RuleFailure[];
}

147
node_modules/tslint/lib/rules/curlyRule.js generated vendored Normal file
View file

@ -0,0 +1,147 @@
"use strict";
/**
* @license
* Copyright 2013 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var tsutils_1 = require("tsutils");
var ts = require("typescript");
var Lint = require("../index");
var utils_1 = require("../utils");
var curly_examples_1 = require("./code-examples/curly.examples");
var OPTION_AS_NEEDED = "as-needed";
var OPTION_IGNORE_SAME_LINE = "ignore-same-line";
var Rule = /** @class */ (function (_super) {
tslib_1.__extends(Rule, _super);
function Rule() {
return _super !== null && _super.apply(this, arguments) || this;
}
Rule.FAILURE_STRING_FACTORY = function (kind) {
return kind + " statements must be braced";
};
Rule.prototype.apply = function (sourceFile) {
if (this.ruleArguments.indexOf(OPTION_AS_NEEDED) !== -1) {
return this.applyWithFunction(sourceFile, walkAsNeeded);
}
return this.applyWithWalker(new CurlyWalker(sourceFile, this.ruleName, {
ignoreSameLine: this.ruleArguments.indexOf(OPTION_IGNORE_SAME_LINE) !== -1,
}));
};
/* tslint:disable:object-literal-sort-keys */
Rule.metadata = {
ruleName: "curly",
description: "Enforces braces for `if`/`for`/`do`/`while` statements.",
rationale: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n ```ts\n if (foo === bar)\n foo++;\n bar++;\n ```\n\n In the code above, the author almost certainly meant for both `foo++` and `bar++`\n to be executed only if `foo === bar`. However, they forgot braces and `bar++` will be executed\n no matter what. This rule could prevent such a mistake."], ["\n \\`\\`\\`ts\n if (foo === bar)\n foo++;\n bar++;\n \\`\\`\\`\n\n In the code above, the author almost certainly meant for both \\`foo++\\` and \\`bar++\\`\n to be executed only if \\`foo === bar\\`. However, they forgot braces and \\`bar++\\` will be executed\n no matter what. This rule could prevent such a mistake."]))),
optionsDescription: Lint.Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n One of the following options may be provided:\n\n * `\"", "\"` forbids any unnecessary curly braces.\n * `\"", "\"` skips checking braces for control-flow statements\n that are on one line and start on the same line as their control-flow keyword\n "], ["\n One of the following options may be provided:\n\n * \\`\"", "\"\\` forbids any unnecessary curly braces.\n * \\`\"", "\"\\` skips checking braces for control-flow statements\n that are on one line and start on the same line as their control-flow keyword\n "])), OPTION_AS_NEEDED, OPTION_IGNORE_SAME_LINE),
options: {
type: "array",
items: {
type: "string",
enum: [OPTION_AS_NEEDED, OPTION_IGNORE_SAME_LINE],
},
},
optionExamples: [true, [true, OPTION_IGNORE_SAME_LINE], [true, OPTION_AS_NEEDED]],
type: "functionality",
typescriptOnly: false,
hasFix: true,
codeExamples: curly_examples_1.codeExamples,
};
/* tslint:enable:object-literal-sort-keys */
Rule.FAILURE_STRING_AS_NEEDED = "Block contains only one statement; remove the curly braces.";
return Rule;
}(Lint.Rules.AbstractRule));
exports.Rule = Rule;
function walkAsNeeded(ctx) {
ts.forEachChild(ctx.sourceFile, function cb(node) {
if (tsutils_1.isBlock(node) && isBlockUnnecessary(node)) {
ctx.addFailureAt(node.statements.pos - 1, 1, Rule.FAILURE_STRING_AS_NEEDED);
}
ts.forEachChild(node, cb);
});
}
function isBlockUnnecessary(node) {
var parent = node.parent;
if (node.statements.length !== 1) {
return false;
}
var statement = node.statements[0];
if (tsutils_1.isIterationStatement(parent)) {
return true;
}
/*
Watch out for this case:
if (so) {
if (also)
foo();
} else
bar();
*/
return (tsutils_1.isIfStatement(parent) &&
!(tsutils_1.isIfStatement(statement) &&
statement.elseStatement === undefined &&
parent.thenStatement === node &&
parent.elseStatement !== undefined));
}
var CurlyWalker = /** @class */ (function (_super) {
tslib_1.__extends(CurlyWalker, _super);
function CurlyWalker() {
return _super !== null && _super.apply(this, arguments) || this;
}
CurlyWalker.prototype.walk = function (sourceFile) {
var _this = this;
var cb = function (node) {
if (tsutils_1.isIterationStatement(node)) {
_this.checkStatement(node.statement, node, 0, node.end);
}
else if (tsutils_1.isIfStatement(node)) {
_this.checkStatement(node.thenStatement, node, 0);
if (node.elseStatement !== undefined &&
node.elseStatement.kind !== ts.SyntaxKind.IfStatement) {
_this.checkStatement(node.elseStatement, node, 5);
}
}
return ts.forEachChild(node, cb);
};
return ts.forEachChild(sourceFile, cb);
};
CurlyWalker.prototype.checkStatement = function (statement, node, childIndex, end) {
if (end === void 0) { end = statement.end; }
var sameLine = tsutils_1.isSameLine(this.sourceFile, statement.pos, statement.end);
if (statement.kind !== ts.SyntaxKind.Block && !(this.options.ignoreSameLine && sameLine)) {
var token = node.getChildAt(childIndex, this.sourceFile);
var tokenText = ts.tokenToString(token.kind);
this.addFailure(token.end - tokenText.length, end, Rule.FAILURE_STRING_FACTORY(tokenText), this.createMissingBraceFix(statement, node, sameLine));
}
};
/** Generate the necessary replacement to add braces to a statement that needs them. */
CurlyWalker.prototype.createMissingBraceFix = function (statement, node, sameLine) {
if (sameLine) {
return [
Lint.Replacement.appendText(statement.pos, " {"),
Lint.Replacement.appendText(statement.end, " }"),
];
}
else {
var newLine = utils_1.newLineWithIndentation(node, this.sourceFile);
return [
Lint.Replacement.appendText(statement.pos, " {"),
Lint.Replacement.appendText(statement.end, newLine + "}"),
];
}
};
return CurlyWalker;
}(Lint.AbstractWalker));
var templateObject_1, templateObject_2;

Some files were not shown because too many files have changed in this diff Show more