-
-
Notifications
You must be signed in to change notification settings - Fork 653
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
Capitalization rules (L010, L014, L030, L040) should ignore templated code #2566
Conversation
@@ -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: |
There was a problem hiding this comment.
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 Report
@@ Coverage Diff @@
## main #2566 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 163 163
Lines 11844 11846 +2
=========================================
+ Hits 11844 11846 +2
Continue to review full report at Codecov.
|
test_pass_ignore_templated_code: | ||
pass_str: | | ||
SELECT | ||
{{ "greatest(a, b)" }}, | ||
GREATEST(i, j) |
There was a problem hiding this comment.
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?)
There was a problem hiding this comment.
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
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...
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...
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 intest/fixtures/rules/std_rule_cases
..sql
/.yml
parser test cases intest/fixtures/dialects
(note YML files can be auto generated withtox -e generate-fixture-yml
).test/fixtures/linter/autofix
.Added appropriate documentation for the change.
Created GitHub issues for any relevant followup/future enhancements if appropriate.