Style: Minor refactor (#12308)

This commit is contained in:
fisker Cheung authored and GitHub committed 2022-02-16 08:34:55 +08:00
1 parent e11ea84efe
commit 7efc67a7ef
2 files changed
+12 -6

No files matched your search

+3
View File
@@ -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",
+9 -6
View File
@@ -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(/^(?<leadingSpace> *)[^\n\r ]/m);
leadingSpaceCount = matches
? matches.groups.leadingSpace.length
: Number.POSITIVE_INFINITY;
} else {
leadingSpaceCount = node.indent - 1 + parentIndent;
}
const rawLineContents = content
.split("\n")