Skip to content

Commit

Permalink
Update: Improve report location for no-unneeded-ternary (refs #12334) (
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjermanovic authored Jul 7, 2020
1 parent b77b420 commit 1050ee7
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 31 deletions.
2 changes: 0 additions & 2 deletions lib/rules/no-unneeded-ternary.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ module.exports = {
if (isBooleanLiteral(node.alternate) && isBooleanLiteral(node.consequent)) {
context.report({
node,
loc: node.consequent.loc.start,
messageId: "unnecessaryConditionalExpression",
fix(fixer) {
if (node.consequent.value === node.alternate.value) {
Expand All @@ -144,7 +143,6 @@ module.exports = {
} else if (!defaultAssignment && matchesDefaultAssignment(node)) {
context.report({
node,
loc: node.consequent.loc.start,
messageId: "unnecessaryConditionalAssignment",
fix: fixer => {
const shouldParenthesizeAlternate =
Expand Down
116 changes: 87 additions & 29 deletions tests/lib/rules/no-unneeded-ternary.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ ruleTester.run("no-unneeded-ternary", rule, {
messageId: "unnecessaryConditionalExpression",
type: "ConditionalExpression",
line: 1,
column: 19
column: 9,
endLine: 1,
endColumn: 31
}]
},
{
Expand All @@ -64,7 +66,9 @@ ruleTester.run("no-unneeded-ternary", rule, {
messageId: "unnecessaryConditionalExpression",
type: "ConditionalExpression",
line: 1,
column: 18
column: 9,
endLine: 1,
endColumn: 30
}]
},
{
Expand All @@ -74,7 +78,9 @@ ruleTester.run("no-unneeded-ternary", rule, {
messageId: "unnecessaryConditionalExpression",
type: "ConditionalExpression",
line: 1,
column: 13
column: 9,
endLine: 1,
endColumn: 25
}]
},
{
Expand All @@ -84,7 +90,9 @@ ruleTester.run("no-unneeded-ternary", rule, {
messageId: "unnecessaryConditionalExpression",
type: "ConditionalExpression",
line: 1,
column: 19
column: 9,
endLine: 1,
endColumn: 31
}]
},
{
Expand All @@ -94,7 +102,9 @@ ruleTester.run("no-unneeded-ternary", rule, {
messageId: "unnecessaryConditionalExpression",
type: "ConditionalExpression",
line: 1,
column: 18
column: 9,
endLine: 1,
endColumn: 30
}]
},
{
Expand All @@ -104,7 +114,9 @@ ruleTester.run("no-unneeded-ternary", rule, {
messageId: "unnecessaryConditionalExpression",
type: "ConditionalExpression",
line: 1,
column: 17
column: 9,
endLine: 1,
endColumn: 29
}]
},
{
Expand All @@ -114,7 +126,9 @@ ruleTester.run("no-unneeded-ternary", rule, {
messageId: "unnecessaryConditionalExpression",
type: "ConditionalExpression",
line: 1,
column: 18
column: 9,
endLine: 1,
endColumn: 30
}]
},
{
Expand All @@ -124,7 +138,9 @@ ruleTester.run("no-unneeded-ternary", rule, {
messageId: "unnecessaryConditionalExpression",
type: "ConditionalExpression",
line: 1,
column: 21
column: 9,
endLine: 1,
endColumn: 33
}]
},
{
Expand All @@ -134,7 +150,9 @@ ruleTester.run("no-unneeded-ternary", rule, {
messageId: "unnecessaryConditionalExpression",
type: "ConditionalExpression",
line: 1,
column: 28
column: 9,
endLine: 1,
endColumn: 40
}]
},
{
Expand All @@ -144,7 +162,9 @@ ruleTester.run("no-unneeded-ternary", rule, {
messageId: "unnecessaryConditionalExpression",
type: "ConditionalExpression",
line: 1,
column: 15
column: 9,
endLine: 1,
endColumn: 28
}]
},
{
Expand All @@ -154,7 +174,9 @@ ruleTester.run("no-unneeded-ternary", rule, {
messageId: "unnecessaryConditionalExpression",
type: "ConditionalExpression",
line: 1,
column: 17
column: 9,
endLine: 1,
endColumn: 30
}]
},
{
Expand All @@ -164,7 +186,9 @@ ruleTester.run("no-unneeded-ternary", rule, {
messageId: "unnecessaryConditionalExpression",
type: "ConditionalExpression",
line: 1,
column: 28
column: 9,
endLine: 1,
endColumn: 40
}]
},
{
Expand All @@ -174,7 +198,9 @@ ruleTester.run("no-unneeded-ternary", rule, {
messageId: "unnecessaryConditionalExpression",
type: "ConditionalExpression",
line: 1,
column: 16
column: 9,
endLine: 1,
endColumn: 28
}]
},
{
Expand All @@ -193,7 +219,9 @@ ruleTester.run("no-unneeded-ternary", rule, {
messageId: "unnecessaryConditionalAssignment",
type: "ConditionalExpression",
line: 4,
column: 38
column: 30,
endLine: 4,
endColumn: 78
}]
},
{
Expand All @@ -204,7 +232,9 @@ ruleTester.run("no-unneeded-ternary", rule, {
messageId: "unnecessaryConditionalAssignment",
type: "ConditionalExpression",
line: 1,
column: 7
column: 1,
endLine: 1,
endColumn: 30
}]
},
{
Expand All @@ -216,7 +246,9 @@ ruleTester.run("no-unneeded-ternary", rule, {
messageId: "unnecessaryConditionalAssignment",
type: "ConditionalExpression",
line: 1,
column: 24
column: 18,
endLine: 1,
endColumn: 39
}]
},
{
Expand All @@ -227,7 +259,9 @@ ruleTester.run("no-unneeded-ternary", rule, {
messageId: "unnecessaryConditionalAssignment",
type: "ConditionalExpression",
line: 1,
column: 15
column: 9,
endLine: 1,
endColumn: 25
}]
},
{
Expand All @@ -238,7 +272,9 @@ ruleTester.run("no-unneeded-ternary", rule, {
messageId: "unnecessaryConditionalAssignment",
type: "ConditionalExpression",
line: 1,
column: 24
column: 9,
endLine: 1,
endColumn: 66
}]
},
{
Expand All @@ -250,7 +286,9 @@ ruleTester.run("no-unneeded-ternary", rule, {
messageId: "unnecessaryConditionalAssignment",
type: "ConditionalExpression",
line: 1,
column: 13
column: 9,
endLine: 1,
endColumn: 23
}]
},
{
Expand All @@ -262,7 +300,9 @@ ruleTester.run("no-unneeded-ternary", rule, {
messageId: "unnecessaryConditionalAssignment",
type: "ConditionalExpression",
line: 1,
column: 13
column: 9,
endLine: 1,
endColumn: 22
}]
},
{
Expand All @@ -274,7 +314,9 @@ ruleTester.run("no-unneeded-ternary", rule, {
messageId: "unnecessaryConditionalAssignment",
type: "ConditionalExpression",
line: 1,
column: 13
column: 9,
endLine: 1,
endColumn: 25
}]
},
{
Expand All @@ -286,7 +328,9 @@ ruleTester.run("no-unneeded-ternary", rule, {
messageId: "unnecessaryConditionalAssignment",
type: "ConditionalExpression",
line: 1,
column: 13
column: 9,
endLine: 1,
endColumn: 24
}]
},
{
Expand All @@ -298,7 +342,9 @@ ruleTester.run("no-unneeded-ternary", rule, {
messageId: "unnecessaryConditionalAssignment",
type: "ConditionalExpression",
line: 1,
column: 13
column: 9,
endLine: 1,
endColumn: 27
}]
},
{
Expand All @@ -310,7 +356,9 @@ ruleTester.run("no-unneeded-ternary", rule, {
messageId: "unnecessaryConditionalAssignment",
type: "ConditionalExpression",
line: 1,
column: 13
column: 9,
endLine: 1,
endColumn: 18
}]
},
{
Expand All @@ -322,7 +370,9 @@ ruleTester.run("no-unneeded-ternary", rule, {
messageId: "unnecessaryConditionalAssignment",
type: "ConditionalExpression",
line: 1,
column: 13
column: 9,
endLine: 1,
endColumn: 23
}]
},
{
Expand All @@ -333,7 +383,9 @@ ruleTester.run("no-unneeded-ternary", rule, {
messageId: "unnecessaryConditionalAssignment",
type: "ConditionalExpression",
line: 1,
column: 7
column: 3,
endLine: 1,
endColumn: 12
}]
},
{
Expand All @@ -344,7 +396,9 @@ ruleTester.run("no-unneeded-ternary", rule, {
messageId: "unnecessaryConditionalAssignment",
type: "ConditionalExpression",
line: 1,
column: 5
column: 1,
endLine: 1,
endColumn: 10
}]
},
{
Expand All @@ -355,7 +409,9 @@ ruleTester.run("no-unneeded-ternary", rule, {
messageId: "unnecessaryConditionalAssignment",
type: "ConditionalExpression",
line: 1,
column: 15
column: 9,
endLine: 1,
endColumn: 24
}]
},
{
Expand All @@ -367,7 +423,9 @@ ruleTester.run("no-unneeded-ternary", rule, {
messageId: "unnecessaryConditionalAssignment",
type: "ConditionalExpression",
line: 1,
column: 15
column: 9,
endLine: 1,
endColumn: 27
}]
}
]
Expand Down

0 comments on commit 1050ee7

Please sign in to comment.