Page MenuHomePhabricator

D14604.id35324.diff
No OneTemporary

D14604.id35324.diff

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
@@ -190,6 +190,7 @@
'ArcanistInvalidDefaultParameterXHPASTLinterRuleTestCase' => 'lint/linter/xhpast/rules/__tests__/ArcanistInvalidDefaultParameterXHPASTLinterRuleTestCase.php',
'ArcanistInvalidModifiersXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistInvalidModifiersXHPASTLinterRule.php',
'ArcanistInvalidModifiersXHPASTLinterRuleTestCase' => 'lint/linter/xhpast/rules/__tests__/ArcanistInvalidModifiersXHPASTLinterRuleTestCase.php',
+ 'ArcanistInvalidNumeralXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistInvalidNumeralXHPASTLinterRule.php',
'ArcanistJSHintLinter' => 'lint/linter/ArcanistJSHintLinter.php',
'ArcanistJSHintLinterTestCase' => 'lint/linter/__tests__/ArcanistJSHintLinterTestCase.php',
'ArcanistJSONLintLinter' => 'lint/linter/ArcanistJSONLintLinter.php',
@@ -590,6 +591,7 @@
'ArcanistInvalidDefaultParameterXHPASTLinterRuleTestCase' => 'ArcanistXHPASTLinterRuleTestCase',
'ArcanistInvalidModifiersXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
'ArcanistInvalidModifiersXHPASTLinterRuleTestCase' => 'ArcanistXHPASTLinterRuleTestCase',
+ 'ArcanistInvalidNumeralXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
'ArcanistJSHintLinter' => 'ArcanistExternalLinter',
'ArcanistJSHintLinterTestCase' => 'ArcanistExternalLinterTestCase',
'ArcanistJSONLintLinter' => 'ArcanistExternalLinter',
diff --git a/src/lint/linter/xhpast/rules/ArcanistInvalidNumeralXHPASTLinterRule.php b/src/lint/linter/xhpast/rules/ArcanistInvalidNumeralXHPASTLinterRule.php
new file mode 100644
--- /dev/null
+++ b/src/lint/linter/xhpast/rules/ArcanistInvalidNumeralXHPASTLinterRule.php
@@ -0,0 +1,40 @@
+<?php
+
+final class ArcanistInvalidNumeralXHPASTLinterRule
+ extends ArcanistXHPASTLinterRule {
+
+ const ID = 125;
+
+ public function getLintName() {
+ return pht('Invalid Number');
+ }
+
+ public function process(XHPASTNode $root) {
+ $octals = $this->getOctalNumericScalars($root);
+
+ foreach ($octals as $octal) {
+ if (!preg_match('/^0[0-7]*$/', $octal->getConcreteString())) {
+ $this->raiseLintAtNode(
+ $octal,
+ pht('Invalid octal.'));
+ }
+ }
+ }
+
+ private function getOctalNumericScalars(XHPASTNode $root) {
+ $numeric_scalars = $root->selectDescendantsOfType('n_NUMERIC_SCALAR');
+ $octals = array();
+
+ foreach ($numeric_scalars as $numeric_scalar) {
+ $number = $numeric_scalar->getConcreteString();
+
+ if ($number[0] === '0' ) {
+ $octals[] = $numeric_scalar;
+ }
+ }
+
+ return $octals;
+
+ }
+
+}
diff --git a/test.php b/test.php
deleted file mode 100644
--- a/test.php
+++ /dev/null
@@ -1,3 +0,0 @@
-<?php
-
-$x = &foobar();

File Metadata

Mime Type
text/plain
Expires
Fri, Mar 21, 12:58 PM (2 w, 2 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7715480
Default Alt Text
D14604.id35324.diff (2 KB)

Event Timeline