Repository: sqlfluff/sqlfluff

Issue:
L003 behavior different between 0.3.6 and 0.4.0a3
I have a dbt model that looks like the following:

```sql
-- TODO: Update this model
with source_data as (
    select * from {{ source('source_name', 'xxx_yyy_zzz') }}   
)

select *
from source_data
```

Using `sqlfluff==0.3.6` (with `jinja` templater) I get the following lint output:
```
L:   3 | P:  44 | L001 | Unneccessary trailing whitespace.
```

Using `sqlfluff==0.4.0a3` (with `jinja` templater) I get the following lint output:
```
L:   3 | P:  44 | L001 | Unnecessary trailing whitespace.
L:   4 | P:   1 | L003 | Indentation not consistent with line #3
L:   6 | P:   1 | L003 | Indentation not consistent with line #3
L:   7 | P:   1 | L003 | Line under-indented compared to line #3
```

When I run `sqlfluff fix` on the file with `0.4.0a3` it tries to fix it to be:

```sql
-- TODO: Update this model
with source_data as (
    select * from {{ source('source_name', 'xxx_yyy_zzz') }}

)

    select *
        from source_data
```

This seems like unexpected behavior to me. The fix suggests that sqlfluff may be misunderstanding the indentation levels of my model.

Discussion:

Patch:
diff --git a/src/sqlfluff/core/dialects/dialect_snowflake.py b/src/sqlfluff/core/dialects/dialect_snowflake.py
index a2701f978..55052862b 100644
--- a/src/sqlfluff/core/dialects/dialect_snowflake.py
+++ b/src/sqlfluff/core/dialects/dialect_snowflake.py
@@ -386,6 +386,9 @@ class SelectStatementSegment(ansi_SelectClauseSegment):
 
     parse_grammar = Sequence(
         Ref("SelectClauseSegment"),
+        # Dedent for the indent in the select clause.
+        # It's here so that it can come AFTER any whitespace.
+        Dedent,
         Ref("FromClauseSegment", optional=True),
         Ref("WhereClauseSegment", optional=True),
         Ref("GroupByClauseSegment", optional=True),


Test patch:
diff --git a/test/core/rules/test_cases/L003.yml b/test/core/rules/test_cases/L003.yml
index 50c72649b..30fcf47a3 100644
--- a/test/core/rules/test_cases/L003.yml
+++ b/test/core/rules/test_cases/L003.yml
@@ -139,3 +139,31 @@ test_12:
         t1
     -- Comment
     JOIN t2 USING (user_id)
+
+# https://github.com/sqlfluff/sqlfluff/issues/643
+snowflake_with_indent:
+  pass_str: |
+    with source_data as (
+        select * from {{ source('source_name', 'xxx_yyy_zzz') }}   
+    )
+
+    select *
+    from source_data
+  
+  configs:
+    core:
+      dialect: snowflake
+
+# https://github.com/sqlfluff/sqlfluff/issues/643
+bigquery_with_indent:
+  pass_str: |
+    with source_data as (
+        select * from {{ source('source_name', 'xxx_yyy_zzz') }}   
+    )
+
+    select *
+    from source_data
+  
+  configs:
+    core:
+      dialect: bigquery