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

L014 leading underscore capitalization inference fix #3841

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/sqlfluff/rules/L010.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
)


def is_capitalizable(character: str) -> bool:
if character.lower() == character.upper():
barrywhart marked this conversation as resolved.
Show resolved Hide resolved
return False
return True


@document_groups
@document_fix_compatible
@document_configuration
Expand Down Expand Up @@ -121,7 +127,13 @@ def _handle_segment(self, segment, memory) -> LintResult:
refuted_cases = memory.get("refuted_cases", set())

# Which cases are definitely inconsistent with the segment?
if segment.raw[0] != segment.raw[0].upper():
for character in segment.raw:
if is_capitalizable(character):
first_letter_is_lowercase = character != character.upper()
break
first_letter_is_lowercase = False # If none of the characters are letters there will be a parsing error, so not sure we need this statement
barrywhart marked this conversation as resolved.
Show resolved Hide resolved

if first_letter_is_lowercase:
refuted_cases.update(["upper", "capitalise", "pascal"])
if segment.raw != segment.raw.lower():
refuted_cases.update(["lower"])
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/rules/std_rule_cases/L014.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ test_pass_consistent_capitalisation_with_multiple_words_with_numbers:
# Numbers count as part of words so following letter can be upper or lower
pass_str: SELECT AppleFritter, Apple123fritter, Apple123Fritter

test_pass_consistent_capitalisation_with_leading_underscore:
pass_str: SELECT _a, b

test_fail_inconsistent_capitalisation_lower_case:
# Test that fixes are consistent
fail_str: SELECT a, B
Expand Down