Skip to content

feat: per-file config resolution for multi-directory linting#2355

Open
garymm wants to merge 3 commits into
quarylabs:mainfrom
garymm:garymm/comparison
Open

feat: per-file config resolution for multi-directory linting#2355
garymm wants to merge 3 commits into
quarylabs:mainfrom
garymm:garymm/comparison

Conversation

@garymm
Copy link
Copy Markdown
Contributor

@garymm garymm commented Feb 18, 2026

Summary

  • When linting files across multiple directories, each file now uses the nearest .sqruff/.sqlfluff config found in its ancestor directories
  • Adds ConfigLoader::find_nearest_config_dir() to walk ancestor directories for config files
  • The CLI groups files by nearest config directory, builds a fully-resolved FluffConfig per group (with --dialect applied), and sets it on the Linter before linting each group
  • The Linter itself has no override mechanism — it always receives a single fully-resolved config
  • --config flag disables per-file config resolution, using the explicit config for all files
  • --dialect works correctly for all code paths (file linting, stdin, parse)

Motivation

Two issues fixed:

  1. Running sqruff in dir a/ with a/b/.sqruff and a/c/.sqruff — files in b/ now use b/.sqruff, files in c/ use c/.sqruff
  2. Running sqruff with CWD=a/c/d/ now finds a/c/.sqruff in an ancestor directory

Test Plan

  • Added test_find_nearest_config_dir unit test for ancestor config discovery
  • Added test_lint_paths_per_file_config integration test verifying bigquery and ansi files use different configs via set_config
  • All existing tests pass (cargo test -p sqruff-lib --lib, cargo test -p sqruff-cli-lib)

fixes: #2016

When linting files across multiple directories, each file now uses the
nearest .sqruff/.sqlfluff config found in its ancestor directories.
This fixes two issues:

1. Running sqruff from a parent directory with different configs in
   subdirectories now applies the correct config per file.
2. Running sqruff from a subdirectory finds config in ancestor dirs.

CLI --dialect override is applied on top of any per-file config.
@garymm garymm marked this pull request as draft February 18, 2026 19:53
When linting files across multiple directories, each file now uses the
nearest .sqruff/.sqlfluff config found in its ancestor directories.
This fixes two issues:

1. Running sqruff from a parent directory with different configs in
   subdirectories now applies the correct config per file.
2. Running sqruff from a subdirectory finds config in ancestor dirs.

The Linter accepts optional CLI overrides (e.g. --dialect) at
construction time and applies them on top of each per-file config
via FluffConfig::from_path's existing overrides parameter.
Instead of storing CLI overrides on the Linter and doing per-file
config resolution inside lint_paths, the grouping and config
resolution now happens in the CLI layer (commands_lint/commands_fix).

Each config group gets a fully-resolved FluffConfig with --dialect
already applied, so the Linter only ever sees a single resolved
config with no override mechanism needed.

This also fixes:
- --dialect being ignored for stdin and parse commands
- --config being overridden by per-file config discovery
- Files with no .sqruff in ancestry inheriting stale config from
  a previous group
@garymm garymm marked this pull request as ready for review February 18, 2026 21:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: sqruff is not finding the right config file

1 participant