Skip to content

Rule proposal: no-submodule-import #2815

@fisker

Description

@fisker

Description

A repo can contain many submodules, they should only share code via the entries, but not import internal files directly.

This rule should require a configuration step, it should look like

{
  'unicorn/this-rule-name': [
    'error',
    [
      {
        module: "a-module", // path to the module directory
        entries: [
          "index.js",
          "another-private-entry.js",
        ],
        message: "Please import functionality from `index.js` or `another-private-entry.js`"
      },
      // ... another submodule
    ]
  ]
}

Examples

// ❌
import {functionality} from "../a-module/internal-functionality.js"

// ✅
import {functionality} from "../a-module/index.js"

Proposed rule name

no-submodule-import

Additional Info

This is just the basic idea, open for discussion.

We should only support module with ./ or ../, we don't want to dive into the module resolution hell.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions