Skip to content

Commit

Permalink
eslint#12579 Simplify the code
Browse files Browse the repository at this point in the history
  • Loading branch information
sunghyunjo committed Aug 9, 2020
1 parent 7423641 commit 7667054
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions lib/rules/no-underscore-dangle.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,23 +139,21 @@ module.exports = {
function checkForDanglingUnderscoreInFunctionParameters(node) {
if (!allowFunctionParams) {
node.params.forEach(param => {
let identifier = "";
const { type } = param;
let nodeToCheck;

if (type === "RestElement" && param.argument !== "undefined") {
if (param.argument.name !== "undefined") {
identifier = param.argument.name;
}
} else if (type === "AssignmentPattern" && param.left !== "undefined") {
if (param.left.name !== "undefined") {
identifier = param.left.name;
}
} else if (type === "Identifier" && param.name !== "undefined") {
identifier = param.name;
if (type === "RestElement") {
nodeToCheck = param.argument;
} else if (type === "AssignmentPattern") {
nodeToCheck = param.left;
} else {
nodeToCheck = param;
}

if (identifier !== "") {
if (typeof identifier !== "undefined" && hasDanglingUnderscore(identifier) && !isAllowed(identifier)) {
if (nodeToCheck.type === "Identifier") {
const identifier = nodeToCheck.name;

if (hasDanglingUnderscore(identifier) && !isAllowed(identifier)) {
context.report({
node: param,
messageId: "unexpectedUnderscore",
Expand Down

0 comments on commit 7667054

Please sign in to comment.