Skip to content

Commit

Permalink
Fix clippy lints (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
oulgen authored Apr 9, 2024
1 parent bd224ae commit 9aa3080
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 21 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/Lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,5 @@ jobs:
sarif_file: lintrunner.sarif
category: lintrunner
checkout_path: ${{ github.workspace }}
- name: Run Clippy
run: cargo clippy -- -D warnings --verbose
2 changes: 1 addition & 1 deletion src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ mod tests {
}

#[test]
fn invalid_get_paths_from_cmd_fails() -> () {
fn invalid_get_paths_from_cmd_fails() {
assert!(get_paths_from_cmd("asoidjfoaisdjf").is_err());
assert!(get_paths_from_cmd("false").is_err());
}
Expand Down
10 changes: 3 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ fn group_lints_by_file(
lints: Vec<LintMessage>,
) {
lints.into_iter().fold(all_lints, |acc, lint| {
acc.entry(lint.path.clone())
.or_insert_with(Vec::new)
.push(lint);
acc.entry(lint.path.clone()).or_default().push(lint);
acc
});
}
Expand Down Expand Up @@ -160,6 +158,7 @@ pub fn get_version_control() -> Result<Box<dyn VersionControl>> {
Ok(Box::new(sapling::Repo::new()?))
}

#[allow(clippy::too_many_arguments)]
pub fn do_lint(
linters: Vec<Linter>,
paths_opt: PathsOpt,
Expand Down Expand Up @@ -207,10 +206,7 @@ pub fn do_lint(

// Sort and unique the files so we pass a consistent ordering to linters
if let Some(config_dir) = config_dir {
files = files
.into_iter()
.filter(|path| path.starts_with(&config_dir))
.collect();
files.retain(|path| path.starts_with(&config_dir));
}
files.sort();
files.dedup();
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ fn do_main() -> Result<i32> {
// clone split by commas and trim whitespace
let config_paths: Vec<String> = args
.configs
.split(",")
.split(',')
.map(|path| path.trim().to_string())
.collect_vec();
// check if first config path exists
Expand Down
4 changes: 2 additions & 2 deletions src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ pub fn path_relative_from(path: &Path, base: &Path) -> Option<PathBuf> {
}
(None, _) => comps.push(Component::ParentDir),
(Some(a), Some(b)) if comps.is_empty() && a == b => (),
(Some(a), Some(b)) if b == Component::CurDir => comps.push(a),
(Some(_), Some(b)) if b == Component::ParentDir => return None,
(Some(a), Some(Component::CurDir)) => comps.push(a),
(Some(_), Some(Component::ParentDir)) => return None,
(Some(a), Some(_)) => {
comps.push(Component::ParentDir);
for _ in itb {
Expand Down
8 changes: 4 additions & 4 deletions src/persistent_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl PersistentDataStore {
let runs_dir = config_data_dir.join(RUNS_DIR_NAME);
let cur_run_dir = runs_dir.join(cur_run_info.dir_name());

std::fs::create_dir_all(&cur_run_dir)?;
std::fs::create_dir_all(cur_run_dir)?;

PersistentDataStore::clean_old_runs(&runs_dir)?;

Expand Down Expand Up @@ -116,10 +116,10 @@ impl PersistentDataStore {
std::fs::create_dir(&run_path)?;
}
let run_info = serde_json::to_string_pretty(&self.cur_run_info)?;
std::fs::write(&run_path.join("run_info.json"), &run_info)?;
std::fs::write(run_path.join("run_info.json"), run_info)?;

let exit_info = serde_json::to_string_pretty(&exit_info)?;
std::fs::write(&run_path.join("exit_info.json"), exit_info)?;
std::fs::write(run_path.join("exit_info.json"), exit_info)?;
Ok(())
}

Expand Down Expand Up @@ -257,7 +257,7 @@ impl PersistentDataStore {
let config_contents = config_contents.extract::<LintRunnerConfig>()?;
let path = self.relative_path(CONFIG_DATA_NAME);
let serialized_contents = serde_json::to_string_pretty(&config_contents)?;
std::fs::write(path, &serialized_contents)?;
std::fs::write(path, serialized_contents)?;
Ok(())
}

Expand Down
2 changes: 1 addition & 1 deletion src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ fn write_context_diff(stdout: &mut impl Write, original: &str, replacement: &str
let diff = TextDiff::from_lines(original, replacement);

let mut max_line_number = 1;
for (_, group) in diff.grouped_ops(3).iter().enumerate() {
for group in diff.grouped_ops(3).iter() {
for op in group {
for change in diff.iter_inline_changes(op) {
let old_line = change.old_index().unwrap_or(0) + 1;
Expand Down
6 changes: 3 additions & 3 deletions src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl GitCheckout {

pub fn checkout_new_branch(&self, branch_name: &str) -> Result<()> {
let output = Command::new("git")
.args(&["checkout", "-b", branch_name])
.args(["checkout", "-b", branch_name])
.current_dir(self.root())
.output()?;
assert!(output.status.success());
Expand All @@ -64,7 +64,7 @@ impl GitCheckout {

pub fn add(&self, pathspec: &str) -> Result<()> {
let output = Command::new("git")
.args(&["add", pathspec])
.args(["add", pathspec])
.current_dir(self.root())
.output()?;
assert!(output.status.success());
Expand All @@ -73,7 +73,7 @@ impl GitCheckout {

pub fn commit(&self, message: &str) -> Result<()> {
let output = Command::new("git")
.args(&["commit", "-m", message])
.args(["commit", "-m", message])
.current_dir(self.root())
.output()?;
assert!(output.status.success());
Expand Down
4 changes: 2 additions & 2 deletions tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use assert_cmd::Command;
use insta::{assert_snapshot, assert_yaml_snapshot};
use lintrunner::lint_message::{LintMessage, LintSeverity};
use regex::Regex;
use serde_json;

use std::io::Write;

fn assert_output_snapshot(name: &str, cmd: &mut Command) -> Result<()> {
Expand Down Expand Up @@ -870,7 +870,7 @@ fn linter_replacement_trailing_newlines() -> Result<()> {
"--data-path={}",
data_path.path().to_str().unwrap()
));
cmd.arg(format!("--force-color"));
cmd.arg("--force-color");
// Run on a file to ensure that the linter is run.
cmd.arg("README.md");
cmd.assert().failure();
Expand Down

0 comments on commit 9aa3080

Please sign in to comment.