Skip to content
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

Bug fix: L036 handle single-column SELECT with comment on same line as SELECT keyword #3259

Conversation

barrywhart
Copy link
Member

@barrywhart barrywhart commented May 4, 2022

Brief summary of the change made

Fixes #3252

Are there any other side effects of this change that we should be aware of?

Pull Request checklist

  • Please confirm you have completed any of the necessary steps below.

  • Included test cases to demonstrate any code changes, which may be one or more of the following:

    • .yml rule test cases in test/fixtures/rules/std_rule_cases.
    • .sql/.yml parser test cases in test/fixtures/dialects (note YML files can be auto generated with tox -e generate-fixture-yml).
    • Full autofix test cases in test/fixtures/linter/autofix.
    • Other.
  • Added appropriate documentation for the change.

  • Created GitHub issues for any relevant followup/future enhancements if appropriate.

@barrywhart barrywhart marked this pull request as draft May 4, 2022 20:51
select_clause[0],
filter_meta=True,
),
select_clause[0],
Copy link
Member Author

Choose a reason for hiding this comment

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

Unrelated to the issue, but no longer necessary to call _choose_anchor_segment() here due to recent improvements in the core linter.

@barrywhart barrywhart requested a review from tunetheweb May 4, 2022 21:59
@barrywhart barrywhart marked this pull request as ready for review May 4, 2022 21:59
@tunetheweb
Copy link
Member

Instead of moving the select target up, before the comment, could we move the comment down after the select target (or temporary delete it)? Then fix the select target as it would if not comment was there?

@@ -384,15 +392,25 @@ def _fixes_for_move_after_select_clause(
],
)

fixes += [
Copy link
Member Author

Choose a reason for hiding this comment

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

Review this section with "Hide whitespace" enabled.

@codecov
Copy link

codecov bot commented May 4, 2022

Codecov Report

Merging #3259 (48136f9) into main (179289a) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##              main     #3259   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          167       167           
  Lines        12531     12539    +8     
=========================================
+ Hits         12531     12539    +8     
Impacted Files Coverage Δ
src/sqlfluff/rules/L036.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 179289a...48136f9. Read the comment docs.

@barrywhart
Copy link
Member Author

barrywhart commented May 5, 2022

@tunetheweb: We could. I don't think I'm up for tackling it now. Would you want to create a separate issue for this? Often when I look at one of these rules that moves stuff around, I am surprised how complicated it is and how many special cases arise, and how easy it is to make a mistake and corrupt the code. Here are a couple of other test cases that occur to me if we try to handle this:

SELECT -- comment 1
a -- comment 2;

SELECT --comment 1
/* comment 2 */ a -- comment 3;

🤯

I feel like rule #1 is, don't corrupt anyone's code. Auto-fixing is nice, but definitely lower priority, and the balance between effort, risk, and reward is important.

@tunetheweb
Copy link
Member

Fair enough!

@tunetheweb tunetheweb merged commit 03d9799 into sqlfluff:main May 5, 2022
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.

L036 - sqlfluff fix will remove a single SELECT target on a new line if there's a comment after the SELECT
2 participants