Skip to content

Commit

Permalink
Merge pull request #269 from stdweird/heredoc
Browse files Browse the repository at this point in the history
panlint: fix heredoc linting
  • Loading branch information
wpoely86 authored Jan 22, 2025
2 parents acd5596 + edd9a05 commit 14ed479
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
10 changes: 9 additions & 1 deletion panc/src/main/scripts/panlint/panlint.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ def __init__(self, filename, number, text):
self.text = str(text)
self.problems = []

def __repr__(self):
return f"Line('{self.filename}', {self.number}, '{self.text}')"


class Problem(object):
"""A class representing the abstract concept of a problem with a line of code.
Expand Down Expand Up @@ -90,7 +93,9 @@ def __str__(self):
RE_COMMENT = re.compile(RS_COMMENT)
RE_COMMENT_LINE = re.compile(r'^\s*' + RS_COMMENT + '.*$')
RE_ANNOTATION = re.compile(r'@\w*\s*{.*?}', re.S)
RE_OPERATOR = re.compile(r'([>=<!?]=|[<>+*=/-])')
# Deal with heredoc as fake operator incl tag (so no bitshift). Will ignore it in the code.
# The order here is important: the < at the end must remain at the end or linting heredocs will fail.
RE_OPERATOR = re.compile(r'([>=<!?]=|[>+*=/-]|<<\w+(?!;)|<)')
RE_HEREDOC = re.compile(r'<<(\w+);\s*$.*?\1$', re.S | re.M)

# Find usage and inclusion of components
Expand Down Expand Up @@ -196,6 +201,9 @@ def whitespace_around_operators(line, string_ranges):
valid = True
if inside_string(start, end, string_ranges):
continue
elif op.startswith('<<') and len(op) > 2:
# ignore fake heredoc operator
continue
elif op == '-' and (
(
re.search(r'[^\w\s)=]\s*$', chars_before) and re.search(r'^\s*\d+\s*[^\w\s]', chars_after)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
unique template unique/heredoc;

'/abc' = <<EOF;
verbatim text
lots of stuff not allowed in pan, like 1+1
EOF

0 comments on commit 14ed479

Please sign in to comment.