refactor(dotfiles): share Nix file discovery #101
@@ -17,6 +17,15 @@ If the target includes multiple matching file types, use all matching skills.
|
||||
If the target is a diff, choose skills from the changed files.
|
||||
Do not use a style skill when no reviewed file matches it.
|
||||
|
||||
For every reviewed `*.nix` file, run:
|
||||
|
||||
```bash
|
||||
bazel run //src/natu:natu -- <reviewed-nix-paths>
|
||||
```
|
||||
|
||||
Pass every reviewed Nix path to Natu.
|
||||
Report every Natu diagnostic as an actionable finding.
|
||||
|
||||
Report only actionable findings.
|
||||
Order findings by severity.
|
||||
Do not report preferences unless a loaded rule states them.
|
||||
@@ -36,6 +45,7 @@ Keep the code excerpt to one to three lines when possible.
|
||||
Use a longer excerpt only when the violation needs surrounding context.
|
||||
Use `...` to omit unrelated lines from a multi-line excerpt.
|
||||
Use a style-skill rule citation in the form `skill::rule-file:line`.
|
||||
Cite Natu diagnostics as `natu::<rule-id>`.
|
||||
Make the fix direct.
|
||||
Do not include alternatives when one fix best follows the cited rule.
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ let
|
||||
util = import ./util.nix { inherit lib; };
|
||||
|
||||
registry = import ./registry.nix {
|
||||
inherit lib;
|
||||
inherit lib util;
|
||||
hosts = self.nixosConfigurations;
|
||||
root = root + "/registry";
|
||||
};
|
||||
|
||||
@@ -276,10 +276,7 @@ let
|
||||
};
|
||||
};
|
||||
|
||||
names = map (file: lib.removeSuffix ".nix" file) (lib.attrNames guestFiles);
|
||||
guestFiles = lib.filterAttrs (file: type: type == "regular" && lib.hasSuffix ".nix" file) (
|
||||
builtins.readDir root
|
||||
);
|
||||
names = map (path: lib.removeSuffix ".nix" (builtins.baseNameOf path)) files;
|
||||
in
|
||||
{
|
||||
imports = files ++ map mkGuest names;
|
||||
|
||||
@@ -2,20 +2,14 @@
|
||||
hosts,
|
||||
lib,
|
||||
root,
|
||||
util,
|
||||
}:
|
||||
let
|
||||
definitions =
|
||||
lib.mapAttrs'
|
||||
(
|
||||
name: _type:
|
||||
let
|
||||
path = root + "/${name}";
|
||||
in
|
||||
lib.nameValuePair (registryName name) (mkRegistry path)
|
||||
)
|
||||
(
|
||||
lib.filterAttrs (name: type: type == "regular" && lib.hasSuffix ".nix" name) (builtins.readDir root)
|
||||
);
|
||||
definitions = lib.listToAttrs (
|
||||
map (path: lib.nameValuePair (registryName (builtins.baseNameOf path)) (mkRegistry path)) (
|
||||
util.collectNixFiles root
|
||||
)
|
||||
);
|
||||
|
||||
registryName = fileName: lib.removeSuffix ".nix" fileName;
|
||||
|
||||
|
||||
12
src/skills/style/nix/rules/general.md
Normal file
12
src/skills/style/nix/rules/general.md
Normal file
@@ -0,0 +1,12 @@
|
||||
## Discover Nix files
|
||||
|
||||
### Rule
|
||||
|
||||
Use `util.collectNixFiles` to discover Nix files.
|
||||
Do not use `builtins.readDir` with a `.nix` suffix filter for this purpose.
|
||||
Pass `util` to Nix functions that need the helper.
|
||||
|
||||
### Rationale
|
||||
|
||||
`util.collectNixFiles` centralizes recursive discovery of Nix files.
|
||||
Repository Nix code uses one implementation.
|
||||
Reference in New Issue
Block a user