question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use same alphabetize props as ESLint sort-imports

See original GitHub issue

ESLint’s native sort-imports does the sorting I want, but doesn’t care about the grouping of imports. On the other hand, import/order gives me the ordering I want, but not the powerful alphabetization sort from sort-imports.

For sort-imports, this is the config I use:

{
  'sort-imports': [
    'warn',
    {
      ignoreCase: true,
      memberSyntaxSortOrder: [
        'single',
        'all',
        'multiple',
        'none',
      ],
    },
  ],
}

I’d like to do something similar with import/order:

{
  alphabetize: {
    caseInsensitive: true,
    memberSyntaxSortOrder: [
      'single',
      'all',
      'multiple',
      'none',
    ],
    order: 'asc',
  },
}

I would like this functionality because I’m grouping them differently than the default:

{
  groups: [
    [
      'builtin',
      'external',
    ],
    [
      'index',
      'parent',
      'sibling',
    ],
  ],
}

Here’s an example I’d expect to see:

import PropTypes from 'prop-types'
import React from 'react'

import useMediaQuery from './useMediaQuery'
import useMediaQueryState from './useMediaQueryState'
import { * as actions } from './actions'
import { breakpointsList } from './breakpoints'
import './styles.css'

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:15
  • Comments:20 (6 by maintainers)

github_iconTop GitHub Comments

22reactions
pcarncommented, Apr 28, 2020

I’d also like to have the imports inside the group sorted.

10reactions
KevinNovakcommented, Jan 21, 2022

I have the following setup with “sort-imports” and “import/order” and they seem to be working well together:

{
    "import/order": [
        "error",
        {
            "alphabetize": {
                "caseInsensitive": true,
                "order": "asc"
            },
            "groups": [
                ["builtin", "external", "object", "type"],
                ["internal", "parent", "sibling", "index"]
            ],
            "newlines-between": "always"
        }
    ],
    "sort-imports": [
        "error",
        {
            "allowSeparatedGroups": true,
            "ignoreCase": true,
            "ignoreDeclarationSort": true,
            "ignoreMemberSort": false,
            "memberSyntaxSortOrder": ["none", "all", "multiple", "single"]
        }
    ]
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Use same alphabetize props as ESLint sort-imports #1670
It does alphabetize, but the ordering is based on the from string (from what I can tell), not the characters of the variables...
Read more >
sort-imports - ESLint - Pluggable JavaScript Linter
This rule checks all import declarations and verifies that all imports are first sorted by the used member syntax and then alphabetically by...
Read more >
Sorting your imports with ESLint - DEV Community ‍ ‍
The "react" import should always come first; Package imports should come next, sorted by alphabetical order; The named imports should be sorted ...
Read more >
Using eslint, prettier and sort-imports vscode extensions for ...
when you see props property destructure, those are not formatted perfectly. this is when prettier plays in! Use Prettier to format better.
Read more >
eslint-plugin-simple-import-sort - npm
Easy autofixable import sorting. Latest version: 8.0.0, last published: 2 months ago. Start using eslint-plugin-simple-import-sort in your ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found