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 happy #1425

Merged
merged 2 commits into from
Jan 31, 2025
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
1 change: 0 additions & 1 deletion Cargo.lock

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

6 changes: 3 additions & 3 deletions backends/src/anchor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ use necessist_core::{
framework::{Interface, Postprocess, SourceFileSpanTestMap},
LightContext, SourceFile, Span, __Backup as Backup, __Rewriter as Rewriter,
};
use once_cell::sync::Lazy;
use regex::Regex;
use std::{
fs::{read_to_string, write},
path::{Path, PathBuf},
process::Command,
sync::LazyLock,
};
use subprocess::Exec;
use toml_edit::{DocumentMut, Value};
Expand Down Expand Up @@ -138,7 +138,7 @@ impl Anchor {
let output = command.output_stripped_of_ansi_escapes()?;
if !output.status().success() {
return Err(output.into());
};
}
Ok(())
}

Expand All @@ -165,7 +165,7 @@ impl Anchor {
}
}

static TEST_RE: Lazy<Regex> = Lazy::new(|| {
static TEST_RE: LazyLock<Regex> = LazyLock::new(|| {
// smoelius: If the space in the first capture group `(.* )` is replaced with `\b`, then the
// capture group captures too much.
#[allow(clippy::unwrap_used)]
Expand Down
64 changes: 35 additions & 29 deletions backends/src/go/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ use necessist_core::{
framework::{SpanTestMaps, TestSet},
util, LightContext, LineColumn, SourceFile, Span, __Rewriter as Rewriter,
};
use once_cell::sync::Lazy;
use regex::Regex;
use std::{
collections::BTreeMap, convert::Infallible, fs::read_to_string, path::Path, process::Command,
sync::LazyLock,
};
use streaming_iterator::StreamingIterator;
use tree_sitter::{
Expand Down Expand Up @@ -42,37 +42,43 @@ const EXPRESSION_STATEMENT_EXPRESSION_SOURCE: &str = r"
) @expression_statement
";

static LANGUAGE: Lazy<Language> = Lazy::new(|| Language::from(tree_sitter_go::LANGUAGE));
static BLOCK_STATEMENTS_QUERY: Lazy<Query> = Lazy::new(|| valid_query(BLOCK_STATEMENTS_SOURCE));
static EXPRESSION_STATEMENT_EXPRESSION_QUERY: Lazy<Query> =
Lazy::new(|| valid_query(EXPRESSION_STATEMENT_EXPRESSION_SOURCE));
static LANGUAGE: LazyLock<Language> = LazyLock::new(|| Language::from(tree_sitter_go::LANGUAGE));
static BLOCK_STATEMENTS_QUERY: LazyLock<Query> =
LazyLock::new(|| valid_query(BLOCK_STATEMENTS_SOURCE));
static EXPRESSION_STATEMENT_EXPRESSION_QUERY: LazyLock<Query> =
LazyLock::new(|| valid_query(EXPRESSION_STATEMENT_EXPRESSION_SOURCE));

fn valid_query(source: &str) -> Query {
#[allow(clippy::unwrap_used)]
Query::new(&LANGUAGE, source).unwrap()
}

static FIELD_FIELD: Lazy<u16> = Lazy::new(|| valid_field_id("field"));
static FUNCTION_FIELD: Lazy<u16> = Lazy::new(|| valid_field_id("function"));
static OPERAND_FIELD: Lazy<u16> = Lazy::new(|| valid_field_id("operand"));
static FIELD_FIELD: LazyLock<u16> = LazyLock::new(|| valid_field_id("field"));
static FUNCTION_FIELD: LazyLock<u16> = LazyLock::new(|| valid_field_id("function"));
static OPERAND_FIELD: LazyLock<u16> = LazyLock::new(|| valid_field_id("operand"));

fn valid_field_id(field_name: &str) -> u16 {
LANGUAGE.field_id_for_name(field_name).unwrap().into()
}

static BLOCK_KIND: Lazy<u16> = Lazy::new(|| non_zero_kind_id("block"));
static BREAK_STATEMENT_KIND: Lazy<u16> = Lazy::new(|| non_zero_kind_id("break_statement"));
static CALL_EXPRESSION_KIND: Lazy<u16> = Lazy::new(|| non_zero_kind_id("call_expression"));
static CONST_DECLARATION_KIND: Lazy<u16> = Lazy::new(|| non_zero_kind_id("const_declaration"));
static CONTINUE_STATEMENT_KIND: Lazy<u16> = Lazy::new(|| non_zero_kind_id("continue_statement"));
static DEFER_STATEMENT_KIND: Lazy<u16> = Lazy::new(|| non_zero_kind_id("defer_statement"));
static IDENTIFIER_KIND: Lazy<u16> = Lazy::new(|| non_zero_kind_id("identifier"));
static RETURN_STATEMENT_KIND: Lazy<u16> = Lazy::new(|| non_zero_kind_id("return_statement"));
static SELECTOR_EXPRESSION_KIND: Lazy<u16> = Lazy::new(|| non_zero_kind_id("selector_expression"));
static SHORT_VAR_DECLARATION_KIND: Lazy<u16> =
Lazy::new(|| non_zero_kind_id("short_var_declaration"));
static TYPE_DECLARATION_KIND: Lazy<u16> = Lazy::new(|| non_zero_kind_id("type_declaration"));
static VAR_DECLARATION_KIND: Lazy<u16> = Lazy::new(|| non_zero_kind_id("var_declaration"));
static BLOCK_KIND: LazyLock<u16> = LazyLock::new(|| non_zero_kind_id("block"));
static BREAK_STATEMENT_KIND: LazyLock<u16> = LazyLock::new(|| non_zero_kind_id("break_statement"));
static CALL_EXPRESSION_KIND: LazyLock<u16> = LazyLock::new(|| non_zero_kind_id("call_expression"));
static CONST_DECLARATION_KIND: LazyLock<u16> =
LazyLock::new(|| non_zero_kind_id("const_declaration"));
static CONTINUE_STATEMENT_KIND: LazyLock<u16> =
LazyLock::new(|| non_zero_kind_id("continue_statement"));
static DEFER_STATEMENT_KIND: LazyLock<u16> = LazyLock::new(|| non_zero_kind_id("defer_statement"));
static IDENTIFIER_KIND: LazyLock<u16> = LazyLock::new(|| non_zero_kind_id("identifier"));
static RETURN_STATEMENT_KIND: LazyLock<u16> =
LazyLock::new(|| non_zero_kind_id("return_statement"));
static SELECTOR_EXPRESSION_KIND: LazyLock<u16> =
LazyLock::new(|| non_zero_kind_id("selector_expression"));
static SHORT_VAR_DECLARATION_KIND: LazyLock<u16> =
LazyLock::new(|| non_zero_kind_id("short_var_declaration"));
static TYPE_DECLARATION_KIND: LazyLock<u16> =
LazyLock::new(|| non_zero_kind_id("type_declaration"));
static VAR_DECLARATION_KIND: LazyLock<u16> = LazyLock::new(|| non_zero_kind_id("var_declaration"));

fn non_zero_kind_id(kind: &str) -> u16 {
let kind_id = LANGUAGE.id_for_node_kind(kind, true);
Expand Down Expand Up @@ -531,14 +537,14 @@ const PREFIX: &str = r"\([^)]*";
const NAME: &str = r"(\.|[A-Za-z_][0-9A-Za-z_]*)( )?";
const SUFFIX: &str = r"[^)]*\)";

static IMPORT_NAMED_OS_RE: Lazy<Regex> =
Lazy::new(|| Regex::new(&import_os_re("", NAME, "")).unwrap());
static IMPORT_UNNAMED_OS_RE: Lazy<Regex> =
Lazy::new(|| Regex::new(&import_os_re("", "", "")).unwrap());
static PARENTHESIZED_IMPORT_NAMED_OS_RE: Lazy<Regex> =
Lazy::new(|| Regex::new(&import_os_re(PREFIX, NAME, SUFFIX)).unwrap());
static PARENTHESIZED_IMPORT_UNNAMED_OS_RE: Lazy<Regex> =
Lazy::new(|| Regex::new(&import_os_re(PREFIX, "", SUFFIX)).unwrap());
static IMPORT_NAMED_OS_RE: LazyLock<Regex> =
LazyLock::new(|| Regex::new(&import_os_re("", NAME, "")).unwrap());
static IMPORT_UNNAMED_OS_RE: LazyLock<Regex> =
LazyLock::new(|| Regex::new(&import_os_re("", "", "")).unwrap());
static PARENTHESIZED_IMPORT_NAMED_OS_RE: LazyLock<Regex> =
LazyLock::new(|| Regex::new(&import_os_re(PREFIX, NAME, SUFFIX)).unwrap());
static PARENTHESIZED_IMPORT_UNNAMED_OS_RE: LazyLock<Regex> =
LazyLock::new(|| Regex::new(&import_os_re(PREFIX, "", SUFFIX)).unwrap());

fn import_os_re(prefix: &str, name: &str, suffix: &str) -> String {
format!(r#"\bimport {prefix}{name}"os"{suffix}"#)
Expand Down
13 changes: 6 additions & 7 deletions backends/src/go/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ use super::{
};
use anyhow::Result;
use necessist_core::framework::{SpanTestMaps, TestSet};
use once_cell::sync::Lazy;
use std::{cell::RefCell, collections::BTreeMap};
use std::{cell::RefCell, collections::BTreeMap, sync::LazyLock};
use streaming_iterator::StreamingIterator;
use tree_sitter::{Query, QueryCursor, QueryMatch, Tree};

Expand Down Expand Up @@ -41,11 +40,11 @@ const STATEMENT_SOURCE: &str = r"
(_statement) @statement
";

static FUNCTION_DECLARATION_QUERY: Lazy<Query> =
Lazy::new(|| valid_query(FUNCTION_DECLARATION_SOURCE));
static TEST_FUNCTION_DECLARATION_QUERY: Lazy<Query> =
Lazy::new(|| valid_query(TEST_FUNCTION_DECLARATION_SOURCE));
static STATEMENT_QUERY: Lazy<Query> = Lazy::new(|| valid_query(STATEMENT_SOURCE));
static FUNCTION_DECLARATION_QUERY: LazyLock<Query> =
LazyLock::new(|| valid_query(FUNCTION_DECLARATION_SOURCE));
static TEST_FUNCTION_DECLARATION_QUERY: LazyLock<Query> =
LazyLock::new(|| valid_query(TEST_FUNCTION_DECLARATION_SOURCE));
static STATEMENT_QUERY: LazyLock<Query> = LazyLock::new(|| valid_query(STATEMENT_SOURCE));

pub(super) fn collect_local_functions<'ast>(
text: &'ast str,
Expand Down
2 changes: 1 addition & 1 deletion backends/src/hardhat/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,6 @@ fn compile(context: &LightContext) -> Result<()> {
let output = command.output_stripped_of_ansi_escapes()?;
if !output.status().success() {
return Err(output.into());
};
}
Ok(())
}
8 changes: 4 additions & 4 deletions backends/src/rust/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use necessist_core::{
framework::{SpanTestMaps, TestSet},
LightContext, SourceFile, Span, ToInternalSpan, __Rewriter as Rewriter,
};
use once_cell::sync::{Lazy, OnceCell};
use once_cell::sync::OnceCell;
use quote::ToTokens;
use std::{
cell::RefCell,
Expand All @@ -17,7 +17,7 @@ use std::{
fs::read_to_string,
path::{Path, PathBuf},
process::Command,
sync::RwLock,
sync::{LazyLock, RwLock},
};

mod storage;
Expand Down Expand Up @@ -103,8 +103,8 @@ impl<'ast> Test<'ast> {

// smoelius: `TEST_PATH_ID_MAP` and `TEST_PATHS` cannot go in `Storage` because they are used by
// `Test`'s implementation of `Named`.
static TEST_PATH_ID_MAP: RwLock<Lazy<HashMap<Vec<String>, usize>>> =
RwLock::new(Lazy::new(HashMap::new));
static TEST_PATH_ID_MAP: RwLock<LazyLock<HashMap<Vec<String>, usize>>> =
RwLock::new(LazyLock::new(HashMap::new));
static TEST_PATHS: RwLock<Vec<Vec<String>>> = RwLock::new(Vec::new());

fn reserve_test_path_id(test_path: Vec<String>) -> usize {
Expand Down
6 changes: 3 additions & 3 deletions backends/src/ts/mocha/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use necessist_core::{
framework::{Postprocess, SpanTestMaps, TestSet},
source_warn, util, LightContext, LineColumn, SourceFile, Span, WarnFlags, Warning,
};
use once_cell::sync::Lazy;
use regex::Regex;
use std::{
cell::RefCell,
Expand All @@ -19,6 +18,7 @@ use std::{
path::{Path, PathBuf},
process::Command,
rc::Rc,
sync::LazyLock,
};
use subprocess::{Exec, NullFile};
use swc_core::{
Expand Down Expand Up @@ -59,13 +59,13 @@ impl Default for ItMessageState {
}
}

static LINE_WITH_TIME_RE: Lazy<Regex> = Lazy::new(|| {
static LINE_WITH_TIME_RE: LazyLock<Regex> = LazyLock::new(|| {
// smoelius: The initial `.` is the check mark.
#[allow(clippy::unwrap_used)]
Regex::new(r"^\s*. (.*) \([0-9]+ms\)$").unwrap()
});

static LINE_WITHOUT_TIME_RE: Lazy<Regex> = Lazy::new(|| {
static LINE_WITHOUT_TIME_RE: LazyLock<Regex> = LazyLock::new(|| {
#[allow(clippy::unwrap_used)]
Regex::new(r"^\s*. (.*)$").unwrap()
});
Expand Down
5 changes: 2 additions & 3 deletions core/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -807,13 +807,12 @@ fn sqlite_and_past_removals_init_lazy(
#[cfg(all(feature = "limit_threads", unix))]
mod rlimit {
use anyhow::Result;
use once_cell::sync::Lazy;
pub use rlimit::Resource;
use rlimit::{getrlimit, setrlimit};
use std::process::Command;
use std::{process::Command, sync::LazyLock};

#[allow(clippy::unwrap_used)]
pub static NPROC_INIT: Lazy<u64> = Lazy::new(|| {
pub static NPROC_INIT: LazyLock<u64> = LazyLock::new(|| {
let output = Command::new("ps").arg("-eL").output().unwrap();
let stdout = std::str::from_utf8(&output.stdout).unwrap();
stdout.lines().count().try_into().unwrap()
Expand Down
5 changes: 2 additions & 3 deletions core/src/span.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use crate::{Backup, Rewriter, SourceFile, __ToConsoleString as ToConsoleString};
use anyhow::{anyhow, Result};
use once_cell::sync::Lazy;
use regex::Regex;
use sha2::{Digest, Sha256};
use std::{fs::OpenOptions, io::Write, path::PathBuf, rc::Rc};
use std::{fs::OpenOptions, io::Write, path::PathBuf, rc::Rc, sync::LazyLock};

#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd)]
pub struct Span {
Expand Down Expand Up @@ -42,7 +41,7 @@ impl ToConsoleString for Span {
}
}

static SPAN_RE: Lazy<Regex> = Lazy::new(|| {
static SPAN_RE: LazyLock<Regex> = LazyLock::new(|| {
#[allow(clippy::unwrap_used)]
Regex::new(r"^([^:]*):([^:]*):([^-]*)-([^:]*):(.*)$").unwrap()
});
Expand Down
4 changes: 2 additions & 2 deletions core/src/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use crate::{util, warn, LightContext, Outcome, Span, WarnFlags, Warning};
use anyhow::{bail, Context, Result};
use diesel::{insert_into, prelude::*, sql_query};
use git2::{Oid, Repository, RepositoryOpenFlags};
use once_cell::sync::Lazy;
use regex::Regex;
use std::{
ffi::OsStr,
Expand All @@ -17,6 +16,7 @@ use std::{
iter::empty,
path::{Path, PathBuf},
rc::Rc,
sync::LazyLock,
};

pub(crate) struct Sqlite {
Expand Down Expand Up @@ -177,7 +177,7 @@ pub(crate) fn insert(sqlite: &mut Sqlite, removal: &crate::Removal) -> Result<()
Ok(())
}

static SSH_RE: Lazy<Regex> = Lazy::new(|| {
static SSH_RE: LazyLock<Regex> = LazyLock::new(|| {
#[allow(clippy::unwrap_used)]
Regex::new(r"^[^@]*@([^:]*):(.*)$").unwrap()
});
Expand Down
1 change: 0 additions & 1 deletion necessist/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ cargo_metadata = "0.19"
ctor = "0.2"
curl = "0.4"
dunce = "1.0"
once_cell = "1.20"
predicates = "3.1"
regex = "1.11"
serde = "1.0"
Expand Down
5 changes: 2 additions & 3 deletions necessist/tests/tempfile_util.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use once_cell::sync::Lazy;
use std::{env::temp_dir, io::Result, path::PathBuf};
use std::{env::temp_dir, io::Result, path::PathBuf, sync::LazyLock};
use tempfile::tempdir_in;

pub use tempfile::TempDir;

// smoelius: macOS requires the paths to be canonicalized, because `/tmp` is symlinked to
// `private/tmp`.
#[allow(clippy::disallowed_methods)]
static TEMPDIR_ROOT: Lazy<PathBuf> = Lazy::new(|| dunce::canonicalize(temp_dir()).unwrap());
static TEMPDIR_ROOT: LazyLock<PathBuf> = LazyLock::new(|| dunce::canonicalize(temp_dir()).unwrap());

/// Canonicalizes [`std::env::temp_dir`] and creates a directory therein.
///
Expand Down
15 changes: 7 additions & 8 deletions necessist/tests/third_party_common/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use assert_cmd::output::OutputError;
use necessist_core::{util, Span};
use once_cell::sync::Lazy;
use regex::Regex;
use serde::Deserialize;
use similar_asserts::SimpleDiff;
Expand All @@ -16,7 +15,7 @@ use std::{
path::{Path, PathBuf},
process::{exit, Command},
rc::Rc,
sync::mpsc::channel,
sync::{mpsc::channel, LazyLock},
thread::{available_parallelism, spawn},
time::{Duration, Instant},
};
Expand Down Expand Up @@ -651,8 +650,8 @@ fn normalize_paths(mut s: &str, path: &Path) -> String {
buf
}

static LINE_COLUMN_RE: Lazy<Regex> =
Lazy::new(|| Regex::new(r"(?m)^\$DIR/([^:]*):[0-9]+:[0-9]+-[0-9]+:[0-9]+:").unwrap());
static LINE_COLUMN_RE: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"(?m)^\$DIR/([^:]*):[0-9]+:[0-9]+-[0-9]+:[0-9]+:").unwrap());

fn remove_line_columns(s: &str) -> String {
LINE_COLUMN_RE.replace_all(s, r"$$DIR/$1:").to_string()
Expand All @@ -661,7 +660,7 @@ fn remove_line_columns(s: &str) -> String {
// smoelius: Don't put a `\b` at the start of this pattern. `assert_cmd::output::OutputError`
// escapes control characters (e.g., `\t`) and its output appears in the stdout files. So adding a
// `\b` could introduce false negatives.
static TIMING_RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"[0-9]+\.[0-9]+(m?)s\b").unwrap());
static TIMING_RE: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"[0-9]+\.[0-9]+(m?)s\b").unwrap());

fn remove_timings(s: &str) -> String {
TIMING_RE.replace_all(s, "[..]${1}s").to_string()
Expand Down Expand Up @@ -736,7 +735,7 @@ fn subsequence<'a, 'b>(
true
}

static BIN_RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"/[^/]*-[0-9a-f]{16}\b").unwrap());
static BIN_RE: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"/[^/]*-[0-9a-f]{16}\b").unwrap());

pub fn stdout_files_are_sanitary_in(path: impl AsRef<Path>) {
for entry in read_dir(path).unwrap() {
Expand All @@ -757,8 +756,8 @@ pub fn stdout_files_are_sanitary_in(path: impl AsRef<Path>) {
}
}

static SPACE_RE: Lazy<Regex> = Lazy::new(|| Regex::new(" +").unwrap());
static DASH_RE: Lazy<Regex> = Lazy::new(|| Regex::new("-+").unwrap());
static SPACE_RE: LazyLock<Regex> = LazyLock::new(|| Regex::new(" +").unwrap());
static DASH_RE: LazyLock<Regex> = LazyLock::new(|| Regex::new("-+").unwrap());

#[cfg_attr(dylint_lib = "general", allow(non_thread_safe_call_in_test))]
#[test]
Expand Down