Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
* 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;
};
/* tslint:disable:object-literal-sort-keys */
Rule.metadata = {
ruleName: "no-void-expression",
description: "Requires expressions of type `void` to appear in statement position.",
optionsDescription: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n If `", "` is provided, `() => returnsVoid()` will be allowed.\n Otherwise, it must be written as `() => { returnsVoid(); }`."], ["\n If \\`", "\\` is provided, \\`() => returnsVoid()\\` will be allowed.\n Otherwise, it must be written as \\`() => { returnsVoid(); }\\`."])), OPTION_IGNORE_ARROW_FUNCTION_SHORTHAND),
options: {
type: "array",
items: {
type: "string",
enum: [OPTION_IGNORE_ARROW_FUNCTION_SHORTHAND],
},
minLength: 0,
maxLength: 1,
},
rationale: Lint.Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n It's misleading returning the results of an expression whose type is `void`.\n Attempting to do so is likely a symptom of expecting a different return type from a function.\n For example, the following code will log `undefined` but looks like it logs a value:\n\n ```\n const performWork = (): void => {\n workFirst();\n workSecond();\n };\n\n console.log(performWork());\n ```\n "], ["\n It's misleading returning the results of an expression whose type is \\`void\\`.\n Attempting to do so is likely a symptom of expecting a different return type from a function.\n For example, the following code will log \\`undefined\\` but looks like it logs a value:\n\n \\`\\`\\`\n const performWork = (): void => {\n workFirst();\n workSecond();\n };\n\n console.log(performWork());\n \\`\\`\\`\n "]))),
requiresTypeInfo: true,
type: "functionality",
typescriptOnly: false,
};
/* tslint:enable:object-literal-sort-keys */
Rule.FAILURE_STRING = "Expression has type `void`. Put it on its own line as a statement.";
return Rule;
}(Lint.Rules.TypedRule));
exports.Rule = Rule;
if (this.ruleArguments[0] !== undefined) {
return this.ruleArguments[0];
}
return Rule.DEFAULT_THRESHOLD;
},
enumerable: true,
configurable: true
});
Rule.DEFAULT_THRESHOLD = 20;
Rule.MINIMUM_THRESHOLD = 2;
/* tslint:disable:object-literal-sort-keys */
Rule.metadata = {
ruleName: "cyclomatic-complexity",
description: "Enforces a threshold of cyclomatic complexity.",
descriptionDetails: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n Cyclomatic complexity is assessed for each function of any type. A starting value of 0\n is assigned and this value is then incremented for every statement which can branch the\n control flow within the function. The following statements and expressions contribute\n to cyclomatic complexity:\n * `catch`\n * `if` and `? :`\n * `||` and `&&` due to short-circuit evaluation\n * `for`, `for in` and `for of` loops\n * `while` and `do while` loops\n * `case` clauses that contain statements"], ["\n Cyclomatic complexity is assessed for each function of any type. A starting value of 0\n is assigned and this value is then incremented for every statement which can branch the\n control flow within the function. The following statements and expressions contribute\n to cyclomatic complexity:\n * \\`catch\\`\n * \\`if\\` and \\`? :\\`\n * \\`||\\` and \\`&&\\` due to short-circuit evaluation\n * \\`for\\`, \\`for in\\` and \\`for of\\` loops\n * \\`while\\` and \\`do while\\` loops\n * \\`case\\` clauses that contain statements"]))),
rationale: Lint.Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n Cyclomatic complexity is a code metric which indicates the level of complexity in a\n function. High cyclomatic complexity indicates confusing code which may be prone to\n errors or difficult to modify.\n\n It's better to have smaller, single-purpose functions with self-documenting names."], ["\n Cyclomatic complexity is a code metric which indicates the level of complexity in a\n function. High cyclomatic complexity indicates confusing code which may be prone to\n errors or difficult to modify.\n\n It's better to have smaller, single-purpose functions with self-documenting names."]))),
optionsDescription: Lint.Utils.dedent(templateObject_3 || (templateObject_3 = tslib_1.__makeTemplateObject(["\n An optional upper limit for cyclomatic complexity can be specified. If no limit option\n is provided a default value of ", " will be used."], ["\n An optional upper limit for cyclomatic complexity can be specified. If no limit option\n is provided a default value of ", " will be used."])), Rule.DEFAULT_THRESHOLD),
options: {
type: "number",
minimum: Rule.MINIMUM_THRESHOLD,
},
optionExamples: [true, [true, 20]],
type: "maintainability",
typescriptOnly: false,
};
return Rule;
}(Lint.Rules.AbstractRule));
exports.Rule = Rule;
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"]],
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) {
return this.applyWithFunction(sourceFile, walk, parseOptions(this.ruleArguments), program.getTypeChecker());
};
/* tslint:disable:object-literal-sort-keys */
Rule.metadata = {
ruleName: "promise-function-async",
description: "Requires any function or method that returns a promise to be marked async.",
rationale: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n Ensures that each function is only capable of 1) returning a rejected promise, or 2)\n throwing an Error object. In contrast, non-`async` `Promise`-returning functions\n are technically capable of either. This practice removes a requirement for consuming\n code to handle both cases.\n\n If no optional arguments are provided then all function types are checked,\n otherwise the specific function types are checked:\n\n * `\"", "\"` check function declarations.\n * `\"", "\"` check function expressions.\n * `\"", "\"` check arrow functions.\n * `\"", "\"` check method declarations.\n "], ["\n Ensures that each function is only capable of 1) returning a rejected promise, or 2)\n throwing an Error object. In contrast, non-\\`async\\` \\`Promise\\`-returning functions\n are technically capable of either. This practice removes a requirement for consuming\n code to handle both cases.\n\n If no optional arguments are provided then all function types are checked,\n otherwise the specific function types are checked:\n\n * \\`\"", "\"\\` check function declarations.\n * \\`\"", "\"\\` check function expressions.\n * \\`\"", "\"\\` check arrow functions.\n * \\`\"", "\"\\` check method declarations.\n "])), OPTION_FUNCTION_DECLARATION, OPTION_FUNCTION_EXPRESSION, OPTION_ARROW_FUNCTION, OPTION_METHOD_DECLARATION),
optionsDescription: "Not configurable.",
options: {
type: "array",
items: {
type: "string",
enum: [
OPTION_FUNCTION_DECLARATION,
OPTION_FUNCTION_EXPRESSION,
OPTION_ARROW_FUNCTION,
OPTION_METHOD_DECLARATION,
],
},
minLength: 0,
maxLength: 4,
},
optionExamples: [true, [true, OPTION_FUNCTION_DECLARATION, OPTION_METHOD_DECLARATION]],
var Rule = /** @class */ (function (_super) {
tslib_1.__extends(Rule, _super);
function Rule() {
return _super !== null && _super.apply(this, arguments) || this;
}
Rule.id = function (input) {
return input;
};
Rule.prototype.apply = function (sourceFile) {
return this.applyWithFunction(sourceFile, walk);
};
/* tslint:disable:object-literal-sort-keys */
Rule.metadata = {
ruleName: "no-string-literal",
description: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n Forbids unnecessary string literal property access.\n Allows `obj[\"prop-erty\"]` (can't be a regular property access).\n Disallows `obj[\"property\"]` (should be `obj.property`)."], ["\n Forbids unnecessary string literal property access.\n Allows \\`obj[\"prop-erty\"]\\` (can't be a regular property access).\n Disallows \\`obj[\"property\"]\\` (should be \\`obj.property\\`)."]))),
rationale: Lint.Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n If `--noImplicitAny` is turned off,\n property access via a string literal will be 'any' if the property does not exist."], ["\n If \\`--noImplicitAny\\` is turned off,\n property access via a string literal will be 'any' if the property does not exist."]))),
optionsDescription: "Not configurable.",
options: null,
optionExamples: [true],
type: "functionality",
typescriptOnly: false,
hasFix: true,
};
/* tslint:enable:object-literal-sort-keys */
Rule.FAILURE_STRING = "object access via string literals is disallowed";
return Rule;
}(Lint.Rules.AbstractRule));
exports.Rule = Rule;
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, {
firstLineOfMultiline: this.ruleArguments.indexOf(OPTION_CHECK_MULTILINE_START) !== -1,
});
};
/* tslint:disable:object-literal-sort-keys */
Rule.metadata = {
ruleName: "jsdoc-format",
description: "Enforces basic format rules for JSDoc comments.",
descriptionDetails: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n The following rules are enforced for JSDoc comments (comments starting with `/**`):\n\n * each line contains an asterisk and asterisks must be aligned\n * each asterisk must be followed by either a space or a newline (except for the first and the last)\n * the only characters before the asterisk on each line must be whitespace characters\n * one line comments must start with `/** ` and end with `*/`\n * multiline comments don't allow text after `/** ` in the first line (with option `\"", "\"`)\n "], ["\n The following rules are enforced for JSDoc comments (comments starting with \\`/**\\`):\n\n * each line contains an asterisk and asterisks must be aligned\n * each asterisk must be followed by either a space or a newline (except for the first and the last)\n * the only characters before the asterisk on each line must be whitespace characters\n * one line comments must start with \\`/** \\` and end with \\`*/\\`\n * multiline comments don't allow text after \\`/** \\` in the first line (with option \\`\"", "\"\\`)\n "])), OPTION_CHECK_MULTILINE_START),
rationale: "Helps maintain a consistent, readable style for JSDoc comments.",
optionsDescription: Lint.Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n You can optionally specify the option `\"", "\"` to enforce the first line of a\n multiline JSDoc comment to be empty.\n "], ["\n You can optionally specify the option \\`\"", "\"\\` to enforce the first line of a\n multiline JSDoc comment to be empty.\n "])), OPTION_CHECK_MULTILINE_START),
options: {
type: "array",
minItems: 0,
maxItems: 1,
items: {
type: "string",
enum: [OPTION_CHECK_MULTILINE_START],
},
},
optionExamples: [true, [true, OPTION_CHECK_MULTILINE_START]],
type: "style",
typescriptOnly: false,
};
/* tslint:enable:object-literal-sort-keys */
Rule.ALIGNMENT_FAILURE_STRING = "asterisks in jsdoc must be aligned";
Rule.FORMAT_FAILURE_STRING = "jsdoc is not formatted correctly on this line";
import { css } from '@emotion/core/macro'
import { __makeTemplateObject } from 'tslib'
var templateObject_1
const someVar = css(
templateObject_1 ||
(templateObject_1 = __makeTemplateObject(
['\n color: hotpink;\n'],
['\n color: hotpink;\n']
))
)
type: "string",
describe: "tsconfig.json file",
description: utils_1.dedent(templateObject_9 || (templateObject_9 = tslib_1.__makeTemplateObject(["\n The path to the tsconfig.json file or to the directory containing\n the tsconfig.json file. The file will be used to determine which\n files will be linted. This flag also enables rules that require the\n type checker."], ["\n The path to the tsconfig.json file or to the directory containing\n the tsconfig.json file. The file will be used to determine which\n files will be linted. This flag also enables rules that require the\n type checker."]))),
},
{
short: "q",
name: "quiet",
type: "boolean",
describe: "hide errors on lint",
description: "If true, hides warnings from linting output.",
},
{
name: "type-check",
type: "boolean",
describe: "(deprecated) check for type errors before linting the project",
description: utils_1.dedent(templateObject_10 || (templateObject_10 = tslib_1.__makeTemplateObject(["\n (deprecated) Checks for type errors before linting a project.\n --project must be specified in order to enable type checking."], ["\n (deprecated) Checks for type errors before linting a project.\n --project must be specified in order to enable type checking."]))),
},
];
var builtinOptions = [
{
short: "v",
name: "version",
type: "boolean",
describe: "current version",
description: "The current version of tslint.",
},
{
short: "h",
name: "help",
type: "boolean",
describe: "display detailed help",
description: "Prints this help message.",
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));
};
Rule.metadata = {
ruleName: "whitespace",
description: "Enforces whitespace style conventions.",
rationale: "Helps maintain a readable, consistent style in your codebase.",
optionsDescription: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n Several arguments may be optionally provided:\n\n * `\"check-branch\"` checks branching statements (`if`/`else`/`for`/`while`) are followed by whitespace.\n * `\"check-decl\"`checks that variable declarations have whitespace around the equals token.\n * `\"check-operator\"` checks for whitespace around operator tokens.\n * `\"check-module\"` checks for whitespace in import & export statements.\n * `\"check-separator\"` checks for whitespace after separator tokens (`,`/`;`).\n * `\"check-rest-spread\"` checks that there is no whitespace after rest/spread operator (`...`).\n * `\"check-type\"` checks for whitespace before a variable type specification.\n * `\"check-typecast\"` checks for whitespace between a typecast and its target.\n * `\"check-type-operator\"` checks for whitespace between type operators `|` and `&`.\n * `\"check-preblock\"` checks for whitespace before the opening brace of a block.\n * `\"check-postbrace\"` checks for whitespace after an opening brace."], ["\n Several arguments may be optionally provided:\n\n * \\`\"check-branch\"\\` checks branching statements (\\`if\\`/\\`else\\`/\\`for\\`/\\`while\\`) are followed by whitespace.\n * \\`\"check-decl\"\\`checks that variable declarations have whitespace around the equals token.\n * \\`\"check-operator\"\\` checks for whitespace around operator tokens.\n * \\`\"check-module\"\\` checks for whitespace in import & export statements.\n * \\`\"check-separator\"\\` checks for whitespace after separator tokens (\\`,\\`/\\`;\\`).\n * \\`\"check-rest-spread\"\\` checks that there is no whitespace after rest/spread operator (\\`...\\`).\n * \\`\"check-type\"\\` checks for whitespace before a variable type specification.\n * \\`\"check-typecast\"\\` checks for whitespace between a typecast and its target.\n * \\`\"check-type-operator\"\\` checks for whitespace between type operators \\`|\\` and \\`&\\`.\n * \\`\"check-preblock\"\\` checks for whitespace before the opening brace of a block.\n * \\`\"check-postbrace\"\\` checks for whitespace after an opening brace."]))),
options: {
type: "array",
items: {
type: "string",
enum: [
"check-branch",
"check-decl",
"check-operator",
"check-module",
"check-separator",
"check-rest-spread",
"check-type",
"check-typecast",
"check-type-operator",
"check-preblock",
"check-postbrace",