treewide: enforce strict clippy check

This commit is contained in:
2026-08-22 18:41:23 +08:00
parent 5f494983b8
commit cb38031f85
51 changed files with 1237 additions and 568 deletions
+4
View File
@@ -48,5 +48,9 @@ fix-vm = { path = "../fix-vm" }
[dev-dependencies]
criterion = { version = "0.8", features = ["html_reports"] }
serial_test = "3.5"
tempfile = "3.24"
test-log = { version = "0.2", features = ["trace"] }
[lints]
workspace = true
+2 -1
View File
@@ -1,4 +1,5 @@
#![allow(dead_code)]
#![allow(clippy::allow_attributes_without_reason)]
#![allow(dead_code, clippy::unwrap_used, clippy::unwrap_in_result)]
use fix::Evaluator;
use fix_error::{Result, Source};
+7 -11
View File
@@ -1,6 +1,3 @@
#![warn(clippy::unwrap_used)]
#![allow(dead_code)]
use fix_bytecode::InstructionPtr;
use fix_bytecode::disassembler::{Disassembler, DisassemblerContext};
use fix_compiler::{CodeState, ExtraScope};
@@ -11,7 +8,6 @@ use fix_vm::Vm;
use hashbrown::{HashMap, HashSet};
use string_interner::{DefaultStringInterner, Symbol as _};
mod derivation;
pub mod logging;
#[global_allocator]
@@ -101,12 +97,12 @@ impl VmRuntimeCtx for RuntimeState {
StringId(self.strings.get_or_intern(s))
}
fn resolve_string(&self, id: StringId) -> &str {
#[allow(clippy::unwrap_used)]
self.strings.resolve(id.0).unwrap()
self.strings
.resolve(id.0)
.expect("interned string id must resolve")
}
fn get_const(&self, id: u32) -> StaticValue {
#[allow(clippy::unwrap_used)]
self.constants.get(id).unwrap()
self.constants.get(id).expect("const id must be valid")
}
fn add_const(&mut self, val: StaticValue) -> u32 {
self.constants.insert(val)
@@ -145,9 +141,9 @@ impl DisassemblerContext for Evaluator {
&self.code.bytecode
}
#[allow(clippy::unwrap_used)]
fn resolve_string(&self, id: u32) -> &str {
let id = string_interner::symbol::SymbolU32::try_from_usize(id as usize).unwrap();
self.runtime.strings.resolve(id).unwrap()
let id = string_interner::symbol::SymbolU32::try_from_usize(id as usize)
.expect("invalid string id");
self.runtime.strings.resolve(id).expect("invalid string id")
}
}
+3 -4
View File
@@ -5,7 +5,7 @@ use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
use tracing_subscriber::{EnvFilter, Layer, fmt};
pub fn init_logging() {
pub fn init_logging() -> Result<(), miette::InstallError> {
let is_terminal = std::io::stderr().is_terminal();
let show_time = env::var("NIX_JS_LOG_TIME")
.map(|v| v == "1" || v.to_lowercase() == "true")
@@ -32,10 +32,10 @@ pub fn init_logging() {
.with(fmt_layer)
.init();
init_miette_handler();
init_miette_handler()
}
fn init_miette_handler() {
fn init_miette_handler() -> Result<(), miette::InstallError> {
let is_terminal = std::io::stderr().is_terminal();
miette::set_hook(Box::new(move |_| {
Box::new(
@@ -46,5 +46,4 @@ fn init_miette_handler() {
.build(),
)
}))
.ok();
}
+34 -19
View File
@@ -20,33 +20,49 @@ struct Cli {
enum Command {
Compile {
#[clap(flatten)]
source: ExprSource,
source: ExprSourceArgs,
#[arg(long)]
silent: bool,
},
Eval {
#[clap(flatten)]
source: ExprSource,
source: ExprSourceArgs,
},
Repl,
}
#[derive(Args)]
#[group(required = true, multiple = false)]
struct ExprSource {
struct ExprSourceArgs {
#[clap(short, long)]
expr: Option<String>,
#[clap(short, long)]
file: Option<PathBuf>,
}
enum ExprSource {
Expr(String),
File(PathBuf),
}
#[expect(
clippy::unreachable,
reason = "clap's arg group guarantees exactly one of --expr/--file is set"
)]
impl From<ExprSourceArgs> for ExprSource {
fn from(args: ExprSourceArgs) -> Self {
match (args.expr, args.file) {
(Some(expr), None) => ExprSource::Expr(expr),
(None, Some(file)) => ExprSource::File(file),
_ => unreachable!(),
}
}
}
fn run_compile(eval: &mut Evaluator, src: ExprSource, silent: bool) -> Result<()> {
let src = if let Some(expr) = src.expr {
Source::new_eval(expr)?
} else if let Some(file) = src.file {
Source::new_file(file)?
} else {
unreachable!()
let src = match src {
ExprSource::Expr(expr) => Source::new_eval(expr)?,
ExprSource::File(file) => Source::new_file(file)?,
};
match eval.compile_bytecode(src) {
Ok(ip) => {
@@ -63,12 +79,9 @@ fn run_compile(eval: &mut Evaluator, src: ExprSource, silent: bool) -> Result<()
}
fn run_eval(eval: &mut Evaluator, src: ExprSource) -> Result<()> {
let src = if let Some(expr) = src.expr {
Source::new_eval(expr)?
} else if let Some(file) = src.file {
Source::new_file(file)?
} else {
unreachable!()
let src = match src {
ExprSource::Expr(expr) => Source::new_eval(expr)?,
ExprSource::File(file) => Source::new_file(file)?,
};
match eval.eval_deep(src) {
Ok(value) => {
@@ -93,7 +106,9 @@ fn run_repl(eval: &mut Evaluator) -> Result<()> {
if line.trim().is_empty() {
continue;
}
let _ = rl.add_history_entry(line.as_str());
if let Err(err) = rl.add_history_entry(line.as_str()) {
eprintln!("[WARN] Failed to add history entry: {err}");
}
if let Some([Some(_), Some(ident), Some(rest)]) = RE.exec(&line) {
if let Some(expr) = rest.strip_prefix('=') {
let expr = expr.trim_start();
@@ -137,15 +152,15 @@ fn run_repl(eval: &mut Evaluator) -> Result<()> {
}
fn main() -> Result<()> {
fix::logging::init_logging();
fix::logging::init_logging()?;
let cli = Cli::parse();
let mut eval = Evaluator::new();
match cli.command {
Command::Compile { source, silent } => run_compile(&mut eval, source, silent),
Command::Eval { source } => run_eval(&mut eval, source),
Command::Compile { source, silent } => run_compile(&mut eval, source.into(), silent),
Command::Eval { source } => run_eval(&mut eval, source.into()),
Command::Repl => run_repl(&mut eval),
}
}
+4 -6
View File
@@ -402,17 +402,15 @@ fn fixed_output_sha256_flat() {
#[test_log::test]
fn fixed_output_missing_hashalgo() {
assert!(
eval_deep_result(
r#"derivation {
eval_deep_result(
r#"derivation {
name = "default";
builder = "/bin/sh";
system = "x86_64-linux";
outputHash = "0000000000000000000000000000000000000000000000000000000000000000";
}"#,
)
.is_err()
);
)
.unwrap_err();
}
#[test_log::test]
+1 -1
View File
@@ -350,7 +350,7 @@ fn read_dir_nonexistent_fails() {
let expr = r#"builtins.readDir "/nonexistent/directory""#;
let result = eval_result(expr);
assert!(result.is_err());
result.unwrap_err();
}
#[test_log::test]
+18 -7
View File
@@ -5,6 +5,7 @@ use std::path::PathBuf;
use fix::Evaluator;
use fix_error::{Source, SourceType};
use fix_lang::Value;
use serial_test::serial;
fn get_lang_dir() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/tests/lang")
@@ -160,9 +161,14 @@ mod okay {
eval_okay_test!(getattrpos);
eval_okay_test!(getattrpos_functionargs);
eval_okay_test!(getattrpos_undefined);
eval_okay_test!(getenv, || {
unsafe { std::env::set_var("TEST_VAR", "foo") };
});
eval_okay_test!(
#[serial(env)]
getenv,
|| {
// SAFETY: guarded with #[serial_test::serial]
unsafe { std::env::set_var("TEST_VAR", "foo") };
}
);
eval_okay_test!(groupBy);
eval_okay_test!(r#if);
eval_okay_test!(ind_string);
@@ -194,11 +200,16 @@ mod okay {
eval_okay_test!(partition);
eval_okay_test!(path);
eval_okay_test!(pathexists);
eval_okay_test!(path_string_interpolation, || {
unsafe {
std::env::set_var("HOME", "/fake-home");
eval_okay_test!(
#[serial(env)]
path_string_interpolation,
|| {
// SAFETY: guarded with #[serial_test::serial]
unsafe {
std::env::set_var("HOME", "/fake-home");
}
}
});
);
eval_okay_test!(patterns);
eval_okay_test!(print);
eval_okay_test!(readDir);
+8
View File
@@ -1,3 +1,11 @@
#![allow(clippy::allow_attributes_without_reason)]
#![allow(
dead_code,
clippy::unwrap_used,
clippy::unwrap_in_result,
clippy::panic
)]
mod derivation;
mod findfile;
mod io_operations;
+8 -8
View File
@@ -348,7 +348,7 @@ fn substring_zero_length_empty_value() {
}
#[test_log::test]
#[allow(non_snake_case)]
#[expect(non_snake_case)]
fn concatStringsSep_preserves_context() {
let result = eval(
r#"
@@ -365,7 +365,7 @@ fn concatStringsSep_preserves_context() {
}
#[test_log::test]
#[allow(non_snake_case)]
#[expect(non_snake_case)]
fn concatStringsSep_merges_contexts() {
let result = eval(
r#"
@@ -383,7 +383,7 @@ fn concatStringsSep_merges_contexts() {
}
#[test_log::test]
#[allow(non_snake_case)]
#[expect(non_snake_case)]
fn concatStringsSep_separator_has_context() {
let result = eval(
r#"
@@ -398,7 +398,7 @@ fn concatStringsSep_separator_has_context() {
}
#[test_log::test]
#[allow(non_snake_case)]
#[expect(non_snake_case)]
fn replaceStrings_input_context_preserved() {
let result = eval(
r#"
@@ -413,7 +413,7 @@ fn replaceStrings_input_context_preserved() {
}
#[test_log::test]
#[allow(non_snake_case)]
#[expect(non_snake_case)]
fn replaceStrings_replacement_context_collected() {
let result = eval(
r#"
@@ -428,7 +428,7 @@ fn replaceStrings_replacement_context_collected() {
}
#[test_log::test]
#[allow(non_snake_case)]
#[expect(non_snake_case)]
fn replaceStrings_merges_contexts() {
let result = eval(
r#"
@@ -446,7 +446,7 @@ fn replaceStrings_merges_contexts() {
}
#[test_log::test]
#[allow(non_snake_case)]
#[expect(non_snake_case)]
fn replaceStrings_lazy_evaluation_context() {
let result = eval(
r#"
@@ -461,7 +461,7 @@ fn replaceStrings_lazy_evaluation_context() {
}
#[test_log::test]
#[allow(non_snake_case)]
#[expect(non_snake_case)]
fn baseNameOf_preserves_context() {
let result = eval(
r#"
-2
View File
@@ -1,5 +1,3 @@
#![allow(dead_code)]
use fix::Evaluator;
use fix_error::{Result, Source};
use fix_lang::Value;