Skip to content

Userp: Rust formatting tool for clustering use statements

Notifications You must be signed in to change notification settings

crowncodeman/userp-format-tool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

userp

This is a tool for formatting Rust code. In particular, it clusters use statements like this:

BEFORE:

use std::collections::{HashSet, BTreeSet};
use {serde, combine::*};
use itertools::Iterator;
use crate::foo::bar;
use crate::foo::baz;
use crate::badger;
use std::collections::HashMap;

AFTER:

use std::collections::{BTreeSet, HashMap, HashSet};

use {combine::*, itertools::Iterator, serde};

use crate::{badger, foo::{bar, baz}};

How it works

userp recursively looks for .rs files and does a shallow parse of them, looking specifically for use statements. These are grouped and written to the .rs file. Then userp runs cargofmt on them.

userp clusters the use statements by this order:

  • use std::
  • third party
  • workspace members
  • use crate::
  • use super::
  • use self::

Workspace members are found by parsing the root Cargo.toml, or can be given with the --special flag.

About

Userp: Rust formatting tool for clustering use statements

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages