Skip to content

import/order fixer is not working properly? #2154

@AgainPsychoX

Description

@AgainPsychoX

I am trying to use eslint with the plugin in my project, and I was happy when I saw that there are fixers for import ordering, so I don't have to visit hundreds of files to satisfy the linter.

+(fixable) The --fix option on the [command line] automatically fixes problems reported by this rule.

(from https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/order.md)

Unfortunately, in quite a lot of cases it does not work.

I use both plugin:import/recommended and plugin:import/typescript (project uses Typescript/React (.ts/.tsx)).

Rules (only import/* listed):

		"import/no-named-as-default-member": "off",
		"import/newline-after-import": "warn",
		"import/no-duplicates": "warn",
		"import/order": ["warn", {
			"groups": ["builtin", "external", "internal", "parent", "sibling", "index", "object"],
			"pathGroups": [
				{"pattern": "@flyparks/**", "group": "internal", "position": "before"}
			],
			"newlines-between": "never",
			"alphabetize": {
				"order": "desc",
				"caseInsensitive": true
			}
		}]

Settings (only import/* listed):

		"import/resolver": {
			"webpack": {
				"config": "../node_modules/react-scripts/config/webpack.config.js"
			}
		},

Example

File (only imports):

import { useHistory } from 'react-router-dom';
import React, {useEffect, useState } from 'react';
import { BookingEntry, getPathToBookingPage } from '@flyparks/models';
import './AccessBookingNoAuthPage.scss';
import { CircularProgress, TextField } from '@material-ui/core';
import { httpsCallable } from 'firebase/functions';
import FirebaseServices from 'utils/FirebaseServices';

Linter output:

   3:1   warning  There should be no empty line between import groups                           import/order
   7:1   warning  `@material-ui/core` import should occur before import of `@flyparks/models`   import/order
   8:1   warning  `firebase/functions` import should occur before import of `@flyparks/models`  import/order

Using --fix does nothing, despite I imagine removing empty lines should be easy (its obviously detected already, isn't it?).
Reordering the lines also should be quite easy...

Is there issue with Typescript/React files maybe?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions