aboutsummaryrefslogtreecommitdiff
path: root/node_modules/tslint/lib/rules/curlyRule.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/tslint/lib/rules/curlyRule.js')
-rw-r--r--node_modules/tslint/lib/rules/curlyRule.js18
1 files changed, 10 insertions, 8 deletions
diff --git a/node_modules/tslint/lib/rules/curlyRule.js b/node_modules/tslint/lib/rules/curlyRule.js
index 906201a12..c6421dd83 100644
--- a/node_modules/tslint/lib/rules/curlyRule.js
+++ b/node_modules/tslint/lib/rules/curlyRule.js
@@ -20,6 +20,7 @@ var tslib_1 = require("tslib");
var tsutils_1 = require("tsutils");
var ts = require("typescript");
var Lint = require("../index");
+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) {
@@ -42,8 +43,8 @@ var Rule = /** @class */ (function (_super) {
Rule.metadata = {
ruleName: "curly",
description: "Enforces braces for `if`/`for`/`do`/`while` statements.",
- rationale: (_a = ["\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, he forgot braces and `bar++` will be executed\n no matter what. This rule could prevent such a mistake."], _a.raw = ["\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, he forgot braces and \\`bar++\\` will be executed\n no matter what. This rule could prevent such a mistake."], Lint.Utils.dedent(_a)),
- optionsDescription: (_b = ["\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 "], _b.raw = ["\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 "], Lint.Utils.dedent(_b, OPTION_AS_NEEDED, OPTION_IGNORE_SAME_LINE)),
+ 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: {
@@ -62,6 +63,7 @@ var Rule = /** @class */ (function (_super) {
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.";
@@ -71,7 +73,7 @@ exports.Rule = Rule;
function walkAsNeeded(ctx) {
ts.forEachChild(ctx.sourceFile, function cb(node) {
if (tsutils_1.isBlock(node) && isBlockUnnecessary(node)) {
- ctx.addFailureAtNode(Lint.childOfKind(node, ts.SyntaxKind.OpenBraceToken), Rule.FAILURE_STRING_AS_NEEDED);
+ ctx.addFailureAt(node.statements.pos - 1, 1, Rule.FAILURE_STRING_AS_NEEDED);
}
ts.forEachChild(node, cb);
});
@@ -133,8 +135,8 @@ var CurlyWalker = /** @class */ (function (_super) {
CurlyWalker.prototype.createMissingBraceFix = function (statement, node, sameLine) {
if (sameLine) {
return [
- Lint.Replacement.appendText(statement.getStart(), "{ "),
- Lint.Replacement.appendText(statement.getEnd(), " }"),
+ Lint.Replacement.appendText(statement.pos, " {"),
+ Lint.Replacement.appendText(statement.end, " }"),
];
}
else {
@@ -145,11 +147,11 @@ var CurlyWalker = /** @class */ (function (_super) {
match[1].repeat(ts.getLineAndCharacterOfPosition(this.sourceFile, node.getStart(this.sourceFile)).character);
var maybeCarriageReturn = this.sourceFile.text[this.sourceFile.getLineEndOfPosition(node.pos) - 1] === "\r" ? "\r" : "";
return [
- Lint.Replacement.appendText(this.sourceFile.getLineEndOfPosition(statement.pos), " {"),
- Lint.Replacement.appendText(statement.getEnd(), maybeCarriageReturn + "\n" + indentation + "}"),
+ Lint.Replacement.appendText(statement.pos, " {"),
+ Lint.Replacement.appendText(statement.end, maybeCarriageReturn + "\n" + indentation + "}"),
];
}
};
return CurlyWalker;
}(Lint.AbstractWalker));
-var _a, _b;
+var templateObject_1, templateObject_2;