Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update: add end location to report in consistent-return (refs #12334) #14798

Merged
merged 2 commits into from Jul 17, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/rules/consistent-return.js
Expand Up @@ -104,18 +104,18 @@ module.exports = {
} else if (node.type === "ArrowFunctionExpression") {

// `=>` token
loc = context.getSourceCode().getTokenBefore(node.body, astUtils.isArrowToken).loc.start;
loc = context.getSourceCode().getTokenBefore(node.body, astUtils.isArrowToken).loc;
} else if (
node.parent.type === "MethodDefinition" ||
(node.parent.type === "Property" && node.parent.method)
) {

// Method name.
loc = node.parent.key.loc.start;
loc = node.parent.key.loc;
} else {

// Function name or `function` keyword.
loc = (node.id || node).loc.start;
loc = (node.id || node).loc;
}

if (!name) {
Expand Down
108 changes: 88 additions & 20 deletions tests/lib/rules/consistent-return.js
Expand Up @@ -52,7 +52,11 @@ ruleTester.run("consistent-return", rule, {
{
messageId: "missingReturnValue",
data: { name: "Function 'foo'" },
type: "ReturnStatement"
type: "ReturnStatement",
line: 1,
column: 46,
endLine: 1,
endColumn: 53
}
]
},
Expand All @@ -63,7 +67,11 @@ ruleTester.run("consistent-return", rule, {
{
messageId: "missingReturnValue",
data: { name: "Arrow function" },
type: "ReturnStatement"
type: "ReturnStatement",
line: 1,
column: 47,
endLine: 1,
endColumn: 54
}
]
},
Expand All @@ -73,7 +81,11 @@ ruleTester.run("consistent-return", rule, {
{
messageId: "unexpectedReturnValue",
data: { name: "Function 'foo'" },
type: "ReturnStatement"
type: "ReturnStatement",
line: 1,
column: 41,
endLine: 1,
endColumn: 54
}
]
},
Expand All @@ -83,7 +95,11 @@ ruleTester.run("consistent-return", rule, {
{
messageId: "missingReturnValue",
data: { name: "Function" },
type: "ReturnStatement"
type: "ReturnStatement",
line: 1,
column: 44,
endLine: 1,
endColumn: 51
}
]
},
Expand All @@ -93,7 +109,11 @@ ruleTester.run("consistent-return", rule, {
{
messageId: "unexpectedReturnValue",
data: { name: "Function" },
type: "ReturnStatement"
type: "ReturnStatement",
line: 1,
column: 39,
endLine: 1,
endColumn: 52
}
]
},
Expand All @@ -104,7 +124,11 @@ ruleTester.run("consistent-return", rule, {
{
messageId: "unexpectedReturnValue",
data: { name: "Arrow function" },
type: "ReturnStatement"
type: "ReturnStatement",
line: 1,
column: 33,
endLine: 1,
endColumn: 46
}
]
},
Expand All @@ -116,7 +140,10 @@ ruleTester.run("consistent-return", rule, {
messageId: "missingReturnValue",
data: { name: "Function 'foo'" },
type: "ReturnStatement",
column: 41
line: 1,
column: 41,
endLine: 1,
endColumn: 58
}
]
},
Expand All @@ -128,7 +155,10 @@ ruleTester.run("consistent-return", rule, {
messageId: "missingReturnValue",
data: { name: "Function 'foo'" },
type: "ReturnStatement",
column: 41
line: 1,
column: 41,
endLine: 1,
endColumn: 55
}
]
},
Expand All @@ -140,7 +170,10 @@ ruleTester.run("consistent-return", rule, {
messageId: "unexpectedReturnValue",
data: { name: "Function 'foo'" },
type: "ReturnStatement",
column: 46
line: 1,
column: 46,
endLine: 1,
endColumn: 58
}
]
},
Expand All @@ -152,7 +185,10 @@ ruleTester.run("consistent-return", rule, {
messageId: "unexpectedReturnValue",
data: { name: "Function 'foo'" },
type: "ReturnStatement",
column: 43
line: 1,
column: 43,
endLine: 1,
endColumn: 55
}
]
},
Expand All @@ -163,7 +199,11 @@ ruleTester.run("consistent-return", rule, {
{
messageId: "missingReturnValue",
data: { name: "Program" },
type: "ReturnStatement"
type: "ReturnStatement",
line: 1,
column: 25,
endLine: 1,
endColumn: 32
}
]
},
Expand All @@ -174,7 +214,10 @@ ruleTester.run("consistent-return", rule, {
messageId: "missingReturn",
data: { name: "function 'foo'" },
type: "FunctionDeclaration",
column: 10
line: 1,
column: 10,
endLine: 1,
endColumn: 13
}
]
},
Expand All @@ -185,7 +228,10 @@ ruleTester.run("consistent-return", rule, {
messageId: "missingReturn",
data: { name: "function '_foo'" },
type: "FunctionDeclaration",
column: 10
line: 1,
column: 10,
endLine: 1,
endColumn: 14
}
]
},
Expand All @@ -196,7 +242,10 @@ ruleTester.run("consistent-return", rule, {
messageId: "missingReturn",
data: { name: "function 'foo'" },
type: "FunctionExpression",
column: 12
line: 1,
column: 12,
endLine: 1,
endColumn: 15
}
]
},
Expand All @@ -207,7 +256,10 @@ ruleTester.run("consistent-return", rule, {
messageId: "missingReturn",
data: { name: "function" },
type: "FunctionExpression",
column: 3
line: 1,
column: 3,
endLine: 1,
endColumn: 37
snitin315 marked this conversation as resolved.
Show resolved Hide resolved
}
]
},
Expand All @@ -219,7 +271,10 @@ ruleTester.run("consistent-return", rule, {
messageId: "missingReturn",
data: { name: "arrow function" },
type: "ArrowFunctionExpression",
column: 6
line: 1,
column: 6,
endLine: 1,
endColumn: 8
}
]
},
Expand All @@ -231,7 +286,10 @@ ruleTester.run("consistent-return", rule, {
messageId: "missingReturn",
data: { name: "method 'foo'" },
type: "FunctionExpression",
column: 12
line: 1,
column: 12,
endLine: 1,
endColumn: 15
}
]
},
Expand All @@ -243,7 +301,10 @@ ruleTester.run("consistent-return", rule, {
messageId: "missingReturn",
data: { name: "method 'foo'" },
type: "FunctionExpression",
column: 10
line: 1,
column: 10,
endLine: 1,
endColumn: 13
}
]
},
Expand All @@ -255,6 +316,7 @@ ruleTester.run("consistent-return", rule, {
messageId: "missingReturn",
data: { name: "program" },
type: "Program",
line: 1,
column: 1
snitin315 marked this conversation as resolved.
Show resolved Hide resolved
}
]
Expand All @@ -267,7 +329,10 @@ ruleTester.run("consistent-return", rule, {
messageId: "missingReturn",
data: { name: "method 'CapitalizedFunction'" },
type: "FunctionExpression",
column: 11
line: 1,
column: 11,
endLine: 1,
endColumn: 30
}
]
},
Expand All @@ -279,7 +344,10 @@ ruleTester.run("consistent-return", rule, {
messageId: "missingReturn",
data: { name: "method 'constructor'" },
type: "FunctionExpression",
column: 4
line: 1,
column: 4,
endLine: 1,
endColumn: 15
}
]
}
Expand Down