-
Notifications
You must be signed in to change notification settings - Fork 155
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
typos: unset pass_filenames #387
Conversation
Typos is supposed to run on the whole tree. If this is set to true, the system gets stuck for large projects due to very high memory consumption. The restriction on with files typos run, should be specified in the typos config file.
Could we link to some upstream issue about memory consumption? |
Relevant upstream issues/PRs are:
TL;DR: I didn't investigate it with |
Update. I did some more investigation and better understand what happens. So again, the project is very huge. If I run I suppose a combination of the relatively big memory usage of TL;DR: It is correct to use |
@phip1611 I don't think this change is desirable. While I understand the issue at hand, changing the default behaviour of the hook to align with the call of I disagree with your statement "Typos is supposed to run on the whole tree.". pre-commit hooks are supposed to be run on changes that are being committed, not for the whole repository every time you commit changes. If you wished to run the pre-commit hook on the whole directory/repository, you always had the option to run The way the hook is set up now, there is no option to just check a single file that you'd like to commit and ignore the rest of the repository. This change 'broke' the After all, it is a pre-commit hook. @domenkozar I'd suggest that this gets reverted and we discuss how we can otherwise fix the issue that @phip1611 was running into. |
@phip1611 I don't quite understand why pre-commit would be running on 74000 files in the first place... Were you committing the whole project at once? By default pre-commit passes only files to each configured hook that are about to be committed, so it should not care about the rest of your sizable repository, as long as you do not run If you indeed wished to check all files in your repository, I guess you have to expect it taking a while and it consuming quite a lot of resources. After all, that is something that should not be necessary for every commit. If you know that it is quicker to run Running a pre-commit hook on the whole repository every time you commit is IMO a waste of resources and is not what a pre-commit hook is supposed to be for. If you want to make absolutely sure, that your project at no point contains a typo, you will have to use a pipeline test running TL;DR A pre-commit hook is supposed to only check files that are about to be committed and not the whole repository. |
In the meantime, I had more time to better understand the issue and thought about it again @totoroot. But first of all, I'm sorry if I broke your project's CI with that change.
No. But I want to be able to run We can set
What do you think of that idea? I'd like to do this in a generic way and don't manually do it in my project. We might force Actually, I don't use git hooks because I don't like them as part of my workflow 🤣 . But
I'd like to extend this to:
|
Update. I have a solution that is compatible with all goals. What do you think? @domenkozar @totoroot With that, users must specify either diff --git a/modules/hooks.nix b/modules/hooks.nix
index f162b44..bf5689b 100644
--- a/modules/hooks.nix
+++ b/modules/hooks.nix
@@ -1111,12 +1111,11 @@ in
'';
};
- configPath =
+ configFile =
mkOption {
- type = types.str;
- description = lib.mdDoc "Path to a custom config file.";
- default = "";
- example = ".typos.toml";
+ type = types.path;
+ description = lib.mdDoc "Path to the config file.";
+ default = null;
};
diff =
@@ -2418,18 +2417,27 @@ in
entry = "${settings.treefmt.package}/bin/treefmt --fail-on-change";
};
typos =
+ let
+ configAsFile =
+ if settings.typos.config != ""
+ then builtins.toFile "config.toml" settings.typos.config
+ else settings.typos.configFile;
+ excludesFromConfig =
+ let
+ toml = builtins.fromTOML (builtins.readFile configAsFile);
+ in
+ (toml.files or { }).extend-exclude or [ ];
+ in
{
name = "typos";
description = "Source code spell checker";
entry =
let
- configFile = builtins.toFile "config.toml" "${settings.typos.config}";
cmdArgs =
mkCmdArgs
(with settings.typos; [
[ (color != "") "--color ${color}" ]
- [ (configPath != "") "--config ${configPath}" ]
- [ (config != "" && configPath == "") "--config ${configFile}" ]
+ [ (true) "--config ${toString configAsFile}" ]
[ (exclude != "") "--exclude ${exclude} --force-exclude" ]
[ (format != "") "--format ${format}" ]
[ (locale != "") "--locale ${locale}" ]
@@ -2438,11 +2446,7 @@ in
in
"${tools.typos}/bin/typos ${cmdArgs}${lib.optionalString settings.typos.diff " --diff"}${lib.optionalString settings.typos.hidden " --hidden"}";
types = [ "text" ];
- # Typos is supposed to run on the whole tree. If this is set to true,
- # the system gets stuck for large projects due to very high memory
- # consumption. The restriction on with files typos run, should be
- # specified in the typos config file.
- pass_filenames = false;
+ excludes = excludesFromConfig;
};
typstfmt = {
name = "typstfmt"; |
I can report this PR breaks my config having:
sure I can workaround with:
But the @totoroot said correctly:
|
Use excludes from .typos.toml when running `pre-commit run typos --all-files`. Since we don't set "pass_filenames = false" for typos (see upstream discussions [0]), we must ensure that pre-commit never passes the files specified as excludes in `.typos.toml` to `typos` as argument, if possible. Otherwise, `$ pre-commit run typos --all-files` has another behaviour than `$ typos .`, which is confusing and wrong. To not break anything, and to be compliant with the existing API, we encourage users to provide the `.typos.toml` as Nix path, so the excludes can be read via evaluation time. The `configAsFile` variable is the path where the configuration file can be found by the `typos` utility when it executes in the user environment. Not necessarily in Nix store. [0]: cachix#387 (comment)
Use excludes from .typos.toml when running `pre-commit run typos --all-files`. Since we don't set "pass_filenames = false" for typos (see upstream discussions [0]), we must ensure that pre-commit never passes the files specified as excludes in `.typos.toml` to `typos` as argument, if possible. Otherwise, `$ pre-commit run typos --all-files` has another behaviour than `$ typos .`, which is confusing and wrong. To not break anything, and to be compliant with the existing API, we encourage users to provide the `.typos.toml` as Nix path, so the excludes can be read via evaluation time. The `configAsFile` variable is the path where the configuration file can be found by the `typos` utility when it executes in the user environment. Not necessarily in Nix store. [0]: cachix#387 (comment)
Use excludes from .typos.toml when running `pre-commit run typos --all-files`. Since we don't set "pass_filenames = false" for typos (see upstream discussions [0]), we must ensure that pre-commit never passes the files specified as excludes in `.typos.toml` to `typos` as argument, if possible. Otherwise, `$ pre-commit run typos --all-files` has another behaviour than `$ typos .`, which is confusing and wrong. To not break anything, and to be compliant with the existing API, we encourage users to provide the `.typos.toml` as Nix path, so the excludes can be read via evaluation time. The `configAsFile` variable is the path where the configuration file can be found by the `typos` utility when it executes in the user environment. Not necessarily in Nix store. [0]: cachix#387 (comment)
Enable typos.configPath to be of type path. This way, we can use excludes from .typos.toml when running `pre-commit run typos --all-files`. Otherwise, the execution differs from a normal invocation of typos, which is unexpected and leads to wrong results. To not break anything, and to be compliant with the existing API, I modified configPath to be either a Nix path or a string. [0]: cachix#387 (comment)
Enable typos.configPath to be of type path. This way, we can use excludes from .typos.toml when running `pre-commit run typos --all-files`. Otherwise, the execution differs from a normal invocation of typos, which is unexpected and leads to wrong results. To not break anything, and to be compliant with the existing API, I modified configPath to be either a Nix path or a string. [0]: cachix#387 (comment)
Enable typos.configPath to be of type path. This way, we can use excludes from .typos.toml when running `pre-commit run typos --all-files`. Otherwise, the execution differs from a normal invocation of typos, which is unexpected and leads to wrong results. To not break anything, and to be compliant with the existing API, I modified configPath to be either a Nix path or a string. [0]: cachix#387 (comment)
Enable typos.configPath to be of type path. This way, we can use excludes from .typos.toml when running `pre-commit run typos --all-files`. Otherwise, the execution differs from a normal invocation of typos, which is unexpected and leads to wrong results. To not break anything, and to be compliant with the existing API, I modified configPath to be either a Nix path or a string. [0]: cachix#387 (comment)
Enable typos.configPath to be of type path. This way, we can use excludes from .typos.toml when running `pre-commit run typos --all-files`. Otherwise, the execution differs from a normal invocation of typos, which is unexpected and leads to wrong results. To not break anything, and to be compliant with the existing API, I modified configPath to be either a Nix path or a string. The main motivation for this change is a repository on my machine where pre-commit ignores directory foobar (which is excluded by .typos.toml) but passes all 65,000 files of foobar as argument to typos. In these situation, typos goes nuts and often the system freezes. So with this change, I prevent that possibly tens of thousands of files that should not be checked in any case are passed to typos, which results in a smooth experience. [0]: cachix#387 (comment)
Typos is supposed to run on the whole tree. If this is set to true, the system gets stuck for large projects due to very high memory consumption. The restriction on with files typos run, should be specified in the typos config file.
Tested this locally with a large project.