EBernhardson has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/325963 )

Change subject: Add script to support @suppress annotations in Phan
......................................................................

Add script to support @suppress annotations in Phan

This script is copied over from CirrusSearch. It adds the functionality
of per-line @suppress annotations. Phan already supports per-class
or per-method annotations, but does not have any per-line support due
to the PHP AST only returning comments that are class/property/method
level docblocks.

Change-Id: I5066b3b431fb69175a711ee366e95f31c7c47639
---
M tests/phan/bin/phan
A tests/phan/bin/postprocess-phan.php
2 files changed, 41 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/63/325963/1

diff --git a/tests/phan/bin/phan b/tests/phan/bin/phan
index 07caee6..efa94ee 100755
--- a/tests/phan/bin/phan
+++ b/tests/phan/bin/phan
@@ -31,7 +31,11 @@
        --project-root-directory "$ROOT" \
        --config-file "$ROOT/tests/phan/config.php" \
        --output "$ROOT/tests/phan/issues/issues-${REV}" \
-       -j 4
+       -j 2 \
+
+cat "$RUN" | php "${ROOT}/tests/phan/bin/postprocess-phan.php" > /tmp/phan.$$
+mv /tmp/phan.$$ "$RUN"
+rm /tmp/phan.$$
 
 # Re-link the latest directory
 rm -f "${ISSUES}/latest"
diff --git a/tests/phan/bin/postprocess-phan.php 
b/tests/phan/bin/postprocess-phan.php
new file mode 100644
index 0000000..3409a26
--- /dev/null
+++ b/tests/phan/bin/postprocess-phan.php
@@ -0,0 +1,36 @@
+<?php
+
+/**
+ * Phan does not natively support per-line @suppress annotations. To
+ * rectify that this script post-processes the results and checks if
+ * the line prior to an error has a matching @suppress annotation.
+ */
+
+$results = file( "php://stdin" );
+$errors = [];
+foreach ( $results as $error ) {
+       if ( !preg_match( '/^(.*):(\d+) (Phan\w+) (.*)$/', $error, $matches ) ) 
{
+               echo "Failed to parse line: $error\n";
+               continue;
+       }
+       list( $source, $file, $lineno, $type, $message ) = $matches;
+       $errors[$file][] = [
+               'orig' => $error,
+               // convert from 1 indexed to 0 indexed
+               'lineno' => $lineno - 1,
+               'type' => $type,
+       ];
+}
+
+foreach ( $errors as $file => $errors ) {
+       $source = file( $file );
+       foreach ( $errors as $error ) {
+               if ( $error['lineno'] === 0 || !preg_match(
+                       "|/\*\* @suppress {$error["type"]} |",
+                       $source[$error['lineno'] - 1]
+               ) ) {
+                       echo $error['orig'];
+               }
+       }
+}
+

-- 
To view, visit https://gerrit.wikimedia.org/r/325963
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5066b3b431fb69175a711ee366e95f31c7c47639
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: EBernhardson <ebernhard...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to