11

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!

Sander van den Oord
  • 10,986
  • 5
  • 51
  • 96
Albin
  • 822
  • 1
  • 7
  • 25

3 Answers3

9

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.

Albin
  • 822
  • 1
  • 7
  • 25
  • 2
    Hi Albin, i have tried the creating .sqlfluff file to exclude few rules, but after using lint command still the rules are not excluded and displaying the error or warnings for those rules, could you please where we need to keep the .sqlfluff file so that rules will be excluded – Arvind A Nov 11 '22 at 17:21
  • @Albin The exclude_rules part isn't working for me either. – TwerkingPanda Nov 18 '22 at 05:08
  • What is the syntax for sqlfluff 2.x ? – Cyril Duchon-Doris Mar 20 '23 at 14:30
6

Try looking into .sqlfluff config file

https://docs.sqlfluff.com/en/stable/configuration.html#

suhprano
  • 1,723
  • 1
  • 16
  • 22
  • 1
    thank you for referring to this. This actually helped me to find the solution. I will add a more specific answer to my question. This may help some others to find it more easily – Albin Apr 01 '21 at 07:05
0

Just an addition to the answer:
The default config of the rules can be found inside the package in file core\default_config.cfg

See also:

As already mentioned by @Albin the easiest way to override the config is to add a .sqlfluff file in the user profile folder.

See also:
https://docs.sqlfluff.com/en/stable/configuration.html#rule-configuration

Sander van den Oord
  • 10,986
  • 5
  • 51
  • 96