Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15489566
D13942.id33653.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
9 KB
Referenced Files
None
Subscribers
None
D13942.id33653.diff
View Options
diff --git a/.arclint b/.arclint
--- a/.arclint
+++ b/.arclint
@@ -49,11 +49,7 @@
"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
@@ -186,6 +186,7 @@
'ArcanistPHPEchoTagXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistPHPEchoTagXHPASTLinterRule.php',
'ArcanistPHPOpenTagXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistPHPOpenTagXHPASTLinterRule.php',
'ArcanistPHPShortTagXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistPHPShortTagXHPASTLinterRule.php',
+ 'ArcanistPSR2XHPASTLinterStandard' => 'lint/linter/xhpast/standards/ArcanistPSR2XHPASTLinterStandard.php',
'ArcanistParenthesesSpacingXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistParenthesesSpacingXHPASTLinterRule.php',
'ArcanistParseStrUseXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistParseStrUseXHPASTLinterRule.php',
'ArcanistPasteWorkflow' => 'workflow/ArcanistPasteWorkflow.php',
@@ -198,6 +199,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',
@@ -274,6 +276,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',
@@ -471,6 +475,7 @@
'ArcanistPHPEchoTagXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
'ArcanistPHPOpenTagXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
'ArcanistPHPShortTagXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
+ 'ArcanistPSR2XHPASTLinterStandard' => 'ArcanistXHPASTLinterStandard',
'ArcanistParenthesesSpacingXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
'ArcanistParseStrUseXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
'ArcanistPasteWorkflow' => 'ArcanistWorkflow',
@@ -483,6 +488,7 @@
'ArcanistPhrequentWorkflow' => 'ArcanistWorkflow',
'ArcanistPhutilLibraryLinter' => 'ArcanistLinter',
'ArcanistPhutilXHPASTLinter' => 'ArcanistBaseXHPASTLinter',
+ 'ArcanistPhutilXHPASTLinterStandard' => 'ArcanistXHPASTLinterStandard',
'ArcanistPhutilXHPASTLinterTestCase' => 'ArcanistLinterTestCase',
'ArcanistPlusOperatorOnStringsXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
'ArcanistPregQuoteMisuseXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
@@ -559,6 +565,8 @@
'ArcanistXHPASTLinter' => 'ArcanistBaseXHPASTLinter',
'ArcanistXHPASTLinterRule' => 'Phobject',
'ArcanistXHPASTLinterRuleTestCase' => 'PhutilTestCase',
+ 'ArcanistXHPASTLinterStandard' => 'Phobject',
+ 'ArcanistXHPASTLinterStandardTestCase' => 'PhutilTestCase',
'ArcanistXHPASTLinterTestCase' => 'ArcanistLinterTestCase',
'ArcanistXMLLinter' => 'ArcanistLinter',
'ArcanistXMLLinterTestCase' => 'ArcanistLinterTestCase',
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,44 @@
}
public function getLinterConfigurationOptions() {
- return parent::getLinterConfigurationOptions() + array_mergev(
- mpull($this->rules, 'getLinterConfigurationOptions'));
+ $options = array(
+ 'xhpast.standard' => array(
+ 'type' => 'optional string',
+ 'help' => pht('The coding standard 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':
+ $standard = ArcanistXHPASTLinterStandard::getStandard($value);
+ $standard->configure($this);
+ return;
+
+ default:
+ $matched = false;
+
+ foreach ($this->rules as $rule) {
+ foreach ($rule->getLinterConfigurationOptions() as $k => $spec) {
+ if ($k == $key) {
+ $matched = true;
+ $rule->setLinterConfigurationValue($key, $value);
+ }
+ }
+ }
- foreach ($this->rules as $rule) {
- foreach ($rule->getLinterConfigurationOptions() as $k => $spec) {
- if ($k == $key) {
- $matched = true;
- $rule->setLinterConfigurationValue($key, $value);
+ if ($matched) {
+ return;
}
- }
- }
- if ($matched) {
- return;
+ return parent::setLinterConfigurationValue($key, $value);
}
-
- 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,44 @@
+<?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();
+
+ final public function configure(ArcanistXHPASTLinter $linter) {
+ foreach ($this->getLinterConfiguration() as $key => $value) {
+ $linter->setLinterConfigurationValue($key, $value);
+ }
+
+ // TODO: Adjust linter severity.
+ }
+
+ protected function getLinterConfiguration() {
+ return array();
+ }
+
+ protected function getLinterSeverities() {
+ 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/ArcanistPSR2XHPASTLinterStandard.php b/src/lint/linter/xhpast/standards/ArcanistPSR2XHPASTLinterStandard.php
new file mode 100644
--- /dev/null
+++ b/src/lint/linter/xhpast/standards/ArcanistPSR2XHPASTLinterStandard.php
@@ -0,0 +1,24 @@
+<?php
+
+final class ArcanistPSR2XHPASTLinterStandard
+ extends ArcanistXHPASTLinterStandard {
+
+ public function getKey() {
+ return 'PSR2';
+ }
+
+ public function getName() {
+ return pht('PSR-2');
+ }
+
+ public function getDescription() {
+ return pht('PSR-2 Coding Standard.');
+ }
+
+ protected function getLinterConfiguration() {
+ return array(
+ 'xhpast.allow-elseif' => 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,32 @@
+<?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.');
+ }
+
+ protected function getLinterConfiguration() {
+ return array(
+ 'xhpast.allow-elseif' => false,
+ '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',
+ ),
+ );
+ }
+
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Apr 12, 10:16 AM (3 d, 14 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7740514
Default Alt Text
D13942.id33653.diff (9 KB)
Attached To
Mode
D13942: Add XHAST linter standards
Attached
Detach File
Event Timeline
Log In to Comment