From c0561767ef57ef4bfbb38f50a50bcfea7e3dfdf7 Mon Sep 17 00:00:00 2001 From: Finjineersdev Date: Sat, 28 Nov 2026 03:15:45 +0500 Subject: [PATCH] feat(rules): Elixir (Mix) _build and deps A Mix project (mix.exs) builds into _build and fetches dependencies into deps; those are Mix's defaults ("defaults to _build", "Defaults to deps", https://hexdocs.pm/mix/Mix.Project.html). _build is Safe: the next compile recreates it. deps is Caution: it needs `mix deps.get` (a download) first, so it is never ticked for the user. An umbrella's apps share the umbrella's folders, so only the top project offers them, and the walk never enters deps, so the dependencies' own mix.exs files are not reported as projects. Adds elixir.toml to BUNDLED, match and nomatch fixtures, the README table row, and a line in RULE-SCHEMA.md that new files go in BUNDLED (bundled_rules_match_the_rules_folder fails otherwise). Co-Authored-By: Claude Opus 5.5 --- README.md | 1 + docs/RULE-SCHEMA.md | 2 ++ .../tests/snapshots/rules-check.json | 4 ++-- engine/crates/opensweep-core/src/rules.rs | 1 + engine/rules/elixir.toml | 21 +++++++++++++++++++ .../elixir/match/app/_build/dev/lib/.keep | 0 .../elixir/match/app/deps/jason/mix.exs | 0 .../fixtures/elixir/match/app/expected.txt | 2 ++ .../fixtures/elixir/match/app/lib/app.ex | 0 .../rules/fixtures/elixir/match/app/mix.exs | 0 .../elixir/nomatch/no-mix-file/README.md | 0 .../elixir/nomatch/no-mix-file/_build/.keep | 0 .../elixir/nomatch/no-mix-file/deps/.keep | 0 13 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 engine/rules/elixir.toml create mode 100644 engine/rules/fixtures/elixir/match/app/_build/dev/lib/.keep create mode 100644 engine/rules/fixtures/elixir/match/app/deps/jason/mix.exs create mode 100644 engine/rules/fixtures/elixir/match/app/expected.txt create mode 100644 engine/rules/fixtures/elixir/match/app/lib/app.ex create mode 100644 engine/rules/fixtures/elixir/match/app/mix.exs create mode 100644 engine/rules/fixtures/elixir/nomatch/no-mix-file/README.md create mode 100644 engine/rules/fixtures/elixir/nomatch/no-mix-file/_build/.keep create mode 100644 engine/rules/fixtures/elixir/nomatch/no-mix-file/deps/.keep diff --git a/README.md b/README.md index 727d960..d525415 100644 --- a/README.md +++ b/README.md @@ -192,6 +192,7 @@ project runs again, so they are never ticked for you. | Swift Package Manager | `.build` | | | Xcode (CocoaPods) | | `Pods` | | .NET | `bin` `obj` | | +| Elixir (Mix) | `_build` | `deps` | | PHP (Composer) | | `vendor` | Add your own rules in `~/Library/Application Support/OpenSweep/rules`, or keep a diff --git a/docs/RULE-SCHEMA.md b/docs/RULE-SCHEMA.md index 785f208..8f8a744 100644 --- a/docs/RULE-SCHEMA.md +++ b/docs/RULE-SCHEMA.md @@ -106,6 +106,8 @@ rules. ## Contributing a rule 1. Add or edit a file in `engine/rules/`, with match and nomatch fixtures. + A new file also goes in `BUNDLED` in `opensweep-core/src/rules.rs`, which + builds the catalogue into the binary. 2. Run `cargo run -p opensweep-cli -- rules-check rules` and `cargo test`. 3. In the pull request, link the tool's documentation that says the path is generated. Rule changes need two reviewers. diff --git a/engine/crates/opensweep-cli/tests/snapshots/rules-check.json b/engine/crates/opensweep-cli/tests/snapshots/rules-check.json index 1fa6d40..1e5e20d 100644 --- a/engine/crates/opensweep-cli/tests/snapshots/rules-check.json +++ b/engine/crates/opensweep-cli/tests/snapshots/rules-check.json @@ -1,8 +1,8 @@ [ { - "artifacts": 32, + "artifacts": 34, "command": "rules-check", - "rule_files": 11, + "rule_files": 12, "schema_version": 1 } ] diff --git a/engine/crates/opensweep-core/src/rules.rs b/engine/crates/opensweep-core/src/rules.rs index 1cf36f7..0b11f6c 100644 --- a/engine/crates/opensweep-core/src/rules.rs +++ b/engine/crates/opensweep-core/src/rules.rs @@ -577,6 +577,7 @@ pub fn load_dir(dir: &Path) -> Result, RuleError> { const BUNDLED: &[(&str, &str)] = &[ ("android.toml", include_str!("../../../rules/android.toml")), ("dotnet.toml", include_str!("../../../rules/dotnet.toml")), + ("elixir.toml", include_str!("../../../rules/elixir.toml")), ("flutter.toml", include_str!("../../../rules/flutter.toml")), ("go.toml", include_str!("../../../rules/go.toml")), ("java.toml", include_str!("../../../rules/java.toml")), diff --git a/engine/rules/elixir.toml b/engine/rules/elixir.toml new file mode 100644 index 0000000..4f658a3 --- /dev/null +++ b/engine/rules/elixir.toml @@ -0,0 +1,21 @@ +schema = 2 +id = "elixir" +name = "Elixir (Mix)" + +# Defaults from https://hexdocs.pm/mix/Mix.Project.html: build_path +# "defaults to _build" and deps_path "Defaults to deps". An umbrella's apps +# share the umbrella's folders, so only the top mix.exs has them. +[detect] +any_files = ["mix.exs"] + +[[artifact]] +path = "_build" +class = "safe" +reason = "Mix build output. Recreated by the next compile." +restore = "mix compile" + +[[artifact]] +path = "deps" +class = "caution" +reason = "Mix dependencies. Fetch them again from mix.lock." +restore = "mix deps.get" diff --git a/engine/rules/fixtures/elixir/match/app/_build/dev/lib/.keep b/engine/rules/fixtures/elixir/match/app/_build/dev/lib/.keep new file mode 100644 index 0000000..e69de29 diff --git a/engine/rules/fixtures/elixir/match/app/deps/jason/mix.exs b/engine/rules/fixtures/elixir/match/app/deps/jason/mix.exs new file mode 100644 index 0000000..e69de29 diff --git a/engine/rules/fixtures/elixir/match/app/expected.txt b/engine/rules/fixtures/elixir/match/app/expected.txt new file mode 100644 index 0000000..0304f65 --- /dev/null +++ b/engine/rules/fixtures/elixir/match/app/expected.txt @@ -0,0 +1,2 @@ +_build +deps diff --git a/engine/rules/fixtures/elixir/match/app/lib/app.ex b/engine/rules/fixtures/elixir/match/app/lib/app.ex new file mode 100644 index 0000000..e69de29 diff --git a/engine/rules/fixtures/elixir/match/app/mix.exs b/engine/rules/fixtures/elixir/match/app/mix.exs new file mode 100644 index 0000000..e69de29 diff --git a/engine/rules/fixtures/elixir/nomatch/no-mix-file/README.md b/engine/rules/fixtures/elixir/nomatch/no-mix-file/README.md new file mode 100644 index 0000000..e69de29 diff --git a/engine/rules/fixtures/elixir/nomatch/no-mix-file/_build/.keep b/engine/rules/fixtures/elixir/nomatch/no-mix-file/_build/.keep new file mode 100644 index 0000000..e69de29 diff --git a/engine/rules/fixtures/elixir/nomatch/no-mix-file/deps/.keep b/engine/rules/fixtures/elixir/nomatch/no-mix-file/deps/.keep new file mode 100644 index 0000000..e69de29