Skip to content

Commit

Permalink
Layout Rules Recode (part 2) (#4456)
Browse files Browse the repository at this point in the history
  • Loading branch information
alanmcruickshank committed Mar 5, 2023
1 parent befc52d commit ce57b75
Show file tree
Hide file tree
Showing 48 changed files with 245 additions and 658 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
7 changes: 4 additions & 3 deletions docs/source/layout.rst
Original file line number Diff line number Diff line change
Expand Up @@ -670,10 +670,11 @@ available:
the spacing before commas (as shown in the config above), where line
breaks may be allowed, but if not they should *touch* the element before.

* The value of :code:`inline` is effectively the same as :code:`touch`
but in addition, no line breaks are allowed. This is best illustrated
* Both of the above can be qualified with the :code:`:inline` modifier -
which prevents newlines within the segment. This is best illustrated
by the spacing found in a qualified identifier like
:code:`my_schema.my_table`.
:code:`my_schema.my_table` which uses `touch:inline` or other clauses
where we want to force some elements to be on the same line.

* **Line Position**: set using the :code:`line_position` option. By default
this is unset, which implies no particular line position requirements. The
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
30 changes: 29 additions & 1 deletion src/sqlfluff/core/default_config.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,29 @@ spacing_within = touch
line_position = leading

[sqlfluff:layout:type:object_reference]
spacing_within = inline
spacing_within = touch:inline

[sqlfluff:layout:type:numeric_literal]
spacing_within = touch:inline

[sqlfluff:layout:type:sign_indicator]
spacing_after = touch:inline

[sqlfluff:layout:type:function_name]
spacing_after = touch:inline

[sqlfluff:layout:type:select_except_clause]
# This prevents space between EXCEPT following brackets:
# e.g. SELECT * EXCEPT()
spacing_within = touch:inline

[sqlfluff:layout:type:select_replace_clause]
# This prevents space between REPLACE following brackets:
# e.g. SELECT * REPLACE()
spacing_within = touch:inline

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

[sqlfluff:layout:type:comment]
spacing_before = any
Expand All @@ -127,6 +149,12 @@ spacing_after = any
spacing_before = any
spacing_after = any

[sqlfluff:layout:type:common_table_expression]
# The definition part of a CTE should fit on one line where possible.
# For users which regularly define column names in their CTEs they
# may which to relax this config to just `single`.
spacing_within = single:inline

# By setting a selection of clauses to "alone", we hint to the reflow
# algorithm that in the case of a long single line statement, the
# first place to add newlines would be around these clauses.
Expand Down
2 changes: 1 addition & 1 deletion src/sqlfluff/core/rules/crawlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def crawl(self, context: RuleContext) -> Iterator[RuleContext]:
# Check whether we should consider this segment _or it's children_
# at all.
if not self.passes_filter(context.segment):
if self.provide_raw_stack:
if self.provide_raw_stack: # pragma: no cover
context.raw_stack += tuple(context.segment.raw_segments)
return

Expand Down
3 changes: 2 additions & 1 deletion src/sqlfluff/dialects/dialect_sparksql.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,8 @@
trim_chars="@",
),
# This is the same as QuotedLiteralSegment but
# is given a different `name` to stop L048 flagging
# is given a different `name` to stop LT01 flagging
# TODO: Work out how the LT01 change influence this.
SignedQuotedLiteralSegment=OneOf(
TypedParser(
"single_quote",
Expand Down
64 changes: 0 additions & 64 deletions src/sqlfluff/rules/L005.py

This file was deleted.

96 changes: 0 additions & 96 deletions src/sqlfluff/rules/L006.py

This file was deleted.

53 changes: 0 additions & 53 deletions src/sqlfluff/rules/L008.py

This file was deleted.

0 comments on commit ce57b75

Please sign in to comment.