Skip to content

Commit

Permalink
Add lint config
Browse files Browse the repository at this point in the history
  • Loading branch information
rossmacarthur committed Jan 26, 2024
1 parent 592abbe commit 085a48c
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:

- name: Clippy
continue-on-error: ${{ matrix.toolchain == 'nightly' }}
run: cargo clippy --workspace -- -D clippy::items-after-statements -D clippy::if-not-else
run: cargo clippy --workspace

# ---------------------------------------------------------------------------
# Test
Expand Down
12 changes: 12 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,15 @@ vendored-libgit2 = ["git2/vendored-libgit2"]
# Disabling this will not force the usage of the system OpenSSL you can do that
# using OPENSSL_NO_VENDOR=1
vendored-openssl = ["git2/vendored-openssl", "curl/static-ssl"]

[lints.rust]
elided_lifetimes_in_paths = "warn"
let_underscore_drop = "warn"
macro_use_extern_crate = "warn"
meta_variable_misuse = "warn"
unsafe_op_in_unsafe_fn = "warn"

[lints.clippy]
if_not_else = "warn"
items_after_statements = "warn"
semicolon_if_nothing_returned = "warn"
6 changes: 3 additions & 3 deletions src/config/edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ tag = "0.1.0"
git = "https://github.com/rossmacarthur/sheldon-test"
branch = "feature"
"#
)
);
}

#[test]
Expand All @@ -217,7 +217,7 @@ branch = "feature"
github = "rossmacarthur/sheldon-test"
tag = "0.1.0"
"#
)
);
}

#[test]
Expand Down Expand Up @@ -267,6 +267,6 @@ use = ["{{ name }}.zsh"]
github = "rossmacarthur/sheldon-test"
tag = "0.1.0"
"#
)
);
}
}
4 changes: 2 additions & 2 deletions src/config/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ mod tests {
#[test]
fn shell_deserialize_as_str() {
let test: ShellTest = toml::from_str("s = 'bash'").unwrap();
assert_eq!(test.s, Shell::Bash)
assert_eq!(test.s, Shell::Bash);
}

#[test]
Expand All @@ -376,7 +376,7 @@ mod tests {
| ^^^^^
expected one of `bash`, `fish`, or `zsh`, got `ksh`
"
)
);
}

#[derive(Debug, Deserialize)]
Expand Down
8 changes: 4 additions & 4 deletions src/config/normalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn normalize(raw_config: RawConfig, warnings: &mut Vec<Error>) -> Result<Con
} = raw_config;

check_extra_toml(rest, |key| {
warnings.push(anyhow!("unused config key: `{key}`"))
warnings.push(anyhow!("unused config key: `{key}`"));
});

// Check that the templates can be compiled.
Expand Down Expand Up @@ -111,7 +111,7 @@ fn normalize_plugin(
}

check_extra_toml(rest, |key| {
warnings.push(anyhow!("unused config key: `plugins.{name}.{key}`"))
warnings.push(anyhow!("unused config key: `plugins.{name}.{key}`"));
});

