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

Use a more clever way to replace parts of a file #67

Merged
merged 8 commits into from
May 4, 2018

Conversation

killercup
Copy link
Member

Addresses #57

Btw, this is still only concerning itself with replacing multiple things in one file. #66 changes the CLI to group suggestions by file. Not sure if we want to make this part of the library.

@killercup
Copy link
Member Author

Works great on top of #66 after adding a single ?

@alexcrichton
Copy link
Member

Nice! I think that merging the replace-rs repo into this one (if you're willing) would probably be a good idea if it's pretty rustfix-specific. Other than that mind also adding a few tests in the cargo-fix/tests folder for situations that have now been fixed?

@alexcrichton
Copy link
Member

Also you may want to rebase on master now as it turns out I forgot to include running of the new tests in the branch this is based off!

@alexcrichton
Copy link
Member

I think this'll handle issues like #77, right? If so, could that test be included?

Cargo.toml Outdated
@@ -20,13 +20,16 @@ exclude = [
serde = "1.0"
serde_json = "1.0"
serde_derive = "1.0"
replace-rs = { git = "https://github.com/killercup/replace-rs" }
Copy link
Member

Choose a reason for hiding this comment

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

This can be removed now I think

src/lib.rs Outdated
@@ -208,16 +219,22 @@ pub fn apply_suggestion(file_content: &mut String, suggestion: &Replacement) ->
new_content
Copy link
Member

Choose a reason for hiding this comment

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

Should this method be removed now?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep. Breaking change! 🙌

Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

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

The replace crate looks great, nice work!

I'm happy that the existing tests work and the new crlf test works, so with a few other nits r=me!


proptest! {
#[test]
#[ignore]
Copy link
Member

Choose a reason for hiding this comment

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

How come these are #[ignore]? Do they take too long?

Copy link
Member Author

Choose a reason for hiding this comment

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

They take a few seconds each, yeah. I don't really want to run them on each cargo test, but I'll add them to CI

@killercup
Copy link
Member Author

Moved it in as a module, and added tests from #77 which automagically work now.

I've also added another test for "overlapping" suggestions. The only one I could think of that I know exists in rustc is missing imports with multiple options. If you have an idea for other tests, let me know (or just add them :))


let stderr = "\
[CHECKING] foo v0.1.0 (CWD)
error: Cannot replace slice of data that was already replaced
Copy link
Member

Choose a reason for hiding this comment

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

Hm I'm not sure that this is the UI we're gonna want long-term, I think we probably want to just skip auto-fixing code and let warnings like these naturally bubble up to the user?

Could we add some logic to avoid attempting to apply suggestions that look like they're gonna fail? (or otherwise just keep track of suggestions that fail to apply)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes that's why I was asking for a better test case :) I opened #78 for the intended user experience

Copy link
Member

Choose a reason for hiding this comment

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

Hm could we tweak this test to assert that the warning isn't updated here? I think it's probably most conservative to start out by not applying any suggestions when they're ambiguous about what to do. Anything we don't fix will end up being seen by the end user anyway

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah. Do you want me to do this here or in another PR? (The behavior isn't changed here AFAIK)

Copy link
Member

Choose a reason for hiding this comment

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

Ah ok let's do that in a follow-up then


fn compile(file: &Path) -> Result<Output, Box<Error>> {
let tmp = TempDir::new("rustfix-tests")?;
let better_call_clippy = cmd!(
"rustc", file,
"--error-format=pretty-json", "-Zunstable-options", "--emit=metadata",
"--crate-name=rustfix_test",
"-Zsuggestion-applicability",
Copy link
Member Author

Choose a reason for hiding this comment

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

Oh! Don't look! Spoilers!

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.

None yet

2 participants