Skip to content
Open
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
15 changes: 11 additions & 4 deletions Cargo.lock

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

12 changes: 5 additions & 7 deletions bin/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,10 @@ fn write_stderr<T: Write>(
let range = |at: TextRange| at.start().into()..at.end().into();
let src_id = path.to_str().unwrap_or("<unknown>");
for report in &lint_result.reports {
let offset = report
.diagnostics
.iter()
.map(|d| d.at.start().into())
.min()
.unwrap_or(0usize);
let report_range = report
.total_diagnostic_range()
.map(range)
.unwrap_or(0usize..0usize);
let report_kind = match report.severity {
Severity::Warn => CliReportKind::Warning,
Severity::Error => CliReportKind::Error,
Expand All @@ -67,7 +65,7 @@ fn write_stderr<T: Write>(
.diagnostics
.iter()
.fold(
CliReport::build(report_kind, src_id, offset)
CliReport::build(report_kind, (src_id, report_range))
.with_config(
CliConfig::default()
.with_cross_gap(true)
Expand Down
25 changes: 24 additions & 1 deletion bin/tests/_utils.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use std::{io::Write, process::Command};
use std::{io::Write, process::Command, process::Stdio};

use tempfile::NamedTempFile;

#[allow(dead_code)]
pub fn test_cli(expression: &str, args: &[&str]) -> anyhow::Result<String> {
let mut fixture = NamedTempFile::with_suffix(".nix")?;
fixture.write_all(expression.as_bytes())?;
Expand All @@ -19,3 +20,25 @@ pub fn test_cli(expression: &str, args: &[&str]) -> anyhow::Result<String> {

Ok(stdout)
}

#[allow(dead_code)]
pub fn test_cli_stdin(input: &str, args: &[&str]) -> anyhow::Result<String> {
let mut child = Command::new("cargo")
.arg("run")
.arg("--")
.args(args)
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.spawn()?;

child
.stdin
.as_mut()
.expect("stdin should be piped")
.write_all(input.as_bytes())?;

let output = child.wait_with_output()?;
let stdout = strip_ansi_escapes::strip(output.stdout)?;

Ok(String::from_utf8(stdout)?)
}
10 changes: 10 additions & 0 deletions bin/tests/empty_file.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
mod _utils;

#[test]
fn check_empty_file_reports_parse_error() {
let stdout = _utils::test_cli("", &["check"]).unwrap();

assert!(stdout.contains("[00] Error: Syntax error"), "{stdout}");
assert!(stdout.contains("Unexpected end of file"), "{stdout}");
assert!(stdout.contains("<temp_file_path>:1:1"), "{stdout}");
}
10 changes: 10 additions & 0 deletions bin/tests/empty_stdin.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
mod _utils;

#[test]
fn check_empty_stdin_reports_parse_error() {
let stdout = _utils::test_cli_stdin("", &["check", "-s"]).unwrap();

assert!(stdout.contains("[00] Error: Syntax error"), "{stdout}");
assert!(stdout.contains("Unexpected end of file"), "{stdout}");
assert!(stdout.contains("<stdin>:1:1"), "{stdout}");
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ source: bin/tests/bool_comparison.rs
---
true != false
---
[W01] Warning: Equality comparison between boolean literals
╭─[<temp_file_path>:1:1]
[01] Warning: Equality comparison between boolean literals
╭─[ <temp_file_path>:1:1 ]
1 │ true != false
· ──────┬──────
· ╰──────── Equality comparison between boolean literals
──────┬──────
╰──────── Equality comparison between boolean literals
───╯
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ source: bin/tests/bool_comparison.rs
---
false != true
---
[W01] Warning: Equality comparison between boolean literals
╭─[<temp_file_path>:1:1]
[01] Warning: Equality comparison between boolean literals
╭─[ <temp_file_path>:1:1 ]
1 │ false != true
· ──────┬──────
· ╰──────── Equality comparison between boolean literals
──────┬──────
╰──────── Equality comparison between boolean literals
───╯
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ source: bin/tests/bool_comparison.rs
---
false == false
---
[W01] Warning: Equality comparison between boolean literals
╭─[<temp_file_path>:1:1]
[01] Warning: Equality comparison between boolean literals
╭─[ <temp_file_path>:1:1 ]
1 │ false == false
· ───────┬──────
· ╰──────── Equality comparison between boolean literals
───────┬──────
╰──────── Equality comparison between boolean literals
───╯
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ source: bin/tests/bool_comparison.rs
---
true == true
---
[W01] Warning: Equality comparison between boolean literals
╭─[<temp_file_path>:1:1]
[01] Warning: Equality comparison between boolean literals
╭─[ <temp_file_path>:1:1 ]
1 │ true == true
· ──────┬─────
· ╰─────── Equality comparison between boolean literals
──────┬─────
╰─────── Equality comparison between boolean literals
───╯
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ source: bin/tests/bool_comparison.rs
---
true != true
---
[W01] Warning: Equality comparison between boolean literals
╭─[<temp_file_path>:1:1]
[01] Warning: Equality comparison between boolean literals
╭─[ <temp_file_path>:1:1 ]
1 │ true != true
· ──────┬─────
· ╰─────── Equality comparison between boolean literals
──────┬─────
╰─────── Equality comparison between boolean literals
───╯
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ source: bin/tests/bool_comparison.rs
---
false == true
---
[W01] Warning: Equality comparison between boolean literals
╭─[<temp_file_path>:1:1]
[01] Warning: Equality comparison between boolean literals
╭─[ <temp_file_path>:1:1 ]
1 │ false == true
· ──────┬──────
· ╰──────── Equality comparison between boolean literals
──────┬──────
╰──────── Equality comparison between boolean literals
───╯
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ source: bin/tests/bool_comparison.rs
---
false != false
---
[W01] Warning: Equality comparison between boolean literals
╭─[<temp_file_path>:1:1]
[01] Warning: Equality comparison between boolean literals
╭─[ <temp_file_path>:1:1 ]
1 │ false != false
· ───────┬──────
· ╰──────── Equality comparison between boolean literals
───────┬──────
╰──────── Equality comparison between boolean literals
───╯
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ source: bin/tests/bool_comparison.rs
---
true == false
---
[W01] Warning: Equality comparison between boolean literals
╭─[<temp_file_path>:1:1]
[01] Warning: Equality comparison between boolean literals
╭─[ <temp_file_path>:1:1 ]
1 │ true == false
· ──────┬──────
· ╰──────── Equality comparison between boolean literals
──────┬──────
╰──────── Equality comparison between boolean literals
───╯
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ source: bin/tests/bool_simplification.rs
---
!(a == b)
---
[W18] Warning: This boolean expression can be simplified
╭─[<temp_file_path>:1:1]
[18] Warning: This boolean expression can be simplified
╭─[ <temp_file_path>:1:1 ]
1 │ !(a == b)
· ────┬────
· ╰────── Try != instead of !(... == ...)
────┬────
╰────── Try != instead of !(... == ...)
───╯
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ let
in
x
---
[W06] Warning: These let-in expressions are collapsible
╭─[<temp_file_path>:1:1]
[06] Warning: These let-in expressions are collapsible
╭─[ <temp_file_path>:1:1 ]
1 │ ╭───▶ let
┆ ┆
4 │ │ ╭─▶ let
┆ ┆ ┆
7 │ │ ├─▶ x
· │ │ │
· │ ╰─────── This let in expression is nested
· │ │
· ╰─────┴─── This let in expression contains a nested let in expression
│ │ │
│ ╰─────── This let in expression is nested
│ │
╰─────┴─── This let in expression contains a nested let in expression
───╯
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ in
in
a + b + c + d
---
[W06] Warning: These let-in expressions are collapsible
╭─[<temp_file_path>:1:1]
[06] Warning: These let-in expressions are collapsible
╭─[ <temp_file_path>:1:1 ]
1 │ ╭───▶ let
┆ ┆
5 │ │ ╭─▶ let
┆ ┆ ┆
9 │ │ ├─▶ a + b + c + d
· │ │ │
· │ ╰───────────────────── This let in expression is nested
· │ │
· ╰───────────────────┴─── This let in expression contains a nested let in expression
│ │ │
│ ╰───────────────────── This let in expression is nested
│ │
╰───────────────────┴─── This let in expression contains a nested let in expression
───╯
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ let
in
c
---
[W06] Warning: These let-in expressions are collapsible
╭─[<temp_file_path>:1:1]
[06] Warning: These let-in expressions are collapsible
╭─[ <temp_file_path>:1:1 ]
1 │ ╭───▶ let
┆ ┆
4 │ │ ╭─▶ let
┆ ┆ ┆
7 │ │ ├─▶ c
· │ │ │
· │ ╰─────── This let in expression is nested
· │ │
· ╰─────┴─── This let in expression contains a nested let in expression
│ │ │
│ ╰─────── This let in expression is nested
│ │
╰─────┴─── This let in expression contains a nested let in expression
───╯
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ let
in
x
---
[W06] Warning: These let-in expressions are collapsible
╭─[<temp_file_path>:1:1]
[06] Warning: These let-in expressions are collapsible
╭─[ <temp_file_path>:1:1 ]
1 │ ╭───▶ let
┆ ┆
4 │ │ ╭─▶ let
┆ ┆ ┆
7 │ │ ├─▶ x
· │ │ │
· │ ╰─────── This let in expression is nested
· │ │
· ╰─────┴─── This let in expression contains a nested let in expression
│ │ │
│ ╰─────── This let in expression is nested
│ │
╰─────┴─── This let in expression contains a nested let in expression
───╯
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ source: bin/tests/deprecated_to_path.rs
---
builtins.toPath "/some/path"
---
[W17] Warning: Found usage of deprecated builtin toPath
╭─[<temp_file_path>:1:1]
[17] Warning: Found usage of deprecated builtin toPath
╭─[ <temp_file_path>:1:1 ]
1 │ builtins.toPath "/some/path"
· ──────────────┬─────────────
· ╰─────────────── builtins.toPath is deprecated, see :doc builtins.toPath within the REPL for more
──────────────┬─────────────
╰─────────────── builtins.toPath is deprecated, see :doc builtins.toPath within the REPL for more
───╯
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ source: bin/tests/deprecated_to_path.rs
---
toPath x
---
[W17] Warning: Found usage of deprecated builtin toPath
╭─[<temp_file_path>:1:1]
[17] Warning: Found usage of deprecated builtin toPath
╭─[ <temp_file_path>:1:1 ]
1 │ toPath x
· ────┬───
· ╰───── toPath is deprecated, see :doc builtins.toPath within the REPL for more
────┬───
╰───── toPath is deprecated, see :doc builtins.toPath within the REPL for more
───╯
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ source: bin/tests/deprecated_to_path.rs
---
builtins.toPath x
---
[W17] Warning: Found usage of deprecated builtin toPath
╭─[<temp_file_path>:1:1]
[17] Warning: Found usage of deprecated builtin toPath
╭─[ <temp_file_path>:1:1 ]
1 │ builtins.toPath x
· ────────┬────────
· ╰────────── builtins.toPath is deprecated, see :doc builtins.toPath within the REPL for more
────────┬────────
╰────────── builtins.toPath is deprecated, see :doc builtins.toPath within the REPL for more
───╯
Loading
Loading