Skip to content

Commit

Permalink
chore: remove formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
oxcabe committed Apr 16, 2024
1 parent 05c3a4e commit 17f3ac6
Showing 1 changed file with 337 additions and 0 deletions.
337 changes: 337 additions & 0 deletions modules/hooks.nix
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ in

# PLEASE keep this sorted alphabetically.
options.hooks = rec
<<<<<<< Updated upstream
{
alejandra = mkOption {
description = lib.mdDoc "alejandra hook";
Expand All @@ -86,6 +87,56 @@ in
description = lib.mdDoc "Check if the input is already formatted and disable writing in-place the modified content";
default = false;
example = true;
=======
{
alejandra = mkOption {
description = lib.mdDoc "alejandra hook";
type = types.submodule {
imports = [ hookModule ];
options.settings = {
check =
mkOption {
type = types.bool;
description = lib.mdDoc "Check if the input is already formatted and disable writing in-place the modified content";
default = false;
example = true;
};
exclude =
mkOption {
type = types.listOf types.str;
description = lib.mdDoc "Files or directories to exclude from formatting.";
default = [ ];
example = [ "flake.nix" "./templates" ];
};
threads =
mkOption {
type = types.nullOr types.int;
description = lib.mdDoc "Number of formatting threads to spawn.";
default = null;
example = 8;
};
verbosity =
mkOption {
type = types.enum [ "normal" "quiet" "silent" ];
description = lib.mdDoc "Whether informational messages or all messages should be hidden or not.";
default = "normal";
example = "quiet";
};
};
};
};
ansible-lint = mkOption {
description = lib.mdDoc "ansible-lint hook";
type = types.submodule {
imports = [ hookModule ];
options.settings = {
configPath = mkOption {
type = types.str;
description = lib.mdDoc "Path to the YAML configuration file.";
# an empty string translates to use default configuration of the
# underlying ansible-lint binary
default = "";
>>>>>>> Stashed changes
};
exclude =
mkOption {
Expand Down Expand Up @@ -684,6 +735,7 @@ in
};
};
};
<<<<<<< Updated upstream
};
mdl = mkOption {
description = lib.mdDoc "mdl hook";
Expand All @@ -701,6 +753,26 @@ in
type = types.bool;
description = lib.mdDoc "Only process files known to git when given a directory.";
default = false;
=======
rome = biome;
rustfmt = mkOption {
description = lib.mdDoc ''
Additional rustfmt settings
Override the `rustfmt` and `cargo` packages by setting `hooks.rustfmt.packageOverrides`.
```
hooks.rustfmt.packageOverrides.cargo = pkgs.cargo;
hooks.rustfmt.packageOverrides.rustfmt = pkgs.rustfmt;
```
'';
type = types.submodule {
imports = [ hookModule ];
options.packageOverrides = {
cargo = mkOption {
type = types.package;
description = lib.mdDoc "The cargo package to use.";
>>>>>>> Stashed changes
};
ignore-front-matter =
mkOption {
Expand Down Expand Up @@ -1203,6 +1275,7 @@ in
};
};
};
<<<<<<< Updated upstream
psalm = mkOption {
description = lib.mdDoc "psalm hook";
type = types.submodule {
Expand All @@ -1217,6 +1290,220 @@ in
"''${tools.psalm}/bin/psalm"
'';
};
=======

# PLEASE keep this sorted alphabetically.
config.hooks = mapAttrs (_: mapAttrs (_: mkDefault)) rec
{
actionlint =
{
name = "actionlint";
description = "Static checker for GitHub Actions workflow files";
files = "^.github/workflows/";
types = [ "yaml" ];
package = tools.actionlint;
entry = "${hooks.actionlint.package}/bin/actionlint";
};
alejandra =
{
name = "alejandra";
description = "The Uncompromising Nix Code Formatter";
package = tools.alejandra;
entry =
let
cmdArgs =
mkCmdArgs (with hooks.alejandra.settings; [
[ check "--check" ]
[ (exclude != [ ]) "--exclude ${lib.escapeShellArgs (lib.unique exclude)}" ]
[ (verbosity == "quiet") "-q" ]
[ (verbosity == "silent") "-qq" ]
[ (threads != null) "--threads ${toString threads}" ]
]);
in
"${hooks.alejandra.package}/bin/alejandra ${cmdArgs}";
files = "\\.nix$";
};
annex =
{
name = "annex";
description = "Runs the git-annex hook for large file support";
package = tools.git-annex;
entry = "${hooks.annex.package}/bin/git-annex pre-commit";
};
ansible-lint =
{
name = "ansible-lint";
description = "Ansible linter";
package = tools.ansible-lint;
entry =
let
cmdArgs =
mkCmdArgs [
[ (hooks.ansible-lint.settings.configPath != "") "-c ${hooks.ansible-lint.settings.configPath}" ]
];
in
"${hooks.ansible-lint.package}/bin/ansible-lint ${cmdArgs}";
files = if hooks.ansible-lint.settings.subdir != "" then "${hooks.ansible-lint.settings.subdir}/" else "";
};
autoflake =
{
name = "autoflake";
description = "Remove unused imports and variables from Python code";

package = tools.autoflake;
entry =
let
binPath = migrateBinPathToPackage hooks.autoflake "/bin/autoflake";
in
"${binPath} ${hooks.autoflake.settings.flags}";
types = [ "python" ];
};
biome =
{
name = "biome";
description = "A toolchain for web projects, aimed to provide functionalities to maintain them";
types_or = [ "javascript" "jsx" "ts" "tsx" "json" ];

package = tools.biome;
entry =
let
binPath = migrateBinPathToPackage hooks.biome "/bin/biome";
cmdArgs =
mkCmdArgs [
[ (hooks.biome.settings.write) "--apply" ]
[ (hooks.biome.settings.configPath != "") "--config-path ${hooks.biome.settings.configPath}" ]
];
in
"${binPath} check ${cmdArgs}";
};
bats =
{
name = "bats";
description = "Run bash unit tests";
types = [ "shell" ];
types_or = [ "bats" "bash" ];
package = tools.bats;
entry = "${hooks.bats.package}/bin/bats -p";
};
beautysh =
{
name = "beautysh";
description = "Format shell files";
types = [ "shell" ];
package = tools.beautysh;
entry = "${hooks.beautysh.package}/bin/beautysh";
};
black =
{
name = "black";
description = "The uncompromising Python code formatter";
package = tools.black;
entry = "${hooks.black.package}/bin/black ${hooks.black.settings.flags}";
types = [ "file" "python" ];
};
cabal-fmt =
{
name = "cabal-fmt";
description = "Format Cabal files";
package = tools.cabal-fmt;
entry = "${hooks.cabal-fmt.package}/bin/cabal-fmt --inplace";
files = "\\.cabal$";
};
cabal2nix =
{
name = "cabal2nix";
description = "Run `cabal2nix` on all `*.cabal` files to generate corresponding `default.nix` files";
package = tools.cabal2nix-dir;
entry = "${hooks.cabal2nix.package}/bin/cabal2nix-dir";
files = "\\.cabal$";
};
cargo-check =
{
name = "cargo-check";
description = "Check the cargo package for errors";
package = tools.cargo;
entry = "${hooks.cargo-check.package}/bin/cargo check ${cargoManifestPathArg}";
files = "\\.rs$";
pass_filenames = false;
};
checkmake = {
name = "checkmake";
description = "Experimental linter/analyzer for Makefiles";
types = [ "makefile" ];
package = tools.checkmake;
entry =
## NOTE: `checkmake` 0.2.2 landed in nixpkgs on 12 April 2023. Once
## this gets into a NixOS release, the following code will be useless.
lib.throwIf
(hooks.checkmake.package == null)
"The version of nixpkgs used by pre-commit-hooks.nix must have `checkmake` in version at least 0.2.2 for it to work on non-Linux systems."
"${hooks.checkmake.package}/bin/checkmake";
};
check-added-large-files =
{
name = "check-added-large-files";
description = "Prevent very large files to be committed (e.g. binaries).";
package = tools.pre-commit-hooks;
entry = "${hooks.check-added-large-files.package}/bin/check-added-large-files";
stages = [ "commit" "push" "manual" ];
};
check-builtin-literals =
{
name = "check-builtin-literals";
description = "Require literal syntax when initializing empty or zero builtin types in Python.";
package = tools.pre-commit-hooks;
entry = "${hooks.check-builtin-literals.package}/bin/check-builtin-literals";
types = [ "python" ];
};
check-case-conflicts =
{
name = "check-case-conflicts";
description = "Check for files that would conflict in case-insensitive filesystems.";
package = tools.pre-commit-hooks;
entry = "${hooks.check-case-conflicts.package}/bin/check-case-conflict";
types = [ "file" ];
};
check-docstring-first =
{
name = "check-docstring-above";
description = "Check that all docstrings appear above the code.";
package = tools.pre-commit-hooks;
entry = "${hooks.check-docstring-first.package}/bin/check-docstring-first";
types = [ "python" ];
};
check-executables-have-shebangs =
{
name = "check-executables-have-shebangs";
description = "Ensure that all non-binary executables have shebangs.";
package = tools.pre-commit-hooks;
entry = "${hooks.check-executables-have-shebangs.package}/bin/check-executables-have-shebangs";
types = [ "text" "executable" ];
stages = [ "commit" "push" "manual" ];
};
check-json =
{
name = "check-json";
description = "Check syntax of JSON files.";
package = tools.pre-commit-hooks;
entry = "${hooks.check-json.package}/bin/check-json";
types = [ "json" ];
};
check-merge-conflicts =
{
name = "check-merge-conflicts";
description = "Check for files that contain merge conflict strings.";
package = tools.pre-commit-hooks;
entry = "${hooks.check-merge-conflicts.package}/bin/check-merge-conflict";
types = [ "text" ];
};
check-python =
{
name = "check-python";
description = "Check syntax of Python file by parsing Python abstract syntax tree.";
package = tools.pre-commit-hooks;
entry = "${hooks.check-python.package}/bin/check-ast";
types = [ "python" ];
>>>>>>> Stashed changes
};
};
};
Expand Down Expand Up @@ -3304,6 +3591,56 @@ lib.escapeShellArgs (lib.concatMap (ext: [ "--ghc-opt" "-X${ext}" ]) hooks.ormol
''
exec treefmt "$@"
'';
<<<<<<< Updated upstream
=======
in
builtins.toString script;
files = "\\.go$";
# to avoid multiple invocations of the same directory input, provide
# all file names in a single run.
require_serial = true;
};
ripsecrets =
{
name = "ripsecrets";
description = "Prevent committing secret keys into your source code";
package = tools.ripsecrets;
entry =
let
cmdArgs = mkCmdArgs (
with hooks.ripsecrets.settings; [
[ true "--strict-ignore" ]
[
(additionalPatterns != [ ])
"--additional-pattern ${lib.strings.concatStringsSep " --additional-pattern " additionalPatterns}"
]
]
);
in
"${hooks.ripsecrets.package}/bin/ripsecrets ${cmdArgs}";
types = [ "text" ];
};
rome = biome;
ruff =
{
name = "ruff";
description = "An extremely fast Python linter, written in Rust.";
package = tools.ruff;
entry = "${hooks.ruff.package}/bin/ruff --fix";
types = [ "python" ];
};
rustfmt =
let
inherit (hooks.rustfmt) packageOverrides;
wrapper = pkgs.symlinkJoin {
name = "rustfmt-wrapped";
paths = [ packageOverrides.rustfmt ];
nativeBuildInputs = [ pkgs.makeWrapper ];
postBuild = ''
wrapProgram $out/bin/cargo-fmt \
--prefix PATH : ${lib.makeBinPath [ packageOverrides.cargo packageOverrides.rustfmt ]}
'';
>>>>>>> Stashed changes
};
in
{
Expand Down

0 comments on commit 17f3ac6

Please sign in to comment.