Page MenuHomePhabricator

D14561.diff
No OneTemporary

D14561.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
@@ -178,6 +178,8 @@
'ArcanistInstallCertificateWorkflow' => 'workflow/ArcanistInstallCertificateWorkflow.php',
'ArcanistInstanceOfOperatorXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistInstanceOfOperatorXHPASTLinterRule.php',
'ArcanistInstanceofOperatorXHPASTLinterRuleTestCase' => 'lint/linter/xhpast/rules/__tests__/ArcanistInstanceofOperatorXHPASTLinterRuleTestCase.php',
+ 'ArcanistInterfaceMethodBodyXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistInterfaceMethodBodyXHPASTLinterRule.php',
+ 'ArcanistInterfaceMethodBodyXHPASTLinterRuleTestCase' => 'lint/linter/xhpast/rules/__tests__/ArcanistInterfaceMethodBodyXHPASTLinterRuleTestCase.php',
'ArcanistInvalidDefaultParameterXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistInvalidDefaultParameterXHPASTLinterRule.php',
'ArcanistInvalidDefaultParameterXHPASTLinterRuleTestCase' => 'lint/linter/xhpast/rules/__tests__/ArcanistInvalidDefaultParameterXHPASTLinterRuleTestCase.php',
'ArcanistInvalidModifiersXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistInvalidModifiersXHPASTLinterRule.php',
@@ -566,6 +568,8 @@
'ArcanistInstallCertificateWorkflow' => 'ArcanistWorkflow',
'ArcanistInstanceOfOperatorXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
'ArcanistInstanceofOperatorXHPASTLinterRuleTestCase' => 'ArcanistXHPASTLinterRuleTestCase',
+ 'ArcanistInterfaceMethodBodyXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
+ 'ArcanistInterfaceMethodBodyXHPASTLinterRuleTestCase' => 'ArcanistXHPASTLinterRuleTestCase',
'ArcanistInvalidDefaultParameterXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
'ArcanistInvalidDefaultParameterXHPASTLinterRuleTestCase' => 'ArcanistXHPASTLinterRuleTestCase',
'ArcanistInvalidModifiersXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
diff --git a/src/lint/linter/xhpast/rules/ArcanistInterfaceMethodBodyXHPASTLinterRule.php b/src/lint/linter/xhpast/rules/ArcanistInterfaceMethodBodyXHPASTLinterRule.php
new file mode 100644
--- /dev/null
+++ b/src/lint/linter/xhpast/rules/ArcanistInterfaceMethodBodyXHPASTLinterRule.php
@@ -0,0 +1,33 @@
+<?php
+
+final class ArcanistInterfaceMethodBodyXHPASTLinterRule
+ extends ArcanistXHPASTLinterRule {
+
+ const ID = 114;
+
+ public function getLintName() {
+ return pht('`%s` Method Cannot Contain Body', 'interface');
+ }
+
+ public function process(XHPASTNode $root) {
+ $interfaces = $root->selectDescendantsOfType('n_INTERFACE_DECLARATION');
+
+ foreach ($interfaces as $interface) {
+ $methods = $interface->selectDescendantsOfType('n_METHOD_DECLARATION');
+
+ foreach ($methods as $method) {
+ $body = $method->getChildByIndex(5);
+
+ if ($body->getTypeName() != 'n_EMPTY') {
+ $this->raiseLintAtNode(
+ $body,
+ pht(
+ '`%s` methods cannot contain a body. This construct will '.
+ 'cause a fatal error.',
+ 'interface'));
+ }
+ }
+ }
+ }
+
+}
diff --git a/src/lint/linter/xhpast/rules/__tests__/ArcanistInterfaceMethodBodyXHPASTLinterRuleTestCase.php b/src/lint/linter/xhpast/rules/__tests__/ArcanistInterfaceMethodBodyXHPASTLinterRuleTestCase.php
new file mode 100644
--- /dev/null
+++ b/src/lint/linter/xhpast/rules/__tests__/ArcanistInterfaceMethodBodyXHPASTLinterRuleTestCase.php
@@ -0,0 +1,10 @@
+<?php
+
+final class ArcanistInterfaceMethodBodyXHPASTLinterRuleTestCase
+ extends ArcanistXHPASTLinterRuleTestCase {
+
+ public function testLinter() {
+ $this->executeTestsInDirectory(dirname(__FILE__).'/interface-method-body/');
+ }
+
+}
diff --git a/src/lint/linter/xhpast/rules/__tests__/interface-method-body/body.lint-test b/src/lint/linter/xhpast/rules/__tests__/interface-method-body/body.lint-test
new file mode 100644
--- /dev/null
+++ b/src/lint/linter/xhpast/rules/__tests__/interface-method-body/body.lint-test
@@ -0,0 +1,7 @@
+<?php
+
+interface SomeInterface {
+ public function someMethod() {}
+}
+~~~~~~~~~~
+error:4:32
diff --git a/src/lint/linter/xhpast/rules/__tests__/interface-method-body/no-body.lint-test b/src/lint/linter/xhpast/rules/__tests__/interface-method-body/no-body.lint-test
new file mode 100644
--- /dev/null
+++ b/src/lint/linter/xhpast/rules/__tests__/interface-method-body/no-body.lint-test
@@ -0,0 +1,6 @@
+<?php
+
+interface SomeInterface {
+ public function someMethod();
+}
+~~~~~~~~~~

File Metadata

Mime Type
text/plain
Expires
Mon, Oct 28, 12:07 AM (2 w, 1 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6735057
Default Alt Text
D14561.diff (4 KB)

Event Timeline