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

feat: create "biome" hook, preserve "rome" hook as alias #432

Merged
merged 7 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,11 @@ clang-format supports.

### JavaScript/TypeScript

- [biome](https://biomejs.dev/)
- denofmt: Runs `deno fmt`
- denolint: Runs `deno lint`
- [eslint](https://github.com/eslint/eslint)
- [rome](https://github.com/rome/tools)
- rome: (alias to the biome hook)

### Python

Expand Down
103 changes: 53 additions & 50 deletions modules/hooks.nix
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ in
"vale" = [ "configPath" "flags" ];
"yamllint" = [ "configPath" ];
})
# Rename `rome` hook to `biome`, since `biome` was being used in both hooks
++ [ (mkRenamedOptionModule [ "settings" "rome" ] [ "hooks" "biome" "settings" ]) ]
# Rename the remaining `settings.<name>` to `hooks.<name>.settings`
++ map (name: mkRenamedOptionModule [ "settings" name ] [ "hooks" name "settings" ])
[ "ansible-lint" "autoflake" "clippy" "cmake-format" "credo" "deadnix" "denofmt" "denolint" "dune-fmt" "eslint" "flake8" "headache" "hlint" "hpack" "isort" "latexindent" "lychee" "mkdocs-linkcheck" "mypy" "nixfmt" "ormolu" "php-cs-fixer" "phpcbf" "phpcs" "phpstan" "prettier" "psalm" "pylint" "pyright" "pyupgrade" "revive" "rome" "statix" ];
[ "ansible-lint" "autoflake" "biome" "clippy" "cmake-format" "credo" "deadnix" "denofmt" "denolint" "dune-fmt" "eslint" "flake8" "headache" "hlint" "hpack" "isort" "latexindent" "lychee" "mkdocs-linkcheck" "mypy" "nixfmt" "ormolu" "php-cs-fixer" "phpcbf" "phpcs" "phpstan" "prettier" "psalm" "pylint" "pyright" "pyupgrade" "revive" "statix" ];

options.hookModule = lib.mkOption {
type = types.deferredModule;
Expand Down Expand Up @@ -155,6 +157,36 @@ in
};
};
};
biome = mkOption {
description = lib.mdDoc "biome hook";
type = types.submodule {
imports = [ hookModule ];
options.settings = {
binPath =
mkOption {
type = types.nullOr types.path;
description = lib.mdDoc "`biome` binary path. E.g. if you want to use the `biome` in `node_modules`, use `./node_modules/.bin/biome`.";
default = null;
defaultText = "\${tools.biome}/bin/biome";
};

write =
mkOption {
type = types.bool;
description = lib.mdDoc "Whether to edit files inplace.";
default = true;
};

configPath = mkOption {
type = types.str;
description = lib.mdDoc "Path to the configuration JSON file";
# an empty string translates to use default configuration of the
# underlying biome binary (i.e biome.json if exists)
default = "";
};
};
};
};
black = mkOption {
description = lib.mdDoc "black hook";
type = types.submodule {
Expand Down Expand Up @@ -1283,36 +1315,6 @@ in
};
};
};
rome = mkOption {
description = lib.mdDoc "rome hook";
type = types.submodule {
imports = [ hookModule ];
options.settings = {
binPath =
mkOption {
type = types.nullOr types.path;
description = lib.mdDoc "`rome` binary path. E.g. if you want to use the `rome` in `node_modules`, use `./node_modules/.bin/rome`.";
default = null;
defaultText = "\${tools.biome}/bin/biome";
};

write =
mkOption {
type = types.bool;
description = lib.mdDoc "Whether to edit files inplace.";
default = true;
};

configPath = mkOption {
type = types.str;
description = lib.mdDoc "Path to the configuration JSON file";
# an empty string translates to use default configuration of the
# underlying rome binary (i.e rome.json if exists)
default = "";
};
};
};
};
rustfmt = mkOption {
description = lib.mdDoc ''
Additional rustfmt settings
Expand Down Expand Up @@ -1638,7 +1640,7 @@ in
};

oxcabe marked this conversation as resolved.
Show resolved Hide resolved
# PLEASE keep this sorted alphabetically.
config.hooks = mapAttrs (_: mapAttrs (_: mkDefault))
config.hooks = mapAttrs (_: mapAttrs (_: mkDefault)) rec
{
actionlint =
{
Expand Down Expand Up @@ -1703,6 +1705,24 @@ 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";
Expand Down Expand Up @@ -3059,24 +3079,7 @@ lib.escapeShellArgs (lib.concatMap (ext: [ "--ghc-opt" "-X${ext}" ]) hooks.ormol
"${hooks.ripsecrets.package}/bin/ripsecrets ${cmdArgs}";
types = [ "text" ];
};
rome =
{
name = "rome";
description = "Unified developer tools for JavaScript, TypeScript, and the web";
types_or = [ "javascript" "jsx" "ts" "tsx" "json" ];

package = tools.biome;
entry =
let
binPath = migrateBinPathToPackage hooks.rome "/bin/biome";
cmdArgs =
mkCmdArgs [
[ (hooks.rome.settings.write) "--apply" ]
[ (hooks.rome.settings.configPath != "") "--config-path ${hooks.rome.settings.configPath}" ]
];
in
"${binPath} check ${cmdArgs}";
};
rome = biome;
ruff =
{
name = "ruff";
Expand Down