Skip to content

Commit

Permalink
More references & test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
alanmcruickshank committed Mar 4, 2023
1 parent 6aeb57b commit 02d3c26
Show file tree
Hide file tree
Showing 17 changed files with 37 additions and 35 deletions.
6 changes: 3 additions & 3 deletions docs/source/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ above:
.. code-block:: cfg
[sqlfluff]
warnings = L019, L006
warnings = L019, LT01
With this configuration, files with no other issues (other than
those set to warn) will pass. If there are still other issues, then
Expand All @@ -300,10 +300,10 @@ the file will still fail, but will show both warnings and failures.
.. code-block::
== [test.sql] PASS
L: 2 | P: 9 | L006 | WARNING: Missing whitespace before +
L: 2 | P: 9 | LT01 | WARNING: Missing whitespace before +
== [test2.sql] FAIL
L: 2 | P: 8 | CP02 | Unquoted identifiers must be consistently upper case.
L: 2 | P: 11 | L006 | WARNING: Missing whitespace before +
L: 2 | P: 11 | LT01 | WARNING: Missing whitespace before +
This is particularly useful as a transitional tool when considering
the introduction on new rules on a project where you might want to
Expand Down
19 changes: 10 additions & 9 deletions docs/source/gettingstarted.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,18 @@ file.
$ sqlfluff lint test.sql --dialect ansi
== [test.sql] FAIL
L: 1 | P: 1 | ST06 | Select wildcards then simple targets before calculations
| and aggregates.
L: 1 | P: 1 | L036 | Select targets should be on a new line unless there is
| only one select target.
L: 1 | P: 1 | ST06 | Select wildcards then simple targets before calculations
| and aggregates. [structure.column_order]
L: 1 | P: 7 | LT02 | Expected line break and indent of 4 spaces before 'a'.
| [layout.indent]
L: 1 | P: 9 | L006 | Expected single whitespace between naked identifier and
| binary operator '+'. [spacing.operators]
L: 1 | P: 10 | L006 | Expected single whitespace between binary operator '+'
| and naked identifier. [spacing.operators]
L: 1 | P: 11 | LT01 | Expected only single space before 'AS' keyword. Found ' '.
L: 1 | P: 9 | LT01 | Expected single whitespace between naked identifier and
| binary operator '+'. [layout.spacing]
L: 1 | P: 10 | LT01 | Expected single whitespace between binary operator '+'
| and naked identifier. [layout.spacing]
L: 1 | P: 11 | LT01 | Expected only single space before 'AS' keyword. Found '
| '. [layout.spacing]
L: 2 | P: 1 | LT02 | Expected indent of 4 spaces.
| [layout.indent]
L: 2 | P: 9 | LT02 | Expected line break and no indent before 'from'.
Expand All @@ -107,7 +108,7 @@ On each of the following lines you can see each of the problems it has
found, with some information about the location and what kind of
problem there is. One of the errors has been found on *line 1*, *position *
(as shown by :code:`L: 1 | P: 9`) and it's a problem with rule
*L006* (for a full list of rules, see :ref:`ruleref`). From this
*LT01* (for a full list of rules, see :ref:`ruleref`). From this
(and the following error) we can see that the problem is that there
is no space either side of the :code:`+` symbol in :code:`a+b`.
Head into the file, and correct this issue so that the file now
Expand All @@ -119,7 +120,7 @@ looks like this:
c AS bar from my_table
Rerun the same command as before, and you'll see that the original
error (violation of *L006*) no longer shows up.
error (violation of *LT01*) no longer shows up.

.. code-block:: text
Expand Down
4 changes: 2 additions & 2 deletions docs/source/rules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ ignore the lack of whitespace surrounding the ``*`` operator.

.. code-block:: sql
a.a*a.b AS bad_1 -- noqa: L006
a.a*a.b AS bad_1 -- noqa: LT01
Multiple rules can be ignored by placing them in a comma-delimited list.

.. code-block:: sql
a.a * a.b AS bad_2, -- noqa: L007, L006
a.a * a.b AS bad_2, -- noqa: L007, LT01
It is also possible to ignore non-rule based errors, and instead opt to
ignore templating (``TMP``) & parsing (``PRS``) errors.
Expand Down
3 changes: 3 additions & 0 deletions src/sqlfluff/core/default_config.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ spacing_after = touch:inline
[sqlfluff:layout:type:function_name]
spacing_after = touch:inline

