Repository: un-ts/eslint-plugin-import-x
Pull request #67 (2024-03-25 03:33:38)

fix: only add `dependencies` when no `exported` found

changeset-bot[bot]: ###  ⚠️  No Changeset found

Latest commit: 3df9bbfc93e776e353287f8dac6b3500fe694a75

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. **If these changes should result in a version bump, you need to add a changeset.**

<details><summary>This PR includes no changesets</summary>

  When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

</details>

[Click here to learn what changesets are, and how to add one](https://github.com/changesets/changesets/blob/main/docs/adding-a-changeset.md).

[Click here if you're a maintainer who wants to add a changeset to this PR](https://github.com/un-ts/eslint-plugin-import-x/new/fix/export_dependencies?filename=.changeset/curly-files-dance.md&value=---%0A%22eslint-plugin-import-x%22%3A%20patch%0A---%0A%0Afix%3A%20only%20add%20%60dependencies%60%20when%20no%20%60exported%60%20found%0A)


codesandbox-ci[bot]: This pull request is automatically built and testable in [CodeSandbox](https://codesandbox.io).

  To see build info of the built libraries, click [here](https://ci.codesandbox.io/status/un-ts/eslint-plugin-import-x/pr/67/builds/487170) or the icon next to each commit SHA.
codecov[bot]: ## [Codecov](https://app.codecov.io/gh/un-ts/eslint-plugin-import-x/pull/67?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=un-ts) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 96.45%. Comparing base [(`cdd6344`)](https://app.codecov.io/gh/un-ts/eslint-plugin-import-x/commit/cdd6344c090197e7617ab5edd717f9f6b48bcdfb?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=un-ts) to head [(`3df9bbf`)](https://app.codecov.io/gh/un-ts/eslint-plugin-import-x/pull/67?dropdown=coverage&src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=un-ts).


<details><summary>Additional details and impacted files</summary>


```diff
@@           Coverage Diff           @@
##           master      #67   +/-   ##
=======================================
  Coverage   96.45%   96.45%           
=======================================
  Files          93       93           
  Lines        4427     4428    +1     
  Branches     1493     1494    +1     
=======================================
+ Hits         4270     4271    +1     
  Misses        151      151           
  Partials        6        6           
```



</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/un-ts/eslint-plugin-import-x/pull/67?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=un-ts).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=un-ts).


Patch:
diff --git a/.changeset/curly-files-dance.md b/.changeset/curly-files-dance.md
new file mode 100644
index 00000000..d9a12b24
--- /dev/null
+++ b/.changeset/curly-files-dance.md
@@ -0,0 +1,5 @@
+---
+"eslint-plugin-import-x": patch
+---
+
+fix: only add `dependencies` when no `exported` found
diff --git a/src/rules/group-exports.ts b/src/rules/group-exports.ts
index ed0373e7..9d953a88 100644
--- a/src/rules/group-exports.ts
+++ b/src/rules/group-exports.ts
@@ -112,7 +112,7 @@ export = createRule<[], 'ExportNamedDeclaration' | 'AssignmentExpression'>({
         }
       },
 
-      'Program:exit': function onExit() {
+      'Program:exit'() {
         // Report multiple `export` declarations (ES2015 modules)
         if (nodes.modules.set.size > 1) {
           for (const node of nodes.modules.set) {
diff --git a/src/rules/namespace.ts b/src/rules/namespace.ts
index c3d4ad4a..0d880a96 100644
--- a/src/rules/namespace.ts
+++ b/src/rules/namespace.ts
@@ -62,7 +62,7 @@ function processBodyStatement(
       case 'ImportDefaultSpecifier':
       case 'ImportSpecifier': {
         const meta = imports.get(
-          'imported' in specifier && specifier.imported
+          'imported' in specifier
             ? getValue(specifier.imported)
             : // default to 'default' for default
               'default',
@@ -135,7 +135,7 @@ export = createRule<[Options], MessageId>({
       allowComputed: false,
     },
   ],
-  create: function namespaceRule(context) {
+  create(context) {
     // read options
     const { allowComputed } = context.options[0] || {}
 
diff --git a/src/rules/no-restricted-paths.ts b/src/rules/no-restricted-paths.ts
index 31c30fd4..833619e7 100644
--- a/src/rules/no-restricted-paths.ts
+++ b/src/rules/no-restricted-paths.ts
@@ -113,7 +113,7 @@ export = createRule<[Options?], MessageId>({
     },
   },
   defaultOptions: [],
-  create: function noRestrictedPaths(context) {
+  create(context) {
     const options = context.options[0] || {}
     const restrictedPaths = options.zones || []
     const basePath = options.basePath || process.cwd()
diff --git a/src/rules/order.ts b/src/rules/order.ts
index e97bae66..a8891263 100644
--- a/src/rules/order.ts
+++ b/src/rules/order.ts
@@ -1061,7 +1061,7 @@ export = createRule<[Options?], MessageId>({
           pathGroupsExcludedImportTypes,
         )
       },
-      'Program:exit': function reportAndReset() {
+      'Program:exit'() {
         for (const imported of importMap.values()) {
           if (newlinesBetweenImports !== 'ignore') {
             makeNewlinesBetweenReport(
diff --git a/src/utils/export-map.ts b/src/utils/export-map.ts
index 526dd6d5..01f78855 100644
--- a/src/utils/export-map.ts
+++ b/src/utils/export-map.ts
@@ -442,13 +442,14 @@ export class ExportMap {
       }
 
       if (n.type === 'ExportAllDeclaration') {
-        const getter = captureDependency(n, n.exportKind === 'type')
-        if (getter) {
-          m.dependencies.add(getter)
-        }
         if (n.exported) {
           namespaces.set(n.exported.name, n.source.value)
           processSpecifier(n, n.exported, m)
+        } else {
+          const getter = captureDependency(n, n.exportKind === 'type')
+          if (getter) {
+            m.dependencies.add(getter)
+          }
         }
         continue
       }
@@ -693,6 +694,7 @@ export class ExportMap {
     if (this.namespace.has(name)) {
       return true
     }
+
     if (this.reexports.has(name)) {
       return true
     }


Test patch:
diff --git a/test/rules/namespace.spec.ts b/test/rules/namespace.spec.ts
index 3c7541a7..4af4e8df 100644
--- a/test/rules/namespace.spec.ts
+++ b/test/rules/namespace.spec.ts
@@ -11,7 +11,6 @@ import {
 import rule from 'eslint-plugin-import-x/rules/namespace'
 
 const ruleTester = new TSESLint.RuleTester({
-  parser: require.resolve('espree'),
   parserOptions: { env: { es6: true } },
 })
 
@@ -401,11 +400,7 @@ const invalid = [
 ///////////////////////
 // deep dereferences //
 //////////////////////
-for (const [folder, parser] of [
-  ['deep'],
-  // FIXME: check and enable
-  // ['deep-es7', parsers.BABEL],
-]) {
+for (const [folder, parser] of [['deep'], ['deep-es7', parsers.BABEL]]) {
   // close over params
   valid.push(
     test({
@@ -428,45 +423,45 @@ for (const [folder, parser] of [
       parser,
       code: `import { b } from "./${folder}/a"; var {c:{d:{e}}} = b`,
     }),
+    // deep namespaces should include explicitly exported defaults
+    test({
+      parser,
+      code: `import * as a from "./${folder}/a"; console.log(a.b.default)`,
+    }),
   )
 
-  // deep namespaces should include explicitly exported defaults
-  test({
-    parser,
-    code: `import * as a from "./${folder}/a"; console.log(a.b.default)`,
-  }),
-    invalid.push(
-      test({
-        parser,
-        code: `import * as a from "./${folder}/a"; console.log(a.b.e)`,
-        errors: ["'e' not found in deeply imported namespace 'a.b'."],
-      }),
-      test({
-        parser,
-        code: `import { b } from "./${folder}/a"; console.log(b.e)`,
-        errors: ["'e' not found in imported namespace 'b'."],
-      }),
-      test({
-        parser,
-        code: `import * as a from "./${folder}/a"; console.log(a.b.c.e)`,
-        errors: ["'e' not found in deeply imported namespace 'a.b.c'."],
-      }),
-      test({
-        parser,
-        code: `import { b } from "./${folder}/a"; console.log(b.c.e)`,
-        errors: ["'e' not found in deeply imported namespace 'b.c'."],
-      }),
-      test({
-        parser,
-        code: `import * as a from "./${folder}/a"; var {b:{ e }} = a`,
-        errors: ["'e' not found in deeply imported namespace 'a.b'."],
-      }),
-      test({
-        parser,
-        code: `import * as a from "./${folder}/a"; var {b:{c:{ e }}} = a`,
-        errors: ["'e' not found in deeply imported namespace 'a.b.c'."],
-      }),
-    )
+  invalid.push(
+    test({
+      parser,
+      code: `import * as a from "./${folder}/a"; console.log(a.b.e)`,
+      errors: ["'e' not found in deeply imported namespace 'a.b'."],
+    }),
+    test({
+      parser,
+      code: `import { b } from "./${folder}/a"; console.log(b.e)`,
+      errors: ["'e' not found in imported namespace 'b'."],
+    }),
+    test({
+      parser,
+      code: `import * as a from "./${folder}/a"; console.log(a.b.c.e)`,
+      errors: ["'e' not found in deeply imported namespace 'a.b.c'."],
+    }),
+    test({
+      parser,
+      code: `import { b } from "./${folder}/a"; console.log(b.c.e)`,
+      errors: ["'e' not found in deeply imported namespace 'b.c'."],
+    }),
+    test({
+      parser,
+      code: `import * as a from "./${folder}/a"; var {b:{ e }} = a`,
+      errors: ["'e' not found in deeply imported namespace 'a.b'."],
+    }),
+    test({
+      parser,
+      code: `import * as a from "./${folder}/a"; var {b:{c:{ e }}} = a`,
+      errors: ["'e' not found in deeply imported namespace 'a.b.c'."],
+    }),
+  )
 }
 
 ruleTester.run('namespace', rule, { valid, invalid })