MCPcopy Index your code
hub / github.com/bfncs/codemod-imports-sort

github.com/bfncs/codemod-imports-sort @v0.5.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.5.0 ↗ · + Follow
11 symbols 29 edges 7 files 0 documented · 0% updated 8y ago★ 383 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Build Status

CodeMod to sort ES6 imports by type

Use this codemod to sort ES6 imports by type in this order:

  • internal Node.js modules before
  • external module imports before
  • local imports from parent folders before
  • local imports from sibling folders.

Imports of the same type are sorted alphabetically.

Install

yarn global add codemod-imports-sort

Use

codemod-imports-sort path/to/file.js

Example

Before:

import './index.css';
import Beta from 'Beta';
import fs from 'fs';
import bar from '../bar';
import './';
import baz from './baz';
import Alpha from 'alpha';
import foo from '../../foo';
import App from './App';

After:

import fs from 'fs';
import Alpha from 'alpha';
import Beta from 'Beta';
import foo from '../../foo';
import bar from '../bar';
import './';
import App from './App';
import baz from './baz';
import './index.css';

Options

--sortConfig FILE.json

Optionally you can pass the path to a JSON file with a config to define the desired order of imports. The config should resemble the config for the import/order plugin of eslint. groups must be an array of string or [string]. The only allowed strings are: "builtin", "external", "internal", "parent", "sibling", "index".

For example to define to sort index imports first, then internal and external modules in a alphabetically sorted group and then sibling, parent and builtin modules together in a group, use this configuration:

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

Omitted types are implicitly grouped together as the last element

Built with jscodeshift.

Core symbols most depended-on inside this repo

Shape

Function 11

Languages

TypeScript100%

Modules by API surface

src/matchers.js6 symbols
src/compareImports.js4 symbols
src/compareImports.test.js1 symbols

For agents

$ claude mcp add codemod-imports-sort \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page