-
Notifications
You must be signed in to change notification settings - Fork 3
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
base: main
Are you sure you want to change the base?
SQLFluff #25
Conversation
📝 WalkthroughWalkthroughA new Changes
Poem
✨ Finishing Touches🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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 underL016
. 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] aboveexample.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
📒 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 |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
SELECT u.id, o.order_id, o.amount FROM users u | ||
JOIN orders o | ||
on u.id = o.user_id | ||
WHERE o.amount>1000; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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.
SELECT | ||
id | ||
name | ||
FROM customers; |
There was a problem hiding this comment.
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.
SELECT | |
id | |
name | |
FROM customers; | |
SELECT | |
id, | |
name, | |
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.
Summary by CodeRabbit