sqlfluff / vscode-sqlfluff

An extension to use the sqlfluff linter in vscode.
https://marketplace.visualstudio.com/items?itemName=dorzey.vscode-sqlfluff
MIT License
156 stars 33 forks source link

What is the syntax for adding rules? #141

Closed nvoq-kimmiesse closed 4 months ago

nvoq-kimmiesse commented 5 months ago

Type: Bug

I am unable to determine the syntax to add rules to settings.json in the extension. Copilot said to add the following but there is an issue with the outer curly braces. The formatter won't run with curly braces but will run with square brackets. However, the rules aren't obeyed by the formatter; its as if there are no rules.

"sqlfluff.rules": {
    "L010": {"capitalisation_policy": "upper"},
    "L014": {"capitalisation_policy": "lower"}
}

Or is there somewhere else I should be setting rules other than settings.json?

Extension version: 3.0.2 VS Code version: Code 1.90.0 (89de5a8d4d6205e5b11647eb6a74844ca23d2573, 2024-06-04T19:33:54.889Z) OS version: Windows_NT x64 10.0.19045 Modes:

nvoq-kimmiesse commented 4 months ago

I am using this for Snowflake SQL. I have it as a language.

 "sqlfluff.linter.languages": [
        "snowflake-sql",
        "sql",
        "sql-bigquery",
        "jinja-sql",
        "postgres"
    ],

If I use square brackets I am able to format the document, unlike with the curly braces, but the rules aren't obeyed. It uses the case of the first keyword for the whole document and doesn't always set it to upper regardless of the case of the first keyword in the file.

"sqlfluff.rules": [
    "L010": {"capitalisation_policy": "upper"},
    "L014": {"capitalisation_policy": "lower"}
]
RobertOstermann commented 4 months ago

@nvoq-kimmiesse The sqlfluff.rules is not for configuring rules, just determining which rules will be run. You will need a separate sqlfluff config file to configure rules. The usage of sqlfluff.rules is an array of rules, only these rules will be executed and all other rules will be excluded.

"sqlfluff.rules": ["L009"]

nvoq-kimmiesse commented 4 months ago

Thank you, @RobertOstermann! I have it working now.