Skip to content

SQLFluff 2.0: Reorganisation of Linting Rules

2.0 brings breaking changes to rule codes and classification. This update dives into why we chose to change and what the new setup is.

· By

Until now, SQLFluff’s rules have been added fairly organically, as members of the community implemented the checks they needed. Each new rule received the next available Lxxx code. That meant the rules were effectively in chronological order: the number reflected when a rule was added, rather than what it checked.

That was a reasonable way to start, but it became less useful as the project grew. Related rules could be quite far apart in the list, and understanding a configuration file often meant looking up several codes before you could work out what it was doing. It also differed from the named rules and categories used by other linting tools.

By 2.0, the set of rules had stabilised enough for us to identify useful groupings. We’ve reorganised them around those groups and given each rule a name. This changes how rules are referenced in configuration, which is the main reason for making it a major release.

Rule names and grouped codes

The old L010 becomes CP01, named capitalisation.keywords. The code is still short enough for terminal output or a review comment, while the prefix identifies the group. The name describes what the rule checks.

Related checks sit together: CP02 is capitalisation.identifiers and CP03 is capitalisation.functions. The same approach applies to aliasing (AL), layout (LT), references (RF) and the other rule families.

The intention is to make it easier to refer to a rule without needing to remember its number. It also gives us a more consistent way to organise the configuration for related checks.

Changes to configuration

Rule-specific configuration sections now use the rule’s name, rather than its old code. For example, this 1.x configuration:

[sqlfluff:rules:L010]
capitalisation_policy = upper

becomes:

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

The setting itself hasn’t changed in this example; only the section heading has. In 2.0, unrecognised rule configuration sections raise warnings and their settings are ignored. This means you need to use the full rule name here, rather than simply replacing L010 with CP01 in the heading.

Rule selection is more flexible. In rules and exclude_rules, you can use names, grouped codes or group names. For example, to select the capitalisation checks, replace:

[sqlfluff]
rules = L010, L014, L030, L040, L063

with:

[sqlfluff]
rules = capitalisation

In 2.0 that group selects CP01 through CP05. A group expresses an ongoing policy, so future rules added to it may also be selected when you upgrade. Use individual names or codes when you want an explicit list.

Legacy codes remain supported as aliases for selecting rules, so these references don’t all need to change immediately. However, some old rules have been combined, so an alias may now select a broader set of checks. It’s worth reviewing those references as part of the upgrade.

Rule code migration table

The table maps legacy codes to the grouped codes introduced in 2.0. It is organised by the new rule families so related changes are easy to find. For rule names, options and behaviour in the version you’re using, consult the current rules reference. Run sqlfluff rules to inspect the rules available in your installed version.

Rule familyPrevious code(s)2.0 code
AliasingL011AL01
AliasingL012AL02
AliasingL013AL03
AliasingL020AL04
AliasingL025AL05
AliasingL066AL06
AliasingL031AL07
AmbiguousL021AM01
AmbiguousL033AM02
AmbiguousL037AM03
AmbiguousL044AM04
AmbiguousL051AM05
AmbiguousL054AM06
AmbiguousL068AM07
CapitalisationL010CP01
CapitalisationL014CP02
CapitalisationL030CP03
CapitalisationL040CP04
CapitalisationL063CP05
ConventionL061CV01
ConventionL060CV02
ConventionL038CV03
ConventionL047CV04
ConventionL049CV05
ConventionL052CV06
ConventionL053CV07
ConventionL055CV08
ConventionL062CV09
ConventionL064CV10
ConventionL067CV11
JinjaL046JJ01
LayoutL001, L005, L006, L008, L023, L024, L039, L048, L071LT01
LayoutL002, L003, L004LT02
LayoutL007LT03
LayoutL019LT04
LayoutL016LT05
LayoutL017LT06
LayoutL018LT07
LayoutL022LT08
LayoutL036LT09
LayoutL041LT10
LayoutL065LT11
LayoutL009LT12
LayoutL050LT13
ReferencesL026RF01
ReferencesL027RF02
ReferencesL028RF03
ReferencesL029RF04
ReferencesL057RF05
ReferencesL059RF06
StructureL035ST01
StructureL043ST02
StructureL045ST03
StructureL058ST04
StructureL042ST05
StructureL034ST06
StructureL032ST07
StructureL015ST08
T-SQLL056TQ01

Why the layout mappings aren’t all one-to-one

The layout work also consolidated checks that had grown separately around different pieces of SQL. Nine spacing rules now map to LT01, while three indentation rules map to LT02. This lets one consistent layout configuration describe how SQL should look, instead of scattering related settings across several checks.

For example, L005 checked for spaces before commas, L008 checked for a single space after them, and L006 checked spacing around operators. These are now all handled by LT01 (layout.spacing). The associated configuration is organised by the type of SQL element: [sqlfluff:layout:type:comma] can specify spacing_before = touch, meaning no space before a comma, while the same layout configuration system describes spacing around operators and other elements. This separates the choice of which checks to run from the description of the layout they should enforce, rather than requiring a separate rule and set of options for each spacing convention.

For example, selecting the legacy L005 now selects LT01, which checks much more than spacing around commas. Review the resulting scope instead of treating every alias as an exact replacement. The layout configuration guide explains the available controls and their current behaviour.

Updating an existing project

Start with your configuration file and remove settings that merely repeat the defaults. Then update rule selections in rules or exclude_rules, and rename rule-specific sections to use full names. Check in-file configuration directives for old references too.

Pay particular attention to layout settings and the many-to-one mappings above. Lint a representative set of files, read any configuration warnings, and review the changes before applying fixes across the project. Where several settings express the same intention, consider whether a group or a shared layout setting would make that easier to maintain.

See the 2.0 migration guide and rule configuration documentation for the detailed upgrade steps. For everything else included in the release, including contributor credits, see the 2.0.0 changelog.