diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 9c9e09ed..4d1a81c6 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -290,6 +290,8 @@ phutil_register_library_map(array( '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 @@ phutil_register_library_map(array( '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 index f780ec6c..d6828e28 100644 --- a/src/lint/linter/xhpast/ArcanistXHPASTLinterRule.php +++ b/src/lint/linter/xhpast/ArcanistXHPASTLinterRule.php @@ -237,6 +237,7 @@ abstract class ArcanistXHPASTLinterRule extends Phobject { 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 index 00000000..da07ef19 --- /dev/null +++ b/src/lint/linter/xhpast/rules/ArcanistPublicPropertyXHPASTLinterRule.php @@ -0,0 +1,35 @@ +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 index 00000000..35e4d5fe --- /dev/null +++ b/src/lint/linter/xhpast/rules/__tests__/ArcanistPublicPropertyXHPASTLinterRuleTestCase.php @@ -0,0 +1,10 @@ +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 index 00000000..a7921aff --- /dev/null +++ b/src/lint/linter/xhpast/rules/__tests__/public-property/class.lint-test @@ -0,0 +1,9 @@ +