From: Joshua Spence Date: Thu, 13 Aug 2015 21:37:48 +0000 (+1000) Subject: Add a linter rule for global variables X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=bf88f4616cdfc8a391012f768e5e226aa0fb9a52;p=arcanist.git Add a linter rule for global variables Summary: Ref T7409. Global variables are gross and should be avoided like the plague. Test Plan: Added test cases. Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: Korvin Maniphest Tasks: T7409 Differential Revision: https://secure.phabricator.com/D13882 --- diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index c4b3d8b1..70f87173 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -110,6 +110,7 @@ phutil_register_library_map(array( 'ArcanistGeneratedLinterTestCase' => 'lint/linter/__tests__/ArcanistGeneratedLinterTestCase.php', 'ArcanistGetConfigWorkflow' => 'workflow/ArcanistGetConfigWorkflow.php', 'ArcanistGitAPI' => 'repository/api/ArcanistGitAPI.php', + 'ArcanistGlobalVariableXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistGlobalVariableXHPASTLinterRule.php', 'ArcanistGoLintLinter' => 'lint/linter/ArcanistGoLintLinter.php', 'ArcanistGoLintLinterTestCase' => 'lint/linter/__tests__/ArcanistGoLintLinterTestCase.php', 'ArcanistGoTestResultParser' => 'unit/parser/ArcanistGoTestResultParser.php', @@ -390,6 +391,7 @@ phutil_register_library_map(array( 'ArcanistGeneratedLinterTestCase' => 'ArcanistLinterTestCase', 'ArcanistGetConfigWorkflow' => 'ArcanistWorkflow', 'ArcanistGitAPI' => 'ArcanistRepositoryAPI', + 'ArcanistGlobalVariableXHPASTLinterRule' => 'ArcanistXHPASTLinterRule', 'ArcanistGoLintLinter' => 'ArcanistExternalLinter', 'ArcanistGoLintLinterTestCase' => 'ArcanistExternalLinterTestCase', 'ArcanistGoTestResultParser' => 'ArcanistTestResultParser', diff --git a/src/lint/linter/__tests__/xhpast/global-variables.lint-test b/src/lint/linter/__tests__/xhpast/global-variables.lint-test new file mode 100644 index 00000000..863cf5fd --- /dev/null +++ b/src/lint/linter/__tests__/xhpast/global-variables.lint-test @@ -0,0 +1,8 @@ +selectDescendantsOfType('n_GLOBAL_DECLARATION_LIST'); + + foreach ($nodes as $node) { + $this->raiseLintAtNode( + $node, + pht( + 'Limit the use of global variables. Global variables are '. + 'generally a bad idea and should be avoided when possible.')); + } + } + +}