Giter Club home page Giter Club logo

sublime-sort-javascript-imports's Introduction

Sort JavaScript Imports

Adds a Sort JavaScript Imports command to Sublime Text 2 or 3, which sorts selected lines containing JavaScript import statements or require() calls by the module path they're importing.

Install via Package Control

Ctrl-Shift-P/Command-Shift-P → Package Control: Install Package → Sort JavaScript Imports

Install via git clone

Preferences → Browse Packages… → git clone https://github.com/insin/sublime-sort-javascript-imports.git "Sort JavaScript Imports"

Usage

Select lines containing the import statements you want to sort, then use either of:

  • Command palette: Ctrl-Shift-P/Command-Shift-P → Sort JavaScript Imports
  • Default key binding: Alt-F9 on Linux/Windows or Alt-F5 on Mac

Lines will be sorted based on the module path being imported, respecting (and normalising) any blank lines used to divide imports into different categories.

Any non-import lines in the selection will be moved to the end, separated by a new blank line if necessary. Let me know if there's a preferable way to handle these.

Import ordering

Where top-level imports and path-based imports are mixed in the same block, they will be ordered as follows:

  1. Top-level imports
  2. Imports which traverse up out of the current directory, from furthest away to closest
  3. Imports within the current directory

Note: if you're using Webpack aliases or a Babel alises plugin for top-level importing of your app's own code, you might want to put those in a separate block for clarity.

Example

MIT Licensed

Unit testing and configuration setup cribbed from Sort Lines (Numerically).

sublime-sort-javascript-imports's People

Contributors

insin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

jihchi

sublime-sort-javascript-imports's Issues

Make sort case-insensitive

Current:

import IndexRoute from 'react-router/lib/IndexRoute'
import Route from 'react-router/lib/Route'
import Router from 'react-router/lib/Router'
import hashHistory from 'react-router/lib/hashHistory'

Expected:

import hashHistory from 'react-router/lib/hashHistory'
import IndexRoute from 'react-router/lib/IndexRoute'
import Route from 'react-router/lib/Route'
import Router from 'react-router/lib/Router'

Code

about code. If i want to /sort/ a.js (all imports), i need to get list of lines in a.js, then call lines=sort_js_imports(lines), write result to a.js.
It enough?
Tks...

Sorting removes empty lines not related to imports

First of all thanks for this plugin! It's quite helpful to keep import order consistent.

One thing I really don't like is that using the plugin removes empty lines from the code that are not related to the import. The plugin should really just touch import lines and not reformat the whole code.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.