From 684adc520c06cdaaa0f8f6f821ffc78f7f12d60e Mon Sep 17 00:00:00 2001 From: Karolina Benitez Date: Thu, 17 Sep 2020 20:54:47 -0700 Subject: [PATCH] Renamed variable & function to be more descriptive. Removed redundant comment check --- lib/rules/jsx-props-no-multi-spaces.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/rules/jsx-props-no-multi-spaces.js b/lib/rules/jsx-props-no-multi-spaces.js index b949ff3148..7c37195e23 100644 --- a/lib/rules/jsx-props-no-multi-spaces.js +++ b/lib/rules/jsx-props-no-multi-spaces.js @@ -24,6 +24,8 @@ module.exports = { }, create(context) { + const sourceCode = context.getSourceCode(); + function getPropName(propNode) { switch (propNode.type) { case 'JSXSpreadAttribute': @@ -37,13 +39,11 @@ module.exports = { } } - function isMultiSpace(node, prev, nodeLineDifference) { - const sourceCode = context.getSourceCode(); + function hasEmptyLines(node, leadingLineCount) { const allComments = sourceCode.getCommentsBefore(node); - const isComment = sourceCode.commentsExistBetween(prev, node); let commentLines = 0; - if (isComment) { + if (allComments.length > 0) { allComments.forEach((comment) => { const start = comment.loc.start.line; const end = comment.loc.end.line; @@ -51,7 +51,7 @@ module.exports = { commentLines += (end - start + 1); }); - return commentLines !== nodeLineDifference; + return commentLines !== leadingLineCount; } return true; @@ -60,9 +60,9 @@ module.exports = { function checkSpacing(prev, node) { const prevNodeEndLine = prev.loc.end.line; const currNodeStartLine = node.loc.start.line; - const nodeLineDifference = currNodeStartLine - prevNodeEndLine - 1; + const leadingLineCount = currNodeStartLine - prevNodeEndLine - 1; - if (nodeLineDifference >= 1 && isMultiSpace(node, prev, nodeLineDifference)) { + if (leadingLineCount > 0 && hasEmptyLines(node, leadingLineCount)) { context.report({ node, message: `Expected no line gap between “${getPropName(prev)}” and “${getPropName(node)}”`