From 7efc67a7effe8294e4f67fcc5ea738ae9d531472 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Wed, 16 Feb 2022 08:34:55 +0800 Subject: [PATCH] Style: Minor refactor (#12308) --- .eslintrc.js | 3 +++ src/language-yaml/utils.js | 15 +++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index b3b4d755f..4f9231b90 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -38,6 +38,9 @@ module.exports = { "error", // `!foo === bar` and `!foo !== bar` 'BinaryExpression[operator=/^[!=]==$/] > UnaryExpression.left[operator="!"]', + // `(() => (foo ? bar : baz))()` + // TODO: Remove this when https://github.com/sindresorhus/eslint-plugin-unicorn/issues/1730 get implemented + 'CallExpression[callee.type="ArrowFunctionExpression"][callee.body.type="ConditionalExpression"]', ], "no-return-await": "error", "no-unneeded-ternary": "error", diff --git a/src/language-yaml/utils.js b/src/language-yaml/utils.js index b1fde2d26..39b768fcc 100644 --- a/src/language-yaml/utils.js +++ b/src/language-yaml/utils.js @@ -253,12 +253,15 @@ function getBlockValueLineContents( // exclude open line `>` or `|` .match(/^[^\n]*\n(.*)$/s)[1]; - const leadingSpaceCount = - node.indent === null - ? ((match) => (match ? match[1].length : Number.POSITIVE_INFINITY))( - content.match(/^( *)[^\n\r ]/m) - ) - : node.indent - 1 + parentIndent; + let leadingSpaceCount; + if (node.indent === null) { + const matches = content.match(/^(? *)[^\n\r ]/m); + leadingSpaceCount = matches + ? matches.groups.leadingSpace.length + : Number.POSITIVE_INFINITY; + } else { + leadingSpaceCount = node.indent - 1 + parentIndent; + } const rawLineContents = content .split("\n")