1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-10-23 17:18:50 +02:00

Add a Composer linter

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
This commit is contained in:
Joshua Spence 2015-08-19 21:39:11 +10:00 committed by Joshua Spence
parent 27ec3a2e34
commit f9bd6b058f
2 changed files with 57 additions and 0 deletions

View file

@ -54,6 +54,7 @@ phutil_register_library_map(array(
'ArcanistCommentStyleXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistCommentStyleXHPASTLinterRule.php', 'ArcanistCommentStyleXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistCommentStyleXHPASTLinterRule.php',
'ArcanistCommitWorkflow' => 'workflow/ArcanistCommitWorkflow.php', 'ArcanistCommitWorkflow' => 'workflow/ArcanistCommitWorkflow.php',
'ArcanistCompilerLintRenderer' => 'lint/renderer/ArcanistCompilerLintRenderer.php', 'ArcanistCompilerLintRenderer' => 'lint/renderer/ArcanistCompilerLintRenderer.php',
'ArcanistComposerLinter' => 'lint/linter/ArcanistComposerLinter.php',
'ArcanistComprehensiveLintEngine' => 'lint/engine/ArcanistComprehensiveLintEngine.php', 'ArcanistComprehensiveLintEngine' => 'lint/engine/ArcanistComprehensiveLintEngine.php',
'ArcanistConcatenationOperatorXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistConcatenationOperatorXHPASTLinterRule.php', 'ArcanistConcatenationOperatorXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistConcatenationOperatorXHPASTLinterRule.php',
'ArcanistConfiguration' => 'configuration/ArcanistConfiguration.php', 'ArcanistConfiguration' => 'configuration/ArcanistConfiguration.php',
@ -337,6 +338,7 @@ phutil_register_library_map(array(
'ArcanistCommentStyleXHPASTLinterRule' => 'ArcanistXHPASTLinterRule', 'ArcanistCommentStyleXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
'ArcanistCommitWorkflow' => 'ArcanistWorkflow', 'ArcanistCommitWorkflow' => 'ArcanistWorkflow',
'ArcanistCompilerLintRenderer' => 'ArcanistLintRenderer', 'ArcanistCompilerLintRenderer' => 'ArcanistLintRenderer',
'ArcanistComposerLinter' => 'ArcanistLinter',
'ArcanistComprehensiveLintEngine' => 'ArcanistLintEngine', 'ArcanistComprehensiveLintEngine' => 'ArcanistLintEngine',
'ArcanistConcatenationOperatorXHPASTLinterRule' => 'ArcanistXHPASTLinterRule', 'ArcanistConcatenationOperatorXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
'ArcanistConfiguration' => 'Phobject', 'ArcanistConfiguration' => 'Phobject',

View file

@ -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'));
}
}
}