sorty

Crates.iosorty
lib.rssorty
version0.1.2
sourcesrc
created_at2016-07-25 11:43:46.372292
updated_at2017-04-17 05:21:16.890314
descriptionA plugin to check whether the 'extern crate', 'mod' and 'use' declarations are in their sorted format
homepage
repositoryhttps://github.com/Wafflespeanut/rust-sorty
max_upload_size
id5781
size42,484
Ravi Shankar (wafflespeanut)

documentation

README

rust-sorty

Build Status Current Version

A lint to help with sorting the extern crate, mod and use declarations, according to the style rules. Have a look at the detailed example for a start! I guess it will be very handy for large projects written in Rust (well, at least once!).

And yeah, this should actually be done by rustfmt, but it doesn't have this option for now. So, this plugin would serve until rustfmt becomes intelligent enough to detect the unsorted declarations.

Usage

Add this to your Cargo.toml...

sorty = "0.1"

... and then to the top of the main module you wanna check,

#![feature(plugin)]
#![plugin(sorty)]

(It can show warnings or errors based on your choice, just like any other lint)

#![deny(unsorted_declarations)]         // throw errors! (poor choice for styling lints)

#![warn(unsorted_declarations)]         // show warnings (default)

#![allow(unsorted_declarations)]        // stay quiet!

Remove it once you've done all the checks, when you'll no longer be needing the plugin!

I was just kidding. I'll be very happy if you just keep it :)

Note:

This is a compiler lint, and it's unstable. So, make sure you're using the latest nightly Rust. Though this lint shows an output of the lexicographically sorted declarations, it follows some rules:

  • stuff with #[macro_use] are sorted and moved to the top, since macros become visible to the surroundings only after their declaration, unlike others.
  • pub declarations (of uses & mods) are sorted and moved to the bottom
  • self in use lists are moved to the left (other list items are sorted as usual)

Also, note that there are some stuff that aren't tracked (for now). It includes comments, spaces, etc.

Commit count: 28

cargo fmt