Skip to content

Commit

Permalink
chore: Fix dprint check bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret committed Jun 17, 2020
1 parent 987a28f commit 50ee0b6
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/dprint/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dprint"
version = "0.4.0"
version = "0.4.1"
authors = ["David Sherret <dsherret@gmail.com>", "Bartek Iwańczuk <biwanczuk@gmail.com>"]
edition = "2018"
license-file = "LICENSE"
Expand Down
1 change: 0 additions & 1 deletion crates/dprint/src/cli/run_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ fn get_plugin_format_contexts(plugins: Vec<Box<dyn Plugin>>, file_paths: Vec<Pat
} else {
file_paths_by_plugin.insert(String::from(plugin.name()), vec![file_path]);
}
continue;
}
}
}
Expand Down
26 changes: 25 additions & 1 deletion crates/dprint/src/utils/get_difference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,14 @@ fn get_pre_processed_chunks<'a>(text1: &'a str, text2: &'a str) -> Vec<dissimila
}

if was_deleted_with_newline {
let add_delete_at_end = if let Some(Chunk::Insert(insert_text)) = chunks.get(i + 1) {
// Do not add a delete newline at the end if the next chunk is inserting a newline.
// TBH: This doesn't seem exactly right and I did this to fix a bug.
!insert_text.contains('\n')
} else {
true
};

let delete_text = if let Chunk::Delete(delete_text) = chunk { delete_text } else { unreachable!() };

// push delete text previous line
Expand Down Expand Up @@ -330,7 +338,9 @@ fn get_pre_processed_chunks<'a>(text1: &'a str, text2: &'a str) -> Vec<dissimila

final_chunks.push(dissimilar::Chunk::Equal(&delete_text[delete_text_new_line_index..delete_text_new_line_index+1]));
final_chunks.extend(next_line_chunks);
final_chunks.push(dissimilar::Chunk::Delete(&delete_text[delete_text_new_line_index..delete_text_new_line_index+1]));
if add_delete_at_end {
final_chunks.push(dissimilar::Chunk::Delete(&delete_text[delete_text_new_line_index..delete_text_new_line_index+1]));
}
} else {
final_chunks.push(chunk);
}
Expand Down Expand Up @@ -432,4 +442,18 @@ mod test {
)
);
}

#[test]
fn it_should_handle_replacements() {
assert_eq!(
get_difference("use::asdf\nuse::test", "use::other\nsomething"),
format!(
"1| use::{}{}\n | {}{}",
get_removal_text("asdf"),
get_addition_text("other"),
get_removal_text("use::test"),
get_addition_text("something")
)
);
}
}
7 changes: 5 additions & 2 deletions dprint.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
"json": {
"indentWidth": 2
},
"rustfmt": {
},
"includes": [
"**/*.{ts,tsx,js,jsx,json}"
"**/*.{ts,tsx,js,jsx,json,rs}"
],
"excludes": [
"website/playground/build",
Expand All @@ -24,6 +26,7 @@
],
"plugins": [
"https://plugins.dprint.dev/typescript-0.19.2.wasm",
"https://plugins.dprint.dev/json-0.4.1.wasm"
"https://plugins.dprint.dev/json-0.4.1.wasm",
"http://localhost:4507/dprint_plugin_rustfmt.wasm"
]
}
1 change: 1 addition & 0 deletions website/plugin-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use dprint_core::configuration::{
GlobalConfiguration,
ResolveConfigurationResult,
get_unknown_property_diagnostics,
ConfigurationDiagnostic,
};

#[derive(Clone, Serialize, Deserialize)]
Expand Down

0 comments on commit 50ee0b6

Please sign in to comment.