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-import-order-aesthetic

v1.0.7

Published

Forget alphabetical or chronological ordering, the future is in bringing aesthetic order to import and require statements.

Downloads

147

Readme

eslint-plugin-import-order-aesthetic

npm Tests Coverage Status npm releasedate license


Forget alphabetical or chronological ordering, the future is in bringing aesthetic order to import and require statements 🌺

Installation

You'll first need to install ESLint:

npm i eslint --save-dev

Next, install eslint-plugin-import-order-aesthetic:

npm install eslint-plugin-import-order-aesthetic --save-dev

View the package on NPM


Requirements

As this rule is linting es6 modules, you are required to add es6 to the env object in your .eslintrc configuration.

You will also need to add sourceType: 'module' to the parserOptions object.

env: {
  es6: true
},
parserOptions: {
  sourceType: 'module'
}

Usage

Add import-order-aesthetic to the plugins section of your .eslintrc configuration file. You can omit the eslint-plugin- prefix:

{
  "plugins": ["import-order-aesthetic"]
}

Configure the rules you want to use under the rules section of your .eslintrc configuration file:

{
  "rules": {
    "import-order-aesthetic/order-import-by-length": ['error', { reverseOrder: true }],
    "import-order-aesthetic/order-require-by-length": ['error', { reverseOrder: false }],
  }
}

Example .eslintrc.js file:

module.exports = {
  env: {
    es6: true,
  },
  parserOptions: {
    parser: "babel-eslint",
    sourceType: "module",
  },
  plugins: ["import-order-aesthetic"],
  rules: {
    "import-order-aesthetic/order-import-by-length": [
      "error",
      { reverseOrder: true },
    ],
    "import-order-aesthetic/order-require-by-length": [
      "error",
      { reverseOrder: false },
    ],
  },
};

Using --fix with your eslint command will auto-arrange your import/require statements.

The fix functionality should work automatically with ESLint extensions in your code editor if you have it configured to fix on save etc.


Rules

order-import-by-length

Organise import statements aesthetically by ordering them according to line length and then alphabetically.

order-require-by-length

Organise require statements aesthetically by ordering them according to line length and then alphabetically.


Options

reverseOrder

The default behaviour of both rules rule is a 'top-heavy' order. Set reverseOrder to true to use a 'bottom-heavy' order.

  • false (default)
  • true

Usage:

"import-order-aesthetic/order-import-by-length": ['error', { reverseOrder: true }],

Default:

const c = require("testing");
const b = require("tester");
const a = require("test");
require("test");

Reversed:

require("test");
const a = require("test");
const b = require("tester");
const c = require("testing");

Issues

At the moment the two rules are interpreted separately so will assess import and require statements independently. If you mix these two in a single file they will be ordered as normal, but not in relation to each other.

This is on the roadmap, PRs welcome.


When Not To Use It

If you want to order your import/require statements by something sensible... :)


Roadmap

  1. Add support for mixed import & require statement (see issues).
  2. Potentially improve the ExpressionStatement type validation.