1
0
Fork 0
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:
Joshua Spence 2015-08-14 07:41:41 +10:00
parent bf88f4616c
commit 2e76e2965c
3 changed files with 37 additions and 0 deletions

View file

@ -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',

View 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.'));
}
}
}

View file

@ -0,0 +1,4 @@
#!/usr/bin/env php
<html>
~~~~~~~~~~
disabled:2:1