Code Monkey home page Code Monkey logo

vsc-sort-imports's Introduction

sort-imports

Sort ES6 imports for JavaScript and TypeScript automatically. Ported from the atom-import-sort package by Renke Grunwald.

Sort Example

Features

Automatically sorts imports on save. You can disable this behavior in the settings and sort imports manually:

  1. Launch the Command Palette (Ctrl/Cmd + Shift + P);
  2. Enter Sort imports

You can also save the document without saving imports. This could become handy when you have auto saving enabled, but don't want to sort the imports in a particular file:

  1. Launch the Command Palette (Ctrl/Cmd + Shift + P);
  2. Enter Save file without sorting imports

Extension Settings

This extension has the following settings:

  • sort-imports.default-sort-style: sorting style if package.json doesn't have import-sort key (default: eslint).
  • sort-imports.on-save: enable/disable auto sorting on save (default: true).
  • sort-imports.suppress-warnings: suppress warnings if sorting imports fails (default: false).
  • sort-imports.languages: selectively choose the languages which should be sported (default: ['javascript', 'typescript']).
  • sort-imports.cache-package-json-config-checks: performance optimization, disable if necessary (default: true).

Obsolete settings

See release notes for version 4

Use a different style or parser

Styles (and parsers) can be configured on a per-project basis including support for different types of files (currently JavaScript and TypeScript).

Just add the following to your package.json and adapt it to your liking:

"importSort": {
  ".js, .jsx, .es6, .es": {
    "parser": "babylon",
    "style": "eslint",
    "options": {}
  },
  ".ts, .tsx": {
    "parser": "typescript",
    "style": "eslint",
    "options": {}
  }
}

The keys are a list of file extensions that map to the parser and style that should be used for files that have any of the listed file extensions.

By default, sort-import comes with these styles:

PRs with more styles are welcome.

Release Notes

5.1.0

5.0.0

4.1.0

  • Implemented by @cliffkoh
    • Introduced sort-imports.default-sort-style, which defaults to eslint. Other possible values are module, module-compact and module-scoped.
    • Introduced sort-imports.cache-package-json-config-checks which defaults to true. When true, will cache calls to import-sort-config thereby improving performance (avoids repeated non-trival disk lookups and parsing).
    • Fixed bug in Save file without sorting import which caused it to not work.

4.0.0

Update to ease transition from @peterjuras' extension.

  • sort-imports.blank-lines-after: removed until a valid implementation is provided
  • sort-imports.sort-type: you can now configure your sorting type folowing with a key in your package.json. Documentation
    • by-module-name: is now "style": "module-compact"
    • by-imported-name: is removed

3.0.0

  • Renamed to sort-imports. Renamed config settings to slug-case.
  • Fixed blank linkes after imports feature.

2.4.0

  • Implemented by @danieloprado: Added setting to selectively choose the languages. Set sortImports.languages to an array of the languages that you want to be sorted, e.g. ['javascript'].
  • Bugfixes

2.4.0 (amq-sort-imports fork)

  • Import style by-module-name added.
  • Added support for blank lines after imports.

2.3.0

  • Import sort style module is now included by default alongside the eslint style.

2.2.0

  • Added setting to suppress warnings. Set sortImports.suppressWarnings to true to hide warnings if sorting imports fails.

2.1.0

2.0.0

  • Added TypeScript support
  • Fixed inline comments on import statements
  • Thanks to @shalomdotnet for the PR!

1.1.0

  • Added 'Save without sorting imports' command

1.0.0

Initial release

Credits

Developed by Peter Juras, maintained by A. Matías Quezada

Thanks

vsc-sort-imports's People

Contributors

amatiasq avatar peterjuras avatar daniel-beet avatar fsmaia avatar renke avatar er9781 avatar shalomdotnet avatar

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.