d-import-sort

A D script for sorting import statements.


Keywords
d, dlang
License
BSL-1.0
Install
dub fetch d-import-sort --version 0.0.4

Documentation

d-import-sort

D codecov Dub downloads Dub downloads License Latest version

A tool for sorting import declarations in D.

Usage

$ dub fetch d-import-sort
$ dub run d-import-sort <files>
<<<<filename:minline-maxline
unsorted imports
...
----
sorted imports
...
>>>>
...

Example

$ dub run -- ./source/*.d

<<<<./source/app.d:2-5
import std.string : empty;
import std.stdio : writeln;
import std.file : readText;
----
import std.file : readText;
import std.stdio : writeln;
import std.string : empty;
>>>>

<<<<./source/dimportsort.d:89-92
    import std.algorithm : find;
    import std.range : drop, take;
    import std.algorithm : maxElement, minElement, joiner, splitter;
----
    import std.algorithm : find, joiner, maxElement, minElement, splitter;
    import std.range : drop, take;
>>>>

TODO

  • fully support import declarations
    • single import e.g. import foo;
    • multiple import e.g. import foo, bar;
    • selective import e.g. import foo : bar;
    • public import e.g. public import foo;
    • static import e.g. static import foo;
    • package attribute e.g. package(app) import foo;.
    • renamed import e.g. import foo = bar;
  • simple sorted output
  • merge imports for redundant modules
  • option for overwriting files
  • option for keeping comments
  • color output
  • diff format output
  • max line length

Links