Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15553616
D12805.id30781.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
D12805.id30781.diff
View Options
diff --git a/src/lint/ArcanistLintMessage.php b/src/lint/ArcanistLintMessage.php
--- a/src/lint/ArcanistLintMessage.php
+++ b/src/lint/ArcanistLintMessage.php
@@ -211,7 +211,7 @@
}
public function setDependentMessages(array $messages) {
- assert_instances_of($messages, 'ArcanistLintMessage');
+ assert_instances_of($messages, __CLASS__);
$this->dependentMessages = $messages;
return $this;
}
diff --git a/src/lint/linter/ArcanistPyLintLinter.php b/src/lint/linter/ArcanistPyLintLinter.php
--- a/src/lint/linter/ArcanistPyLintLinter.php
+++ b/src/lint/linter/ArcanistPyLintLinter.php
@@ -63,10 +63,13 @@
if (!$error_regexp && !$warning_regexp && !$advice_regexp) {
throw new ArcanistUsageException(
- "You are invoking the PyLint linter but have not configured any of ".
- "'lint.pylint.codes.error', 'lint.pylint.codes.warning', or ".
- "'lint.pylint.codes.advice'. Consult the documentation for ".
- "ArcanistPyLintLinter.");
+ pht(
+ "You are invoking the PyLint linter but have not configured any of ".
+ "'%s', '%s', or '%s'. Consult the documentation for %s.",
+ 'lint.pylint.codes.error',
+ 'lint.pylint.codes.warning',
+ 'lint.pylint.codes.advice',
+ __CLASS__));
}
$code_map = array(
diff --git a/src/lint/linter/ArcanistXHPASTLinter.php b/src/lint/linter/ArcanistXHPASTLinter.php
--- a/src/lint/linter/ArcanistXHPASTLinter.php
+++ b/src/lint/linter/ArcanistXHPASTLinter.php
@@ -61,6 +61,7 @@
const LINT_INNER_FUNCTION = 59;
const LINT_DEFAULT_PARAMETERS = 60;
const LINT_LOWERCASE_FUNCTIONS = 61;
+ const LINT_CLASS_NAME_LITERAL = 62;
private $blacklistedFunctions = array();
private $naminghook;
@@ -191,6 +192,8 @@
=> pht('Default Parameters'),
self::LINT_LOWERCASE_FUNCTIONS
=> pht('Lowercase Functions'),
+ self::LINT_CLASS_NAME_LITERAL
+ => pht('Class Name Literal'),
);
}
@@ -240,6 +243,7 @@
self::LINT_INNER_FUNCTION => $warning,
self::LINT_DEFAULT_PARAMETERS => $warning,
self::LINT_LOWERCASE_FUNCTIONS => $advice,
+ self::LINT_CLASS_NAME_LITERAL => $advice,
);
}
@@ -307,7 +311,7 @@
public function getVersion() {
// The version number should be incremented whenever a new rule is added.
- return '24';
+ return '25';
}
protected function resolveFuture($path, Future $future) {
@@ -395,6 +399,7 @@
'lintInnerFunctions' => self::LINT_INNER_FUNCTION,
'lintDefaultParameters' => self::LINT_DEFAULT_PARAMETERS,
'lintLowercaseFunctions' => self::LINT_LOWERCASE_FUNCTIONS,
+ 'lintClassNameLiteral' => self::LINT_CLASS_NAME_LITERAL,
);
foreach ($method_codes as $method => $codes) {
@@ -3727,6 +3732,37 @@
}
}
+ private function lintClassNameLiteral(XHPASTNode $root) {
+ $class_declarations = $root->selectDescendantsOfType('n_CLASS_DECLARATION');
+
+ foreach ($class_declarations as $class_declaration) {
+ $class_name = $class_declaration
+ ->getChildOfType(1, 'n_CLASS_NAME')
+ ->getConcreteString();
+
+ $strings = $class_declaration->selectDescendantsOfType('n_STRING_SCALAR');
+
+ foreach ($strings as $string) {
+ $contents = substr($string->getSemanticString(), 1, -1);
+ $replacement = null;
+
+ if ($contents == $class_name) {
+ $replacement = '__CLASS__';
+ }
+
+ if (strpos($contents, $class_name) === false) {
+ continue;
+ }
+
+ $this->raiseLintAtNode(
+ $string,
+ self::LINT_CLASS_NAME_LITERAL,
+ pht("Don't hardcode class names."),
+ $replacement);
+ }
+ }
+ }
+
/**
* Retrieve all calls to some specified function(s).
*
diff --git a/src/lint/linter/__tests__/xhpast/class-name-literal.lint-test b/src/lint/linter/__tests__/xhpast/class-name-literal.lint-test
new file mode 100644
--- /dev/null
+++ b/src/lint/linter/__tests__/xhpast/class-name-literal.lint-test
@@ -0,0 +1,33 @@
+<?php
+class MyClass {
+ public function someMethod() {
+ return 'MyClass';
+ }
+
+ public function someOtherMethod() {
+ return 'MyClass is awesome';
+ }
+
+ public function anotherMethod() {
+ return __CLASS__;
+ }
+}
+~~~~~~~~~~
+error:2:7
+advice:4:12
+advice:8:12
+~~~~~~~~~~
+<?php
+class MyClass {
+ public function someMethod() {
+ return __CLASS__;
+ }
+
+ public function someOtherMethod() {
+ return 'MyClass is awesome';
+ }
+
+ public function anotherMethod() {
+ return __CLASS__;
+ }
+}
diff --git a/src/unit/engine/ArcanistUnitTestEngine.php b/src/unit/engine/ArcanistUnitTestEngine.php
--- a/src/unit/engine/ArcanistUnitTestEngine.php
+++ b/src/unit/engine/ArcanistUnitTestEngine.php
@@ -53,7 +53,7 @@
if ($this instanceof ArcanistBaseUnitTestEngine) {
phutil_deprecated(
'ArcanistBaseUnitTestEngine',
- 'You should extend from `ArcanistUnitTestEngine` instead.');
+ pht('You should extend from `%s` instead.', __CLASS__));
}
$this->workingCopy = $working_copy;
diff --git a/src/unit/engine/PhutilUnitTestEngine.php b/src/unit/engine/PhutilUnitTestEngine.php
--- a/src/unit/engine/PhutilUnitTestEngine.php
+++ b/src/unit/engine/PhutilUnitTestEngine.php
@@ -25,8 +25,11 @@
if (!function_exists('xdebug_start_code_coverage')) {
if ($enable_coverage === true) {
throw new ArcanistUsageException(
- 'You specified --coverage but xdebug is not available, so '.
- 'coverage can not be enabled for PhutilUnitTestEngine.');
+ pht(
+ 'You specified %s but xdebug is not available, so '.
+ 'coverage can not be enabled for %s.',
+ '--coverage',
+ __CLASS__));
}
} else {
$enable_coverage = true;
diff --git a/src/workflow/ArcanistWorkflow.php b/src/workflow/ArcanistWorkflow.php
--- a/src/workflow/ArcanistWorkflow.php
+++ b/src/workflow/ArcanistWorkflow.php
@@ -88,7 +88,7 @@
if ($this instanceof ArcanistBaseWorkflow) {
phutil_deprecated(
'ArcanistBaseWorkflow',
- 'You should extend from `ArcanistWorkflow` instead.');
+ pht('You should extend from `%s` instead.', __CLASS__));
}
$this->finalizeWorkingCopy();
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Apr 29, 2:49 AM (1 d, 1 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7726202
Default Alt Text
D12805.id30781.diff (6 KB)
Attached To
Mode
D12805: Use `__CLASS__` instead of hardcoding class names
Attached
Detach File
Event Timeline
Log In to Comment