Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

Change example to automatically determine filename #166

Merged
merged 3 commits into from
Apr 3, 2019

Conversation

philipc
Copy link
Contributor

@philipc philipc commented Apr 3, 2019

This is something I hacked together to allow me to automatically apply some clippy fixes. Not sure if this is something that is desired, but I thought I'd share in case others find it useful (eg see #130). Note that this overwrites the existing files. Also I know nothing about the json format for the suggestions, I'm probably making assumptions that I shouldn't.

My usage is:

cargo clippy --message-format json | jq .message | grep -v ^null > clippy.json
fix-json clippy.json

Copy link
Member

@killercup killercup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lookin' good! Aside from the inline suggestion (maybe combine the two as a match with 3 arms), can you replace the file reading with something like this to support reading from stdin?

    let suggestions = if suggestions_file == "--" {
        use std::io::{stdin, prelude::*, BufReader};
        let mut buffer = String::new();
        BufReader::new(stdin()).read_to_string(&mut buffer)?;
        buffer
    } else {
        fs::read_to_string(&suggestions_file)?
    };

This makes cargo clippy --message-format json | jq .message | grep -v '^null' | fix-json -- work for me!

@philipc
Copy link
Contributor Author

philipc commented Apr 3, 2019

Done. Also added another commit to skip suggestions that can't be applied. This is all user-beware stuff.

@philipc
Copy link
Contributor Author

philipc commented Apr 3, 2019

BTW, is there any effort in progress to do this properly? Does that need any help?

@killercup
Copy link
Member

Thanks!

BTW, is there any effort in progress to do this properly? Does that need any help?

There is some effort, and we'll have a rustfix working group meeting sometime next week. I'll ping you about it!

@killercup killercup merged commit 7010307 into rust-lang:master Apr 3, 2019
@philipc philipc deleted the fix-json branch April 5, 2019 01:57
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants