• Stars
    star
    204
  • Rank 191,983 (Top 4 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 5 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Do you hate chaos in javascript imports?

pretty-imports

Opinionated Imports Sorter

npm package codecov CircleCI code style: prettier

No more mixes of default and named imports. Automatically prettify and sort your import statements.

🌟 Perfectly works in addition to prettier and typescript.

😨 Before

import * as React from "react";
import { runKeyHandler } from "../../_shared/hooks/useKeyDown";
import * as PropTypes from "prop-types";
import DayWrapper from "./DayWrapper";
import CalendarHeader from "./CalendarHeader";
import { Theme } from "@material-ui/core";

import { IconButtonProps } from "@material-ui/core/IconButton";
import CircularProgress from "@material-ui/core/CircularProgress";
import SlideTransition, { SlideDirection } from "./SlideTransition";
import { withStyles, WithStyles } from "@material-ui/core/styles";
import { findClosestEnabledDate } from "../../_helpers/date-utils";
// TODO smth
import Day from "./Day";
import { withUtils, WithUtilsProps } from "../../_shared/WithUtils";

😊 After

import * as React from "react";
import * as PropTypes from "prop-types";
// TODO smth
import Day from "./Day";
import DayWrapper from "./DayWrapper";
import CalendarHeader from "./CalendarHeader";
import CircularProgress from "@material-ui/core/CircularProgress";
import SlideTransition, { SlideDirection } from "./SlideTransition";
import { Theme } from "@material-ui/core";
import { runKeyHandler } from "../../_shared/hooks/useKeyDown";
import { IconButtonProps } from "@material-ui/core/IconButton";
import { withStyles, WithStyles } from "@material-ui/core/styles";
import { findClosestEnabledDate } from "../../_helpers/date-utils";
import { withUtils, WithUtilsProps } from "../../_shared/WithUtils";

💿 Installation

npm install eslint-plugin-pretty-imports --save-dev

yarn add --dev eslint-plugin-pretty-imports

Note: If you installed ESLint globally (using the -g flag) then you must also install eslint-plugin-pretty-imports globally.

🌚 Usage

Add pretty-imports to the plugins section of your .eslintrc configuration file. You can omit the eslint-plugin- prefix:

{
  "plugins": ["pretty-imports"],
  "rules": {
    "pretty-imports/sorted": "warn"
  }
}

🦆 Sorting

A little about the sorting logic. This package takes the import type as a first parameter to sort. We sort import groups in the following order:

  1. import 'anyfile'
  2. import * as anything from 'anywhere'
  3. import default from 'anywhere'
  4. import { anything } from 'anywhere

And then we are sorting imports by line length inside each group. It needs only to improve the visual readability of the imports section. This behavior can be disabled by "no-line-length-sort" rule option.

🔧 Customization

This plugin provides only 1 rule, that fully takes care of your imports. But you can also customize the behavior thanks to eslint rule options.

"rules": {
  "pretty-imports/sorted": ["warn", "sort-by-specifiers-length"]
}

Here is a list of available options

  • sort-by-specifiers-length – sorts imports not by line length, but firstly by import specifier length

    Example

    import { one } from "someLongImport.tsx"; // so this imports comes before
    import { longSpecifier } from "b.js";
    import { longSpecifier } from "longImport.js";
  • no-line-length-sort — disable sorting of same-type imports by line length

    Example

    import * as React from "react";
    // imports of one category won't be sorted inside by line length
    import { longSpecifier } from "longImport.js";
    import { longSpecifier } from "b.js";

More Repositories

1

odiff

The fastest pixel-by-pixel image visual difference tool in the world.
OCaml
2,000
star
2

cypress-real-events

Fire native system events from Cypress.
HTML
754
star
3

date-io

Abstraction over common javascript date management libraries
TypeScript
718
star
4

blendr

The hacker's BLE (bluetooth low energy) browser terminal app
Rust
292
star
5

subtitler

Free on-device web app for audio transcribing and rendering subtitles
ReScript
129
star
6

reason-date-fns

Reason binding for date-fns/fp. Curried by default :3
Reason
45
star
7

workspace-climate-control

Your own open-source CO2 sensor with ready to use TUI
C
37
star
8

material-ui-datetimepicker

[UNMAINTAINED] Wrapper for Material UI Date and Time picker components
JavaScript
31
star
9

hook2hoc

Typesafe converter of React hooks to React hocs 🤓
TypeScript
25
star
10

trololors

Not the fastest terminal colors library. Don't even ask about size.
Rust
16
star
11

caps-word.nvim

Much better way to type SCREAMING_SNAKE_CASE words aka constants
Lua
14
star
12

my-nvim-config

My neovim configs (terminal profile neovim 😱)
Lua
12
star
13

CV

The personal CV
TypeScript
8
star
14

ns-react-18next

[Unmaintained] Namespaced i18next localization in react with no tears
TypeScript
8
star
15

bots

TypeScript
2
star
16

date-fns-comparison

JavaScript
2
star
17

reasonml-for-geese-intro

Introduction in ReasonML
JavaScript
2
star
18

bff-workshop

JavaScript
2
star
19

testcon-cypress-demo

Demo project for testcon 2019
JavaScript
2
star
20

Kova-player

The most beautifull music player for Windows
C#
2
star
21

MeetingLiveStream

JavaScript
1
star
22

holyjs-component-testing-workshop

TypeScript
1
star
23

cypress-qa-fwdays-webinar

JavaScript
1
star
24

cypress-4-2020

Repository for the members of https://fwdays.com/en/event/cypress-workshop workshop
TypeScript
1
star
25

test_opam_windows

C
1
star
26

test-date-io-type

Test repo shows how to use @date-io/type
JavaScript
1
star
27

ina3222-pico

Python
1
star
28

odiff-debug

JavaScript
1
star
29

minecraft2024

1
star
30

fframes_ios_demo_project

Rust
1
star
31

chernihiv-it-cypress-demo

TypeScript
1
star
32

meeting-sticker

C
1
star