mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-22 06:42:41 +01:00
Add a linter rule for inline HTML
Summary: Ref T7409. Based on [[https://github.com/squizlabs/PHP_CodeSniffer/blob/master/CodeSniffer/Standards/Generic/Sniffs/Files/InlineHTMLSniff.php | InlineHTMLSniff]]. Test Plan: Added unit tests. Reviewers: #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: Korvin Maniphest Tasks: T9140, T7409 Differential Revision: https://secure.phabricator.com/D13871
This commit is contained in:
parent
bf88f4616c
commit
2e76e2965c
3 changed files with 37 additions and 0 deletions
|
@ -125,6 +125,7 @@ phutil_register_library_map(array(
|
|||
'ArcanistImplicitConstructorXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistImplicitConstructorXHPASTLinterRule.php',
|
||||
'ArcanistImplicitFallthroughXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistImplicitFallthroughXHPASTLinterRule.php',
|
||||
'ArcanistImplicitVisibilityXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistImplicitVisibilityXHPASTLinterRule.php',
|
||||
'ArcanistInlineHTMLXHPASTLinterRule' => 'lint/linter/ArcanistInlineHTMLXHPASTLinterRule.php',
|
||||
'ArcanistInnerFunctionXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistInnerFunctionXHPASTLinterRule.php',
|
||||
'ArcanistInstallCertificateWorkflow' => 'workflow/ArcanistInstallCertificateWorkflow.php',
|
||||
'ArcanistInstanceOfOperatorXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistInstanceOfOperatorXHPASTLinterRule.php',
|
||||
|
@ -406,6 +407,7 @@ phutil_register_library_map(array(
|
|||
'ArcanistImplicitConstructorXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
|
||||
'ArcanistImplicitFallthroughXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
|
||||
'ArcanistImplicitVisibilityXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
|
||||
'ArcanistInlineHTMLXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
|
||||
'ArcanistInnerFunctionXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
|
||||
'ArcanistInstallCertificateWorkflow' => 'ArcanistWorkflow',
|
||||
'ArcanistInstanceOfOperatorXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
|
||||
|
|
31
src/lint/linter/ArcanistInlineHTMLXHPASTLinterRule.php
Normal file
31
src/lint/linter/ArcanistInlineHTMLXHPASTLinterRule.php
Normal file
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
final class ArcanistInlineHTMLXHPASTLinterRule
|
||||
extends ArcanistXHPASTLinterRule {
|
||||
|
||||
const ID = 78;
|
||||
|
||||
public function getLintName() {
|
||||
return pht('Inline HTML');
|
||||
}
|
||||
|
||||
public function getLintSeverity() {
|
||||
return ArcanistLintSeverity::SEVERITY_DISABLED;
|
||||
}
|
||||
|
||||
public function process(XHPASTNode $root) {
|
||||
$inline_html = $root->selectTokensOfType('T_INLINE_HTML');
|
||||
|
||||
foreach ($inline_html as $html) {
|
||||
if (substr($html->getValue(), 0, 2) == '#!') {
|
||||
// Ignore shebang lines.
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->raiseLintAtToken(
|
||||
$html,
|
||||
pht('PHP files must only contain PHP code.'));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
4
src/lint/linter/__tests__/xhpast/inline-html.lint-test
Normal file
4
src/lint/linter/__tests__/xhpast/inline-html.lint-test
Normal file
|
@ -0,0 +1,4 @@
|
|||
#!/usr/bin/env php
|
||||
<html>
|
||||
~~~~~~~~~~
|
||||
disabled:2:1
|
Loading…
Reference in a new issue