feat: per-file config resolution for multi-directory linting#2355
Open
garymm wants to merge 3 commits into
Open
feat: per-file config resolution for multi-directory linting#2355garymm wants to merge 3 commits into
garymm wants to merge 3 commits into
Conversation
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.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
.sqruff/.sqlfluffconfig found in its ancestor directoriesConfigLoader::find_nearest_config_dir()to walk ancestor directories for config filesFluffConfigper group (with--dialectapplied), and sets it on the Linter before linting each group--configflag disables per-file config resolution, using the explicit config for all files--dialectworks correctly for all code paths (file linting, stdin, parse)Motivation
Two issues fixed:
sqruffin dira/witha/b/.sqruffanda/c/.sqruff— files inb/now useb/.sqruff, files inc/usec/.sqruffsqruffwith CWD=a/c/d/now findsa/c/.sqruffin an ancestor directoryTest Plan
test_find_nearest_config_dirunit test for ancestor config discoverytest_lint_paths_per_file_configintegration test verifying bigquery and ansi files use different configs viaset_configcargo test -p sqruff-lib --lib,cargo test -p sqruff-cli-lib)fixes: #2016