mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-12-24 14:30:55 +01:00
Require space after //
Summary: I use `//~` for marking places which shouldn't be committed. It also looks ugly. Maybe it can be just a warning but we provide a patch so error is OK? Test Plan: New test. Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Differential Revision: https://secure.phabricator.com/D2824
This commit is contained in:
parent
d724ed0860
commit
31e36fe3fa
3 changed files with 50 additions and 5 deletions
|
@ -92,6 +92,8 @@ class PhutilLintEngine extends ArcanistLintEngine {
|
|||
=> ArcanistLintSeverity::SEVERITY_WARNING,
|
||||
ArcanistXHPASTLinter::LINT_PHP_53_FEATURES
|
||||
=> ArcanistLintSeverity::SEVERITY_ERROR,
|
||||
ArcanistXHPASTLinter::LINT_COMMENT_SPACING
|
||||
=> ArcanistLintSeverity::SEVERITY_ERROR,
|
||||
));
|
||||
$linters[] = $xhpast_linter;
|
||||
foreach ($paths as $path) {
|
||||
|
|
|
@ -57,6 +57,7 @@ final class ArcanistXHPASTLinter extends ArcanistLinter {
|
|||
const LINT_PHP_53_FEATURES = 31;
|
||||
const LINT_REUSED_AS_ITERATOR = 32;
|
||||
const LINT_PHT_WITH_DYNAMIC_STRING = 33;
|
||||
const LINT_COMMENT_SPACING = 34;
|
||||
|
||||
|
||||
public function getLintNameMap() {
|
||||
|
@ -93,6 +94,7 @@ final class ArcanistXHPASTLinter extends ArcanistLinter {
|
|||
self::LINT_PHP_53_FEATURES => 'Use Of PHP 5.3 Features',
|
||||
self::LINT_REUSED_AS_ITERATOR => 'Variable Reused As Iterator',
|
||||
self::LINT_PHT_WITH_DYNAMIC_STRING => 'Use of pht() on Dynamic String',
|
||||
self::LINT_COMMENT_SPACING => 'Comment Spaces',
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -124,6 +126,9 @@ final class ArcanistXHPASTLinter extends ArcanistLinter {
|
|||
self::LINT_PHT_WITH_DYNAMIC_STRING
|
||||
=> ArcanistLintSeverity::SEVERITY_WARNING,
|
||||
|
||||
self::LINT_COMMENT_SPACING
|
||||
=> ArcanistLintSeverity::SEVERITY_ADVICE,
|
||||
|
||||
// This is disabled by default because it implies a very strict policy
|
||||
// which isn't necessary in the general case.
|
||||
self::LINT_RAGGED_CLASSTREE_EDGE
|
||||
|
@ -194,6 +199,7 @@ final class ArcanistXHPASTLinter extends ArcanistLinter {
|
|||
$this->lintPregQuote($root);
|
||||
$this->lintUndeclaredVariables($root);
|
||||
$this->lintArrayIndexWhitespace($root);
|
||||
$this->lintCommentSpaces($root);
|
||||
$this->lintHashComments($root);
|
||||
$this->lintPrimaryDeclarationFilenameMatch($root);
|
||||
$this->lintTautologicalExpressions($root);
|
||||
|
@ -567,6 +573,24 @@ final class ArcanistXHPASTLinter extends ArcanistLinter {
|
|||
}
|
||||
|
||||
|
||||
protected function lintCommentSpaces($root) {
|
||||
foreach ($root->selectTokensOfType('T_COMMENT') as $comment) {
|
||||
$value = $comment->getValue();
|
||||
if ($value[0] != '#') {
|
||||
$match = null;
|
||||
if (preg_match('@^(/[/*]+)[^/*\s]@', $value, $match)) {
|
||||
$this->raiseLintAtOffset(
|
||||
$comment->getOffset(),
|
||||
self::LINT_COMMENT_SPACING,
|
||||
'Put space after comment start.',
|
||||
$match[1],
|
||||
$match[1].' ');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected function lintHashComments($root) {
|
||||
foreach ($root->selectTokensOfType('T_COMMENT') as $comment) {
|
||||
$value = $comment->getValue();
|
||||
|
@ -579,7 +603,7 @@ final class ArcanistXHPASTLinter extends ArcanistLinter {
|
|||
self::LINT_COMMENT_STYLE,
|
||||
'Use "//" single-line comments, not "#".',
|
||||
'#',
|
||||
'//');
|
||||
(preg_match('/^#\S/', $value) ? '// ' : '//'));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,23 +12,42 @@
|
|||
*/
|
||||
//#yes
|
||||
/*#yes*/
|
||||
#
|
||||
//
|
||||
/////////////////// yes
|
||||
/*no */
|
||||
/**no */
|
||||
/** yes */
|
||||
/**** yes ****/
|
||||
~~~~~~~~~~
|
||||
error:2:1
|
||||
error:3:1
|
||||
error:5:1
|
||||
error:6:11
|
||||
advice:13:1
|
||||
advice:14:1
|
||||
error:15:1
|
||||
advice:18:1
|
||||
advice:19:1
|
||||
~~~~~~~~~~
|
||||
<?php
|
||||
// no
|
||||
//no
|
||||
// no
|
||||
// yes
|
||||
// no
|
||||
/* yes */ //no
|
||||
/* yes */ // no
|
||||
/*
|
||||
* yes
|
||||
*/
|
||||
/**
|
||||
* yes
|
||||
*/
|
||||
//#yes
|
||||
/*#yes*/
|
||||
// #yes
|
||||
/* #yes*/
|
||||
//
|
||||
//
|
||||
/////////////////// yes
|
||||
/* no */
|
||||
/** no */
|
||||
/** yes */
|
||||
/**** yes ****/
|
||||
|
|
Loading…
Reference in a new issue