From 363723fc84f7b8477592e0105aeb331ec9a017af Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Mon, 14 Aug 2017 05:01:11 +0200 Subject: node_modules --- node_modules/tslint/lib/rules/whitespaceRule.js | 81 +++++++++++++++---------- 1 file changed, 49 insertions(+), 32 deletions(-) (limited to 'node_modules/tslint/lib/rules/whitespaceRule.js') diff --git a/node_modules/tslint/lib/rules/whitespaceRule.js b/node_modules/tslint/lib/rules/whitespaceRule.js index b92a075e5..4829fa623 100644 --- a/node_modules/tslint/lib/rules/whitespaceRule.js +++ b/node_modules/tslint/lib/rules/whitespaceRule.js @@ -37,28 +37,28 @@ var Rule = (function (_super) { 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: (_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)), + options: { + type: "array", + items: { + type: "string", + enum: ["check-branch", "check-decl", "check-operator", "check-module", + "check-separator", "check-type", "check-typecast", "check-preblock"], + }, + minLength: 0, + maxLength: 7, + }, + optionExamples: [[true, "check-branch", "check-operator", "check-typecast"]], + type: "style", + typescriptOnly: false, + }; + Rule.FAILURE_STRING = "missing whitespace"; return Rule; }(Lint.Rules.AbstractRule)); -Rule.metadata = { - 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)), - options: { - type: "array", - items: { - type: "string", - enum: ["check-branch", "check-decl", "check-operator", "check-module", - "check-separator", "check-type", "check-typecast", "check-preblock"], - }, - minLength: 0, - maxLength: 7, - }, - optionExamples: [[true, "check-branch", "check-operator", "check-typecast"]], - type: "style", - typescriptOnly: false, -}; -Rule.FAILURE_STRING = "missing whitespace"; exports.Rule = Rule; function parseOptions(ruleArguments) { return { @@ -124,12 +124,27 @@ function walk(ctx) { // an import clause can have _both_ named bindings and a name (the latter for the default import) // but the named bindings always come last, so we only need to check that for whitespace var position = void 0; - var name_1 = importClause.name, namedBindings = importClause.namedBindings; - if (namedBindings !== undefined) { - position = namedBindings.getEnd(); + var namedBindings_1 = importClause.namedBindings; + if (namedBindings_1 !== undefined) { + if (namedBindings_1.kind !== ts.SyntaxKind.NamespaceImport) { + namedBindings_1.elements.forEach(function (element, idx, arr) { + var internalName = element.name; + if (internalName !== undefined) { + if (idx === arr.length - 1) { + var token = namedBindings_1.getLastToken(); + checkForTrailingWhitespace(token.getFullStart()); + } + if (idx === 0) { + var startPos = internalName.getStart() - 1; + checkForTrailingWhitespace(startPos, startPos + 1); + } + } + }); + } + position = namedBindings_1.getEnd(); } - else if (name_1 !== undefined) { - position = name_1.getEnd(); + else if (importClause.name !== undefined) { + position = importClause.name.getEnd(); } if (position !== undefined) { checkForTrailingWhitespace(position); @@ -154,7 +169,6 @@ function walk(ctx) { if (options.decl && initializer !== undefined) { checkForTrailingWhitespace((type !== undefined ? type : name).getEnd()); } - break; } ts.forEachChild(node, cb); }); @@ -199,14 +213,16 @@ function walk(ctx) { } break; case ts.SyntaxKind.ImportKeyword: + if (parent.kind === ts.SyntaxKind.CallExpression && + parent.expression.kind === ts.SyntaxKind.ImportKeyword) { + return; // Don't check ImportCall + } + // falls through case ts.SyntaxKind.ExportKeyword: case ts.SyntaxKind.FromKeyword: if (options.typecast) { prevTokenShouldBeFollowedByWhitespace = true; } - break; - default: - break; } }); function checkEqualsGreaterThanTokenInNode(node) { @@ -221,9 +237,10 @@ function walk(ctx) { checkForTrailingWhitespace(equalsGreaterThanToken.getFullStart()); checkForTrailingWhitespace(equalsGreaterThanToken.getEnd()); } - function checkForTrailingWhitespace(position) { - if (position !== sourceFile.end && !ts.isWhiteSpaceLike(sourceFile.text.charCodeAt(position))) { - addMissingWhitespaceErrorAt(position); + function checkForTrailingWhitespace(position, whiteSpacePos) { + if (whiteSpacePos === void 0) { whiteSpacePos = position; } + if (position !== sourceFile.end && !Lint.isWhiteSpace(sourceFile.text.charCodeAt(position))) { + addMissingWhitespaceErrorAt(whiteSpacePos); } } function addMissingWhitespaceErrorAt(position) { -- cgit v1.2.3