lintpre-commit-hookpre-commitpre-commit.comsqlfluff

Pre-commit hook skips files in directory


I'm trying to implement SQLFLUFF linter on a certain directory (models/market) on a repo. I'm using this command pre-commit run --files models/market/ what I see is that it is skipping .sql files inside the directory showing this message:

sqlfluff-lint........................................(no files to check)Skipped

while this path includes multiple sql files. here is the pre-commit-config.yaml file:

repos:
  - repo: https://github.com/sqlfluff/sqlfluff
    rev: 2.1.3
    hooks:
      - id: sqlfluff-lint
        verbose: true
        additional_dependencies: [
          'dbt-bigquery==1.5.1',
          'sqlfluff-templater-dbt==2.1.3'
        ]

it is worth noting that this path is not included in .sqlfluffignore

I tried various commands like the ones in here: https://github.com/pre-commit/pre-commit/issues/1173

What I expect is to have SQLFLUFF lint my sql files in a certain directory that it's path is mentioned.


Solution

  • the --files argument takes files -- you've passed it a single directory

    try instead pre-commit run --files $(git ls-files -- models/market)

    and before you suggest "it should just recurse" there are special files in git that are directories -- notably submodules -- and there's special meaning for those files.


    disclaimer: I wrote pre-commit