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

Autofix moving a binding import from above to below a side-effecting import

Open
#2,876 3 comments 0 reactions 0 assignees View on GitHub
bug help wanted import/export ordering
Dominant language
JavaScript
Stars
5.9k
Forks
1.5k
PR merge metrics
No merged PRs in 30d

Description

eslint: 7.28.0
eslint-plugin-import: 2.28.1

Repro:

app.tsx
```diff
import 'babel-polyfill'
import * as React from 'react'
import { render } from 'react-dom'
-import { Provider } from 'react-redux'
import { hot } from 'react-hot-loader'
-import { s } from './s/s'
+import { Provider } from 'react-redux'
import { Switch, Route, BrowserRouter as Router } from 'react-router-dom'
-import { M } from './P/M'
+
import { F } from './P/F'
-import { i } from './s/w/w'
+import { M } from './P/M'

import 's/s.min.css' // external dep
import './App.css'
import { D } from './components/D'
+import { s } from './s/s'
+import { i } from './s/w/w'
```

base-eslintrc.js

```js
module.exports = {
root: true,
ignorePatterns: ['**/dist/', '**/node_modules/', '**/build/'],
env: {
es2021: true,
node: true,
jest: true,
},
extends: [
'eslint:recommended',
'prettier',
'plugin:import/errors',
'plugin:import/warnings',
'plugin:prettier/recommended',
],
plugins: ['import'],
settings: {
'import/resolver': {
node: {
extensions: ['.js', '.ts'],
moduleDirectory: ['node_modules', 'src/'],
},
typescript: {
alwaysTryTypes: true,
},
},
},
rules: {
'import/order': [
'error',
{
'newlines-between': 'always',
alphabetize: { order: 'asc' },
},
],
},
}
```

.eslintrc.js
```js
const overrides = [
{
files: ['**/*.ts', '**/*.tsx'],
parser: '@typescript-eslint/parser',
parserOptions: {
jsx: true,
project: true,
tsconfigRootDir: './',
},
plugins: ['@typescript-eslint', 'import'],
extends: ['plugin:@typescript-eslint/recommended', './base-eslintrc.js', 'plugin:import/typescript'],
rules: tsRules,
},
]

module.exports = {
extends: ['./tes-eslint-commons.js'],
plugins: ['import'],
overrides,
}
```

Contributor guide

Open the contributing guide

Research direction

Reproduce the ordering change in app.tsx using the import/order configuration in base-eslintrc.js and .eslintrc.js. Read the import/order autofix behavior around side-effecting imports first; done means autofix no longer moves binding imports across those side-effecting imports.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.