Skip to content

SQLFluff #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

SQLFluff #25

wants to merge 1 commit into from

Conversation

nimratcoderabbit
Copy link

@nimratcoderabbit nimratcoderabbit commented Jul 14, 2025

image

Summary by CodeRabbit

  • New Features
    • Introduced a configuration file for standardized SQL linting and formatting across the project.
    • Added an example SQL file showcasing various SELECT queries, join types, and SQL syntax scenarios.

Copy link

coderabbitai bot commented Jul 14, 2025

📝 Walkthrough

Walkthrough

A new .sqlfluff configuration file has been added to establish SQL linting and formatting standards. Additionally, an example.sql file showcases various SQL queries, illustrating different syntax styles, reserved word usage, and join operations.

Changes

File(s) Change Summary
.sqlfluff Added configuration for SQLFluff: sets dialect, templater, disables/enables specific rules, and output formatting.
example.sql Added sample SQL queries demonstrating SELECT statements, reserved word usage, and different join styles.

Poem

In the land of SQL, new rules now gleam,
With .sqlfluff guiding the formatting dream.
Example queries dance in rows and lines,
Joins and filters, all by design.
Order and clarity, now close at hand—
Let clean SQL flourish across the land!
🐰✨

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch preview/sqlfluff

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🧹 Nitpick comments (2)
.sqlfluff (1)

12-20: Duplicate max-line-length settings – keep a single source of truth

max_line_length appears in both the global section and again under L016. One definition is enough and reduces maintenance friction.

-[sqlfluff:rules:L016]  # Line length
-max_line_length = 100
+# [sqlfluff:rules:L016]  # Line length
+# # inherits max_line_length = 100 from [sqlfluff:rules] above
example.sql (1)

16-18: Comma-join syntax is outdated – switch to explicit JOIN for clarity

-SELECT a.id, b.value
-FROM table1 a, table2 b
-WHERE a.id = b.id;
+SELECT
+    a.id,
+    b.value
+FROM table1 AS a
+INNER JOIN table2 AS b
+    ON a.id = b.id;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ef04b8d and 81a1408.

📒 Files selected for processing (2)
  • .sqlfluff (1 hunks)
  • example.sql (1 hunks)
🧰 Additional context used
🪛 SQLFluff (3.4.1)
example.sql

1-1: Select targets should be on a new line unless there is only one select target.


1-1: Expected only single space before naked identifier. Found ' '.


1-1: Unquoted identifiers must be consistently lower case.


1-1: Expected single whitespace between comma ',' and naked identifier.


1-1: Unexpected whitespace before comma ','.


1-1: Expected only single space before naked identifier. Found ' '.


1-1: The 'WHERE' keyword should always start a new line.


1-1: Expected single whitespace between naked identifier and raw comparison operator '>'.


1-1: Expected single whitespace between raw comparison operator '>' and numeric literal.


1-1: Keywords must be consistently upper case.


1-1: The 'order' keyword should always start a new line.


3-3: Expected line break and indent of 4 spaces before 'select'.


3-3: Line 3, Position 8: Found unparsable section: 'select'


3-3: Trailing comma in select statement forbidden


3-3: Line 3, Position 16: Found unparsable section: 'from, where FROM keywords'


5-5: Expected indent of 4 spaces.


6-6: Expected indent of 8 spaces.


7-7: Expected indent of 12 spaces.


7-7: Implicit/explicit aliasing of columns.


7-7: Keywords should not be used as identifiers.


8-8: Line 8, Position 5: Found unparsable section: 'email'


9-9: Expected indent of 4 spaces.


9-9: Expected only single space before naked identifier. Found ' '.


11-11: Expected indent of 4 spaces.


11-11: Select targets should be on a new line unless there is only one select target.


11-11: Implicit/explicit aliasing of table.


12-12: Join clauses should be fully qualified.


12-12: Expected indent of 4 spaces.


12-12: Implicit/explicit aliasing of table.


13-13: Keywords must be consistently upper case.


13-13: Expected indent of 8 spaces.