let raw_source = match (git, gist, github, remote, local, inline) {
Expand Down Expand Up @@ -243,7 +243,7 @@ where
{
if let Some(toml::Value::Table(table)) = rest {
for key in table.keys() {
f(key)
f(key);
}
}
}
Expand Down Expand Up @@ -302,7 +302,7 @@ mod tests {
&mut Vec::new(),
)
.unwrap_err();
assert_eq!(err.to_string(), "plugin `test` has multiple source fields")
assert_eq!(err.to_string(), "plugin `test` has multiple source fields");
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,13 @@ impl Context {

pub fn log_header(&self, prefix: &str, msg: impl ToMessage) {
if self.verbosity() >= Verbosity::Normal {
self.log_header_impl(prefix, msg.to_message(self))
self.log_header_impl(prefix, msg.to_message(self));
}
}

pub fn log_verbose_header(&self, prefix: &str, msg: impl ToMessage) {
if self.verbosity() >= Verbosity::Verbose {
self.log_header_impl(prefix, msg.to_message(self))
self.log_header_impl(prefix, msg.to_message(self));
}
}

Expand Down Expand Up @@ -184,11 +184,11 @@ impl Context {
}

pub fn log_error(&self, err: &Error) {
log_error(self.output.no_color, err)
log_error(self.output.no_color, err);
}

pub fn log_error_as_warning(&self, err: &Error) {
log_error_as_warning(self.output.no_color, err)
log_error_as_warning(self.output.no_color, err);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/lock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ mod tests {
assert!(warnings.is_empty());
assert!(!test_file.exists());
assert!(!test_dir.exists());
let _ = config(&ctx, cfg).unwrap();
let _locked_cfg = config(&ctx, cfg).unwrap();
assert!(ctx
.clone_dir()
.join("github.com/rossmacarthur/sheldon-test")
Expand Down
6 changes: 3 additions & 3 deletions src/lock/source/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fn checkout(
let current_oid = repo.head()?.target().context("current HEAD as no target")?;
let expected_oid = checkout.resolve(repo)?;
if current_oid == expected_oid {
ctx.log_status("Checked", &format!("{url}{checkout}"))
ctx.log_status("Checked", &format!("{url}{checkout}"));
} else {
git::checkout(repo, expected_oid)?;
git::submodule_update(repo).context("failed to recursively update")?;
Expand Down Expand Up @@ -247,7 +247,7 @@ mod tests {
assert_eq!(
head.target().unwrap().to_string(),
"ad149784a1538291f2477fb774eeeed4f4d29e45"
)
);
}

#[test]
Expand All @@ -271,6 +271,6 @@ mod tests {
assert_eq!(
head.target().unwrap().to_string(),
"ad149784a1538291f2477fb774eeeed4f4d29e45"
)
);
}
}
2 changes: 1 addition & 1 deletion src/lock/source/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ mod tests {
fn lock_local() {
let temp = tempfile::tempdir().expect("create temporary directory");
let dir = temp.path();
let _ = git_clone_sheldon_test(&temp);
let _repo = git_clone_sheldon_test(&temp);

let locked = lock(&Context::testing(dir), dir.to_path_buf()).unwrap();

Expand Down
2 changes: 1 addition & 1 deletion src/lock/source/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@ mod tests {
fs::read_to_string(&file).unwrap(),
fs::read_to_string(manifest_dir.join("LICENSE-MIT")).unwrap()
);
assert!(fs::metadata(&file).unwrap().modified().unwrap() > modified)
assert!(fs::metadata(&file).unwrap().modified().unwrap() > modified);
}
}
2 changes: 1 addition & 1 deletion src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use once_cell::sync::Lazy;

pub use crate::util::temp::TempPath;

pub static TEMPLATE_ENGINE: Lazy<upon::Engine> = Lazy::new(upon::Engine::new);
pub static TEMPLATE_ENGINE: Lazy<upon::Engine<'static>> = Lazy::new(upon::Engine::new);

/// Returns the underlying error kind for the given error.
pub fn underlying_io_error_kind(error: &Error) -> Option<io::ErrorKind> {
Expand Down
5 changes: 3 additions & 2 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ impl TestCase {

/// Load the test case in the given directories.
fn load_with_dirs(name: &str, dirs: TestDirs) -> io::Result<Self> {
SETUP.call_once(setup);
static ENGINE: Lazy<upon::Engine> = Lazy::new(|| {
static ENGINE: Lazy<upon::Engine<'_>> = Lazy::new(|| {
let syntax = upon::Syntax::builder().expr("<", ">").build();
upon::Engine::with_syntax(syntax)
});

SETUP.call_once(setup);

let dir = {
let mut p = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
p.push("tests/testdata");
Expand Down

0 comments on commit 085a48c

Please sign in to comment.