Repository: ember-cli/eslint-plugin-ember
Pull request #367 (2018-12-30 15:57:34)

no-invalid-debug-function-arguments: Fix false positives
Update rule to ignore unrelated function calls underneath `computed`.

For example, we want to ignore calls that look like:

* `computed.equal(...)`
* `Ember.computed.readOnly(...)`

We only care about calls that look like:

* `computed(...)`
* `Ember.computed(...)`


Patch:
diff --git a/lib/rules/no-deeply-nested-dependent-keys-with-each.js b/lib/rules/no-deeply-nested-dependent-keys-with-each.js
index 6ba91302..977cba87 100644
--- a/lib/rules/no-deeply-nested-dependent-keys-with-each.js
+++ b/lib/rules/no-deeply-nested-dependent-keys-with-each.js
@@ -22,7 +22,7 @@ module.exports = {
   create(context) {
     return {
       CallExpression(node) {
-        if (emberUtils.isComputedProp(node)) {
+        if (emberUtils.isComputedProp(node) && (!node.callee.property || node.callee.property.name === 'computed')) {
           emberUtils.parseDependentKeys(node).forEach((key) => {
             const parts = key.split('.');
             const indexOfAtEach = parts.indexOf('@each');


Test patch:
diff --git a/tests/lib/rules/no-deeply-nested-dependent-keys-with-each.js b/tests/lib/rules/no-deeply-nested-dependent-keys-with-each.js
index 894cfc03..36d4562e 100644
--- a/tests/lib/rules/no-deeply-nested-dependent-keys-with-each.js
+++ b/tests/lib/rules/no-deeply-nested-dependent-keys-with-each.js
@@ -16,29 +16,37 @@ ruleTester.run('no-deeply-nested-dependent-keys-with-each', rule, {
   valid: [
     'Ember.computed(function() {})',
     "Ember.computed('foo', function() {})",
+    "Ember.computed('foo', function() {}).readOnly()",
     "Ember.computed('foo.bar', function() {})",
     "Ember.computed('foo.bar.@each.baz', function() {})",
     "Ember.computed('foo.@each.bar', function() {})",
     "Ember.computed('foo.@each.{bar,baz}', function() {})",
     'computed(function() {})',
     "computed('foo', function() {})",
+    "computed('foo', function() {}).readOnly()",
     "computed('foo.bar', function() {})",
     "computed('foo.bar.@each.baz', function() {})",
     "computed('foo.@each.bar', function() {})",
     "computed('foo.@each.{bar,baz}', function() {})",
     "computed('foo.@each.{bar,baz}', function() {})",
 
-    // Not Ember's `computed`:
+    // Not Ember's `computed` function:
     "otherClass.computed('foo.@each.bar.baz', function() {})",
     "otherClass.myFunction('foo.@each.bar.baz', function() {})",
     "myFunction('foo.@each.bar.baz', function() {})",
-    "Ember.myFunction('foo.@each.bar.baz', function() {})"
+    "Ember.myFunction('foo.@each.bar.baz', function() {})",
+    "computed.unrelatedFunction('foo.@each.bar.baz', function() {})",
+    "Ember.computed.unrelatedFunction('foo.@each.bar.baz', function() {})"
   ],
   invalid: [
     {
       code: "Ember.computed('foo.@each.bar.baz', function() {})",
       errors: [{ message: ERROR_MESSAGE, type: 'CallExpression' }]
     },
+    {
+      code: "Ember.computed('foo.@each.bar.baz', function() {}).readOnly()",
+      errors: [{ message: ERROR_MESSAGE, type: 'CallExpression' }]
+    },
     {
       code: "Ember.computed('foo.@each.bar.[]', function() {})",
       errors: [{ message: ERROR_MESSAGE, type: 'CallExpression' }]
@@ -51,6 +59,10 @@ ruleTester.run('no-deeply-nested-dependent-keys-with-each', rule, {
       code: "computed('foo.@each.bar.baz', function() {})",
       errors: [{ message: ERROR_MESSAGE, type: 'CallExpression' }]
     },
+    {
+      code: "computed('foo.@each.bar.baz', function() {}).readOnly()",
+      errors: [{ message: ERROR_MESSAGE, type: 'CallExpression' }]
+    },
     {
       code: "computed('foo.@each.bar.[]', function() {})",
       errors: [{ message: ERROR_MESSAGE, type: 'CallExpression' }]