Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15417290
D14641.id35439.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D14641.id35439.diff
View Options
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
@@ -290,6 +290,8 @@
'ArcanistPlusOperatorOnStringsXHPASTLinterRuleTestCase' => 'lint/linter/xhpast/rules/__tests__/ArcanistPlusOperatorOnStringsXHPASTLinterRuleTestCase.php',
'ArcanistPregQuoteMisuseXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistPregQuoteMisuseXHPASTLinterRule.php',
'ArcanistPregQuoteMisuseXHPASTLinterRuleTestCase' => 'lint/linter/xhpast/rules/__tests__/ArcanistPregQuoteMisuseXHPASTLinterRuleTestCase.php',
+ 'ArcanistPublicPropertyXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistPublicPropertyXHPASTLinterRule.php',
+ 'ArcanistPublicPropertyXHPASTLinterRuleTestCase' => 'lint/linter/xhpast/rules/__tests__/ArcanistPublicPropertyXHPASTLinterRuleTestCase.php',
'ArcanistPuppetLintLinter' => 'lint/linter/ArcanistPuppetLintLinter.php',
'ArcanistPuppetLintLinterTestCase' => 'lint/linter/__tests__/ArcanistPuppetLintLinterTestCase.php',
'ArcanistPyFlakesLinter' => 'lint/linter/ArcanistPyFlakesLinter.php',
@@ -694,6 +696,8 @@
'ArcanistPlusOperatorOnStringsXHPASTLinterRuleTestCase' => 'ArcanistXHPASTLinterRuleTestCase',
'ArcanistPregQuoteMisuseXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
'ArcanistPregQuoteMisuseXHPASTLinterRuleTestCase' => 'ArcanistXHPASTLinterRuleTestCase',
+ 'ArcanistPublicPropertyXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
+ 'ArcanistPublicPropertyXHPASTLinterRuleTestCase' => 'ArcanistXHPASTLinterRuleTestCase',
'ArcanistPuppetLintLinter' => 'ArcanistExternalLinter',
'ArcanistPuppetLintLinterTestCase' => 'ArcanistExternalLinterTestCase',
'ArcanistPyFlakesLinter' => 'ArcanistExternalLinter',
diff --git a/src/lint/linter/xhpast/ArcanistXHPASTLinterRule.php b/src/lint/linter/xhpast/ArcanistXHPASTLinterRule.php
--- a/src/lint/linter/xhpast/ArcanistXHPASTLinterRule.php
+++ b/src/lint/linter/xhpast/ArcanistXHPASTLinterRule.php
@@ -237,6 +237,7 @@
switch ($modifier_list->getTypeName()) {
case 'n_CLASS_ATTRIBUTES':
+ case 'n_CLASS_MEMBER_MODIFIER_LIST':
case 'n_METHOD_MODIFIER_LIST':
break;
diff --git a/src/lint/linter/xhpast/rules/ArcanistPublicPropertyXHPASTLinterRule.php b/src/lint/linter/xhpast/rules/ArcanistPublicPropertyXHPASTLinterRule.php
new file mode 100644
--- /dev/null
+++ b/src/lint/linter/xhpast/rules/ArcanistPublicPropertyXHPASTLinterRule.php
@@ -0,0 +1,35 @@
+<?php
+
+final class ArcanistPublicPropertyXHPASTLinterRule
+ extends ArcanistXHPASTLinterRule {
+
+ const ID = 130;
+
+ public function getLintName() {
+ return pht('Use of `%s` Properties', 'public');
+ }
+
+ public function getLintSeverity() {
+ return ArcanistLintSeverity::SEVERITY_ADVICE;
+ }
+
+ public function process(XHPASTNode $root) {
+ $members = $root->selectDescendantsOfType(
+ 'n_CLASS_MEMBER_DECLARATION_LIST');
+
+ foreach ($members as $member) {
+ $modifiers = $this->getModifiers($member);
+
+ if (isset($modifiers['public'])) {
+ $this->raiseLintAtNode(
+ $member,
+ pht(
+ '`%s` properties should be avoided. Instead of exposing '.
+ 'the property value directly, consider using getter '.
+ 'and setter methods.',
+ 'public'));
+ }
+ }
+ }
+
+}
diff --git a/src/lint/linter/xhpast/rules/__tests__/ArcanistPublicPropertyXHPASTLinterRuleTestCase.php b/src/lint/linter/xhpast/rules/__tests__/ArcanistPublicPropertyXHPASTLinterRuleTestCase.php
new file mode 100644
--- /dev/null
+++ b/src/lint/linter/xhpast/rules/__tests__/ArcanistPublicPropertyXHPASTLinterRuleTestCase.php
@@ -0,0 +1,10 @@
+<?php
+
+final class ArcanistPublicPropertyXHPASTLinterRuleTestCase
+ extends ArcanistXHPASTLinterRuleTestCase {
+
+ public function testLinter() {
+ $this->executeTestsInDirectory(dirname(__FILE__).'/public-property/');
+ }
+
+}
diff --git a/src/lint/linter/xhpast/rules/__tests__/public-property/class.lint-test b/src/lint/linter/xhpast/rules/__tests__/public-property/class.lint-test
new file mode 100644
--- /dev/null
+++ b/src/lint/linter/xhpast/rules/__tests__/public-property/class.lint-test
@@ -0,0 +1,9 @@
+<?php
+
+class SomeClass {
+ private $x;
+ protected $y;
+ public $z;
+}
+~~~~~~~~~~
+advice:6:3
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Mar 21, 4:30 PM (12 h, 50 m ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7628722
Default Alt Text
D14641.id35439.diff (4 KB)
Attached To
Mode
D14641: Add a linter rule for public properties
Attached
Detach File
Event Timeline
Log In to Comment