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

Change subject: Cheap yaml lint job.
......................................................................


Cheap yaml lint job.

Change-Id: Iaaad8cfd31c02871824b1c018e99d91836637195
---
M composer.json
A tests/LintYaml.php
2 files changed, 53 insertions(+), 0 deletions(-)

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



diff --git a/composer.json b/composer.json
index 1fc4afd..d38cef6 100644
--- a/composer.json
+++ b/composer.json
@@ -42,5 +42,8 @@
        "config": {
                "optimize-autoloader": true,
                "prepend-autoloader": false
+       },
+       "scripts": {
+               "test": "php tests/LintYaml.php"
        }
 }
diff --git a/tests/LintYaml.php b/tests/LintYaml.php
new file mode 100644
index 0000000..340ad44
--- /dev/null
+++ b/tests/LintYaml.php
@@ -0,0 +1,50 @@
+<?php
+// Sadly, I didn't find any off-the-shelf yaml linters that didn't make me mad.
+// Requires PHP 5.4
+
+use Symfony\Component\Yaml\Parser;
+
+function runForYamlFiles( $callback ) {
+       $directoryIterator = new RecursiveDirectoryIterator( __DIR__ . '/../' );
+       $filter = new RecursiveCallbackFilterIterator( $directoryIterator, 
function( $current, $key, $iterator ) {
+               // Skip tests and vendor directories.
+               if ( $current->getFilename() === 'tests'
+                       || $current->getFilename() === 'vendor'
+                       || $current->getFilename() === 'node_modules'
+               ) {
+                       return false;
+               }
+
+               // Recurse
+               if ( $current->isDir() ) {
+                       return true;
+               }
+
+               // Match .yaml or .yml
+               return preg_match( '/\.ya?ml$/', $current->getFilename() );
+       } );
+
+       $iterator = new RecursiveIteratorIterator( $filter );
+       foreach ( $iterator as $file ) {
+               if ( $file->isFile() ) {
+                       $callback( $file->getPathname() );
+               }
+       }
+}
+
+function lintYamlFile( $path ) {
+       $yamlParser = new Parser();
+       try {
+               $data = $yamlParser->parse( file_get_contents( $path ) );
+       } catch ( Exception $ex ) {
+               global $exitStatus;
+               $exitStatus = -1;
+
+               error_log( $path . ': ' . $ex->getMessage() );
+       }
+}
+
+$exitStatus = 0;
+require_once __DIR__ . '/../vendor/autoload.php';
+runForYamlFiles( 'lintYamlFile' );
+exit($exitStatus);

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Iaaad8cfd31c02871824b1c018e99d91836637195
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: master
Gerrit-Owner: Awight <[email protected]>
Gerrit-Reviewer: AndyRussG <[email protected]>
Gerrit-Reviewer: Awight <[email protected]>
Gerrit-Reviewer: Cdentinger <[email protected]>
Gerrit-Reviewer: Ejegg <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: Ssmith <[email protected]>
Gerrit-Reviewer: XenoRyet <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to