14-14: Expected indent of 8 spaces.


14-14: Expected single whitespace between naked identifier and raw comparison operator '>'.


14-14: Expected single whitespace between raw comparison operator '>' and numeric literal.


16-16: Expected indent of 8 spaces.


16-16: Select targets should be on a new line unless there is only one select target.


17-17: Expected indent of 8 spaces.


17-17: Implicit/explicit aliasing of table.


17-17: Implicit/explicit aliasing of table.


18-18: Expected indent of 8 spaces.

[sqlfluff]
dialect = ansi
templater = jinja
exclude_rules = L009 # trailing comma enforcement skipped
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Potential rule conflict – double-check the intent behind disabling L009 while keeping L019 active

You disable L009 (“trailing comma enforcement”) but immediately configure L019 for comma_style = trailing. If you actually want trailing commas enforced, drop L009 from exclude_rules; if not, remove or change the comma_style entry so the two settings don’t contradict each other.

Example quick fix:

-exclude_rules = L009  # trailing comma enforcement skipped
+# exclude_rules =  # keep empty OR list rules you really want off

🏁 Script executed:

#!/bin/bash
# Show the exclude_rules and comma_style settings in .sqlfluff for verification
grep -nE 'exclude_rules|comma_style' .sqlfluff || true

Length of output: 135


Align SQLFluff comma rules

You’ve turned off L009 but left comma_style = trailing for L019—those settings fight each other. Decide whether you want trailing commas or not and update both accordingly:

.sqlfluff, line 4 – adjust your exclude_rules
.sqlfluff, line 22 – update or remove the comma_style setting

Example fixes:

If you want to enforce trailing commas:

-.sqlfluff (line 4)
-exclude_rules = L009  # trailing comma enforcement skipped
+.sqlfluff (line 4)
+# exclude_rules =    # no rules disabled, keep L019’s trailing commas

If you don’t want trailing commas:

-.sqlfluff (line 22)
-comma_style = trailing
+.sqlfluff (line 22)
+comma_style = none   # or remove this line entirely

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In the .sqlfluff file around lines 4 and 22, there is a conflict between
disabling rule L009 and setting comma_style to trailing for rule L019. Decide if
you want to enforce trailing commas or not, then either remove L009 from
exclude_rules and keep comma_style as trailing, or keep L009 excluded and change
or remove the comma_style setting to avoid conflicting rules.

@@ -0,0 +1,19 @@
SELECT id,Name , age FROM users WHERE age>25 order BY name;

SELECT select, from, where FROM keywords;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Reserved words used as column names – quote or rename

select, from, and where are reserved. Either wrap them in double quotes/back-ticks or choose different identifiers to avoid parser errors in most RDBMSs.

-SELECT select, from, where FROM keywords;
+SELECT "select", "from", "where"
+FROM keywords;
🧰 Tools
🪛 SQLFluff (3.4.1)

3-3: Expected line break and indent of 4 spaces before 'select'.


3-3: Line 3, Position 8: Found unparsable section: 'select'


3-3: Trailing comma in select statement forbidden


3-3: Line 3, Position 16: Found unparsable section: 'from, where FROM keywords'

🤖 Prompt for AI Agents
In example.sql at line 3, reserved SQL keywords "select", "from", and "where"
are used as column names without quoting, which will cause parser errors. Fix
this by wrapping these column names in double quotes or backticks, or rename
them to non-reserved identifiers to ensure compatibility with SQL parsers.

@@ -0,0 +1,19 @@
SELECT id,Name , age FROM users WHERE age>25 order BY name;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

First query violates almost every configured rule – re-format or mark as an intentional anti-example

Unless you purposely keep this broken for demo purposes, tidy it:

-SELECT  id,Name , age FROM   users WHERE age>25 order BY name;
+SELECT
+    id,
+    name,
+    age
+FROM users
+WHERE age > 25
+ORDER BY name;
🧰 Tools
🪛 SQLFluff (3.4.1)

1-1: Select targets should be on a new line unless there is only one select target.


