npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

eslint-plugin-pretty-imports

v1.3.0

Published

Eslint plugin to prettify import statements

Downloads

1,878

Readme

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" // or ["warn", ...options (see below)]
}

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";