Skip to content

Commit faecf56

Browse files
authored
Update: change reporting location for curly rule (refs #12334) (#14766)
* 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
1 parent d7dc07a commit faecf56

2 files changed

Lines changed: 528 additions & 27 deletions

File tree

lib/rules/curly.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,6 @@ module.exports = {
131131
return token.value === "else" && token.type === "Keyword";
132132
}
133133

134-
/**
135-
* Gets the `else` keyword token of a given `IfStatement` node.
136-
* @param {ASTNode} node A `IfStatement` node to get.
137-
* @returns {Token} The `else` keyword token.
138-
*/
139-
function getElseKeyword(node) {
140-
return node.alternate && sourceCode.getFirstTokenBetween(node.consequent, node.alternate, isElseKeywordToken);
141-
}
142-
143134
/**
144135
* Determines whether the given node has an `else` keyword token as the first token after.
145136
* @param {ASTNode} node The node to check.
@@ -361,7 +352,7 @@ module.exports = {
361352
if (this.expected) {
362353
context.report({
363354
node,
364-
loc: (name !== "else" ? node : getElseKeyword(node)).loc.start,
355+
loc: body.loc,
365356
messageId: opts && opts.condition ? "missingCurlyAfterCondition" : "missingCurlyAfter",
366357
data: {
367358
name
@@ -371,7 +362,7 @@ module.exports = {
371362
} else {
372363
context.report({
373364
node,
374-
loc: (name !== "else" ? node : getElseKeyword(node)).loc.start,
365+
loc: body.loc,
375366
messageId: opts && opts.condition ? "unexpectedCurlyAfterCondition" : "unexpectedCurlyAfter",
376367
data: {
377368
name

0 commit comments

Comments
 (0)