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

fix: on-unmatched option #298

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
45 changes: 26 additions & 19 deletions module-options.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,39 @@ let

configFormat = pkgs.formats.toml { };

# Remove keys in the setting that are "empty" to keep the config file lean
emptySettingsKeys =
lib.optional (config.settings.excludes == []) "excludes"
++ lib.optional (config.settings.on-unmatched == null) "on-unmatched";

settingsData = builtins.removeAttrs config.settings emptySettingsKeys;

configFile = configFormat.generate "treefmt.toml" settingsData;

# The schema of the treefmt.toml data structure.
configSchema = mkOption {
default = { };
description = "The contents of treefmt.toml";
type = types.submodule {
freeformType = configFormat.type;
options = {
global = {
excludes = mkOption {
description = "A global list of paths to exclude. Supports glob.";
type = types.listOf types.str;
default = [ ];
example = [ "./node_modules/**" ];
};
excludes = mkOption {
description = "A global list of paths to exclude. Supports glob.";
type = types.listOf types.str;
default = [ ];
example = [ "./node_modules/**" ];
};

on-unmatched = mkOption {
description = "Log paths that did not match any formatters at the specified log level.";
type = types.enum [
"debug"
"info"
"warn"
"error"
"fatal"
];
default = "warn";
};
on-unmatched = mkOption {
description = "Log paths that did not match any formatters at the specified log level.";
type = types.nullOr (types.enum [
"debug"
"info"
"warn"
"error"
"fatal"
]);
default = null;
};

formatter = mkOption {
Expand Down Expand Up @@ -276,7 +283,7 @@ in

# Config
config.build = {
configFile = configFormat.generate "treefmt.toml" config.settings;
inherit configFile;
devShell = pkgs.mkShell {
nativeBuildInputs = [ config.build.wrapper ] ++ (lib.attrValues config.build.programs);
};
Expand Down