Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refac(doc): #1055 use statix #1056

Merged
merged 1 commit into from
Mar 17, 2023
Merged
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
22 changes: 11 additions & 11 deletions src/args/agnostic.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@
deployContainerImage = import ./deploy-container-image/default.nix self;
deployNomad = import ./deploy-nomad/default.nix self;
deployTerraform = import ./deploy-terraform/default.nix self;
escapeShellArg = self.__nixpkgs__.lib.strings.escapeShellArg;
escapeShellArgs = self.__nixpkgs__.lib.strings.escapeShellArgs;
fakeSha256 = self.__nixpkgs__.lib.fakeSha256;
inherit (self.__nixpkgs__.lib.strings) escapeShellArg;
inherit (self.__nixpkgs__.lib.strings) escapeShellArgs;
inherit (self.__nixpkgs__.lib) fakeSha256;
fetchArchive = import ./fetch-archive/default.nix self;
fetchGithub = import ./fetch-github/default.nix self;
fetchGitlab = import ./fetch-gitlab/default.nix self;
fetchNixpkgs = import ./fetch-nixpkgs/default.nix self;
fetchRubyGem = import ./fetch-rubygem/default.nix self;
fetchUrl = import ./fetch-url/default.nix self;
filterAttrs = self.__nixpkgs__.lib.filterAttrs;
flatten = self.__nixpkgs__.lib.lists.flatten;
inherit (self.__nixpkgs__.lib) filterAttrs;
inherit (self.__nixpkgs__.lib.lists) flatten;
formatBash = import ./format-bash/default.nix self;
formatNix = import ./format-nix/default.nix self;
formatTerraform = import ./format-terraform/default.nix self;
Expand All @@ -50,10 +50,10 @@
fromYaml = import ./from-yaml/default.nix self;
fromYamlFile = path: self.fromYaml (builtins.readFile path);
gitlabCi = import ./gitlab-ci/default.nix;
hasPrefix = self.__nixpkgs__.lib.strings.hasPrefix;
hasSuffix = self.__nixpkgs__.lib.strings.hasSuffix;
isDarwin = self.__nixpkgs__.stdenv.isDarwin;
isLinux = self.__nixpkgs__.stdenv.isLinux;
inherit (self.__nixpkgs__.lib.strings) hasPrefix;
inherit (self.__nixpkgs__.lib.strings) hasSuffix;
inherit (self.__nixpkgs__.stdenv) isDarwin;
inherit (self.__nixpkgs__.stdenv) isLinux;
libGit = import ./lib-git/default.nix self;
listOptional = self.__nixpkgs__.lib.lists.optional;
lintClojure = import ./lint-clojure/default.nix self;
Expand All @@ -65,7 +65,7 @@
lintTerraform = import ./lint-terraform/default.nix self;
lintWithAjv = import ./lint-with-ajv/default.nix self;
lintWithLizard = import ./lint-with-lizard/default.nix self;
listFilesRecursive = self.__nixpkgs__.lib.filesystem.listFilesRecursive;
inherit (self.__nixpkgs__.lib.filesystem) listFilesRecursive;
makeContainerImage = import ./make-container-image/default.nix self;
makeDerivation = import ./make-derivation/default.nix self;
makeDerivationParallel = import ./make-derivation-parallel/default.nix self;
Expand Down Expand Up @@ -97,7 +97,7 @@
makeWorkspaceForTerraformFromEnv = import ./make-workspace-for-terraform-from-env/default.nix self;
managePorts = import ./manage-ports/default.nix self;
patchShebangs = import ./patch-shebangs/default.nix self;
removePrefix = self.__nixpkgs__.lib.removePrefix;
inherit (self.__nixpkgs__.lib) removePrefix;
secureKubernetesWithRbacPolice = import ./secure-kubernetes-with-rbac-police/default.nix self;
securePythonWithBandit = import ./secure-python-with-bandit/default.nix self;
sortAscii = builtins.sort (a: b: a < b);
Expand Down
4 changes: 2 additions & 2 deletions src/args/chunks/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
sublist,
...
}: list: n: let
lib = __nixpkgs__.lib;
inherit (__nixpkgs__) lib;

