Search code examples
gityamlpre-commit-hookpre-commit

Force extension for given file type in a hook


How can I configure a pre-commit hook which will force yaml/yml files to have yaml extension. Pass:

lol.yaml

Fail:

lol.yml

Solution

  • Actually it turned out to be fairly easy. It's enough to add the following hook to the config:

      - repo: local
        hooks:
          - id: yaml-file-extension
            name: Check if YAML files has *.yaml extension.
            entry: YAML filenames must have .yaml extension.
            language: fail
            files: .yml$
    

    It will not verify the content however, just the extension.