eslint-plugin-import-order-alphabetical icon indicating copy to clipboard operation
eslint-plugin-import-order-alphabetical copied to clipboard

Mixed import/require bugs

Open jaydenseric opened this issue 6 years ago • 3 comments

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')

jaydenseric avatar Aug 08 '18 05:08 jaydenseric

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.

janpaul123 avatar Aug 08 '18 06:08 janpaul123

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.

jaydenseric avatar Aug 08 '18 06:08 jaydenseric

Ah I see. Yeah in that case this is a problem. Thanks for reporting and explaining!

janpaul123 avatar Aug 08 '18 07:08 janpaul123