]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Add a Composer linter
authorJoshua Spence <josh@joshuaspence.com>
Wed, 19 Aug 2015 11:39:11 +0000 (21:39 +1000)
committerJoshua Spence <josh@freelancer.com>
Wed, 19 Aug 2015 11:39:11 +0000 (21:39 +1000)
Summary: Adds a basic linter for ensuring that `composer.lock` files are up-to-date.

Test Plan: We have been using this in a private project for around a month.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: johnny-bit, Korvin

Differential Revision: https://secure.phabricator.com/D13883

src/__phutil_library_map__.php
src/lint/linter/ArcanistComposerLinter.php [new file with mode: 0644]

index ca5061e4d658bf1929667effe1e7cd9fdacc22d4..722bea0adef5215fff064cd0ac9bfd94fc4aea66 100644 (file)
@@ -54,6 +54,7 @@ phutil_register_library_map(array(
     'ArcanistCommentStyleXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistCommentStyleXHPASTLinterRule.php',
     'ArcanistCommitWorkflow' => 'workflow/ArcanistCommitWorkflow.php',
     'ArcanistCompilerLintRenderer' => 'lint/renderer/ArcanistCompilerLintRenderer.php',
+    'ArcanistComposerLinter' => 'lint/linter/ArcanistComposerLinter.php',
     'ArcanistComprehensiveLintEngine' => 'lint/engine/ArcanistComprehensiveLintEngine.php',
     'ArcanistConcatenationOperatorXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistConcatenationOperatorXHPASTLinterRule.php',
     'ArcanistConfiguration' => 'configuration/ArcanistConfiguration.php',
@@ -337,6 +338,7 @@ phutil_register_library_map(array(
     'ArcanistCommentStyleXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
     'ArcanistCommitWorkflow' => 'ArcanistWorkflow',
     'ArcanistCompilerLintRenderer' => 'ArcanistLintRenderer',
+    'ArcanistComposerLinter' => 'ArcanistLinter',
     'ArcanistComprehensiveLintEngine' => 'ArcanistLintEngine',
     'ArcanistConcatenationOperatorXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
     'ArcanistConfiguration' => 'Phobject',
diff --git a/src/lint/linter/ArcanistComposerLinter.php b/src/lint/linter/ArcanistComposerLinter.php
new file mode 100644 (file)
index 0000000..02b7c67
--- /dev/null
@@ -0,0 +1,55 @@
+<?php
+
+final class ArcanistComposerLinter extends ArcanistLinter {
+
+  const LINT_OUT_OF_DATE = 1;
+
+  public function getInfoName() {
+    return pht('Composer');
+  }
+
+  public function getInfoDescription() {
+    return pht('A linter for Composer related files.');
+  }
+
+  public function getLinterName() {
+    return 'COMPOSER';
+  }
+
+  public function getLinterConfigurationName() {
+    return 'composer';
+  }
+
+  public function getLintNameMap() {
+    return array(
+      self::LINT_OUT_OF_DATE => pht('Lock file out-of-date'),
+    );
+  }
+
+  public function lintPath($path) {
+    switch (basename($path)) {
+      case 'composer.json':
+        $this->lintComposerJson($path);
+        break;
+      case 'composer.lock':
+        break;
+    }
+  }
+
+  private function lintComposerJson($path) {
+    $composer_hash = md5(Filesystem::readFile(dirname($path).'/composer.json'));
+    $composer_lock = phutil_json_decode(
+      Filesystem::readFile(dirname($path).'/composer.lock'));
+
+    if ($composer_hash !== $composer_lock['hash']) {
+      $this->raiseLintAtPath(
+        self::LINT_OUT_OF_DATE,
+        pht(
+          "The '%s' file seems to be out-of-date. ".
+          "You probably need to run `%s`.",
+          'composer.lock',
+          'composer update'));
+    }
+  }
+
+}