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

Side-effecting imports should be treated as a special case

Open
#505 5 comments 7 reactions 0 assignees View on GitHub
enhancement semver-minor style-guide
Dominant language
JavaScript
Stars
5.9k
Forks
1.5k
PR merge metrics
No merged PRs in 30d

Description

By side-effecting imports, I mean when you import something just for its side effects, without assigning a variable. (Not sure what the correct term is.)

For example:

``` js
import './lib/env'; // side-effects!

import path from 'path';
import execa from 'execa';
```

Side-effecting imports do things like reading config files and setting up the environment (in ways that might impact the way other modules initialise), so it usually makes sense for them to go first, regardless of whether they're absolute/relative. But the `imports-first` rule doesn't consider this, and complains about the above snippet, saying "Absolute imports should come before relative imports."

I think it would make sense for the `imports-first` rule to make an exception for side-effecting imports.

(Sorry if this already exists as an option and I'm just missing it.)

Contributor guide

Open the contributing guide

Research direction

Start by locating the imports-first rule and its existing tests, then read how relative and absolute imports are classified. Add coverage for an unassigned side-effect import appearing before other imports, and consider the issue done when that case no longer reports the ordering error while existing ordering behavior remains covered.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.