import-js / import-js/eslint-plugin-import

Request: rule for banning synchronous imports of arbitrary packages

Open
#1,245 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

rule proposal
Dominant language
JavaScript
Stars
5.9k
Forks
1.5k
PR merge metrics
No merged PRs in 30d

Description

Managing bundle sizes and enforcing code-splitting in large applications can be delicate, and there is currently no mechanism which I know of to enforce that specific libraries must not be imported with ordinary import moment from 'moment'; syntax, and instead must be split like const momentPromise = import('moment').

Proposed API:

  "rules": {
    "import/no-synchronous-dependencies": ["error", {
      "packages": ['moment', 'zxcvbn']
    }]
  }

Example No. 1, errors:

import moment from 'moment'

Example No. 2, errors:

const moment = require('moment')

Example No. 3, passes

const momentLoader = import('moment')

Would there be an appetite for this? If there would be, I would consider making a PR of my own.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue does not name implementation files, tests, or an entry point; begin by locating the plugin’s existing rule definitions and rule tests. Compare the proposed configuration with the three import examples, and consider the work complete when synchronous imports and require calls for configured packages are rejected while dynamic import() is accepted.

Written by the indexing model from the issue text.

Assessment

Tech stack
eslint, javascript
Domain
devtools, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.