Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add linting of SQL files using sqlfluff #1480

Merged
merged 8 commits into from
Feb 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .github/workflows/lint_sqlfluff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: SQLFluff

on:
- pull_request

jobs:
lint-mimic-iv:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v3
- name: Install Python
uses: "actions/setup-python@v2"
with:
python-version: "3.7"
- name: install sqlfluff
run: "pip install sqlfluff==1.4.5"
- name: Get changed files
id: get_file_changes
uses: trilom/file-changes-action@v1.2.4
with:
output: ' '
- name: Get changed .sql files in mimic-iv concepts folder
id: get_files_to_lint
shell: bash -l {0}
run: |
# Set the command in the $() brackets as an output to use in later steps
echo "lintees=$(
echo \
$(echo ${{ steps.get_file_changes.outputs.files_modified }} |
tr -s ' ' '\n' |
grep -E '^mimic-iv/concepts/.*[.]sql$' |
tr -s '\n' ' ') \
$(echo ${{ steps.get_file_changes.outputs.files_added }} |
tr -s ' ' '\n' |
grep -E '^mimic-iv/concepts/.*[.]sql$' |
tr -s '\n' ' ')
) >> $GITHUB_OUTPUT"

- name: Lint SQL files
id: sqlfluff_json
if: steps.get_files_to_lint.outputs.lintees != ''
shell: bash -l {0}
run: sqlfluff lint --format github-annotation --annotation-level failure --nofail ${{ steps.get_files_to_lint.outputs.lintees }} > annotations.json
- name: Annotate
uses: yuzutech/annotations-action@v0.3.0
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
title: "SQLFluff Lint"
input: "./annotations.json"
20 changes: 20 additions & 0 deletions .sqlfluff
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[sqlfluff:core]
rules = core,L019
large_file_skip_byte_limit = 40000
dialect = bigquery

[sqlfluff:layout:type:comma]
line_position = leading

[sqlfluff:indentation]
indented_joins = false
indented_using_on = true
template_blocks_indent = false

[sqlfluff:rules:L010]
# Keywords should be upper case
capitalisation_policy = upper

[sqlfluff:rules:L030]
# Functions should be upper case
extended_capitalisation_policy = upper
Loading