Repository: ember-cli/eslint-plugin-ember
Pull request #586 (2019-11-10 20:57:52)

Update `use-brace-expansion` rule to only report the string arguments of a computed property as the violation (and not the entire computed property function body)
It's annoying and disruptive when the entire computed property (including function body) is reported as a violation (and thus highlighted in the IDE) when only the string arguments (dependent keys) should be reported.


Patch:
diff --git a/lib/rules/use-brace-expansion.js b/lib/rules/use-brace-expansion.js
index 6969176f..27014ee5 100644
--- a/lib/rules/use-brace-expansion.js
+++ b/lib/rules/use-brace-expansion.js
@@ -24,10 +24,6 @@ module.exports = {
   ERROR_MESSAGE,
 
   create(context) {
-    function report(node) {
-      context.report(node, ERROR_MESSAGE);
-    }
-
     return {
       CallExpression(node) {
         if (!ember.isComputedProp(node) || types.isMemberExpression(node.callee)) {
@@ -66,7 +62,15 @@ module.exports = {
           );
 
         if (problem) {
-          report(node);
+          context.report({
+            node,
+            message: ERROR_MESSAGE,
+            loc: {
+              // Only report the string arguments (dependent keys) of the computed property (not the entire function body).
+              start: node.arguments[0].loc.start,
+              end: node.arguments[node.arguments.length - 2].loc.end,
+            },
+          });
         }
       },
     };


Test patch:
diff --git a/tests/lib/rules/use-brace-expansion.js b/tests/lib/rules/use-brace-expansion.js
index fe2c7a81..6991cba7 100644
--- a/tests/lib/rules/use-brace-expansion.js
+++ b/tests/lib/rules/use-brace-expansion.js
@@ -34,6 +34,10 @@ eslintTester.run('use-brace-expansion', rule, {
         {
           message: ERROR_MESSAGE,
           type: 'CallExpression',
+          line: 1,
+          endLine: 1,
+          column: 18,
+          endColumn: 73,
         },
       ],
     },
@@ -44,6 +48,10 @@ eslintTester.run('use-brace-expansion', rule, {
         {
           message: ERROR_MESSAGE,
           type: 'CallExpression',
+          line: 1,
+          endLine: 1,
+          column: 18,
+          endColumn: 37,
         },
       ],
     },
@@ -54,6 +62,10 @@ eslintTester.run('use-brace-expansion', rule, {
         {
           message: ERROR_MESSAGE,
           type: 'CallExpression',
+          line: 1,
+          endLine: 1,
+          column: 18,
+          endColumn: 52,
         },
       ],
     },
@@ -64,6 +76,10 @@ eslintTester.run('use-brace-expansion', rule, {
         {
           message: ERROR_MESSAGE,
           type: 'CallExpression',
+          line: 1,
+          endLine: 1,
+          column: 18,
+          endColumn: 45,
         },
       ],
     },
@@ -74,6 +90,10 @@ eslintTester.run('use-brace-expansion', rule, {
         {
           message: ERROR_MESSAGE,
           type: 'CallExpression',
+          line: 1,
+          endLine: 1,
+          column: 18,
+          endColumn: 56,
         },
       ],
     },
@@ -84,6 +104,10 @@ eslintTester.run('use-brace-expansion', rule, {
         {
           message: ERROR_MESSAGE,
           type: 'CallExpression',
+          line: 1,
+          endLine: 1,
+          column: 18,
+          endColumn: 45,
         },
       ],
     },
@@ -94,6 +118,10 @@ eslintTester.run('use-brace-expansion', rule, {
         {
           message: ERROR_MESSAGE,
           type: 'CallExpression',
+          line: 1,
+          endLine: 1,
+          column: 18,
+          endColumn: 37,
         },
       ],
     },