[sqlfluff:layout:type:array_accessor]
spacing_before = touch:inline

[sqlfluff:layout:type:comment]
spacing_before = any
spacing_after = any
Expand Down
1 change: 1 addition & 0 deletions src/sqlfluff/rules/layout/LT01.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class Rule_LT01(BaseRule):
name = "layout.spacing"
# NOTE: This rule combines the following legacy rules:
# - L001: Trailing Whitespace
# - L006: Space around operators
# - L023: Space after AS in WITH clause
# - L024: Space immediately after USING
# - L039: Unnecessary Whitespace
Expand Down
8 changes: 4 additions & 4 deletions test/cli/commands_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,9 @@ def test__cli__command_render_stdin():
[
"-n",
"--rules",
"CP01,L006",
"CP01,LT01",
"--exclude-rules",
"L006,L031",
"LT01,L031",
"test/fixtures/linter/operator_errors.sql",
],
),
Expand All @@ -397,7 +397,7 @@ def test__cli__command_render_stdin():
[
"-n",
"--exclude-rules",
"L006,L007,L031,LT01,L071",
"LT01,L007,L031,LT01,L071",
"test/fixtures/linter/operator_errors.sql",
],
),
Expand Down Expand Up @@ -586,7 +586,7 @@ def test__cli__command_lint_warning():
# But should also contain the warnings.
# NOTE: Not including the whole description because it's too long.
assert (
"L: 4 | P: 9 | L006 | WARNING: Expected single whitespace"
"L: 4 | P: 9 | LT01 | WARNING: Expected single whitespace"
in result.output.strip()
)

Expand Down
14 changes: 7 additions & 7 deletions test/core/linter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,17 +402,17 @@ def test__linter__empty_file():
@pytest.mark.parametrize(
"ignore_templated_areas,check_tuples",
[
(True, [("L006", 3, 39), ("L006", 3, 40)]),
(True, [("LT01", 3, 39), ("LT01", 3, 40)]),
(
False,
[
# there are still two of each because L006 checks
# there are still two of each because LT01 checks
# for both *before* and *after* the operator.
# The deduplication filter makes sure there aren't 4.
("L006", 3, 16),
("L006", 3, 16),
("L006", 3, 39),
("L006", 3, 40),
("LT01", 3, 16),
("LT01", 3, 16),
("LT01", 3, 39),
("LT01", 3, 40),
],
),
],
Expand Down Expand Up @@ -536,7 +536,7 @@ def test__linter__encoding(fname, config_encoding, lexerror):
"noqa:L00*",
NoQaDirective(
0,
("L005", "L006", "L007", "L008", "L009", "LT01", "LT02"),
("L005", "L007", "L008", "L009", "LT01", "LT02"),
None,
),
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
test-config:
rules:
- L022
- L023
- LT01
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
test-config:
rules:
- LT01
- LT02
- L006
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
test-config:
rules:
- L006
- LT01
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
select *
from `{{project}}.{{dataset}}.user_labels_with_probs`
from `{{project}}.{{dataset}}.user_labels_with_probs`
where prob_max >= {{label_prob_threshold}}
--- only focus on 3 segments
and label_str not in ('marketing_maven', 'growth_services')
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
test-config:
rules:
- LT02
- L006
- LT01
- L009
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
test-config:
rules:
- LT01
- LT02
- L006
- L008
- L009
- L016
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ test-config:
rules:
- LT01
- LT02
- L006
- L008
- L009
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ test-config:
rules:
- LT01
- LT02
- L006
- L008
- L009
2 changes: 1 addition & 1 deletion test/fixtures/linter/operator_errors_ignore.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ are still present. No errors should be found on line 8 at all. */
SELECT
a.a + a.b AS good,
a.a-a.b AS bad_1, -- noqa
a.a*a.b AS bad_2, -- noqa: L007, L006
a.a*a.b AS bad_2, -- noqa: L007, LT01
a.a*a.b AS bad_3 -- noqa: L007
FROM tbl AS a
2 changes: 1 addition & 1 deletion test/rules/std_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
# Distinct and Group by
("AM01", "select_distinct_group_by.sql", [(1, 8)]),
# Make sure that ignoring works as expected
("L006", "operator_errors_ignore.sql", [(10, 8), (10, 9)]),
("LT01", "operator_errors_ignore.sql", [(10, 8), (10, 9)]),
(
"L031",
"aliases_in_join_error.sql",
Expand Down

0 comments on commit 02d3c26

Please sign in to comment.