Skip to content
master
Go to file
Code
This branch is 178 commits behind rust-lang:master.

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Readme.md

rustfix

HIGHLY EXPERIMENTAL – MIGHT EAT YOUR CODE

The goal of this tool is to read and apply the suggestions made by rustc (and third-party lints, like those offered by clippy).

Build Status Build status

Current state

This tool can

  • parse rustc's diagnostics (it calls cargo for you and reads its output)
  • read a file of diagnostics (one JSON object per line)
  • interactively step through the suggestions and ask the user what to do
  • apply suggestions (currently whole lines only)

rustfix demo

Installation

Assuming you have a recent Rust nightly and Cargo installed:

$ cargo install --git https://github.com/killercup/rustfix.git

Make sure the binaries installed by Cargo are in your $PATH.

Usage

In your project directory, just execute rustfix!

You probably want to use rustfix --clippy to get all the suggestions from Clippy as well. Make sure you have cargo clippy installed (cargo install clippy).

Please note that running rustfix multiple times in a project where no file was changed in the meantime will currently not generate any suggestions (as Cargo/Rust will skip the unchanged code and not compile it again).

CLI Options

rustfix 0.1.0
Automatically apply suggestions made by rustc

USAGE:
    rustfix [FLAGS] [OPTIONS]

FLAGS:
        --clippy     Use `cargo clippy` for suggestions
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
        --from-file <FILE>    Read suggestions from file (each line is a JSON object)

Get the example running

My current example output for diagnostics is based on libui-rs. You can find the example JSON in tests/fixtures/libui-rs/clippy.json.

Run rustfix:

$ cargo test

Generate the example diagnostics JSON yourself

$ APPLY_RUSTFIX=1 cargo test

Gotchas

  • rustc JSON output is unstable
  • Not all suggestions can be applied trivially (e.g. clippy's "You should use Default instead of that fn new() you just wrote"-lint will replace your new-method with an impl block -- which is obviously invalid syntax.)
  • This tool will eat your laundry

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

About

Automatically apply the suggestions made by rustc

Resources

License

Languages

You can’t perform that action at this time.