Repository: ember-cli/eslint-plugin-ember (js)

Issue:
[no-private-routing-service] TypeError: Cannot read property 'value' of undefined
```
Occurred while linting /home/boris/code/project/some-file.ts:80
    at Property (/home/boris/code/project/node_modules/eslint-plugin-ember/lib/rules/no-private-routing-service.js:36:35)
    at /home/boris/code/project/node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (/home/boris/code/project/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/home/boris/code/project/node_modules/eslint/lib/linter/node-event-generator.js:254:26)
    at NodeEventGenerator.applySelectors (/home/boris/code/project/node_modules/eslint/lib/linter/node-event-generator.js:283:22)
    at NodeEventGenerator.enterNode (/home/boris/code/project/node_modules/eslint/lib/linter/node-event-generator.js:297:14)
    at CodePathAnalyzer.enterNode (/home/boris/code/project/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:634:23)
    at /home/boris/code/project/node_modules/eslint/lib/linter/linter.js:936:32
    at Array.forEach (<anonymous>)
```

That file around that line looks like:

```typescript
import Service, { inject } from '@ember/service';

Service.reopen(foo, {
  session: inject(),
  bar: readOnly('session.isLoggedIn'),
});
```

Pull request:
Handle service injections with no arguments in `no-private-routing-service` rule
Fixes #696. Sorry @boris-petrov!

Patch:
diff --git a/lib/rules/no-private-routing-service.js b/lib/rules/no-private-routing-service.js
index 9020d6ff..04b335b9 100644
--- a/lib/rules/no-private-routing-service.js
+++ b/lib/rules/no-private-routing-service.js
@@ -33,6 +33,7 @@ module.exports = {
       Property(node) {
         if (
           emberUtils.isInjectedServiceProp(node) &&
+          node.value.arguments.length > 0 &&
           node.value.arguments[0].value === ROUTING_SERVICE_NAME
         ) {
           context.report({ node, message: ERROR_MESSAGE });
@@ -48,6 +49,7 @@ module.exports = {
           return (
             expression &&
             expression.arguments &&
+            expression.arguments.length > 0 &&
             expression.arguments[0].value === ROUTING_SERVICE_NAME
           );
         });


Test patch:
diff --git a/tests/lib/rules/no-private-routing-service.js b/tests/lib/rules/no-private-routing-service.js
index 9e28e0f9..22689a0f 100644
--- a/tests/lib/rules/no-private-routing-service.js
+++ b/tests/lib/rules/no-private-routing-service.js
@@ -21,11 +21,17 @@ const ruleTester = new RuleTester({
 
 ruleTester.run('no-private-routing-service', rule, {
   valid: [
+    // Classic
     "export default Component.extend({ someService: service('routing') });",
     "export default Component.extend({ someService: service('-router') });",
     "export default Component.extend({ '-routing': service('routing') });",
     "export default Component.extend({ '-routing': service('-router') });",
     "Component.extend({ routing: someOtherFunction('-routing') });",
+    'export default Component.extend({ someService: service() });',
+    'export default Component.extend({ notAService: "a value" });',
+    'export default Component.extend({ anInt: 25 });',
+
+    // Octane
     'export default class MyComponent extends Component { @service router; }',
     "export default class MyComponent extends Component { @service('router') routing; }",
     'export default class MyComponent extends Component { @service routing; }',
@@ -38,6 +44,12 @@ ruleTester.run('no-private-routing-service', rule, {
       }
     }
     `,
+    'class MyComponent extends Component { @service() routing; }',
+    'class MyComponent extends Component { @service() notRouting; }',
+    'class MyComponent extends Component { aProp="routing"; }',
+    'class MyComponent extends Component { aProp="-routing"; }',
+    'class MyComponent extends Component { aProp="another value"; }',
+    'class MyComponent extends Component { anIntProp=25; }',
   ],
   invalid: [
     // Classic