jenkins-bot has submitted this change and it was merged.

Change subject: Have utils.check_php_opening_tag check the file extension suffix
......................................................................


Have utils.check_php_opening_tag check the file extension suffix

php -l will happily say that non-PHP files don't have syntax errors, and
is unconditionally called in sync-file. But since check_php_opening_tag is
more restrictive, only actually check PHP files.

Change-Id: Ie1d16423787a25e3c45e77d9447e8e2d51fd0299
---
M scap/tasks.py
M scap/utils.py
A tests/data/good_notphp.py
3 files changed, 5 insertions(+), 2 deletions(-)

Approvals:
  BryanDavis: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/scap/tasks.py b/scap/tasks.py
index 92c7eab..c23d4ce 100644
--- a/scap/tasks.py
+++ b/scap/tasks.py
@@ -91,8 +91,7 @@
     for path in paths:
         for root, dirs, files in os.walk(path):
             for filename in files:
-                if filename.endswith(('.php', '.inc', '.phtml', '.php5')):
-                    utils.check_php_opening_tag(os.path.join(root, filename))
+                utils.check_php_opening_tag(os.path.join(root, filename))
 
 
 def compile_wikiversions_cdb(source_tree, cfg):
diff --git a/scap/utils.py b/scap/utils.py
index bb6e126..c78be39 100644
--- a/scap/utils.py
+++ b/scap/utils.py
@@ -313,6 +313,8 @@
     :param path: Location of file
     :raises: ValueError on invalid file
     """
+    if not path.endswith(('.php', '.inc', '.phtml', '.php5')):
+        return
     with open(path) as f:
         text = f.read()
         if text.strip() and not text.startswith('<?php'):
diff --git a/tests/data/good_notphp.py b/tests/data/good_notphp.py
new file mode 100644
index 0000000..9e6bb77
--- /dev/null
+++ b/tests/data/good_notphp.py
@@ -0,0 +1,2 @@
+#!/usr/bin/env python3
+print("I'm not PHP!")

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ie1d16423787a25e3c45e77d9447e8e2d51fd0299
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/tools/scap
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>
Gerrit-Reviewer: BryanDavis <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to