8000 exclude_rules override in files are not used · Issue #5697 · sqlfluff/sqlfluff · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

exclude_rules override in files are not used #5697

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

Closed
2 of 3 tasks
rdevans0 opened this issue Mar 19, 2024 · 2 comments · Fixed by #6010
Closed
2 of 3 tasks

exclude_rules override in files are not used #5697

rdevans0 opened this issue Mar 19, 2024 · 2 comments · Fixed by #6010
Labels
bug Something isn't working

Comments

@rdevans0
Copy link
rdevans0 commented Mar 19, 2024

Search before asking

  • I searched the issues and found no similar issues.

What Happened

When setting sqlfluff:exclude_rules in a file override, the override is not honored, for example, putting:

-- sqlfluff:exclude_rules:CP02

Expected Behaviour

The rule is excluded during the file. According to the docs, this is the preferred way to do file-specific overrides for rules.

When considering configuration inheritance, each of rules and exclude_rules will totally overwrite any values in parent config files if they are set in a child file. While the subtraction operation between both of them is calculated “per file”, there is no combination operation between two definitions of rules (just one overwrites the other).

The exclude_rules is overridden for that file.

Observed Behaviour

The rule is not excluded for the file. This is in contrast to other in-file overrides, which take effect for only the current file.

How to reproduce

Using the following example:

# config.toml
[sqlfluff]
dialect = ansi

[sqlfluff:rules:capitalisation.identifiers]
extended_capitalisation_policy = lower

[sqlfluff:rules:capitalisation.keywords]
capitalisation_policy = lower
-- query.sql
-- sqlfluff:exclude_rules:CP02
-- sqlfluff:rules:capitalisation.keywords:capitalisation_policy:upper

SELECT A FROM B.C;

We expect that running sqlfluff lint --config config.toml query.sql would result in no errors, as the file overrides:

  • CP02 (capitalisation.identifiers) is disabled (identifiers can be any case)
  • keywords capitalization is set to upper

In actuality, linting fails, and only part of the overrides are honored:

== [query.sql] FAIL                                                            
L:   5 | P:   8 | CP02 | Unquoted identifiers must be lower case.
                       | [capitalisation.identifiers]
L:   5 | P:  15 | CP02 | Unquoted identifiers must be lower case.
                       | [capitalisation.identifiers]
L:   5 | P:  17 | CP02 | Unquoted identifiers must be lower case.
                       | [capitalisation.identifiers]
All Finished 📜 🎉!

This shows that just the rules exclusion was skipped.

Dialect

ansi

Version

sqlfluff, version 3.0.2
Python 3.8.10

Configuration

[sqlfluff]
dialect = ansi

[sqlfluff:rules:capitalisation.identifiers]
extended_capitalisation_policy = lower

[sqlfluff:rules:capitalisation.keywords]
capitalisation_policy = lower

Are you willing to work on and submit a PR to address the issue?

  • Yes I am willing to submit a PR!

Code of Conduct

@rdevans0 rdevans0 added the bug Something isn't working label Mar 19, 2024
@WittierDinosaur
Copy link
Contributor

This may be more of a documentation issue. You can ignore rules at the file level, by doing this:

-- noqa: disable=CP02

8000

@alesbukovsky
Copy link
Contributor

While the file-wide noqa directive works, it is not consistent with the rest of overrides where sqlfluff prefix makes the purpose clear.

The issue here is that when it comes to lists (ignores, warnings, rules and exclude rules), the configuration object keeps the comma-separated string under the original key, e.g. exclude_rules, but also parses it as an actual list into a dedicated internal variable, e.g. rule_denylist.

This is only done during the configuration object initialization, typically after the content of the configuration file is parsed into a buffer and passed in. However, the inline configuration is read differently - the child configuration object is created and individual parameters are set on it as they are encountered in the SQL file they are declared. This means the list parsing into internal variables is done before the values are set.

The code that assembles the applicable rule set to apply uses the internal variables rule_allowlist and rule_denylist. Since these are not injected with the parsed lists, the rules declared in-line are ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants
0