Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clippy lints #80

Closed
wants to merge 9 commits into from
2 changes: 1 addition & 1 deletion examples/ci.rs
Original file line number Diff line number Diff line change
@@ -51,7 +51,7 @@ fn publish(sh: &Shell) -> Result<()> {

let tag = format!("v{}", version);
let tags = cmd!(sh, "git tag --list").read()?;
let tag_exists = tags.split_ascii_whitespace().any(|it| it == &tag);
let tag_exists = tags.split_ascii_whitespace().any(|it| it == tag);

let current_branch = cmd!(sh, "git branch --show-current").read()?;

3 changes: 1 addition & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -802,8 +802,7 @@ impl From<Cmd<'_>> for Command {

impl<'a> Cmd<'a> {
fn new(shell: &'a Shell, prog: &Path) -> Cmd<'a> {
let mut data = CmdData::default();
data.prog = prog.to_path_buf();
let data = CmdData { prog: prog.to_path_buf(), ..Default::default() };
Cmd { shell, data }
}

16 changes: 8 additions & 8 deletions tests/it/main.rs
Original file line number Diff line number Diff line change
@@ -320,7 +320,7 @@ fn test_push_env_and_set_var() {
let _e = sh.push_env(VAR, "1");
let e2 = sh.var_os(VAR);
assert_eq!(e2, Some("1".into()));
let _e = sh.set_var(VAR, "2");
sh.set_var(VAR, "2");
let e3 = sh.var_os(VAR);
assert_eq!(e3, Some("2".into()));
}
@@ -371,17 +371,17 @@ fn test_copy_file() {
{
let tempdir = sh.create_temp_dir().unwrap();
path = tempdir.path().to_path_buf();
let foo = tempdir.path().join("foo.txt");
let path_foo = tempdir.path().join("foo.txt");
let bar = tempdir.path().join("bar.txt");
let dir = tempdir.path().join("dir");
sh.write_file(&foo, "hello world").unwrap();
sh.write_file(&path_foo, "hello world").unwrap();
sh.create_dir(&dir).unwrap();

sh.copy_file(&foo, &bar).unwrap();
sh.copy_file(&path_foo, &bar).unwrap();
assert_eq!(sh.read_file(&bar).unwrap(), "hello world");

sh.copy_file(&foo, &dir).unwrap();
assert_eq!(sh.read_file(&dir.join("foo.txt")).unwrap(), "hello world");
sh.copy_file(&path_foo, &dir).unwrap();
assert_eq!(sh.read_file(dir.join("foo.txt")).unwrap(), "hello world");
assert!(path.exists());
}
assert!(!path.exists());
@@ -391,14 +391,14 @@ fn test_copy_file() {
fn test_exists() {
let sh = setup();
let tmp = sh.create_temp_dir().unwrap();
let _d = sh.change_dir(tmp.path());
sh.change_dir(tmp.path());
assert!(!sh.path_exists("foo.txt"));
sh.write_file("foo.txt", "foo").unwrap();
assert!(sh.path_exists("foo.txt"));
assert!(!sh.path_exists("bar"));
sh.create_dir("bar").unwrap();
assert!(sh.path_exists("bar"));
let _d = sh.change_dir("bar");
sh.change_dir("bar");
assert!(!sh.path_exists("quz.rs"));
sh.write_file("quz.rs", "fn main () {}").unwrap();
assert!(sh.path_exists("quz.rs"));
2 changes: 1 addition & 1 deletion tests/it/tidy.rs
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ fn versions_match() {
let read_version = |path: &str| {
let text = sh.read_file(path).unwrap();
let vers = text.lines().find(|it| it.starts_with("version =")).unwrap();
let vers = vers.splitn(2, '#').next().unwrap();
let vers = vers.split('#').next().unwrap();
vers.trim_start_matches("version =").trim().trim_matches('"').to_string()
};

4 changes: 2 additions & 2 deletions xshell-macros/src/lib.rs
Original file line number Diff line number Diff line change
@@ -171,8 +171,8 @@ fn next_token(s: &str) -> Result<(usize, TokenKind)> {
let splat = s[..len].ends_with("...}");
return Ok((len, TokenKind::Interpolation { splat }));
}
if s.starts_with('\'') {
let len = s[1..].find('\'').ok_or_else(|| "unclosed `'` in command".to_string())? + 2;
if let Some(tail) = s.strip_prefix('\'') {
let len = tail.find('\'').ok_or_else(|| "unclosed `'` in command".to_string())? + 2;
return Ok((len, TokenKind::String));
}
let len =