Search code examples
sqlpostgresqldbtsqlfluff

Configure SQLFluff rules


I use SQLFluff to ensure a uniform syntax in the company and reduce error warnings before running the models in dbt. Since our syntax does not completely match the syntax of SQLFluff I would like to make some changes.

The Rules References provided by SQLFluff helped me to set up Inline Ignoring Errors, as displayed in the code below (last line of code).

So I have two questions, which I was not able to answer also with the help of the Rules References of SQLFluff.

  1. I would like to set Rule L032 as default 'false' without typing it manually every time in my SQL.

  2. How do I change the maximal length of a line regarding Rule L016? I would like to set the default value e.g. 150.

Rule_L016

SELECT
    country.country_name,
    country.population,
    currency.currency_name,
    currency.currency_id,
    currency.strange_long_variable_name_which_is_too_long as not_so_long_variable_name
FROM country
LEFT JOIN currency
    USING (country) -- noqa: L032

I tried to figure it out with the Rules References but could not figure it out. Help is very much appreciated!


Solution

  • With the help of @suhprano's answer, I was able to find the proper solution for my issue. For this reason, I will post an answer to my own question. I do this intending to provide others assistant with similar issues.

    I created the .sqlfluff file in my user profile folder. In this file I have then included the following:

    [sqlfluff]
    exclude_rules = L032
    [sqlfluff:rules]
    max_line_length = 150
    

    In this case, SQLFluff will load the configuration from any .sql file found at the path specified on this variable.