Skip to content

Commit

Permalink
fix(linter): fixed overly greedy H037, improved linter tests
Browse files Browse the repository at this point in the history
closes #631
  • Loading branch information
christopherpickering committed May 9, 2023
1 parent 6048c46 commit 66c9187
Show file tree
Hide file tree
Showing 7 changed files with 526 additions and 306 deletions.
2 changes: 1 addition & 1 deletion src/djlint/rules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,4 @@
message: Duplicate attribute found.
flags: re.I
patterns:
- <\w[^>]*?\s([a-z][a-z-]*?)(?==.+?\1=[^>]*?>)
- <\w[^>]*?\s\K([a-z][a-z-]*?)(?==[^>]+?\1=[^>]*?>)
55 changes: 20 additions & 35 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,24 +134,17 @@ def printer(expected, source, actual):
print(f"{ color.get(diff[:1], Style.RESET_ALL)}{diff}{Style.RESET_ALL}")


def lint_printer(source, expected, excluded, actual):
def lint_printer(source, expected, actual):
width, _ = shutil.get_terminal_size()

expected_text = "Expected Rules"
excluded_text = "Excluded Rules"
actual_text = "Actual"
source_text = "Source"

expected_width = int((width - len(expected_text) - 2) / 2)
excluded_width = int((width - len(excluded_text) - 2) / 2)
actual_width = int((width - len(actual_text) - 2) / 2)
source_width = int((width - len(source_text) - 2) / 2)

def padder(value, width):
if len(value) < width:
return str(value) + " " * (width - len(value))
return value[:20]

print()
print(
f"{Fore.BLUE}{Style.BRIGHT}{'─' * source_width} {source_text} {'─' * source_width}{Style.RESET_ALL}"
Expand All @@ -160,42 +153,34 @@ def padder(value, width):
print(source)
print()

if expected != ():
print(
f"{Fore.BLUE}{Style.BRIGHT}{'─' * expected_width} {expected_text} {'─' * expected_width}{Style.RESET_ALL}"
)
print()
for x in expected:
if isinstance(x, tuple):
print(f"{x[0]}, line #{x[1]}")
else:
print(x)
print()
if excluded != ():
print(
f"{Fore.BLUE}{Style.BRIGHT}{'─' * expected_width} {expected_text} {'─' * expected_width}{Style.RESET_ALL}"
)
print()
for x in expected:
print(
f"{Fore.BLUE}{Style.BRIGHT}{'─' * excluded_width} {excluded_text} {'─' * excluded_width}{Style.RESET_ALL}"
f"{Fore.RED}{Style.BRIGHT}{x['code']}{Style.RESET_ALL} {x['line']} {x['match']}"
)
print(f' {x["message"]}')
print()
for x in excluded:
if isinstance(x, tuple):
print(f"{x[0]}, line #{x[1]}")
else:
print(x)
print()

print(
f"{Fore.BLUE}{Style.BRIGHT}{'─' * actual_width} {actual_text} {'─' * actual_width}{Style.RESET_ALL}"
)
print()

if actual:
max_code = max(len(x["code"]) for x in actual)
max_line = max(len(x["line"]) for x in actual)
max_match = min(max(len(x["match"]) for x in actual), 20)
for x in actual:
print(
f'{padder(x["code"],max_code)} {padder(x["line"], max_line)} {padder(x["match"],max_match)} >> {x["message"]}'
)
for x in actual:
print(
f"{Fore.RED}{Style.BRIGHT}{x['code']}{Style.RESET_ALL} {x['line']} {x['match']}"
)
print(f' {x["message"]}')
print()
if len(actual) == 0:
print(f"{Fore.YELLOW}No codes found.{Style.RESET_ALL}")
print()

else:
print(f"{Fore.YELLOW}{actual}{Style.RESET_ALL}")
print()


Expand Down
Loading

0 comments on commit 66c9187

Please sign in to comment.