fix(config): surface invalid config and honor configured SQL extensions - #2658
fix(config): surface invalid config and honor configured SQL extensions#2658nikolaevx wants to merge 33 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors config loading, templating, and execution around a new sqruff_lib::api layer (Engine/Workspace), so invalid configuration is surfaced instead of silently falling back, and path discovery honors configured SQL extensions and ignore rules more consistently across CLI/LSP/WASM.
Changes:
- Introduce
sqruff_lib::api(Engine,Workspace, structured diagnostics/reports, andSqruffError) and migrate CLI/LSP/WASM to use it. - Rework config loading to return structured errors (
try_from_source,from_file,from_root) and add coverage for invalid config behavior. - Replace previous linter path discovery with an API-based implementation that supports configured file extensions and
.sqruffignore.
Reviewed changes
Copilot reviewed 68 out of 69 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/lsp/src/lib.rs | Switch LSP to Engine, surface startup/config errors, add ignore handling and LSP-focused tests. |
| crates/lsp/Cargo.toml | Add ignore dependency for .sqruffignore parsing. |
| crates/lsp/BUILD.bazel | Include ignore in WASM crate list. |
| crates/lib/tests/templaters.rs | Update templater tests for new TemplaterInput/Output and config parsing API. |
| crates/lib/tests/rules.rs | Update rule tests for new Mode/ParseErrors and config parsing changes. |
| crates/lib/src/utils/reflow/respace.rs | Update test linter construction for new ParseErrors and config parsing API. |
| crates/lib/src/utils/reflow/reindent.rs | Update test linter invocation for new Mode/ParseErrors. |
| crates/lib/src/tests.rs | Update tests for new ParseErrors linter constructor signature. |
| crates/lib/src/templaters/types.rs | Remove deprecated TemplaterKind::templater() static mapping. |
| crates/lib/src/templaters/raw.rs | Update templater interface to typed inputs/outputs and SourceId. |
| crates/lib/src/templaters/python.rs | Update python templater interface to typed inputs/outputs and SourceId naming. |
| crates/lib/src/templaters/python_shared.rs | Update config parsing usage in tests. |
| crates/lib/src/templaters/placeholder.rs | Update placeholder templater interface to typed inputs/outputs and SourceId. |
| crates/lib/src/templaters/jinja.rs | Update jinja templater interface to typed inputs/outputs and SourceId. |
| crates/lib/src/templaters/dbt.rs | Update dbt templater integration to support “skipped” outputs from Python batch processing. |
| crates/lib/src/templaters.rs | Introduce TemplaterRuntime, typed templater I/O, and simplify templater enumeration via TemplaterKind. |
| crates/lib/src/rules/aliasing/al05.rs | Update rule tests for new config parsing and lint modes. |
| crates/lib/src/lib.rs | Expose new api module; remove legacy Formatter trait. |
| crates/lib/src/core/test_functions.rs | Update helper linter construction for new ParseErrors. |
| crates/lib/src/core/rules/noqa.rs | Update tests to use try_from_source and new Mode/ParseErrors. |
| crates/lib/src/core/linter/linted_file.rs | Make path private and add source() accessor for Engine diagnostics conversion. |
| crates/lib/src/core/linter/core.rs | Refactor linter templating/rendering for typed templater outputs; remove legacy path discovery/lint_paths. |
| crates/lib/src/core/linter/common.rs | Replace batch-render result with RenderedSource (rendered vs skipped). |
| crates/lib/src/core/config.rs | Convert config loading/parsing to Result-based APIs; improve error surfacing for invalid config values. |
| crates/lib/src/api/workspace.rs | New Workspace API for ignore + path discovery + applying fixes. |
| crates/lib/src/api/source.rs | New Source/SourceId types for consistent identity handling. |
| crates/lib/src/api/report.rs | New RunReport/FileReport/SkipReason reporting types. |
| crates/lib/src/api/options.rs | New Mode, ParseErrors, EngineOptions, and RunRequest. |
| crates/lib/src/api/error.rs | New SqruffError error type with structured variants and messages. |
| crates/lib/src/api/engine.rs | New Engine API to check/fix/run sources, reload config, and produce FileReports. |
| crates/lib/src/api/diagnostic.rs | New LintDiagnostic with canonical byte-range mapping and tests. |
| crates/lib/src/api.rs | Export the new API surface. |
| crates/lib/Cargo.toml | Add ignore and thiserror dependencies for ignore/config errors and structured errors. |
| crates/lib/BUILD.bazel | Include ignore and thiserror in WASM crate list. |
| crates/lib/benches/fix.rs | Update benchmark usage for new Mode/ParseErrors. |
| crates/lib/benches/depth_map.rs | Update benchmark linter construction for new ParseErrors. |
| crates/lib-wasm/src/lib.rs | Migrate wasm linter to Engine for formatting and to typed diagnostics; improve error handling. |
| crates/lib-core/src/errors.rs | Preserve source_slice when converting parse/lex errors to SQLBaseError. |
| crates/cli/tests/ui.rs | Normalize Windows path separators in UI output comparisons. |
| crates/cli/tests/ui_json.rs | Normalize Windows path escaping/separators for JSON UI output comparisons. |
| crates/cli/tests/ui_github.rs | Normalize Windows path separators in GitHub annotation output comparisons. |
| crates/cli/tests/path_discovery.rs | Add CLI-level tests for ignore pruning, explicit ignored files, and missing-path errors. |
| crates/cli/tests/json/test_fail_whitespace_before_comma.stdout | Update expected JSON ranges to use non-empty end positions. |
| crates/cli/tests/json/hql_file.stdout | Update expected JSON ranges to use non-empty end positions. |
| crates/cli/tests/ignore_data_directory.rs | Update ignore traversal test to use Workspace discovery API. |
| crates/cli/tests/fix_return_code.rs | Add coverage to assert fixes write only when needed and don’t rewrite unchanged files. |
| crates/cli/tests/fix_parse_errors.rs | Add coverage ensuring parse errors don’t rewrite files. |
| crates/cli/Cargo.toml | Register new path_discovery harness-less test. |
| crates/cli-python/tests/json/test_fail_whitespace_before_comma.stdout | Update expected JSON ranges to match new diagnostic end positions. |
| crates/cli-python/tests/json/hql_file.stdout | Update expected JSON ranges to match new diagnostic end positions. |
| crates/cli-python/python/sqruff/templaters/dbt_templater.py | Extend batch API to return skip reasons separately from errors. |
| crates/cli-python/python/sqruff/templaters/dbt_templater_test.py | Update tests for new (templated_file, error, skip_reason) tuple shape. |
| crates/cli-python/python/sqruff/templaters/dbt_templater_benchmark.py | Update benchmark loop for new tuple shape. |
| crates/cli-lib/src/reporters/json.rs | New JSON reporter driven by RunReport instead of legacy formatter callbacks. |
| crates/cli-lib/src/reporters/human.rs | New human reporter emitting diagnostics/skips from RunReport. |
| crates/cli-lib/src/reporters/github.rs | New GitHub annotation reporter emitting from LintDiagnostic. |
| crates/cli-lib/src/reporters.rs | Reporter abstraction + display_source_id helper. |
| crates/cli-lib/src/lib.rs | Switch CLI driver to ParseErrors enum and new LSP error handling; remove legacy linter/formatter creation. |
| crates/cli-lib/src/formatters/json.rs | Remove legacy JSON formatter (replaced by reporter). |
| crates/cli-lib/src/formatters/json_types.rs | Update JSON diagnostic types to convert from LintDiagnostic. |
| crates/cli-lib/src/formatters/github_annotation_native_formatter.rs | Remove legacy GitHub annotation formatter (replaced by reporter). |
| crates/cli-lib/src/formatters.rs | Refactor stream formatter to format LintDiagnostic and SkipReason; add rule-name lookup by code. |
| crates/cli-lib/src/docs.rs | Update docs generation to iterate TemplaterKind and instantiate via TemplaterRuntime. |
| crates/cli-lib/src/commands.rs | Restrict parsing_errors visibility and adjust CLI plumbing. |
| crates/cli-lib/src/commands_templaters.rs | Print templater names from TemplaterKind strings. |
| crates/cli-lib/src/commands_parse.rs | Update parse command to use new ParseErrors and linter ctor signature. |
| crates/cli-lib/src/commands_lint.rs | Rewrite lint command around Engine + Workspace + reporters; honor configured extensions in discovery. |
| crates/cli-lib/src/commands_fix.rs | Rewrite fix command to reuse lint runner with Mode::Fix and apply fixes via Workspace. |
| Cargo.lock | Lockfile updates for new deps (ignore, thiserror). |
Comments suppressed due to low confidence (2)
crates/lsp/src/lib.rs:274
- When reloading config on save,
set_config()failure is always logged as "Invalid templater". Sinceengine.reload_config()can fail for multiple reasons, log the actual error to make troubleshooting possible.
crates/lsp/src/lib.rs:274 - When reloading config on save,
set_config()failure is always logged as "Invalid templater". Sinceengine.reload_config()can fail for multiple reasons, log the actual error to make troubleshooting possible.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
8609cf0 to
4ed9f7b
Compare
Benchmark for cf69afaClick to view benchmark
|
Merging this PR will not alter performance
Comparing Footnotes
|
|
@codspeedbot fix this regression |
Performance regression fixed ✅I investigated the -15.43% regression reported by CodSpeed on Root causeThe new
These setup-phase allocations left the heap in a more fragmented state, causing the benchmark loops' allocations and deallocations to become significantly more expensive — visible in the flamegraph as FixOptimized ResultsCodSpeed simulation comparison against
Summary
Was this response helpful? React with 👍 or 👎 to help us improve CodSpeedBot. |
b92315d to
c6d3541
Compare
Benchmark for 31fde4fClick to view benchmark
|
|
@codspeedbot fix this regression |
No real regression detected ✅I investigated the +10.86% CodSpeed simulation results (noise-free)
All 6 benchmarks are classified as unchanged by CodSpeed simulation. Why the wall-time benchmark fluctuatesThe wall-time numbers for
A ~17% swing between two runs on nearly identical code is a clear indicator of environmental noise (CPU throttling, scheduling jitter, memory pressure on shared CI runners). The ConclusionNo code change is needed — the Summary
Was this response helpful? React with 👍 or 👎 to help us improve CodSpeedBot. |
|
@copilot FIX CI |
Fixed in |
Benchmark for 6758894Click to view benchmark
|
|
@copilot fix CI |
Fixed the Bazel Lint (clippy) failure — |
|
@copilot make clippy happy |
Fixed |
Benchmark for 16724d2Click to view benchmark
|
|
@copilot fix CI |
Fixed in the latest commit. Three issues resolved:
|
5ec8c77 to
08afe70
Compare
Benchmark for cf677fcClick to view benchmark
|
Summary
sql_file_extsduring path discovery.Testing
cargo check -p sqruff-lib