sqlfluff / sqlfluff

A modular SQL linter and auto-formatter with support for multiple dialects and templated code.

Home Page:https://www.sqlfluff.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Developing custom rules

miodeqqq opened this issue · comments

Search before asking

  • I searched the issues and found no similar issues.

Links or command line

Hello SQLFluff Team and Community,

I've been attempting to implement custom rules for SQLFluff, aiming to extend its functionality for a project. Despite following the guidelines provided in the Developing Rules documentation, I've encountered some challenges getting SQLFluff to recognize and apply these custom rules.

Objective

My goal is to create a set of custom rules, specifically to enforce certain GROUP BY clause usage patterns that are not currently supported by SQLFluff out-of-the-box.

Steps Taken

  • I've set up a custom rule within a directory structured as follows: sqlfluff_rules/custom, containing the files FD01.py and __init__.py.
  • The FD01.py file defines a custom rule class Rule_FD01, intended to check for consistency in GROUP BY clause usage (for now there are only print statements to see if that works).
  • My .sqlfluff config file includes the line rule_paths = sqlfluff_rules/custom, aiming to direct SQLFluff to my custom rule files.

Issue

Upon running sqlfluff lint test.sql --rules FD01, I receive a warning:

WARNING Tried to allowlist unknown rule references: ['FD01'].

It seems that SQLFluff does not recognize the custom rule specified.

Thank you in advance for your time and help.

Best regards, Maciej

sqlfluff_v2

Issue/Suggested Improvement

I'm unsure if I've misunderstood the documentation or if there's a gap in the guide that might have led to this issue. I would greatly appreciate any insights, clarifications, or suggestions on how to correctly implement and recognize custom rules in SQLFluff. Additionally, if there are improvements to be made in the documentation to help others navigate this process more smoothly, I'm keen to contribute or assist in any way I can.

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

2 things here @miodeqqq :

  • Generally we encourage plugins to have names, so your rules never collide with core rules, so it should be Rule_PluginName_RuleCode. This shouldn't be what's blocking you.
  • The other is that you need to run pip install -e . inside your plugin directory