len = lib.lists.length list;
div = len / n;
mod = lib.trivial.mod len n;
range = lib.lists.range 0 (n - 1);
min = lib.trivial.min;
inherit (lib.trivial) min;
startIndex = i: i * div + (min i mod);
endIndex = i: (i + 1) * div + (min (i + 1) mod);
in
Expand Down
7 changes: 3 additions & 4 deletions src/args/make-node-js-modules/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
packageLockJson,
searchPaths ? {},
shouldIgnoreScripts ? false,
}:
let
}: let
nodeJs = makeNodeJsVersion nodeJsVersion;
packageLock = fromJsonFile packageLockJson;

Expand Down Expand Up @@ -57,7 +56,7 @@ let
// (attrsGet packageLock "devDependencies" {})
);
dependenciesGrouped =
__nixpkgs__.lib.lists.groupBy
builtins.groupBy
(dep: dep.name)
dependenciesFlat;

Expand All @@ -77,7 +76,7 @@ let
dist.tarball = versionAttrs.resolvedName;
};
})
(dependenciesGrouped.${name}));
dependenciesGrouped.${name});
};
})
(builtins.attrNames dependenciesGrouped);
Expand Down
6 changes: 3 additions & 3 deletions src/args/make-python-pypi-environment/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ assert builtins.any (_: _) [
url = "https://files.pythonhosted.org/packages/ec/30/8707699ea6e1c1cbe79c37e91f5b06a6266de24f699a5e19b8c0a63c4b65/Cython-0.29.24-py2.py3-none-any.whl";
}
];
python = sources.python;
inherit (sources) python;
};
}))
(listOptional withNumpy_1_24_0 (makePythonPypiEnvironment {
Expand All @@ -83,7 +83,7 @@ assert builtins.any (_: _) [
url = "https://pypi.org/packages/py2.py3/w/wheel/wheel-0.37.0-py2.py3-none-any.whl";
}
];
python = sources.python;
inherit (sources) python;
};
}))
];
Expand All @@ -108,7 +108,7 @@ assert builtins.any (_: _) [
};
})
(builtins.concatLists [
(sources.links)
sources.links
(listOptional withSetuptools_57_4_0 {
name = "setuptools-57.4.0-py3-none-any.whl";
sha256 = "1mhq6jw21sglccqmimydqi2rjvh3g5xjykb16gcvkkx6gabk14m4";
Expand Down
2 changes: 1 addition & 1 deletion src/args/make-ruby-gems-install/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
rubyGem: let
gem = fetchRubyGem rubyGem;
in {
name = gem.name;
inherit (gem) name;
path = gem;
}
)
Expand Down
2 changes: 1 addition & 1 deletion src/args/string-capitalize/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{__nixpkgs__, ...}: str: let
lib = __nixpkgs__.lib;
inherit (__nixpkgs__) lib;
head = lib.strings.toUpper (builtins.substring 0 1 str);
tail = builtins.concatStringsSep "" (
builtins.tail (lib.stringToCharacters str)
Expand Down
2 changes: 1 addition & 1 deletion src/args/sublist/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{__nixpkgs__, ...}: list: start: end: let
lib = __nixpkgs__.lib;
inherit (__nixpkgs__) lib;

range = lib.lists.range start (end - 1);
in
Expand Down
4 changes: 2 additions & 2 deletions src/evaluator/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@

args = import "${makesSrcOverriden}/src/args/default.nix" {
inputs = flakeInputs // result.config.inputs;
outputs = result.config.outputs;
projectIdentifier = result.config.projectIdentifier;
inherit (result.config) outputs;
inherit (result.config) projectIdentifier;
inherit projectSrc;
stateDirs = {
global = result.config.globalStateDir;
Expand Down
4 changes: 2 additions & 2 deletions src/evaluator/modules/calculate-scorecard/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
if config.calculateScorecard.checks == []
then config.calculateScorecard.checks
else builtins.concatStringsSep "," config.calculateScorecard.checks;
format = config.calculateScorecard.format;
target = config.calculateScorecard.target;
inherit (config.calculateScorecard) format;
inherit (config.calculateScorecard) target;
}
);
};
Expand Down
4 changes: 2 additions & 2 deletions src/evaluator/modules/lint-git-commit-msg/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
outputs = {
"/lintGitCommitMsg" =
lib.mkIf
(config.lintGitCommitMsg.enable)
config.lintGitCommitMsg.enable
(lintGitCommitMsg {
branch = config.lintGitCommitMsg.branch;
inherit (config.lintGitCommitMsg) branch;
config =
if config.lintGitCommitMsg.config == null
then ./config.js
Expand Down
2 changes: 1 addition & 1 deletion src/evaluator/modules/lint-git-mailmap/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
outputs = {
"/lintGitMailMap" =
lib.mkIf
(config.lintGitMailMap.enable)
config.lintGitMailMap.enable
(lintGitMailMap {
name = "lint-git-mailmap";
src = ".";
Expand Down
25 changes: 1 addition & 24 deletions src/evaluator/modules/lint-nix/builder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,11 @@
function main {
export LANG=C.UTF-8
source "${envTargets}/template" local targets
local args=(
# --check=AlphabeticalArgs
# --check=AlphabeticalBindings
--check=BetaReduction
--check=DIYInherit
--check=EmptyVariadicParamSet
--check=EmptyInherit
--check=EmptyLet
--check=EtaReduce
--check=FreeLetInFunc
--check=LetInInheritRecset
--check=ListLiteralConcat
--check=NegateAtom
--check=SequentialLet
--check=SetLiteralUpdate
--check=UnfortunateArgName
--check=UnneededAntiquote
--check=UnneededRec
--check=UnusedArg
--check=UnusedLetBind
--check=UpdateEmptySet
--recursive
)

info Linting Nix code \
&& for target in "${targets[@]}"; do
info Linting "${target}" \
&& nix-linter "${args[@]}" "${target}" \
&& statix check "${args[@]}" "${target}" \
|| return 1
done \
&& touch "${out}"
Expand Down
2 changes: 1 addition & 1 deletion src/evaluator/modules/lint-nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
name = "lint-nix";
searchPaths = {
bin = [
__nixpkgs__.nix-linter
__nixpkgs__.statix
];
};
builder = ./builder.sh;
Expand Down
14 changes: 8 additions & 6 deletions src/evaluator/modules/lint-python/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,18 @@
builtins.map
(moduleName: {
name = "/lintPython/dirOfModules/${name}/${moduleName}";
value =
(makeModule moduleName {
inherit
((makeModule moduleName {
inherit searchPaths;
inherit python;
src = "${src}/${moduleName}";
})
.value;
}))
value
;
})
(projectPathLsDirs src);
in (modules
in
modules
++ [
{
name = "/lintPython/dirOfModules/${name}";
Expand All @@ -66,7 +68,7 @@
name = "lint-python-dir-of-modules-for-${name}";
};
}
]);
];
in {
options = {
lintPython = {
Expand Down
23 changes: 12 additions & 11 deletions src/nix/sources.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@ let

fetch_git = name: spec: let
ref =
if spec ? ref
then spec.ref
else if spec ? branch
then "refs/heads/${spec.branch}"
else if spec ? tag
then "refs/tags/${spec.tag}"
else abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!";
spec.ref
or (
if spec ? branch
then "refs/heads/${spec.branch}"
else if spec ? tag
then "refs/tags/${spec.tag}"
else abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!"
);
in
builtins.fetchGit {
url = spec.repo;
Expand Down Expand Up @@ -119,7 +120,7 @@ let
# the path directly as opposed to the fetched source.
replace = name: let
saneName = stringAsChars (c:
if isNull (builtins.match "[a-zA-Z0-9]" c)
if ((builtins.match "[a-zA-Z0-9]" c) == null)
then "_"
else c)
name;
Expand Down Expand Up @@ -178,7 +179,7 @@ let
inherit (builtins) lessThan nixVersion fetchTarball;
in
if lessThan nixVersion "1.12"
then fetchTarball ({inherit url;} // (optionalAttrs (!isNull name) {inherit name;}))
then fetchTarball ({inherit url;} // (optionalAttrs (name != null) {inherit name;}))
else fetchTarball attrs;

# fetchurl version that is compatible between all the versions of Nix
Expand All @@ -190,7 +191,7 @@ let
inherit (builtins) lessThan nixVersion fetchurl;
in
if lessThan nixVersion "1.12"
then fetchurl ({inherit url;} // (optionalAttrs (!isNull name) {inherit name;}))
then fetchurl ({inherit url;} // (optionalAttrs (name != null) {inherit name;}))
else fetchurl attrs;

# Create the final "sources" from the config
Expand All @@ -213,7 +214,7 @@ let
then ./sources.json
else null,
sources ?
if isNull sourcesFile
if (sourcesFile == null)
then {}
else builtins.fromJSON (builtins.readFile sourcesFile),
system ? builtins.currentSystem,
Expand Down