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

Change subject: Move phpcs.xml to .phpcs.xml
......................................................................

Move phpcs.xml to .phpcs.xml

Bug: T177256
Change-Id: Ic86360ecb94eb09daf5babe2d73cf6112cef2f0a
---
M container/thing.py
1 file changed, 23 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/labs/libraryupgrader 
refs/changes/05/385505/1

diff --git a/container/thing.py b/container/thing.py
index 96f2f3a..9151962 100755
--- a/container/thing.py
+++ b/container/thing.py
@@ -35,6 +35,7 @@
     'composer.json',
     'package.json',
     'phpcs.xml',
+    '.phpcs.xml',
 }
 RULE = '<rule ref="./vendor/mediawiki/mediawiki-codesniffer/MediaWiki">'
 RULE_NO_EXCLUDE = '<rule 
ref="(\./)?vendor/mediawiki/mediawiki-codesniffer/MediaWiki"( )?/>'
@@ -79,10 +80,10 @@
     os.unlink(f.name)
 
 
-def rename_old_sniff_codes():
-    with open('phpcs.xml', 'r') as f:
+def rename_old_sniff_codes(phpcs_xml):
+    with open(phpcs_xml, 'r') as f:
         old = f.read()
-    with open('phpcs.xml', 'w') as f:
+    with open(phpcs_xml, 'w') as f:
         new = old.replace(
             'MediaWiki.FunctionComment.Missing.Protected',
             
'MediaWiki.Commenting.FunctionComment.MissingDocumentationProtected'
@@ -104,6 +105,10 @@
     setup(env)
     with open('composer.json', 'r') as f:
         j = json.load(f, object_pairs_hook=OrderedDict)
+    if os.path.exists('.phpcs.xml'):
+        phpcs_xml = '.phpcs.xml'
+    else:
+        phpcs_xml = 'phpcs.xml'
     added_fix = False
     if 'fix' not in j['scripts']:
         j['scripts']['fix'] = ['phpcbf']
@@ -113,16 +118,17 @@
         out = json.dumps(j, indent='\t', ensure_ascii=False)
         f.write(out + '\n')
 
-    rename_old_sniff_codes()
+    moved_phpcs = False
+    rename_old_sniff_codes(phpcs_xml)
 
     failing = set()
     now_failing = set()
     now_pass = set()
 
-    with open('phpcs.xml', 'r') as f:
+    with open(phpcs_xml, 'r') as f:
         old = f.read()
 
-    tree = ET.parse('phpcs.xml')
+    tree = ET.parse(phpcs_xml)
     root = tree.getroot()
     previously_failing = set()
     for child in root:
@@ -133,7 +139,7 @@
     print(previously_failing)
 
     # Re-enable all disabled rules
-    with open('phpcs.xml', 'w') as f:
+    with open(phpcs_xml, 'w') as f:
         new = FIND_RULE.sub(
             '<rule ref="./vendor/mediawiki/mediawiki-codesniffer/MediaWiki" 
/>',
             old
@@ -167,9 +173,9 @@
         for sniff in failing:
             if sniff not in previously_failing:
                 now_failing.add(sniff)
-        subprocess.check_call(['git', 'checkout', 'phpcs.xml'])
-        rename_old_sniff_codes()
-        with open('phpcs.xml') as f:
+        subprocess.check_call(['git', 'checkout', phpcs_xml])
+        rename_old_sniff_codes(phpcs_xml)
+        with open(phpcs_xml) as f:
             text = f.read()
         for sniff in now_pass:
             text = re.sub(
@@ -191,8 +197,11 @@
                         '<exclude name="{}" />\n\t\t<exclude name="{}" 
/>'.format(failing[i - 1], sniff),
                         text
                     )
-        with open('phpcs.xml', 'w') as f:
+        with open(phpcs_xml, 'w') as f:
             f.write(text)
+        if phpcs_xml == 'phpcs.xml':
+            subprocess.call(['git', 'mv', 'phpcs.xml', '.phpcs.xml'])
+            moved_phpcs = True
         try:
             subprocess.check_call(['composer', 'test'])
         except subprocess.CalledProcessError:
@@ -216,6 +225,9 @@
             msg += '* ' + sniff_name + '\n'
         msg += '\n'
 
+    if moved_phpcs:
+        msg += 'And moved phpcs.xml to .phpcs.xml (T177256).\n\n'
+
     if added_fix:
         msg += 'Also added "composer fix" command.'
     print(msg)

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic86360ecb94eb09daf5babe2d73cf6112cef2f0a
Gerrit-PatchSet: 1
Gerrit-Project: labs/libraryupgrader
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>

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

Reply via email to