eslint-plugin-import-order-alphabetical
eslint-plugin-import-order-alphabetical copied to clipboard
Mixed import/require bugs
Although using imports and requires in the same file should be avoided, there are some bugs if you do.
With these ESLint rules:
{
"import/newline-after-import": "error",
"import-order-alphabetical/order": [
"error",
{
"newlines-between": "never"
}
]
}
This should be valid, but instead results in the error There should be no empty line between import groups (import-order-alphabetical/order)
on the first line:
import a from 'a'
const b = require('b')
Also, this should be valid, but instead results in the error `a` import should occur before import of `./b` (import-order-alphabetical/order)
on the require
:
import b from './b'
import c from './c'
const a = require('a')
Does it autofix to a stable ordering? The goal of this plugin is not to mark particular orders as valid or invalid, but to give you consistency so you don't have to worry about what particular ordering to choose.
If this autofixes to
import a from 'a'
const b = require('b')
and
const a = require('a')
import b from './b'
import c from './c'
respectively, then the goal of this plugin is met.
Neither of those examples you provide are ok. The autofixed state is also a lint error, and another autofix changes it back again in an infinite loop.
As import-order-alphabetical/order
is intended to be a substitute for import/order
it should not conflict with other rules such as import/newline-after-import
.
import
statements should be the first thing in the file; if they are not they get hoisted at runtime.
Ah I see. Yeah in that case this is a problem. Thanks for reporting and explaining!