Skip to content

Commit

Permalink
Merge branch 'main' into snowflake_dollar_quoted_literal
Browse files Browse the repository at this point in the history
  • Loading branch information
jpy-git committed Mar 2, 2022
2 parents f0ab1a5 + 251f223 commit 1a55603
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
22 changes: 11 additions & 11 deletions src/sqlfluff/rules/L036.py
Expand Up @@ -268,9 +268,11 @@ def _fixes_for_move_after_select_clause(
these segments may, for example, be *siblings* of
select_clause.
"""
start_seg = select_children[
select_targets_info.first_new_line_idx
]
start_seg = (
modifier[0]
if modifier
else select_children[select_targets_info.first_new_line_idx]
)
move_after_select_clause = select_children.select(
start_seg=start_seg,
stop_seg=stop_seg,
Expand Down Expand Up @@ -352,14 +354,12 @@ def _fixes_for_move_after_select_clause(
)
fixes += [LintFix.delete(seg) for seg in to_delete]

fixes += _fixes_for_move_after_select_clause(
to_delete[-1],
# If we stopped due to something other than a newline,
# we want to include a newline here.
not select_children[
select_clause_idx - len(to_delete) - 2
].is_type("newline"),
)
if to_delete:
fixes += _fixes_for_move_after_select_clause(
to_delete[-1],
# If we deleted a newline, create a newline.
any(seg for seg in to_delete if seg.is_type("newline")),
)
else:
fixes += _fixes_for_move_after_select_clause(
select_children[
Expand Down
16 changes: 15 additions & 1 deletion test/fixtures/rules/std_rule_cases/L036.yml
Expand Up @@ -153,6 +153,20 @@ test_cte:
SELECT 1
FROM cte1
test_single_newline_no_from:
fail_str: |
SELECT
id
fix_str: |
SELECT id
test_single_distinct_no_from:
fail_str: |
SELECT
DISTINCT id
fix_str: |
SELECT DISTINCT id
test_distinct_many:
fail_str: |
SELECT distinct a, b, c
Expand Down Expand Up @@ -193,7 +207,7 @@ test_single_select_with_no_from:

test_single_select_with_no_from_previous_comment:
fail_str: "SELECT\n /* test */ 10000000\n"
fix_str: "SELECT 10000000\n /* test */\n"
fix_str: "SELECT 10000000 /* test */\n"

test_single_select_with_comment_after_column:
fail_str: |
Expand Down

0 comments on commit 1a55603

Please sign in to comment.