feat(natu): detect redundant let expressions
This commit was merged in pull request #125.
This commit is contained in:
@@ -69,7 +69,7 @@ fn natu_reports_out_of_order_let_bindings() -> googletest::Result<()> {
|
||||
fn natu_preserves_suppressed_bindings() -> googletest::Result<()> {
|
||||
let report = natu::future_sight(vec![SourceFile {
|
||||
path: PathBuf::from("testdata/nolint.nix"),
|
||||
source: "{ config, ... }: let\n cfg = config.example; # NOLINT(let_order)\n value = cfg;\nin value\n".into(),
|
||||
source: "{ config, ... }: let # NOLINT(redundant_let)\n cfg = config.example; # NOLINT(let_order)\n value = cfg;\nin value\n".into(),
|
||||
}])
|
||||
.or_fail()?;
|
||||
|
||||
@@ -101,6 +101,66 @@ entry
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[gtest]
|
||||
fn natu_reports_redundant_let() -> googletest::Result<()> {
|
||||
let report = natu::future_sight(vec![SourceFile {
|
||||
path: PathBuf::from("testdata/redundant_let.nix"),
|
||||
source: r#"
|
||||
let
|
||||
helper = 1;
|
||||
value = helper;
|
||||
in
|
||||
value
|
||||
"#
|
||||
.into(),
|
||||
}])
|
||||
.or_fail()?;
|
||||
|
||||
let count = report
|
||||
.diagnostics
|
||||
.iter()
|
||||
.filter(|diagnostic| diagnostic.finding.rule_id == "redundant_let")
|
||||
.count();
|
||||
expect_that!(count, eq(1));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[gtest]
|
||||
fn natu_accepts_nonredundant_let() -> googletest::Result<()> {
|
||||
let report = natu::future_sight(vec![
|
||||
SourceFile {
|
||||
path: PathBuf::from("testdata/recursive_let.nix"),
|
||||
source: r#"
|
||||
let
|
||||
recursive = recursive;
|
||||
in
|
||||
recursive
|
||||
"#
|
||||
.into(),
|
||||
},
|
||||
SourceFile {
|
||||
path: PathBuf::from("testdata/dependent_let.nix"),
|
||||
source: r#"
|
||||
let
|
||||
value = 1;
|
||||
dependent = value;
|
||||
in
|
||||
value
|
||||
"#
|
||||
.into(),
|
||||
},
|
||||
])
|
||||
.or_fail()?;
|
||||
|
||||
let count = report
|
||||
.diagnostics
|
||||
.iter()
|
||||
.filter(|diagnostic| diagnostic.finding.rule_id == "redundant_let")
|
||||
.count();
|
||||
expect_that!(count, eq(0));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[gtest]
|
||||
fn natu_reports_redundant_parameter_forwarding() -> googletest::Result<()> {
|
||||
let report = natu::future_sight(vec![
|
||||
|
||||
Reference in New Issue
Block a user