-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sql linting using SQLFluff (#417)
* Enable sql-formatter * Fix formatting * Replace with variables & bind * Update .git-blame-ignore-revs * Fix formatting * Remove sqlformatter & enable sqlfluff * Fix formatting * Fix formatting * Use sqlfluff lint and fix * Bump pyproject * Fix Download query placeholders * Add sql linting * Fixed slug_lookup query * Fix query param binding * Update .sqlfluff * Rename keyword identifier to non keyword identifier * Revert makefile changes * Fix linting errors * Update download query logic based on linting * Update formatting * Remove debug function * Revert SQLalchemy 2
- Loading branch information
1 parent
b1ec83b
commit 9089898
Showing
11 changed files
with
774 additions
and
553 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
[sqlfluff] | ||
dialect = postgres | ||
exclude_rules = LT02, LT09 | ||
|
||
[sqlfluff:indentation] | ||
indented_ctes = True | ||
|
||
[sqlfluff:layout:type:colon] | ||
spacing_before = single | ||
spacing_after = single | ||
|
||
[sqlfluff:layout:type:parameter] | ||
spacing_before = touch | ||
spacing_after = any | ||
|
||
[sqlfluff:rules:references.special_chars] | ||
allow_space_in_identifier = True | ||
additional_allowed_characters = ["/", "_", "-", "(", ")"] | ||
|
||
[sqlfluff:rules:capitalisation.keywords] | ||
capitalisation_policy = upper | ||
|
||
[sqlfluff:rules:capitalisation.identifiers] | ||
extended_capitalisation_policy = lower | ||
|
||
[sqlfluff:rules:capitalisation.functions] | ||
extended_capitalisation_policy = upper | ||
|
||
[sqlfluff:rules:capitalisation.types] | ||
extended_capitalisation_policy = upper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,14 @@ version: 0.1 | |
cli: | ||
version: 1.22.0 | ||
|
||
tools: | ||
definitions: | ||
- name: sqlfluff | ||
runtime: python | ||
package: sqlfluff | ||
shims: [sqlfluff] | ||
known_good_version: 1.4.5 | ||
|
||
# Trunk provides extensibility via plugins. | ||
# (https://docs.trunk.io/plugins) | ||
plugins: | ||
|
@@ -27,13 +35,53 @@ lint: | |
disabled: | ||
- hadolint | ||
- oxipng | ||
|
||
definitions: | ||
- name: bandit | ||
direct_configs: [bandit.yaml] | ||
commands: | ||
- name: lint | ||
run: bandit --exit-zero -c bandit.yaml --format json --output ${tmpfile} ${target} | ||
|
||
- name: sqlfluff | ||
files: [sql, sql-j2, dml, ddl] | ||
tools: [sqlfluff] | ||
description: A dialect-flexible and configurable SQL linter | ||
known_good_version: 1.4.5 | ||
direct_configs: | ||
- .sqlfluff | ||
affects_cache: | ||
- pyproject.toml | ||
suggest_if: config_present | ||
commands: | ||
- name: lint | ||
run: sqlfluff lint ${target} --format json --nofail | ||
output: sarif | ||
success_codes: [0] | ||
read_output_from: stdout | ||
parser: | ||
runtime: python | ||
run: python3 ${plugin}/linters/sqlfluff/sqlfluff_to_sarif.py | ||
|
||
- name: fix | ||
version: ">=3.0.0" | ||
run: sqlfluff fix ${target} --disable-progress-bar | ||
output: rewrite | ||
formatter: true | ||
in_place: true | ||
success_codes: [0, 1] | ||
enabled: false | ||
batch: true | ||
|
||
- name: format | ||
run: sqlfluff format ${target} --disable-progress-bar | ||
output: rewrite | ||
formatter: true | ||
in_place: true | ||
success_codes: [0, 1] | ||
enabled: false | ||
batch: true | ||
|
||
ignore: | ||
- linters: [ALL] | ||
paths: | ||
|
@@ -45,6 +93,8 @@ lint: | |
- LICENSE.md | ||
|
||
enabled: | ||
- [email protected]: | ||
commands: [lint, fix, format] | ||
- [email protected] | ||
- [email protected] | ||
- [email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.