file_types

Filter files in a run templates by their type. Special file types and MIME types are supported1:

File typeExlanation
textAny file that contains text. Symlinks are not followed.
binaryAny file that contains non-text bytes. Symlinks are not followed.
executableAny file that has executable bits set. Symlinks are not followed.
not executableAny file without executable bits in file mode. Symlinks included.
symlinkA symlink file.
not symlinkAny non-symlink file.
text/htmlAn HTML file.
text/xmlAn XML file.
text/javascriptA Javascript file.
text/x-phpA PHP file.
text/x-luaA Lua file.
text/x-perlA Perl file.
text/x-pythonA Python file.
text/x-shellscriptShell script file.
text/x-shAlso shell script file.
application/jsonJSON file.

Important The following types are applied using AND logic:

  • text
  • binary
  • executable
  • not executable
  • symlink
  • not symlink

The mime types are applied using OR logic. So, you can have both text/x-lua and text/x-sh, but you can't specify both symlink and not symlink.

Examples

Apply some different linters on text and binary files.

# lefthook.yml

pre-commit:
  commands:
    lint-code:
      run: yarn lint {staged_files}
      file_types: text
    check-hex-codes:
      run: yarn check-hex {staged_files}
      file_types: binary

Skip symlinks.

# lefthook.yml

pre-commit:
  commands:
    lint:
      run: yarn lint --fix {staged_files}
      file_types:
        - not symlink

Lint executable scripts.

# lefthook.yml

pre-commit:
  commands:
    lint:
      run: yarn lint --fix {staged_files}
      file_types:
        - executable
        - text

Check typos in scripts.

# lefthook.yml

pre-commit:
  jobs:
    - run: typos -w {staged_files}
      file_types:
        - text/x-perl
        - text/x-python
        - text/x-php
        - text/x-lua
        - text/x-sh
1

All supported MIME types can be found here: supported_mimes.md