Open Sugatoshifumi opened 1 year ago
I also have the same issue, When running sqlfluff lint from CLI, I get all the warnings. However during pre-commit, the hook passes.
At that time, I didn't perform the validation specifying .sqlfluff in the argument. However, when I tried it in a different environment, I received an error saying the path could not be found. If I change it to an absolute path, then I get a different error...
repos:
- repo: https://github.com/sqlfluff/sqlfluff
rev: 3.0.2
hooks:
- id: sqlfluff-lint
additional_dependencies : ['dbt-bigquery==1.7.3', 'sqlfluff-templater-dbt==3.0.2']
log_file : 'true'
args: [--config, ".sqlfluff"]
root@6c325701b789:~/workspace/jobs/dbt_project# pre-commit run --files models/staging/dwh/XXXX.sql
sqlfluff-lint............................................................Failed
- hook id: sqlfluff-lint
- exit code: 2
Error loading config: Extra config '.sqlfluff' does not exist.
root@6c325701b789:~/workspace/jobs/dbt_project#
Additional verification details I was able to solve the problem by using git diff on GitHubActions side, so I implemented it there and achieved something close to what I wanted to do. I'll leave this as a note in case anyone else comes across this page.
Make minor modifications depending on your execution environment and repository configuration.
- name: Execute sqlfluff
shell: bash
working-directory: ${{ inputs.POETRY_LOCK_DIR }}/dbt_project
run: |
git fetch origin develop
MODIFIED_SQL_FILES=$(git diff origin/develop --name-only --diff-filter=ACMRT -- '*.sql' | sed 's|^jobs/dbt_project/||')
if [[ -z $MODIFIED_SQL_FILES ]]; then
echo "No changes in the files. Exiting with success."
exit 0
else
echo "Linting files"
poetry run sqlfluff lint $MODIFIED_SQL_FILES
fi
Search before asking
What Happened
Rules that were picked up by local .sqlfluff customization are not picked up during git commit execution. The following bug report may be a little close to my report. https://github.com/sqlfluff/sqlfluff/issues/4304
I've written this at length, but as I mentioned in the title, if I could figure out how to customize the sqlfluff rules that are applied when a git commit is executed, I think I could solve this problem.
Expected Behaviour
The same content that is locally linted can be detected in a git commit.
Observed Behaviour
As stated in the title. Errors in lint displayed when running with .sqlfluff differ from errors when running with commit
Created files
.pre-commit-config.yaml
sample sql(orders_payments.sql)
target_date is defined in dbt_project.yml
Verification results
First, let the linter run manually, and the following message will be returned
Execute add as-is without making any changes, and then execute commit. As a result, a different result is returned than when lint is executed in sqlfluff.
How to reproduce
Additional Verification
Change the contents of .sqlfluff to simple rules
Confirmation that .sqlfluff and pre-commit picked up the same error
Adapting fixes in fixes based on the contents of .sqlfluff
No particular problem with pass when pre-commit run is executed.
The "trailing whitespace." error that was occurring on line 17 was not picked up and an error was returned.
Dialect
BigQuery
Version
dbt: 1.6.0 sqlfluff-templater-dbt: 2.3.0 sqlfluff: 2.3.0 python: 3.10
Configuration
.sqlfluff
.sqlfluffignore
Are you willing to work on and submit a PR to address the issue?
Code of Conduct