Skip to content

Commit

Permalink
Renamed variable & function to be more descriptive. Removed redundant…
Browse files Browse the repository at this point in the history
… comment check
  • Loading branch information
karolina-benitez committed Sep 18, 2020
1 parent c3c2a5e commit 684adc5
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/rules/jsx-props-no-multi-spaces.js
Expand Up @@ -24,6 +24,8 @@ module.exports = {
},

create(context) {
const sourceCode = context.getSourceCode();

function getPropName(propNode) {
switch (propNode.type) {
case 'JSXSpreadAttribute':
Expand All @@ -37,21 +39,19 @@ 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;

commentLines += (end - start + 1);
});

return commentLines !== nodeLineDifference;
return commentLines !== leadingLineCount;
}

return true;
Expand All @@ -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)}”`
Expand Down

0 comments on commit 684adc5

Please sign in to comment.