Skip to content

Linter#7

Open
melonamin wants to merge 320 commits intomasterfrom
linter
Open

Linter#7
melonamin wants to merge 320 commits intomasterfrom
linter

Conversation

@melonamin
Copy link
Member

No description provided.

Split comma-separated rule codes in multi-rule fixtures (e.g. CP02,LT01)
so detection comparison matches individual violation codes correctly.
… and AM08

Refine detection and autofix patches across multiple rules to close
SQLFluff fixture gaps. Key changes: exclude trailing newlines from
single-line comment protected ranges in fix engine, improve CV06
semicolon placement with block-comment awareness, add LT03/LT04
config-driven operator and comma positioning, make LT09/LT10
select-target autofix more precise, implement ST02 simple-case
detection, and extend ST09 comparison-operator handling.
Tested against 85 production PostgreSQL files to align FlowScope
detection with SQLFluff defaults. Key fixes:

- CP01: exclude INTERVAL from keyword tracking; skip keywords after
  period in compound identifiers (e.g. wu.type)
- CP05: remove WITH/ZONE from tracked type names (CTE false positives)
- LT01: add FILTER/CONFLICT/BY to space-before-paren keyword list;
  recognise INSERT INTO target table before column-list paren;
  expand type-name list for bracket spacing (uuid, jsonb, etc.);
  allow ] followed by ) without space
CP01: Exclude function-like keywords (COALESCE, CAST, ANY, SOME,
REPLACE) and TYPE from keyword capitalisation tracking — these are
handled by CP03/CP05 in SQLFluff and TYPE is commonly used as a
column name.

LT09: Skip PostgreSQL DISTINCT ON (...) clause when finding the
first select target, preventing false positives on multi-target
SELECTs with DISTINCT ON.

LT14: Restrict legacy (no-config) inconsistency check to top-level
SELECT statements (paren_depth == 0) and top-level clause keywords,
preventing false positives on compact EXISTS subqueries like
SELECT 1 FROM t WHERE ...
Separate span resolution from autofix generation so violations always
get proper source locations even when autofix is blocked (implicit
column refs, comments in projection). Previously these fell back to
line 1 with no span. Also extract positioned token building into a
shared helper to reduce duplication.
ST06: Classify any top-level cast expression as band 1 (simple) to
match SQLFluff's behavior where EXTRACT(...)::integer etc. are
treated as simple regardless of inner complexity. Adds tests for
WITH...INSERT INTO parsing (Statement::Query with SetExpr::Insert).

RF01: Fix ORDER BY scope resolution — qualified references in ORDER BY
were validated against inherited_sources (empty for top-level queries)
instead of the body SELECT's FROM/JOIN scope. Adds
order_by_scope_from_body() helper and regression tests.

Net effect: ST06 over-reporting reduced +9→+4, RF01 eliminated +12→0.
Add ON CONFLICT / ON DUPLICATE KEY UPDATE support to both
visit_expressions (for expression-based rules) and
collect_identifier_candidates (for identifier-based rules like CP02).

This enables detection of EXCLUDED.* references in PostgreSQL
ON CONFLICT DO UPDATE SET clauses.
Switch capitalization rules (CP02, CP03, CP04, CP05) and reference
consistency (RF03) from per-statement to per-identifier/per-reference
issue emission to match SQLFluff's violation granularity. Add
UPDATE/DELETE/subquery traversal to AL01 table alias detection.

Parity improvements: AL01 -121→0, CP02 -77→+1, CP03 -18→+7,
CP04 -3→0, RF03 -22→-13.
Add is_non_function_sql_keyword blocklist to prevent SQL clause keywords
like IN, AS, OVER, USING, etc. from being misidentified as function calls
in tokenizer-based CP03 function capitalization checks.

CP03 parity: +7 → +1.
Fall back to ON expression span when autofix spans fail, and suppress
issues where neither can be resolved to avoid misleading L1:1 reports.
SQLFluff flags only the first reversed join condition per SELECT/FROM
clause, not all of them. Match this behaviour by gating detection in
check_table_factor_joins with an issues_before counter and breaking out
of the from_loop after the first hit.

ST09 parity: +9 → 0
…QL UNNEST parity

AL03: Remove in_set_rhs early return that suppressed all checks in
UNION/INTERSECT/EXCEPT right-hand branches. SQLFluff still requires
aliases on scalar literals there, so disable allow_scalar for RHS
instead. (Δ: -4 → 0)

RF02: Extend value table function recognition to PostgreSQL UNNEST so
aliases are treated as column names rather than table references,
matching SQLFluff behaviour. (Δ: +2 → 0)
…ype candidates

ARRAY[] and DATE() are constructors/function calls, not type annotations.
Including them in the type candidate pool created false mixed-case
violations against lowercase types like `text`. Skip tracked type names
followed by `[` (array constructor) or `(` (function call for types that
don't take parenthesised precision). (Δ: +5 → 0)
…-keywords

sqlparser's ALL_KEYWORDS includes function names (ROW_NUMBER, DATE_PART)
and dialect-specific terms (METADATA, CHANNEL, STATUS, GENERATED) that
SQLFluff does not treat as keywords. Exclude compound function names
(containing underscores, except CURRENT_*/LOCAL_*/SESSION_*/SYSTEM_*
pseudo-functions) and a small set of widely-used non-keyword identifiers
from the keyword check. (Δ: +3 → -1)
Previously, all operator layout violations were aggregated into a single
issue using the first violation's span. SQLFluff reports one violation
per misplaced operator. Emit one issue per violation, each with its own
span and autofix edits. (Δ: -1 → 0)
…overy

Add rayon-based parallel file processing for both lint and fix passes,
with a configurable --jobs flag and thread-safe progress bar. Directory
expansion now respects .gitignore by default via the ignore crate, with
--no-respect-gitignore to opt out.
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.

1 participant

Comments