Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capitalization rules (L010, L014, L030, L040) should ignore templated code #2566

Conversation

barrywhart
Copy link
Member

@barrywhart barrywhart commented Feb 5, 2022

Brief summary of the change made

Fixes #2565

Are there any other side effects of this change that we should be aware of?

Pull Request checklist

  • 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 tox -e generate-fixture-yml).
    • 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.

@@ -260,7 +260,7 @@ def raw_segments_upper(self) -> Optional[str]:
# return [seg.raw_upper for seg in self.raw_segments]

@cached_property
def templated(self) -> bool:
def is_templated(self) -> bool:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this property recently. Afterwards, I realized that, for consistency with other properties of BaseSegment (e.g. is_whitespace), I should've named it with an is_ prefix.

@codecov
Copy link

codecov bot commented Feb 5, 2022

Codecov Report

Merging #2566 (3efd2bb) into main (04b8ca9) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##              main     #2566   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          163       163           
  Lines        11844     11846    +2     
=========================================
+ Hits         11844     11846    +2     
Impacted Files Coverage Δ
src/sqlfluff/core/parser/segments/base.py 100.00% <100.00%> (ø)
src/sqlfluff/rules/L003.py 100.00% <100.00%> (ø)
src/sqlfluff/rules/L010.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 04b8ca9...3efd2bb. Read the comment docs.

Comment on lines +58 to +62
test_pass_ignore_templated_code:
pass_str: |
SELECT
{{ "greatest(a, b)" }},
GREATEST(i, j)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add the same test to L010.yml?

It's possible we break L010, but override that breakage in L030.

Adding test for all 4 is probably overkill, but think we should add in L010 anyway (maybe instead of L030?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I added a similar test case to L010.yml. It's a bit different -- I tailored the test case to the rule.

{{ "select" }} a
FROM foo
WHERE 1

@barrywhart barrywhart merged commit a2c280b into sqlfluff:main Feb 5, 2022
james-johnston-thumbtack added a commit to james-johnston-thumbtack/sqlfluff that referenced this pull request Apr 9, 2023
The pull request at sqlfluff#2566
made sense for users who set ignore_templated_areas to true because
those macros are not under their control.  However, if a user is writing
their own macros and would like to lint those, that commit made the
capitalization rules completely unusable.

For example, the following code in a single file would not trigger any
violations, even if ignore_templated_areas is set to false:

    {% macro abc() %}
        sElEcT a, B fRoM abc;
    {% endmacro %}
    {{ abc() }}

That is... a surprising result...
james-johnston-thumbtack added a commit to james-johnston-thumbtack/sqlfluff that referenced this pull request Apr 9, 2023
The pull request at sqlfluff#2566
made sense for users who set ignore_templated_areas to true because
those macros are not under their control.  However, if a user is writing
their own macros and would like to lint those, that commit made the
capitalization rules completely unusable.

For example, the following code in a single file would not trigger any
violations, even if ignore_templated_areas is set to false:

    {% macro abc() %}
        sElEcT a, B fRoM abc;
    {% endmacro %}
    {{ abc() }}

That is... a surprising result...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rule L030 consistency expectation doesn't seem to exclude templated code.
2 participants