prettier-plugin-sort-imports-length
v0.0.8
Published
A prettier plugin that sorts imports by line length (longer to shorter)
Maintainers
Readme
prettier-plugin-sort-imports-by-length
A Prettier plugin that sorts import declarations by line length, from longer to shorter.
Installation
# npm
npm install --save-dev prettier-plugin-sort-imports-by-length
# yarn
yarn add --dev prettier-plugin-sort-imports-by-length
# pnpm
pnpm add -D prettier-plugin-sort-imports-by-lengthUsage
Once installed, Prettier will automatically detect and use the plugin.
Add to your Prettier config file:
// .prettierrc.js
module.exports = {
// your other prettier options
importOrderSortByLength: true,
};Example
Before:
import React from 'react';
import { useState, useEffect, useCallback, useMemo } from 'react';
import a from 'a';
import SomeComponentWithReallyLongName from './components/SomeComponentWithReallyLongName';After:
import SomeComponentWithReallyLongName from './components/SomeComponentWithReallyLongName';
import { useState, useEffect, useCallback, useMemo } from 'react';
import React from 'react';
import a from 'a';Features
- Sorts imports by their line length (longer to shorter)
- Works with JavaScript, TypeScript, JSX, and TSX files
- Preserves directives and interpreter directives
- Ignores files with a
// sort-imports-ignorecomment at the top
License
MIT
