Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .azure-pipelines/pull-requests/clippy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
trigger: none

pr:
- master

pool:
vmImage: 'Ubuntu-16.04'

steps:
- script: |
curl https://sh.rustup.rs -sSf | sh -s -- -y
echo "##vso[task.setvariable variable=PATH;]$PATH:$HOME/.cargo/bin"
echo "##vso[task.setvariable variable=cargoBinPath;]$HOME/.cargo/bin"
displayName: 'Install Rust'

- script: |
rustup component add clippy
displayName: 'Install clippy'

- script: |
set -eo pipefail
cargo clippy --all-targets -- -D warnings
displayName: 'Run clippy'
24 changes: 24 additions & 0 deletions .azure-pipelines/pull-requests/rustfmt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
trigger: none

pr:
- master

pool:
vmImage: 'Ubuntu-16.04'

steps:
- script: |
curl https://sh.rustup.rs -sSf | sh -s -- -y
echo "##vso[task.setvariable variable=PATH;]$PATH:$HOME/.cargo/bin"
echo "##vso[task.setvariable variable=cargoBinPath;]$HOME/.cargo/bin"
displayName: 'Install Rust'

- script: |
rustup component add rustfmt
displayName: 'Install rustfmt'

- script: |
set -eo pipefail
cargo fmt -- --check
displayName: 'Run rustfmt'

1 change: 1 addition & 0 deletions .vscode/cSpell.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"githook",
"junit",
"kcov",
"pipefail",
"repo",
"rustc",
"rustfmt",
Expand Down
2 changes: 1 addition & 1 deletion src/config_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ mod find_config_file_tests {
let found_file = "rusty-hook.toml";
let exp_path = format!("{}/{}", root_dir, found_file);
let file_exists = |path: &str| {
if path == &exp_path {
if path == exp_path {
return Ok(true);
}
Ok(false)
Expand Down
6 changes: 6 additions & 0 deletions src/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ const HOOK_NAMES: [&str; 19] = [
const CLI_SCRIPT_NAME: &str = "cli.sh";
const SEMVER_SCRIPT_NAME: &str = "semver.sh";

// For unknown reasons, kcov is reporting an uncovered line for the closing `}`
// when using the idiomatic expression.
#[allow(clippy::needless_return)]
fn get_hook_file_contents() -> String {
return String::from(HOOK_FILE_TEMPLATE).replace("{{VERSION}}", VERSION);
}
Expand All @@ -55,6 +58,9 @@ fn get_cli_script_file_contents() -> String {
.replace("{{MINIMUM_ALLOW_PRE}}", minimum_allow_pre)
}

// For unknown reasons, kcov is reporting an uncovered line for the closing `}`
// when using the idiomatic expression.
#[allow(clippy::needless_return)]
fn get_semver_script_file_contents() -> String {
return String::from(HOOK_SEMVER_SCRIPT_FILE_TEMPLATE).replace("{{VERSION}}", VERSION);
}
Expand Down
24 changes: 12 additions & 12 deletions src/hooks_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ mod create_hook_files_tests {
fn errors_when_hook_write_fails() {
let write_file = |path: &str, _contents: &str, _make_executable: bool| {
let file_name = &&path[(path.rfind('/').unwrap() + 1)..];
match file_name {
&EXP_CLI_SCRIPT_NAME => Ok(()),
&EXP_SEMVER_SCRIPT_NAME => Ok(()),
match *file_name {
EXP_CLI_SCRIPT_NAME => Ok(()),
EXP_SEMVER_SCRIPT_NAME => Ok(()),
_ => Err(String::from("")),
}
};
Expand All @@ -131,9 +131,9 @@ mod create_hook_files_tests {
fn errors_when_cli_script_write_fails() {
let write_file = |path: &str, _contents: &str, _make_executable: bool| {
let file_name = &&path[(path.rfind('/').unwrap() + 1)..];
match file_name {
&EXP_CLI_SCRIPT_NAME => Err(String::from("")),
&EXP_SEMVER_SCRIPT_NAME => Ok(()),
match *file_name {
EXP_CLI_SCRIPT_NAME => Err(String::from("")),
EXP_SEMVER_SCRIPT_NAME => Ok(()),
_ => Ok(()),
}
};
Expand All @@ -145,9 +145,9 @@ mod create_hook_files_tests {
fn errors_when_semver_script_write_fails() {
let write_file = |path: &str, _contents: &str, _make_executable: bool| {
let file_name = &&path[(path.rfind('/').unwrap() + 1)..];
match file_name {
&EXP_CLI_SCRIPT_NAME => Ok(()),
&EXP_SEMVER_SCRIPT_NAME => Err(String::from("")),
match *file_name {
EXP_CLI_SCRIPT_NAME => Ok(()),
EXP_SEMVER_SCRIPT_NAME => Err(String::from("")),
_ => Ok(()),
}
};
Expand All @@ -166,12 +166,12 @@ mod create_hook_files_tests {
let exp_semver_contents = get_expected_semver_script_file_contents();
let write_file = |path: &str, contents: &str, make_executable: bool| {
let file_name = &&path[(path.rfind('/').unwrap() + 1)..];
match file_name {
&EXP_CLI_SCRIPT_NAME => {
match *file_name {
EXP_CLI_SCRIPT_NAME => {
assert_eq!(exp_cli_path, path);
assert_eq!(exp_cli_contents, contents);
}
&EXP_SEMVER_SCRIPT_NAME => {
EXP_SEMVER_SCRIPT_NAME => {
assert_eq!(exp_semver_path, path);
assert_eq!(exp_semver_contents, contents);
}
Expand Down