Skip to content

Commit 7be6759

Browse files
committed
✨ Add PHP lint pattern support
Added support for PHP lint error messages to the PATTERNS list in logToCs.py.
1 parent 833678e commit 7be6759

8 files changed

Lines changed: 24 additions & 1 deletion

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ In the script, patterns can be added to "PATTERNS" to match more messages.
153153
154154
To allow multiline patterns, the python module 'regex' is required.
155155
156+
To debug, `python3 -m trace --ignore-dir=/usr/lib -t LogToCs.py` can be
157+
used where you would just call the script to get a line by line trace.
158+
156159
## Author(s):
157160
158161
- [mdeweerd]

logToCs.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,12 @@ def submit( # pylint: disable=too-many-arguments
419419
f"^{FILE_REGEX}{EOL_REGEX}"
420420
rf"\s+{LINE_REGEX}:{COLUMN_REGEX}\s+{SEVERITY_REGEX}\s+{MSG_REGEX}$"
421421
),
422+
# php lint: php -l
423+
# PHP Parse error: syntax error, ... in path/to/file on line 531
424+
re.compile(
425+
rf"^PHP Parse error:\s+{MSG_REGEX} in {FILE_REGEX}"
426+
f" on line {LINE_REGEX}$"
427+
),
422428
# hurl:
423429
# error: Error message
424430
# --> api/contracts/10_contracts.hurl:3:6
@@ -609,7 +615,9 @@ def parse_message(message):
609615
Returns the fields in a dict.
610616
"""
611617
for pattern in PATTERNS:
618+
# print(pattern.pattern) # Help for debug
612619
fields = pattern.match(message, re.IGNORECASE)
620+
# print(f"{fields!r} - {message}") # Help for debug
613621
if not fields:
614622
continue
615623
result = fields.groupdict()
@@ -644,7 +652,7 @@ def parse_message(message):
644652
return None
645653

646654

647-
def add_error_entry( # pylint: disable=too-many-arguments,unused-argument
655+
def add_error_entry( # pylint: disable=too-many-arguments,unused-argument,too-many-positional-arguments # noqa: E501
648656
root,
649657
severity,
650658
file_name,

tests/IN/phan2.log

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
htdocs\public\members\new.php:1027 PhanTypeMismatchArgumentProbablyReal Argument 10 ($disabled) is '' of type '' but \Form::selectarray() takes int (no real type) defined at htdocs\core\class\html.form.class.php:9556 (the inferred real argument type has nothing in common with the parameter's phpdoc type)
2+
htdocs\public\members\new.php:1027 PhanTypeMismatchArgumentProbablyReal Argument 6 ($value_as_key) is '' of type '' but \Form::selectarray() takes int (no real type) defined at htdocs\core\class\html.form.class.php:9556 (the inferred real argument type has nothing in common with the parameter's phpdoc type)
3+
htdocs\public\members\new.php:1027 PhanTypeMismatchArgument Argument 7 ($moreparam) is 0 of type 0 but \Form::selectarray() takes string defined at htdocs\core\class\html.form.class.php:9556

tests/IN/phan2.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
::error file=htdocs/public/members/new.php,line=1027::PhanTypeMismatchArgumentProbablyReal Argument 10 ($disabled) is '' of type '' but \Form::selectarray() takes int (no real type) defined at htdocs\core\class\html.form.class.php:9556 (the inferred real argument type has nothing in common with the parameter's phpdoc type)
2+
::error file=htdocs/public/members/new.php,line=1027::PhanTypeMismatchArgumentProbablyReal Argument 6 ($value_as_key) is '' of type '' but \Form::selectarray() takes int (no real type) defined at htdocs\core\class\html.form.class.php:9556 (the inferred real argument type has nothing in common with the parameter's phpdoc type)
3+
::error file=htdocs/public/members/new.php,line=1027::PhanTypeMismatchArgument Argument 7 ($moreparam) is 0 of type 0 but \Form::selectarray() takes string defined at htdocs\core\class\html.form.class.php:9556

tests/IN/phan2.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version='1.0' encoding='utf_8'?>
2+
<checkstyle version="6.5"><file name="htdocs\public\members\new.php"><error severity="error" line="1027" message="PhanTypeMismatchArgumentProbablyReal Argument 10 ($disabled) is '' of type '' but \Form::selectarray() takes int (no real type) defined at htdocs\core\class\html.form.class.php:9556 (the inferred real argument type has nothing in common with the parameter's phpdoc type)" /><error severity="error" line="1027" message="PhanTypeMismatchArgumentProbablyReal Argument 6 ($value_as_key) is '' of type '' but \Form::selectarray() takes int (no real type) defined at htdocs\core\class\html.form.class.php:9556 (the inferred real argument type has nothing in common with the parameter's phpdoc type)" /><error severity="error" line="1027" message="PhanTypeMismatchArgument Argument 7 ($moreparam) is 0 of type 0 but \Form::selectarray() takes string defined at htdocs\core\class\html.form.class.php:9556" /></file></checkstyle>

tests/IN/phplint.log

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
PHP Parse error: syntax error, unexpected token "." in htdocs/modulebuilder/template/core/modules/modMyModule.class.php on line 531

tests/IN/phplint.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
::error file=htdocs/modulebuilder/template/core/modules/modMyModule.class.php,line=531::syntax error, unexpected token "."

tests/IN/phplint.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version='1.0' encoding='utf_8'?>
2+
<checkstyle version="6.5"><file name="htdocs/modulebuilder/template/core/modules/modMyModule.class.php"><error severity="error" line="531" message="syntax error, unexpected token &quot;.&quot;" /></file></checkstyle>

0 commit comments

Comments
 (0)