Compare commits
1 Commits
1e1e6d6d4d
...
6e19169e11
| Author | SHA1 | Date | |
|---|---|---|---|
| 6e19169e11 |
@@ -96,11 +96,15 @@
|
|||||||
- `rules_rust` `rust_test` targets cannot set both `crate` and `srcs`.
|
- `rules_rust` `rust_test` targets cannot set both `crate` and `srcs`.
|
||||||
Use one input style per test target.
|
Use one input style per test target.
|
||||||
- Rust tests in this monorepo live in separate `*_test.rs` files, not inline `#[cfg(test)]` modules.
|
- Rust tests in this monorepo live in separate `*_test.rs` files, not inline `#[cfg(test)]` modules.
|
||||||
|
- `rnix::ast::HasEntry::entries()` includes assignments and `inherit` statements.
|
||||||
|
Use `attrpath_values()` when code needs only assignment entries.
|
||||||
- Ariadne Rust tests are declared in Bazel `BUILD` files; do not add `[[test]]` entries to
|
- Ariadne Rust tests are declared in Bazel `BUILD` files; do not add `[[test]]` entries to
|
||||||
`src/ariadne/Cargo.toml` unless explicitly requested.
|
`src/ariadne/Cargo.toml` unless explicitly requested.
|
||||||
- In this monorepo, "dotfiles" refers to the dotfiles/NixOS configuration under `src/dotfiles/` and `configs/nixos/`.
|
- In this monorepo, "dotfiles" refers to the dotfiles/NixOS configuration under `src/dotfiles/` and `configs/nixos/`.
|
||||||
- The flake does not currently define `formatter.x86_64-linux`.
|
- The flake does not currently define `formatter.x86_64-linux`.
|
||||||
Do not use `nix fmt` as a validation command until a formatter is added.
|
Do not use `nix fmt` as a validation command until a formatter is added.
|
||||||
|
- The `fix` app passes its current directory to Statix and Deadnix.
|
||||||
|
Run `nix run .#fix` from the repository root so path exclusions match.
|
||||||
- Ariadne extraction must preserve the game-root season prefix for archived source.
|
- Ariadne extraction must preserve the game-root season prefix for archived source.
|
||||||
Different game installs can contain compiled scripts with the same internal path.
|
Different game installs can contain compiled scripts with the same internal path.
|
||||||
- Clew owns Ren'Py extraction, preparation, and compiled-script AST export. Ariadne owns analysis over Clew-produced data.
|
- Clew owns Ren'Py extraction, preparation, and compiled-script AST export. Ariadne owns analysis over Clew-produced data.
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ rust_library(
|
|||||||
"rules.rs",
|
"rules.rs",
|
||||||
"rules/deprecated_to_path.rs",
|
"rules/deprecated_to_path.rs",
|
||||||
"rules/empty_inherit.rs",
|
"rules/empty_inherit.rs",
|
||||||
|
"rules/empty_let_in.rs",
|
||||||
"rules/unquoted_uri.rs",
|
"rules/unquoted_uri.rs",
|
||||||
"xatu.rs",
|
"xatu.rs",
|
||||||
],
|
],
|
||||||
@@ -33,6 +34,7 @@ rust_test(
|
|||||||
"testdata/clean.nix",
|
"testdata/clean.nix",
|
||||||
"testdata/invalid.nix",
|
"testdata/invalid.nix",
|
||||||
"testdata/lint_findings.nix",
|
"testdata/lint_findings.nix",
|
||||||
|
"testdata/lint_interactions.nix",
|
||||||
"testdata/lint_variants.nix",
|
"testdata/lint_variants.nix",
|
||||||
],
|
],
|
||||||
deps = [
|
deps = [
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ impl std::fmt::Display for SourceRange {
|
|||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub enum NodeData {
|
pub enum NodeData {
|
||||||
Apply(Apply),
|
Apply(Apply),
|
||||||
|
LetIn(LetIn),
|
||||||
Inherit(Inherit),
|
Inherit(Inherit),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,6 +55,11 @@ pub struct Select {
|
|||||||
pub attrs: Vec<Ident>,
|
pub attrs: Vec<Ident>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
pub struct LetIn {
|
||||||
|
pub binding_count: usize,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct Inherit {
|
pub struct Inherit {
|
||||||
pub attr_count: usize,
|
pub attr_count: usize,
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use rnix::ast::HasEntry;
|
||||||
use rowan::ast::AstNode;
|
use rowan::ast::AstNode;
|
||||||
|
|
||||||
use crate::{FileId, ast};
|
use crate::{FileId, ast};
|
||||||
@@ -37,6 +38,7 @@ fn convert_syntax(syntax: rnix::SyntaxNode) -> (Vec<ast::Node>, Vec<ast::Token>)
|
|||||||
fn convert_node(node: rnix::SyntaxNode) -> Option<ast::Node> {
|
fn convert_node(node: rnix::SyntaxNode) -> Option<ast::Node> {
|
||||||
match node.kind() {
|
match node.kind() {
|
||||||
rnix::SyntaxKind::NODE_APPLY => convert_apply(node),
|
rnix::SyntaxKind::NODE_APPLY => convert_apply(node),
|
||||||
|
rnix::SyntaxKind::NODE_LET_IN => convert_let_in(node),
|
||||||
rnix::SyntaxKind::NODE_INHERIT => convert_inherit(node),
|
rnix::SyntaxKind::NODE_INHERIT => convert_inherit(node),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
@@ -102,6 +104,27 @@ impl TryFrom<rnix::ast::Select> for ast::Select {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn convert_let_in(node: rnix::SyntaxNode) -> Option<ast::Node> {
|
||||||
|
let let_in = rnix::ast::LetIn::cast(node)?;
|
||||||
|
|
||||||
|
Some(ast::Node {
|
||||||
|
range: let_in.syntax().text_range().into(),
|
||||||
|
data: ast::NodeData::LetIn(let_in.into()),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<rnix::ast::LetIn> for ast::LetIn {
|
||||||
|
fn from(let_in: rnix::ast::LetIn) -> Self {
|
||||||
|
Self {
|
||||||
|
binding_count: let_in.attrpath_values().count()
|
||||||
|
+ let_in
|
||||||
|
.inherits()
|
||||||
|
.map(|inherit| inherit.attrs().count())
|
||||||
|
.sum::<usize>(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn convert_inherit(node: rnix::SyntaxNode) -> Option<ast::Node> {
|
fn convert_inherit(node: rnix::SyntaxNode) -> Option<ast::Node> {
|
||||||
let inherit = rnix::ast::Inherit::cast(node)?;
|
let inherit = rnix::ast::Inherit::cast(node)?;
|
||||||
|
|
||||||
|
|||||||
@@ -2,10 +2,12 @@ use crate::FileId;
|
|||||||
use crate::ast;
|
use crate::ast;
|
||||||
use crate::rules::deprecated_to_path::DeprecatedToPath;
|
use crate::rules::deprecated_to_path::DeprecatedToPath;
|
||||||
use crate::rules::empty_inherit::EmptyInherit;
|
use crate::rules::empty_inherit::EmptyInherit;
|
||||||
|
use crate::rules::empty_let_in::EmptyLetIn;
|
||||||
use crate::rules::unquoted_uri::UnquotedUri;
|
use crate::rules::unquoted_uri::UnquotedUri;
|
||||||
|
|
||||||
pub mod deprecated_to_path;
|
pub mod deprecated_to_path;
|
||||||
pub mod empty_inherit;
|
pub mod empty_inherit;
|
||||||
|
pub mod empty_let_in;
|
||||||
pub mod unquoted_uri;
|
pub mod unquoted_uri;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@@ -54,6 +56,7 @@ pub fn run_rules(file: &ast::ParsedFile) -> Vec<Diagnostic> {
|
|||||||
[
|
[
|
||||||
run_node_rule::<DeprecatedToPath>(node),
|
run_node_rule::<DeprecatedToPath>(node),
|
||||||
run_node_rule::<EmptyInherit>(node),
|
run_node_rule::<EmptyInherit>(node),
|
||||||
|
run_node_rule::<EmptyLetIn>(node),
|
||||||
]
|
]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.flatten()
|
.flatten()
|
||||||
|
|||||||
24
src/xatu/rules/empty_let_in.rs
Normal file
24
src/xatu/rules/empty_let_in.rs
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
use crate::{ast, rules::NodeRule};
|
||||||
|
|
||||||
|
pub struct EmptyLetIn;
|
||||||
|
|
||||||
|
impl NodeRule for EmptyLetIn {
|
||||||
|
type Node = ast::LetIn;
|
||||||
|
|
||||||
|
const ID: &'static str = "empty_let_in";
|
||||||
|
|
||||||
|
fn select(data: &ast::NodeData) -> Option<&Self::Node> {
|
||||||
|
match data {
|
||||||
|
ast::NodeData::LetIn(let_in) => Some(let_in),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn check(node: &Self::Node) -> Option<&'static str> {
|
||||||
|
if node.binding_count == 0 {
|
||||||
|
Some("let expression has no bindings")
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
5
src/xatu/testdata/clean.nix
vendored
5
src/xatu/testdata/clean.nix
vendored
@@ -1,6 +1,11 @@
|
|||||||
{ pkgs }:
|
{ pkgs }:
|
||||||
|
|
||||||
{
|
{
|
||||||
|
nonEmpty =
|
||||||
|
let
|
||||||
|
value = pkgs;
|
||||||
|
in
|
||||||
|
value;
|
||||||
path = ./. + "/foo";
|
path = ./. + "/foo";
|
||||||
url = "https://example.com";
|
url = "https://example.com";
|
||||||
inherit pkgs;
|
inherit pkgs;
|
||||||
|
|||||||
1
src/xatu/testdata/lint_findings.nix
vendored
1
src/xatu/testdata/lint_findings.nix
vendored
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
{
|
{
|
||||||
inherit;
|
inherit;
|
||||||
|
empty = let in src;
|
||||||
path = builtins.toPath src;
|
path = builtins.toPath src;
|
||||||
url = https://example.com;
|
url = https://example.com;
|
||||||
}
|
}
|
||||||
|
|||||||
8
src/xatu/testdata/lint_interactions.nix
vendored
Normal file
8
src/xatu/testdata/lint_interactions.nix
vendored
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
{ src }:
|
||||||
|
|
||||||
|
let
|
||||||
|
inherit;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
value = src;
|
||||||
|
}
|
||||||
5
src/xatu/testdata/lint_variants.nix
vendored
5
src/xatu/testdata/lint_variants.nix
vendored
@@ -1,5 +1,10 @@
|
|||||||
{ src }:
|
{ src }:
|
||||||
|
|
||||||
{
|
{
|
||||||
|
commentedEmpty =
|
||||||
|
let
|
||||||
|
# This comment must not suppress the finding.
|
||||||
|
in
|
||||||
|
src;
|
||||||
path = toPath src;
|
path = toPath src;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,6 +113,51 @@ fn xatu_reports_empty_inherit() -> googletest::Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[gtest]
|
||||||
|
fn xatu_reports_empty_let_in() -> googletest::Result<()> {
|
||||||
|
let source = fixture_source("testdata/lint_findings.nix")?;
|
||||||
|
let range_start = source.source.find("let in src").or_fail()?;
|
||||||
|
let range_end = range_start + "let in src".len();
|
||||||
|
let report = xatu::future_sight(vec![source]).or_fail()?;
|
||||||
|
|
||||||
|
let finding = report
|
||||||
|
.diagnostics
|
||||||
|
.iter()
|
||||||
|
.map(|diagnostic| &diagnostic.finding)
|
||||||
|
.find(|finding| finding.rule_id == "empty_let_in")
|
||||||
|
.or_fail()?;
|
||||||
|
let expected_range = format!("{range_start}..{range_end}");
|
||||||
|
expect_that!(finding.range.to_string(), eq(&expected_range));
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[gtest]
|
||||||
|
fn xatu_reports_commented_empty_let_in() -> googletest::Result<()> {
|
||||||
|
let report = xatu::future_sight(vec![fixture_source("testdata/lint_variants.nix")?]).or_fail()?;
|
||||||
|
|
||||||
|
let findings = report
|
||||||
|
.diagnostics
|
||||||
|
.iter()
|
||||||
|
.map(|diagnostic| diagnostic.finding.rule_id)
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
expect_that!(findings, contains(eq(&"empty_let_in")));
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[gtest]
|
||||||
|
fn xatu_reports_empty_let_with_empty_inherit() -> googletest::Result<()> {
|
||||||
|
let report =
|
||||||
|
xatu::future_sight(vec![fixture_source("testdata/lint_interactions.nix")?]).or_fail()?;
|
||||||
|
|
||||||
|
let findings = report
|
||||||
|
.diagnostics
|
||||||
|
.iter()
|
||||||
|
.map(|diagnostic| diagnostic.finding.rule_id)
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
expect_that!(findings, eq(&vec!["empty_let_in", "empty_inherit"]));
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[gtest]
|
#[gtest]
|
||||||
fn xatu_reports_unquoted_uri() -> googletest::Result<()> {
|
fn xatu_reports_unquoted_uri() -> googletest::Result<()> {
|
||||||
let report = xatu::future_sight(vec![fixture_source("testdata/lint_findings.nix")?]).or_fail()?;
|
let report = xatu::future_sight(vec![fixture_source("testdata/lint_findings.nix")?]).or_fail()?;
|
||||||
|
|||||||
Reference in New Issue
Block a user