Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15489662
D13942.id34982.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
8 KB
Referenced Files
None
Subscribers
None
D13942.id34982.diff
View Options
diff --git a/.arclint b/.arclint
--- a/.arclint
+++ b/.arclint
@@ -45,15 +45,7 @@
"xhpast": {
"type": "xhpast",
"include": "(\\.php$)",
- "severity": {
- "16": "advice",
- "34": "error"
- },
- "xhpast.blacklisted.function": {
- "eval": "The eval() function should be avoided. It is potentially unsafe and makes debugging more difficult."
- },
- "xhpast.php-version": "5.2.3",
- "xhpast.php-version.windows": "5.3.0"
+ "xhpast.standard": "phutil"
}
}
}
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -202,6 +202,7 @@
'ArcanistPhrequentWorkflow' => 'workflow/ArcanistPhrequentWorkflow.php',
'ArcanistPhutilLibraryLinter' => 'lint/linter/ArcanistPhutilLibraryLinter.php',
'ArcanistPhutilXHPASTLinter' => 'lint/linter/ArcanistPhutilXHPASTLinter.php',
+ 'ArcanistPhutilXHPASTLinterStandard' => 'lint/linter/xhpast/standards/ArcanistPhutilXHPASTLinterStandard.php',
'ArcanistPhutilXHPASTLinterTestCase' => 'lint/linter/__tests__/ArcanistPhutilXHPASTLinterTestCase.php',
'ArcanistPlusOperatorOnStringsXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistPlusOperatorOnStringsXHPASTLinterRule.php',
'ArcanistPregQuoteMisuseXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistPregQuoteMisuseXHPASTLinterRule.php',
@@ -278,6 +279,8 @@
'ArcanistXHPASTLinter' => 'lint/linter/ArcanistXHPASTLinter.php',
'ArcanistXHPASTLinterRule' => 'lint/linter/xhpast/ArcanistXHPASTLinterRule.php',
'ArcanistXHPASTLinterRuleTestCase' => 'lint/linter/xhpast/__tests__/ArcanistXHPASTLinterRuleTestCase.php',
+ 'ArcanistXHPASTLinterStandard' => 'lint/linter/xhpast/ArcanistXHPASTLinterStandard.php',
+ 'ArcanistXHPASTLinterStandardTestCase' => 'lint/linter/xhpast/__tests__/ArcanistXHPASTLinterStandardTestCase.php',
'ArcanistXHPASTLinterTestCase' => 'lint/linter/__tests__/ArcanistXHPASTLinterTestCase.php',
'ArcanistXMLLinter' => 'lint/linter/ArcanistXMLLinter.php',
'ArcanistXMLLinterTestCase' => 'lint/linter/__tests__/ArcanistXMLLinterTestCase.php',
@@ -491,6 +494,7 @@
'ArcanistPhrequentWorkflow' => 'ArcanistWorkflow',
'ArcanistPhutilLibraryLinter' => 'ArcanistLinter',
'ArcanistPhutilXHPASTLinter' => 'ArcanistBaseXHPASTLinter',
+ 'ArcanistPhutilXHPASTLinterStandard' => 'ArcanistXHPASTLinterStandard',
'ArcanistPhutilXHPASTLinterTestCase' => 'ArcanistLinterTestCase',
'ArcanistPlusOperatorOnStringsXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
'ArcanistPregQuoteMisuseXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
@@ -567,6 +571,8 @@
'ArcanistXHPASTLinter' => 'ArcanistBaseXHPASTLinter',
'ArcanistXHPASTLinterRule' => 'Phobject',
'ArcanistXHPASTLinterRuleTestCase' => 'PhutilTestCase',
+ 'ArcanistXHPASTLinterStandard' => 'Phobject',
+ 'ArcanistXHPASTLinterStandardTestCase' => 'PhutilTestCase',
'ArcanistXHPASTLinterTestCase' => 'ArcanistLinterTestCase',
'ArcanistXMLLinter' => 'ArcanistLinter',
'ArcanistXMLLinterTestCase' => 'ArcanistLinterTestCase',
diff --git a/src/lint/linter/ArcanistLinter.php b/src/lint/linter/ArcanistLinter.php
--- a/src/lint/linter/ArcanistLinter.php
+++ b/src/lint/linter/ArcanistLinter.php
@@ -196,7 +196,6 @@
return;
}
-
public function getLinterPriority() {
return 1.0;
}
@@ -209,6 +208,11 @@
return $this;
}
+ public function addCustomSeverityMap(array $map) {
+ $this->customSeverityMap = array_merge($this->customSeverityMap, $map);
+ return $this;
+ }
+
final public function setCustomSeverityRules(array $rules) {
$this->customSeverityRules = $rules;
return $this;
diff --git a/src/lint/linter/ArcanistXHPASTLinter.php b/src/lint/linter/ArcanistXHPASTLinter.php
--- a/src/lint/linter/ArcanistXHPASTLinter.php
+++ b/src/lint/linter/ArcanistXHPASTLinter.php
@@ -62,27 +62,53 @@
}
public function getLinterConfigurationOptions() {
- return parent::getLinterConfigurationOptions() + array_mergev(
- mpull($this->rules, 'getLinterConfigurationOptions'));
+ $options = array(
+ 'xhpast.standard' => array(
+ 'type' => 'optional string | list<string>',
+ 'help' => pht('The coding standard(s) to apply.'),
+ ),
+ );
+
+ return array_merge(
+ $options,
+ parent::getLinterConfigurationOptions(),
+ array_mergev(mpull($this->rules, 'getLinterConfigurationOptions')));
}
public function setLinterConfigurationValue($key, $value) {
- $matched = false;
+ switch ($key) {
+ case 'xhpast.standard':
+ $standards = (array)$value;
- foreach ($this->rules as $rule) {
- foreach ($rule->getLinterConfigurationOptions() as $k => $spec) {
- if ($k == $key) {
- $matched = true;
- $rule->setLinterConfigurationValue($key, $value);
+ foreach ($standards as $standard) {
+ $standard = ArcanistXHPASTLinterStandard::getStandard($value);
+
+ foreach ($standard->getLinterConfiguration() as $k => $v) {
+ $this->setLinterConfigurationValue($k, $v);
+ }
+ $this->addCustomSeverityMap($standard->getLinterSeverityMap());
}
- }
- }
- if ($matched) {
- return;
- }
+ return;
- return parent::setLinterConfigurationValue($key, $value);
+ default:
+ $matched = false;
+
+ foreach ($this->rules as $rule) {
+ foreach ($rule->getLinterConfigurationOptions() as $k => $spec) {
+ if ($k == $key) {
+ $matched = true;
+ $rule->setLinterConfigurationValue($key, $value);
+ }
+ }
+ }
+
+ if ($matched) {
+ return;
+ }
+
+ return parent::setLinterConfigurationValue($key, $value);
+ }
}
public function getVersion() {
diff --git a/src/lint/linter/xhpast/ArcanistXHPASTLinterStandard.php b/src/lint/linter/xhpast/ArcanistXHPASTLinterStandard.php
new file mode 100644
--- /dev/null
+++ b/src/lint/linter/xhpast/ArcanistXHPASTLinterStandard.php
@@ -0,0 +1,36 @@
+<?php
+
+abstract class ArcanistXHPASTLinterStandard extends Phobject {
+
+ final public static function getStandard($key) {
+ $standards = self::loadAllStandards();
+
+ if (empty($standards[$key])) {
+ throw new ArcanistUsageException(
+ pht(
+ 'No such XHPAST linter standard. Available standards are: %s.',
+ implode(', ', array_keys($standards))));
+ }
+
+ return $standards[$key];
+ }
+
+ final public static function loadAllStandards() {
+ return id(new PhutilClassMapQuery())
+ ->setAncestorClass(__CLASS__)
+ ->setUniqueMethod('getKey')
+ ->execute();
+ }
+
+ abstract public function getKey();
+ abstract public function getName();
+ abstract public function getDescription();
+
+ public function getLinterConfiguration() {
+ return array();
+ }
+
+ public function getLinterSeverityMap() {
+ return array();
+ }
+}
diff --git a/src/lint/linter/xhpast/__tests__/ArcanistXHPASTLinterStandardTestCase.php b/src/lint/linter/xhpast/__tests__/ArcanistXHPASTLinterStandardTestCase.php
new file mode 100644
--- /dev/null
+++ b/src/lint/linter/xhpast/__tests__/ArcanistXHPASTLinterStandardTestCase.php
@@ -0,0 +1,10 @@
+<?php
+
+final class ArcanistXHPASTLinterStandardTestCase extends PhutilTestCase {
+
+ public function testLoadAllStandards() {
+ ArcanistXHPASTLinterStandard::loadAllStandards();
+ $this->assertTrue(true);
+ }
+
+}
diff --git a/src/lint/linter/xhpast/standards/ArcanistPhutilXHPASTLinterStandard.php b/src/lint/linter/xhpast/standards/ArcanistPhutilXHPASTLinterStandard.php
new file mode 100644
--- /dev/null
+++ b/src/lint/linter/xhpast/standards/ArcanistPhutilXHPASTLinterStandard.php
@@ -0,0 +1,41 @@
+<?php
+
+final class ArcanistPhutilXHPASTLinterStandard
+ extends ArcanistXHPASTLinterStandard {
+
+ public function getKey() {
+ return 'phutil';
+ }
+
+ public function getName() {
+ return pht('Phutil');
+ }
+
+ public function getDescription() {
+ return pht('PHP Coding Standards for Phutil libraries.');
+ }
+
+ public function getLinterConfiguration() {
+ return array(
+ 'xhpast.blacklisted.function' => array(
+ 'eval' => pht(
+ 'The %s function should be avoided. It is potentially unsafe '.
+ 'and makes debugging more difficult.',
+ 'eval()'),
+ 'xhpast.php-version' => '5.2.3',
+ 'xhpast.php-version.windows' => '5.3.0',
+ ),
+ );
+ }
+
+ public function getLinterSeverityMap() {
+ $advice = ArcanistLintSeverity::SEVERITY_ADVICE;
+ $error = ArcanistLintSeverity::SEVERITY_ERROR;
+
+ return array(
+ ArcanistTodoCommentXHPASTLinterRule::ID => $advice,
+ ArcanistCommentSpacingXHPASTLinterRule::ID => $error,
+ );
+ }
+
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Apr 12, 11:08 AM (3 d, 19 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7705600
Default Alt Text
D13942.id34982.diff (8 KB)
Attached To
Mode
D13942: Add XHAST linter standards
Attached
Detach File
Event Timeline
Log In to Comment