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

Issue:
ember/no-classic-components fails on imports from `@ember/component`
The `ember/no-classic-components` rule fails on this code, and it probably shouldn't?

```
import { setComponentTemplate } from '@ember/component';
```

Pull request:
Update `no-classic-components` rule to only disallow the specific component import
Only this default import should be disallowed:

```
import Component from '@ember/component';
```

Other named imports from `@ember/component` should be allowed.

Fixes #653. CC: @mehulkar.

Patch:
diff --git a/lib/rules/no-classic-components.js b/lib/rules/no-classic-components.js
index b08d21be..3224b808 100644
--- a/lib/rules/no-classic-components.js
+++ b/lib/rules/no-classic-components.js
@@ -1,5 +1,8 @@
 'use strict';
 
+const types = require('../utils/types');
+const assert = require('assert');
+
 const ERROR_MESSAGE =
   'Use Glimmer components(@glimmer/component) instead of classic components(@ember/component)';
 
@@ -27,12 +30,18 @@ module.exports = {
 
     return {
       ImportDeclaration(node) {
-        const importSource = node.source.value;
-
-        if (importSource === '@ember/component') {
-          report(node);
+        if (node.source.value === '@ember/component') {
+          const importDefaultSpecifier = getImportDefaultSpecifier(node);
+          if (importDefaultSpecifier) {
+            report(importDefaultSpecifier);
+          }
         }
       },
     };
   },
 };
+
+function getImportDefaultSpecifier(node) {
+  assert(types.isImportDeclaration(node));
+  return node.specifiers.find(specifier => types.isImportDefaultSpecifier(specifier));
+}
diff --git a/lib/utils/types.js b/lib/utils/types.js
index 30886530..07c31e14 100644
--- a/lib/utils/types.js
+++ b/lib/utils/types.js
@@ -18,6 +18,7 @@ module.exports = {
   isFunctionExpression,
   isIdentifier,
   isImportDeclaration,
+  isImportDefaultSpecifier,
   isLiteral,
   isLogicalExpression,
   isMemberExpression,
@@ -225,6 +226,16 @@ function isImportDeclaration(node) {
   return node !== undefined && node.type === 'ImportDeclaration';
 }
 
+/**
+ * Check whether or not a node is an ImportDefaultSpecifier.
+ *
+ * @param {Object} node The node to check.
+ * @returns {boolean} Whether or not the node is an ImportDefaultSpecifier.
+ */
+function isImportDefaultSpecifier(node) {
+  return node !== undefined && node.type === 'ImportDefaultSpecifier';
+}
+
 /**
  * Check whether or not a node is an Literal.
  *


Test patch:
diff --git a/tests/lib/rules/no-classic-components.js b/tests/lib/rules/no-classic-components.js
index 9625cb98..0eaa2533 100644
--- a/tests/lib/rules/no-classic-components.js
+++ b/tests/lib/rules/no-classic-components.js
@@ -19,7 +19,11 @@ const parserOptions = {
 const ruleTester = new RuleTester({ parserOptions });
 
 ruleTester.run('no-classic-components', rule, {
-  valid: ["import Component from '@glimmer/component';"],
+  valid: [
+    "import Component from '@glimmer/component';",
+    "import { setComponentTemplate } from '@ember/component';",
+    "import { helper } from '@ember/component/helper';",
+  ],
 
   invalid: [
     {
@@ -28,7 +32,7 @@ ruleTester.run('no-classic-components', rule, {
       errors: [
         {
           message: ERROR_MESSAGE,
-          type: 'ImportDeclaration',
+          type: 'ImportDefaultSpecifier',
         },
       ],
     },