1-1: Expected only single space before naked identifier. Found ' '.


1-1: Unquoted identifiers must be consistently lower case.


1-1: Expected single whitespace between comma ',' and naked identifier.


1-1: Unexpected whitespace before comma ','.


1-1: Expected only single space before naked identifier. Found ' '.


1-1: The 'WHERE' keyword should always start a new line.


1-1: Expected single whitespace between naked identifier and raw comparison operator '>'.


1-1: Expected single whitespace between raw comparison operator '>' and numeric literal.


1-1: Keywords must be consistently upper case.


1-1: The 'order' keyword should always start a new line.

🤖 Prompt for AI Agents
In example.sql at line 1, the SQL query formatting is inconsistent and violates
style rules. Reformat the query to use consistent spacing, capitalization, and
keyword order: capitalize SQL keywords, ensure proper spacing after commas, and
use consistent case for column names. For example, write SELECT, FROM, WHERE,
ORDER BY in uppercase and align spacing uniformly.

Comment on lines +11 to +14
SELECT u.id, o.order_id, o.amount FROM users u
JOIN orders o
on u.id = o.user_id
WHERE o.amount>1000;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

JOIN block needs consistent casing, aliased tables, and spacing

-SELECT u.id, o.order_id, o.amount FROM users u
-JOIN orders o
-on u.id = o.user_id
-WHERE o.amount>1000;
+SELECT
+    u.id,
+    o.order_id,
+    o.amount
+FROM users AS u
+INNER JOIN orders AS o
+    ON u.id = o.user_id
+WHERE o.amount > 1000;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
SELECT u.id, o.order_id, o.amount FROM users u
JOIN orders o
on u.id = o.user_id
WHERE o.amount>1000;
SELECT
u.id,
o.order_id,
o.amount
FROM users AS u
INNER JOIN orders AS o
ON u.id = o.user_id
WHERE o.amount > 1000;
🧰 Tools
🪛 SQLFluff (3.4.1)

11-11: Expected indent of 4 spaces.


11-11: Select targets should be on a new line unless there is only one select target.


11-11: Implicit/explicit aliasing of table.


12-12: Join clauses should be fully qualified.


12-12: Expected indent of 4 spaces.


12-12: Implicit/explicit aliasing of table.


13-13: Keywords must be consistently upper case.


13-13: Expected indent of 8 spaces.


14-14: Expected indent of 8 spaces.


14-14: Expected single whitespace between naked identifier and raw comparison operator '>'.


14-14: Expected single whitespace between raw comparison operator '>' and numeric literal.

🤖 Prompt for AI Agents
In example.sql around lines 11 to 14, the JOIN clause uses inconsistent casing
and spacing for the aliased tables. Update the JOIN block to use consistent
uppercase SQL keywords, ensure table aliases are clearly defined and spaced
properly, and format the ON condition with appropriate spacing for better
readability and consistency.

Comment on lines +5 to +9
SELECT
id
name
email
FROM customers;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Missing commas & mis-indentation break the multi-line SELECT

Add commas and follow the 4-space indent policy:

-SELECT
-    id
-    name
-    email
-FROM    customers;
+SELECT
+    id,
+    name,
+    email
+FROM customers;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
SELECT
id
name
email
FROM customers;
SELECT
id,
name,
email
FROM customers;
🧰 Tools
🪛 SQLFluff (3.4.1)

5-5: Expected indent of 4 spaces.


6-6: Expected indent of 8 spaces.


7-7: Expected indent of 12 spaces.


7-7: Implicit/explicit aliasing of columns.


7-7: Keywords should not be used as identifiers.


8-8: Line 8, Position 5: Found unparsable section: 'email'


9-9: Expected indent of 4 spaces.


9-9: Expected only single space before naked identifier. Found ' '.

🤖 Prompt for AI Agents
In example.sql around lines 5 to 9, the SELECT statement is missing commas
between columns and the indentation does not follow the 4-space policy. Add
commas after each column name except the last one, and indent each column by 4
spaces for proper formatting and syntax correctness.

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