# Running SQLFluff fix on PRs as a GitHub Action with inline suggestions

**URL:** <https://discourse.getdbt.com/t/running-sqlfluff-fix-on-prs-as-a-github-action-with-inline-suggestions/4174>\
**Category:** Show and Tell\
**Tags:** ci-cd, sqlfluff\
**Created:** [April 10, 2022, 10:23am UTC](https://discourse.getdbt.com/t/running-sqlfluff-fix-on-prs-as-a-github-action-with-inline-suggestions/4174 "2022-04-10T10:23:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![martinburch](https://avatars.discourse-cdn.com/v4/letter/m/e9bcb4/32.png) [@martinburch](https://discourse.getdbt.com/u/martinburch)\
**Post date:** [April 10, 2022, 10:23am UTC](https://discourse.getdbt.com/t/running-sqlfluff-fix-on-prs-as-a-github-action-with-inline-suggestions/4174/1 "2022-04-10T10:23:11Z")

</div>

Here’s a secret: SQLFluff doesn’t need to be specifically configured to use the dbt templater. Using the default Jinja templater, SQLFluff can fix inconsistent capitalisation or indentation without any fancy database connections.

With that in mind, I created this basic GitHub Action file in `my-repo/.github/workflows/sqlfulff.yml`. This action uses the new (as of this post) [**action-sqlfluff**](https://github.com/yu-iskw/action-sqlfluff) project to make inline suggestions on the pull request.

```auto
name: sqlfluff with reviewdog
on:
  pull_request:
jobs:
  test-check:
    name: runner / sqlfluff (github-check)
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      # only run when a comment requests linting
      - uses: khan/pull-request-comment-trigger@master
        id: check
        with:
          trigger: '/lint'
          reaction: rocket
        env:
          GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
      - uses: yu-iskw/action-sqlfluff@v3
        if: steps.check.outputs.triggered == 'true'
        id: lint-sql
        with:
          github_token: ${{ secrets.github_token }}
          reporter: github-pr-review
          sqlfluff_version: "0.11.1"
          sqlfluff_command: "fix" # Or "lint"
          config: "${{ github.workspace }}/.sqlfluff"
          paths: '${{ github.workspace }}/models'
      - name: 'Show outputs (Optional)'
        shell: bash
        run: |
          echo '${{ steps.lint-sql.outputs.sqlfluff-results }}' | jq -r '.'
          echo '${{ steps.lint-sql.outputs.sqlfluff-results-rdjson }}' | jq -r '.'

```

Here are the results, when creating a PR with the comment `/lint` and a missing explicit alias keyword.

 ![blur-demo](https://us1.discourse-cdn.com/flex020/uploads/getdbt/original/2X/5/555d379e300955e4a4337f5995bd71e8a42e380e.jpeg)

P.S. Here’s my SQLFluff configuration file, `my-repo/.sqlfluff`…

```auto
[sqlfluff]
dialect = bigquery

# L031 - Exclude rule requiring fully-qualified table names in joins
# should have been disabled for BigQuery already
# L036 - multiple SELECT columns can appear on the SELECT line
# L051 - Exclude rule requiring INNER JOIN rather than just JOIN
# L003 - Ignore whitespace problems for now
# L034 - Don't move around columns
# L016 - Long lines are fine
# L009 - No need for a single newline at end of file
# L008 - No need for spaces around commas
exclude_rules = L051,L031,L036,L003,L034,L016,L009,L008

[sqlfluff:rules:L010]
# Keywords
capitalisation_policy = upper

```

---

<div class="post-metadata">

**Author:** ![deanja](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/deanja/32/307_2.png) [@deanja](https://discourse.getdbt.com/u/deanja)\
**Post date:** [April 12, 2022, 3:22am UTC](https://discourse.getdbt.com/t/running-sqlfluff-fix-on-prs-as-a-github-action-with-inline-suggestions/4174/2 "2022-04-12T03:22:05Z")

</div>

Nice! Are your rule exclusions for your preference, or must those rules be excluded for it to work without dbt templater?

---

<div class="post-metadata">

**Author:** ![martinburch](https://avatars.discourse-cdn.com/v4/letter/m/e9bcb4/32.png) [@martinburch](https://discourse.getdbt.com/u/martinburch)\
**Post date:** [April 12, 2022, 8:20am UTC](https://discourse.getdbt.com/t/running-sqlfluff-fix-on-prs-as-a-github-action-with-inline-suggestions/4174/3 "2022-04-12T08:20:00Z")

</div>

SQLFluff can provide basic linting of dbt models using the jinja templater without any rule exclusions. These exclusions have more to do with BigQuery (L031), dbt Cloud (L009), and our company’s code preferences (L010).

---

<div class="post-metadata">

**Author:** ![yu-iskw](https://avatars.discourse-cdn.com/v4/letter/y/cab0a1/32.png) [@yu-iskw](https://discourse.getdbt.com/u/yu-iskw)\
**Post date:** [April 18, 2022, 1:49pm UTC](https://discourse.getdbt.com/t/running-sqlfluff-fix-on-prs-as-a-github-action-with-inline-suggestions/4174/4 "2022-04-18T13:49:25Z")

</div>

@martinburch Thanks a lot for using my action.

---

<div class="post-metadata">

**Author:** ![BarelyEvenHuman](https://avatars.discourse-cdn.com/v4/letter/b/f04885/32.png) [@BarelyEvenHuman](https://discourse.getdbt.com/u/BarelyEvenHuman)\
**Post date:** [August 1, 2023, 7:48pm UTC](https://discourse.getdbt.com/t/running-sqlfluff-fix-on-prs-as-a-github-action-with-inline-suggestions/4174/5 "2023-08-01T19:48:11Z")

</div>

Are you in the community slack channel? I would like to chat about some issues I’m having getting this to work.
