Skip to content

Commit 7eb8063

Browse files
committed
feat: Add oxlint hook
1 parent 7275fa6 commit 7eb8063

File tree

2 files changed

+132
-0
lines changed

2 files changed

+132
-0
lines changed

modules/hooks.nix

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,6 +1068,100 @@ in
10681068
};
10691069
};
10701070
};
1071+
oxlint = mkOption {
1072+
description = "oxlint hook";
1073+
type = types.submodule {
1074+
imports = [ hookModule ];
1075+
options.settings = {
1076+
categories =
1077+
mkOption {
1078+
type = types.listOf (types.submodule {
1079+
options = {
1080+
action = mkOption {
1081+
type = types.enum [ "allow" "warn" "deny" ];
1082+
description = "Whether to allow a category and suppress its lints, deny a category and emit warnings, or deny and emit an error.";
1083+
};
1084+
category = mkOption {
1085+
type = types.enum [ "correctness" "suspicious" "pedantic" "style" "nursery" "restriction" "all" ];
1086+
description = ''
1087+
* `correctness` - code that is outright wrong or useless (default).
1088+
* `suspicious` - code that is most likely wrong or useless.
1089+
* `pedantic` - lints which are rather strict or have occasional false positives.
1090+
* `style` - code that should be written in a more idiomatic way.
1091+
* `nursery` - new lints that are still under development.
1092+
* `restriction` - lints which prevent the use of language and library features.
1093+
* `all` - all the categories listed above except nursery. Does not enable plugins
1094+
'';
1095+
};
1096+
};
1097+
});
1098+
description = "List of action-category pairs";
1099+
default = [ ];
1100+
example = [
1101+
{ action = "deny"; category = "correctness"; }
1102+
{ action = "allow"; category = "no-debugger"; }
1103+
];
1104+
};
1105+
configPath = mkOption {
1106+
type = types.nullOr (types.oneOf [ types.str types.path ]);
1107+
description = "Oxlint configuration file. Only `.json` extension is supported.";
1108+
default = null;
1109+
example = "./oxlintrc.json";
1110+
};
1111+
deny-warnings = mkOption {
1112+
type = types.bool;
1113+
description = "Ensure warnings produce a non-zero exit code.";
1114+
default = false;
1115+
};
1116+
fix = mkOption {
1117+
type = types.nullOr (types.enum [ "safe" "suggestions" "dangerously" ]);
1118+
description = "Which issue fixes to apply";
1119+
default = null;
1120+
};
1121+
format = mkOption {
1122+
type = types.enum [ "checkstyle" "default" "github" "gitlab" "json" "junit" "stylish" "unix" ];
1123+
description = "Use a specific output format.";
1124+
default = "default";
1125+
};
1126+
max-warnings = mkOption {
1127+
type = types.nullOr types.int;
1128+
description = "Specify a warning threshold, which can be used to force exit with an error status if there are too many warning-level rule violations in your project.";
1129+
default = null;
1130+
};
1131+
plugins = mkOption {
1132+
type = types.listOf (types.enum [ "import" "jest" "jsdoc" "jsx-a11y" "nextjs" "node" "oxc" "promise" "react" "react-perf" "regex" "typescript" "unicorn" "vitest" "vue" ]);
1133+
description = "The plugins to enable.";
1134+
default = [ "oxc" "unicorn" "typescript" ];
1135+
};
1136+
quiet = mkOption {
1137+
type = types.bool;
1138+
description = "Disable reporting on warnings, only errors are reported.";
1139+
default = false;
1140+
};
1141+
report-unused-disable-directives-severity = mkOption {
1142+
type = types.nullOr (types.enum [ "error" "warn" "log" "debug" ]);
1143+
description = "Specify the severity level of directive comments like `// eslint-disable-line` when no errors would have been reported on that line anyway.";
1144+
default = null;
1145+
};
1146+
silent = mkOption {
1147+
type = types.bool;
1148+
description = "Do not display any diagnostics.";
1149+
default = false;
1150+
};
1151+
threads = mkOption {
1152+
type = types.nullOr types.int;
1153+
description = "Number of threads to use. Set to 1 for using only 1 CPU core.";
1154+
default = null;
1155+
};
1156+
tsconfigPath = mkOption {
1157+
type = types.nullOr (types.oneOf [ types.str types.path ]);
1158+
description = "TypeScript `tsconfig.json` path for reading path alias and project references for import plugin.";
1159+
default = null;
1160+
example = "./tsconfig.json";
1161+
};
1162+
};
1163+
};
1164+
};
10711165
php-cs-fixer = mkOption {
10721166
description = "php-cs-fixer hook";
10731167
type = types.submodule {
@@ -3583,6 +3677,42 @@ lib.escapeShellArgs (lib.concatMap (ext: [ "--ghc-opt" "-X${ext}" ]) hooks.fourm
35833677
"${hooks.ormolu.package}/bin/ormolu --mode inplace ${extensions} ${cabalExtensions}";
35843678
files = "\\.l?hs(-boot)?$";
35853679
};
3680+
oxlint =
3681+
{
3682+
name = "oxlint";
3683+
description = "ESLint replacement written in Rust";
3684+
package = tools.oxlint;
3685+
entry =
3686+
let
3687+
pluginsDefault = [ "oxc" "unicorn" "typescript" ];
3688+
cmdArgs =
3689+
mkCmdArgs
3690+
(with hooks.oxlint.settings; [
3691+
[ (categories != [ ]) (lib.strings.concatStringsSep " " (lib.concatMap (entry: [ "--${entry.0}=${entry.1}" ]) categories)) ]
3692+
[ (config-path != null) "--config=${builtins.toString config-path}" ]
3693+
[ (deny-warnings != null) "--deny-warnings" ]
3694+
[ (fix != null) (if fix == "safe" then "--fix" else "--fix=${fix}") ]
3695+
[ (true) "--format=${format}" ]
3696+
[ (max-warnings != null) "--max-warnings=${builtins.toString max-warnings}" ]
3697+
[
3698+
(plugins != [ ])
3699+
(lib.strings.concatStringsSep " "
3700+
(flatten [
3701+
(lib.concatMap (plugin: [ "--${plugin}-plugin" ]) (lib.subtractLists pluginsDefault plugins))
3702+
(lib.concatMap (plugin: [ "--disable-${plugin}-plugin" ]) (lib.subtractLists plugins pluginsDefault))
3703+
]))
3704+
]
3705+
[ (quiet) "--quiet" ]
3706+
[ (report-unused-disable-directives-severity != null) "--report-unused-disable-directives-severity=${report-unused-disable-directives-severity}" ]
3707+
[ (silent) "--silent" ]
3708+
[ (threads != null) "--threads=${builtins.toString threads}" ]
3709+
[ (tsconfig-path != null) "--tsconfig=${builtins.toString tsconfig-path}" ]
3710+
]);
3711+
in
3712+
"${hooks.oxlint.package}/bin/oxlint ${cmdArgs}";
3713+
types_or = [ "javascript" "jsx" "ts" "tsx" ];
3714+
types = [ "text" ];
3715+
};
35863716
php-cs-fixer =
35873717
{
35883718
name = "php-cs-fixer";

nix/tools.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
, opam
6464
, opentofu
6565
, ormolu
66+
, oxlint
6667
, pkgsBuildBuild
6768
, poetry
6869
, pre-commit-hook-ensure-sops ? null
@@ -165,6 +166,7 @@ in
165166
nixpkgs-fmt
166167
opentofu
167168
ormolu
169+
oxlint
168170
pre-commit-hook-ensure-sops
169171
poetry
170172
proselint

0 commit comments

Comments
 (0)