Repository: sqlfluff/sqlfluff
Pull request: Stop rule L048 complaining if literal is followed by a semicolon
### Brief summary of the change made
Fixes #1626 

### Are there any other side effects of this change that we should be aware of?
Nope. Fairly easy one this.

### Pull Request checklist
- [x] 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 `python test/generate_parse_fixture_yml.py` or by running `tox` locally).
  - 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.


Problem statement:
Snowflake / `L048`: Mistakenly flagged whitespace is needed after 'UTC' in a session set statement.
## Expected Behaviour

Linting should pass in the following SQL:
```
ALTER SESSION SET TIMEZONE = 'UTC';
```

## Observed Behaviour

Linting failed due to whitespace missing between `'UTC'` and `;`

To get the linter to pass, we'll need to add a space between them - Which seems off, especially when it's at the end of the statement.

```
ALTER SESSION SET TIMEZONE = 'UTC' ;
```

## Steps to Reproduce

1. Pull SQLFluff version `0.7.0a1`
2. Create a file with the content below.
3. Run `sqlfluff parse --dialect snowflake sample.sql`

Content
```
ALTER SESSION SET TIMEZONE = 'UTC';
```

## Dialect

Snowflake

## Version

```
(.venv) ~/code/sqlfluff (main) $ sqlfluff --version
sqlfluff, version 0.7.0a1
(.venv) ~/code/sqlfluff (main) $ python --version
Python 3.9.7
```

## Configuration
Default, except dialect is set to Snowflake.

## Parser Output
```
(.venv) ~/code/sqlfluff (main) $ sqlfluff parse --dialect snowflake sample.sql
[L:  1, P:  1]      |file:
[L:  1, P:  1]      |    statement:
[L:  1, P:  1]      |        alter_session_statement:
[L:  1, P:  1]      |            keyword:                                          'ALTER'
[L:  1, P:  6]      |            whitespace:                                       ' '
[L:  1, P:  7]      |            keyword:                                          'SESSION'
[L:  1, P: 14]      |            whitespace:                                       ' '
[L:  1, P: 15]      |            alter_session_set_statement:
[L:  1, P: 15]      |                keyword:                                      'SET'
[L:  1, P: 18]      |                whitespace:                                   ' '
[L:  1, P: 19]      |                parameter:                                    'TIMEZONE'
[L:  1, P: 27]      |                whitespace:                                   ' '
[L:  1, P: 28]      |                comparison_operator:                          '='
[L:  1, P: 29]      |                whitespace:                                   ' '
[L:  1, P: 30]      |                literal:                                      "'UTC'"
[L:  1, P: 35]      |    statement_terminator:                                     ';'
[L:  1, P: 36]      |    newline:                                                  '\n'
```

## Linter Output
```
(.venv) ~/code/sqlfluff (main) $  sqlfluff lint --dialect snowflake sample.sql
== [sample.sql] FAIL
L:   1 | P:  30 | L048 | Missing whitespace after 'UTC'
All Finished 📜 🎉!
```

Hints from issue discussion:
That seems to me like a rule bug with rule L048 rather than something specific to `UTC` or Snowflake.

There’s already an exemption for commas for the same reason so should be easy enough to add semi-colon as well:

https://github.com/sqlfluff/sqlfluff/blob/87710e73a1712366437ef3cc85e3196279cbf007/src/sqlfluff/rules/L048.py#L43-L49

Plus a test case added in `test/fixtures/rules/std_rule_cases/L048.yml` to avoid it regressing and we’re done.

Great first issue if anyone’s looking to contribute!

Commit message: Merge branch 'main' into update-l048-for-semicolons

Patch to review:
diff --git a/src/sqlfluff/rules/L048.py b/src/sqlfluff/rules/L048.py
index 7dfd565f32e..2c0c0568f0b 100644
--- a/src/sqlfluff/rules/L048.py
+++ b/src/sqlfluff/rules/L048.py
@@ -44,6 +44,10 @@ def _missing_whitespace(seg, before=True):
         https://github.com/sqlfluff/sqlfluff/issues/943
         """
         simple_res = Rule_L006._missing_whitespace(seg, before=before)
-        if not before and seg and seg.is_type("comma"):
+        if (
+            not before
+            and seg
+            and (seg.is_type("comma") or seg.is_type("statement_terminator"))
+        ):
             return False
         return simple_res
diff --git a/test/fixtures/rules/std_rule_cases/L048.yml b/test/fixtures/rules/std_rule_cases/L048.yml
index 544d18ce7bc..6dc2ae118b0 100644
--- a/test/fixtures/rules/std_rule_cases/L048.yml
+++ b/test/fixtures/rules/std_rule_cases/L048.yml
@@ -20,6 +20,13 @@ test_pass_comma:
     FROM some_table
     WHERE col2 IN ('a', 'b', 'c', 'd');
 
+test_pass_semicolon:
+  pass_str: |
+   ALTER SESSION SET TIMEZONE = 'UTC';
+  configs:
+    core:
+      dialect: snowflake
+
 test_pass_bigquery_udf_triple_single_quote:
   pass_str: |
    CREATE TEMPORARY FUNCTION a()


Code review comments:
diff_hunk: @@ -44,6 +44,10 @@ def _missing_whitespace(seg, before=True):
         https://github.com/sqlfluff/sqlfluff/issues/943
         """
         simple_res = Rule_L006._missing_whitespace(seg, before=before)
-        if not before and seg and seg.is_type("comma"):
+        if (
+            not before
+            and seg
+            and (seg.is_type("comma") or seg.is_type("statement_terminator"))
path: src/sqlfluff/rules/L048.py
text: @user1:
```suggestion
            and (seg.is_type("comma", "statement_terminator"))
```

@user1:
NOTE: `is_type()` supports passing multiple types and returns `True` if it matches any of them.

@author:
Done!