Skip to content

Typos exclude param implementation failing for globs #618

@norbertwnuk

Description

@norbertwnuk

There are two issues with current implementation of the exclude parameter for the typos hook:

  • the value should be passed in the apostrophes "--exclude '${exclude}' --force-exclude", otherwise it is expanded by the shell and not working when more than one file is found
  • the additional excludes property (to be backward compatible) makes more sense since more than one glob can be defined with multiple --exclude CLI params: /nix/store/xxx-typos-1.32.0/bin/typos --config /nix/store/yyy-typos-config.toml --exclude '*.json1' --exclude '*.json' --exclude '*.json2' --force-exclude. The --exclude '*.json1 *.json *.json2' approach does not work:
 /nix/store/xxx-typos-1.32.0/bin/typos --config /nix/store/yyy-typos-config.toml --exclude '*.json1 *.json *.json2' --force-exclude --dump-config - | grep exclude -A5
extend-exclude = [
    "**.png",
    "*.json1 *.json *.json2",
]

/nix/store/xxx-typos-1.32.0/bin/typos --config /nix/store/yyy-typos-config.toml --exclude '*.json1' --exclude '*.json' --exclude '*.json2' --force-exclude --dump-config - | grep exclude -A5
extend-exclude = [
    "**.png",
    "*.json1",
    "*.json",
    "*.json2",
]

The workaround is to use exclude property from the hook definition:

typos = {
  excludes = [ ".*.yaml" ];
  settings = {
    exclude = "'**/*.json'";
  };
};

All those observations empirically tested, implementation can be checked here: https://github.com/crate-ci/typos/blob/master/crates/typos-cli/src/bin/typos-cli/args.rs#L216

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions