Skip to content

Commit

Permalink
Merge pull request #1063 from jpverde/main
Browse files Browse the repository at this point in the history
refac(back): #1055 update lintnix
  • Loading branch information
dsalaza4 authored Mar 30, 2023
2 parents aaf3deb + cddef8f commit c6c19e4
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 36 deletions.
2 changes: 1 addition & 1 deletion docs/src/api/builtins/lint.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ Example:

## lintNix

Lints Nix code with [nix-linter](https://github.com/Synthetica9/nix-linter).
Lints Nix code with [statix](https://github.com/nerdypepper/statix).

Types:

Expand Down
1 change: 1 addition & 0 deletions src/args/agnostic.nix
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
lintGitCommitMsg = import ./lint-git-commit-msg/default.nix self;
lintGitMailMap = import ./lint-git-mailmap/default.nix self;
lintMarkdown = import ./lint-markdown/default.nix self;
lintNix = import ./lint-nix/default.nix self;
lintPython = import ./lint-python/default.nix self;
lintPythonImports = import ./lint-python-imports/default.nix self;
lintTerraform = import ./lint-terraform/default.nix self;
Expand Down
21 changes: 21 additions & 0 deletions src/args/lint-nix/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
__nixpkgs__,
toBashArray,
makeScript,
...
}: {
name,
targets,
...
}: makeScript {
replace = {
__argTargets__ = toBashArray targets;
};
name = "lint-nix-for-${name}";
searchPaths = {
bin = [
__nixpkgs__.statix
];
};
entrypoint = ./entrypoint.sh;
}
19 changes: 19 additions & 0 deletions src/args/lint-nix/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# shellcheck shell=bash

function main {
export LANG=C.UTF-8
source __argTargets__/template local targets

info Linting Nix code \
&& for target in "${targets[@]}"; do
info Linting "${target}" \
&& if ! statix check "${args[@]}" "${target}"; then
info Source code is being fixed, the job will fail \
&& statix fix "${args[@]}" "${target}" \
&& error Failing as promissed...
fi \
|| return 1
done
}

main "${@}"
16 changes: 0 additions & 16 deletions src/evaluator/modules/lint-nix/builder.sh

This file was deleted.

23 changes: 4 additions & 19 deletions src/evaluator/modules/lint-nix/default.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
__nixpkgs__,
toBashArray,
makeDerivation,
projectPath,
lintNix,
...
}: {
config,
Expand All @@ -23,21 +20,9 @@
};
config = {
outputs = {
"/lintNix" = lib.mkIf config.lintNix.enable (makeDerivation {
env = {
envTargets =
toBashArray
(builtins.map
projectPath
config.lintNix.targets);
};
name = "lint-nix";
searchPaths = {
bin = [
__nixpkgs__.statix
];
};
builder = ./builder.sh;
"/lintNix" = lib.mkIf config.lintNix.enable (lintNix {
name = "builtin";
targets = builtins.map (rel: "." + rel) config.lintNix.targets;
});
};
};
Expand Down

0 comments on commit c6c19e4

Please sign in to comment.