Skip to content

Commit

Permalink
Update: change reporting location for curly rule (refs #12334) (#14766
Browse files Browse the repository at this point in the history
)

* Update: change reporting location for `curly` rule

* Chore: refactor code

* Chore: refactor code

* Update: report body/consequent/alternate node

* Chore: update comment

* Chore: refactor code
  • Loading branch information
snitin315 committed Jul 30, 2021
1 parent d7dc07a commit faecf56
Show file tree
Hide file tree
Showing 2 changed files with 528 additions and 27 deletions.
13 changes: 2 additions & 11 deletions lib/rules/curly.js
Expand Up @@ -131,15 +131,6 @@ module.exports = {
return token.value === "else" && token.type === "Keyword";
}

/**
* Gets the `else` keyword token of a given `IfStatement` node.
* @param {ASTNode} node A `IfStatement` node to get.
* @returns {Token} The `else` keyword token.
*/
function getElseKeyword(node) {
return node.alternate && sourceCode.getFirstTokenBetween(node.consequent, node.alternate, isElseKeywordToken);
}

/**
* Determines whether the given node has an `else` keyword token as the first token after.
* @param {ASTNode} node The node to check.
Expand Down Expand Up @@ -361,7 +352,7 @@ module.exports = {
if (this.expected) {
context.report({
node,
loc: (name !== "else" ? node : getElseKeyword(node)).loc.start,
loc: body.loc,
messageId: opts && opts.condition ? "missingCurlyAfterCondition" : "missingCurlyAfter",
data: {
name
Expand All @@ -371,7 +362,7 @@ module.exports = {
} else {
context.report({
node,
loc: (name !== "else" ? node : getElseKeyword(node)).loc.start,
loc: body.loc,
messageId: opts && opts.condition ? "unexpectedCurlyAfterCondition" : "unexpectedCurlyAfter",
data: {
name
Expand Down

0 comments on commit faecf56

Please sign in to comment.