Skip to content
This repository has been archived by the owner on Aug 4, 2020. It is now read-only.

Commit

Permalink
Combine selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
simonkotwicz committed Jun 27, 2020
1 parent f4ced99 commit 7c96021
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 30 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
node_modules
package-lock.json
51 changes: 22 additions & 29 deletions rules/semi.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,38 +67,31 @@ const report = (context, node, missing) => {
});
};

const checkForSemicolon = (node, context) => {
const options = context.options[1];
const exceptOneLine = options && options.omitLastInOneLineBlock === true;

const sourceCode = context.getSourceCode();
const lastToken = sourceCode.getLastToken(node);

if (context.options[0] === "never") {
if (isUnnecessarySemicolon(context, lastToken)) {
report(context, node, true);
}
} else {
if (!isSemicolon(lastToken)) {
if (!exceptOneLine || !isOneLinerBlock(context, node)) {
report(context, node);
}
} else {
if (exceptOneLine && isOneLinerBlock(context, node)) {
report(context, node, true);
}
}
}
}

const semiRuleWithClassProperty = ruleComposer.joinReports([
semiRule,
context => ({
ClassProperty(node) {
checkForSemicolon(node, context);
},
ClassPrivateProperty(node) {
checkForSemicolon(node, context);
"ClassProperty, ClassPrivateProperty"(node) {
const options = context.options[1];
const exceptOneLine = options && options.omitLastInOneLineBlock === true;

const sourceCode = context.getSourceCode();
const lastToken = sourceCode.getLastToken(node);

if (context.options[0] === "never") {
if (isUnnecessarySemicolon(context, lastToken)) {
report(context, node, true);
}
} else {
if (!isSemicolon(lastToken)) {
if (!exceptOneLine || !isOneLinerBlock(context, node)) {
report(context, node);
}
} else {
if (exceptOneLine && isOneLinerBlock(context, node)) {
report(context, node, true);
}
}
}
},
}),
]);
Expand Down

0 comments on commit 7c96021

Please sign in to comment.