aboutsummaryrefslogtreecommitdiff
path: root/node_modules/tslint/lib/rules/whitespaceRule.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/tslint/lib/rules/whitespaceRule.js')
-rw-r--r--node_modules/tslint/lib/rules/whitespaceRule.js71
1 files changed, 63 insertions, 8 deletions
diff --git a/node_modules/tslint/lib/rules/whitespaceRule.js b/node_modules/tslint/lib/rules/whitespaceRule.js
index 4829fa623..67a8bdfb9 100644
--- a/node_modules/tslint/lib/rules/whitespaceRule.js
+++ b/node_modules/tslint/lib/rules/whitespaceRule.js
@@ -26,10 +26,12 @@ var OPTION_DECL = "check-decl";
var OPTION_OPERATOR = "check-operator";
var OPTION_MODULE = "check-module";
var OPTION_SEPARATOR = "check-separator";
+var OPTION_REST_SPREAD = "check-rest-spread";
var OPTION_TYPE = "check-type";
var OPTION_TYPECAST = "check-typecast";
+var OPTION_TYPE_OPERATOR = "check-type-operator";
var OPTION_PREBLOCK = "check-preblock";
-var Rule = (function (_super) {
+var Rule = /** @class */ (function (_super) {
tslib_1.__extends(Rule, _super);
function Rule() {
return _super !== null && _super.apply(this, arguments) || this;
@@ -41,22 +43,25 @@ var Rule = (function (_super) {
ruleName: "whitespace",
description: "Enforces whitespace style conventions.",
rationale: "Helps maintain a readable, consistent style in your codebase.",
- optionsDescription: (_a = ["\n Eight 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-type\"` checks for whitespace before a variable type specification.\n * `\"check-typecast\"` checks for whitespace between a typecast and its target.\n * `\"check-preblock\"` checks for whitespace before the opening brace of a block"], _a.raw = ["\n Eight 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-type\"\\` checks for whitespace before a variable type specification.\n * \\`\"check-typecast\"\\` checks for whitespace between a typecast and its target.\n * \\`\"check-preblock\"\\` checks for whitespace before the opening brace of a block"], Lint.Utils.dedent(_a)),
+ optionsDescription: (_a = ["\n Ten arguments may be optionally provided:\n\n * `\"check-branch\"` checks branching statements (`if`/`else`/`for`/`while`) are followed by whitespace.\n * `\"check-decl\"`checks that variable declarations have whitespace around the equals token.\n * `\"check-operator\"` checks for whitespace around operator tokens.\n * `\"check-module\"` checks for whitespace in import & export statements.\n * `\"check-separator\"` checks for whitespace after separator tokens (`,`/`;`).\n * `\"check-rest-spread\"` checks that there is no whitespace after rest/spread operator (`...`).\n * `\"check-type\"` checks for whitespace before a variable type specification.\n * `\"check-typecast\"` checks for whitespace between a typecast and its target.\n * `\"check-type-operator\"` checks for whitespace between type operators `|` and `&`.\n * `\"check-preblock\"` checks for whitespace before the opening brace of a block"], _a.raw = ["\n Ten arguments may be optionally provided:\n\n * \\`\"check-branch\"\\` checks branching statements (\\`if\\`/\\`else\\`/\\`for\\`/\\`while\\`) are followed by whitespace.\n * \\`\"check-decl\"\\`checks that variable declarations have whitespace around the equals token.\n * \\`\"check-operator\"\\` checks for whitespace around operator tokens.\n * \\`\"check-module\"\\` checks for whitespace in import & export statements.\n * \\`\"check-separator\"\\` checks for whitespace after separator tokens (\\`,\\`/\\`;\\`).\n * \\`\"check-rest-spread\"\\` checks that there is no whitespace after rest/spread operator (\\`...\\`).\n * \\`\"check-type\"\\` checks for whitespace before a variable type specification.\n * \\`\"check-typecast\"\\` checks for whitespace between a typecast and its target.\n * \\`\"check-type-operator\"\\` checks for whitespace between type operators \\`|\\` and \\`&\\`.\n * \\`\"check-preblock\"\\` checks for whitespace before the opening brace of a block"], Lint.Utils.dedent(_a)),
options: {
type: "array",
items: {
type: "string",
- enum: ["check-branch", "check-decl", "check-operator", "check-module",
- "check-separator", "check-type", "check-typecast", "check-preblock"],
+ enum: [
+ "check-branch", "check-decl", "check-operator", "check-module", "check-separator",
+ "check-rest-spread", "check-type", "check-typecast", "check-type-operator", "check-preblock",
+ ],
},
minLength: 0,
- maxLength: 7,
+ maxLength: 10,
},
optionExamples: [[true, "check-branch", "check-operator", "check-typecast"]],
type: "style",
typescriptOnly: false,
};
- Rule.FAILURE_STRING = "missing whitespace";
+ Rule.FAILURE_STRING_MISSING = "missing whitespace";
+ Rule.FAILURE_STRING_INVALID = "invalid whitespace";
return Rule;
}(Lint.Rules.AbstractRule));
exports.Rule = Rule;
@@ -67,8 +72,10 @@ function parseOptions(ruleArguments) {
operator: has(OPTION_OPERATOR),
module: has(OPTION_MODULE),
separator: has(OPTION_SEPARATOR),
+ restSpread: has(OPTION_REST_SPREAD),
type: has(OPTION_TYPE),
typecast: has(OPTION_TYPECAST),
+ typeOperator: has(OPTION_TYPE_OPERATOR),
preblock: has(OPTION_PREBLOCK),
};
function has(option) {
@@ -169,6 +176,34 @@ function walk(ctx) {
if (options.decl && initializer !== undefined) {
checkForTrailingWhitespace((type !== undefined ? type : name).getEnd());
}
+ break;
+ case ts.SyntaxKind.BindingElement:
+ case ts.SyntaxKind.Parameter:
+ var dotDotDotToken = node.dotDotDotToken;
+ if (options.restSpread && dotDotDotToken !== undefined) {
+ checkForExcessiveWhitespace(dotDotDotToken.end);
+ }
+ break;
+ case ts.SyntaxKind.SpreadAssignment:
+ case ts.SyntaxKind.SpreadElement:
+ if (options.restSpread) {
+ var position = node.expression.getFullStart();
+ checkForExcessiveWhitespace(position);
+ }
+ break;
+ case ts.SyntaxKind.UnionType:
+ case ts.SyntaxKind.IntersectionType:
+ if (options.typeOperator) {
+ var types_1 = node.types;
+ types_1.forEach(function (typeNode, index) {
+ if (index > 0) {
+ checkForTrailingWhitespace(typeNode.getFullStart());
+ }
+ if (index < types_1.length - 1) {
+ checkForTrailingWhitespace(typeNode.getEnd());
+ }
+ });
+ }
}
ts.forEachChild(node, cb);
});
@@ -197,11 +232,22 @@ function walk(ctx) {
}
break;
case ts.SyntaxKind.CommaToken:
- case ts.SyntaxKind.SemicolonToken:
if (options.separator) {
prevTokenShouldBeFollowedByWhitespace = true;
}
break;
+ case ts.SyntaxKind.SemicolonToken:
+ if (!options.separator) {
+ break;
+ }
+ var nextPosition = range.pos + 1;
+ var semicolonInTrivialFor = parent.kind === ts.SyntaxKind.ForStatement &&
+ nextPosition !== sourceFile.end &&
+ (sourceFile.text[nextPosition] === ";" || sourceFile.text[nextPosition] === ")");
+ if (!semicolonInTrivialFor) {
+ prevTokenShouldBeFollowedByWhitespace = true;
+ }
+ break;
case ts.SyntaxKind.EqualsToken:
if (options.decl && parent.kind !== ts.SyntaxKind.JsxAttribute) {
prevTokenShouldBeFollowedByWhitespace = true;
@@ -249,7 +295,16 @@ function walk(ctx) {
return;
}
var fix = Lint.Replacement.appendText(position, " ");
- ctx.addFailureAt(position, 1, Rule.FAILURE_STRING, fix);
+ ctx.addFailureAt(position, 1, Rule.FAILURE_STRING_MISSING, fix);
+ }
+ function checkForExcessiveWhitespace(position) {
+ if (position !== sourceFile.end && Lint.isWhiteSpace(sourceFile.text.charCodeAt(position))) {
+ addInvalidWhitespaceErrorAt(position);
+ }
+ }
+ function addInvalidWhitespaceErrorAt(position) {
+ var fix = Lint.Replacement.deleteText(position, 1);
+ ctx.addFailureAt(position, 1, Rule.FAILURE_STRING_INVALID, fix);
}
}
var _a;