Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a linter rule to prevent hardcoded class names
Summary: Add a linter rule to advise against the use of hardcoded class names. Hardcoded class names make the code harder to refactor and it is generally preferable to use the `__CLASS__` magic constant instead. Test Plan: This works, but needs some polish. Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: Korvin, epriestley Differential Revision: https://secure.phabricator.com/D12605
- Loading branch information
1 parent
73aca1f
commit 9090efc
Showing
2 changed files
with
69 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/lint/linter/__tests__/xhpast/class-name-literal.lint-test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
class MyClass { | ||
public function someMethod() { | ||
return 'MyClass'; | ||
} | ||
|
||
public function someOtherMethod() { | ||
$x = 'MyClass is awesome'; | ||
$y = 'MyClassIsAwesome'; | ||
return __CLASS__; | ||
} | ||
} | ||
~~~~~~~~~~ | ||
error:2:7 | ||
advice:4:12 | ||
advice:8:10 | ||
~~~~~~~~~~ | ||
<?php | ||
class MyClass { | ||
public function someMethod() { | ||
return __CLASS__; | ||
} | ||
|
||
public function someOtherMethod() { | ||
$x = 'MyClass is awesome'; | ||
$y = 'MyClassIsAwesome'; | ||
return __CLASS__; | ||
} | ||
} |