typos: Excluding files unexpected behavior.

Current settings:

_typos.toml

[files]
extend-exclude = ["*.json", "**/*.json"]

.pre-commit-config.yaml

-   repo: https://github.com/crate-ci/typos
    rev: typos-v0.7.4
    hooks:
      - id: typos

Expected behavior: JSON files must be excluded

Expected behavior: All files are checked.

Steps to reproduce

pre-commit run typos --all-files

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 9
  • Comments: 22 (2 by maintainers)

Commits related to this issue

Most upvoted comments

Additional workaround is:

  - repo: https://github.com/crate-ci/typos
    rev: v1.8.1
    hooks:
    - id: typos
      pass_filenames: false

Got it from here as the same issue exists in interrogate package

typos assumes the user knows best when passing in file paths, overriding the exclusions. Unfortunately, this doesn’t layer well with tools like pre-commit.

We need to provide a way to control this behavior.

What about the hook attribute exclude ? It can exclude files with specified pattern.

What about the hook attribute exclude ? It can exclude files with specified pattern.

This is what I’m using. For example:

repos:
- repo: https://github.com/crate-ci/typos
  rev: v1.13.10
  hooks:
    - id: typos
      exclude: |
        (?x)^(
          .*\.csv
          |.*\.xml
        )$

You can also explicitly limit to certain file types by overriding the text type selected in the repo’s hook definition:

repos:
- repo: https://github.com/crate-ci/typos
  rev: v1.13.10
  hooks:
    - id: typos
      types_or:
      - javascript
      - python

IMO one of the powers of pre-commit is that it already passes the correct filenames, based on hook selection and exclusion, so tools don’t have to reimplement undifferentiated inclusion/exclusion features.