Repository: sqlfluff/sqlfluff
Issue: Wrong line number in indentation warning

In the case below, the line number should be 8, not 7. This is pretty confusing because the previous line is a different CTE. (If the query only has one CTE, the warning is for the opening `WITH` line, but I wrote the example this way because it better illustrates the "confusion" factor.)
 
Input:
```
WITH
cte1 AS (
    SELECT
        bucket_id
    FROM
        `t`
),
cte2 AS (
SELECT
    bucket_id
FROM
    `t`
)

SELECT 1
```

Output:
```
$ sqlfluff lint --exclude-rules L001 --dialect bigquery test.sql
== [test.sql] FAIL
L:   9 | P:   1 | L003 | Indent expected and not found compared to line #7
L:  11 | P:   1 | L003 | Indent expected and not found compared to line #7
```

Changed files:
src/sqlfluff/rules/std.py, src/sqlfluff/errors.py, test/cli_commands_test.py

diff --git a/src/sqlfluff/errors.py b/src/sqlfluff/errors.py
index fee9577e..b09a648f 100644
--- a/src/sqlfluff/errors.py
+++ b/src/sqlfluff/errors.py
@@ -101,6 +101,7 @@ class SQLBaseError(ValueError):
 
         Returns:
             A `dictionary` with keys (code, line_no, line_pos, description)
+
         """
         return dict(zip(
             ('code', 'line_no', 'line_pos', 'description'),
diff --git a/src/sqlfluff/rules/std.py b/src/sqlfluff/rules/std.py
index a7ab0369..4a0d789a 100644
--- a/src/sqlfluff/rules/std.py
+++ b/src/sqlfluff/rules/std.py
@@ -331,11 +331,15 @@ class Rule_L003(BaseCrawler):
                 # indent on the previous line. Otherwise it's just an indent.
                 this_line['indent_size'] == last_line_hanger_indent
                 # Or they're if the indent balance is the same and the indent is the
-                # same
+                # same AND the previous line was a hanger
                 or (
                     this_line['indent_size'] == res[this_line_no - 1]['indent_size']
                     and this_line['indent_balance'] == res[this_line_no - 1]['indent_balance']
+                    and this_line_no - 1 in memory['hanging_lines']
                 )
+            ) and (
+                # There MUST also be a non-zero indent. Otherwise we're just on the baseline.
+                this_line['indent_size'] > 0
             ):
                 # This is a HANGER
                 memory['hanging_lines'].append(this_line_no)
diff --git a/test/cli_commands_test.py b/test/cli_commands_test.py
index 44ff31e8..3fad7909 100644
--- a/test/cli_commands_test.py
+++ b/test/cli_commands_test.py
@@ -228,7 +228,7 @@ def test__cli__command_parse_serialize_from_stdin(serialize):
     if serialize == 'json':
         result = json.loads(result.output)
     elif serialize == 'yaml':
-        result = yaml.load(result.output)
+        result = yaml.safe_load(result.output)
     else:
         raise Exception
     result = result[0]  # only one file
@@ -265,7 +265,7 @@ def test__cli__command_lint_serialize_from_stdin(serialize, sql, expected, exit_
     if serialize == 'json':
         assert json.loads(result.output) == expected
     elif serialize == 'yaml':
-        assert yaml.load(result.output) == expected
+        assert yaml.safe_load(result.output) == expected
     else:
         raise Exception
 
@@ -284,7 +284,7 @@ def test__cli__command_lint_serialize_multiple_files(serialize):
     if serialize == 'json':
         result = json.loads(result.output)
     elif serialize == 'yaml':
-        result = yaml.load(result.output)
+        result = yaml.safe_load(result.output)
     else:
         raise Exception
     assert len(result) == 2