diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 70f87173..97a653f0 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -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', diff --git a/src/lint/linter/ArcanistInlineHTMLXHPASTLinterRule.php b/src/lint/linter/ArcanistInlineHTMLXHPASTLinterRule.php new file mode 100644 index 00000000..3cb758ad --- /dev/null +++ b/src/lint/linter/ArcanistInlineHTMLXHPASTLinterRule.php @@ -0,0 +1,31 @@ +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.')); + } + } + +} diff --git a/src/lint/linter/__tests__/xhpast/inline-html.lint-test b/src/lint/linter/__tests__/xhpast/inline-html.lint-test new file mode 100644 index 00000000..13cdd0d1 --- /dev/null +++ b/src/lint/linter/__tests__/xhpast/inline-html.lint-test @@ -0,0 +1,4 @@ +#!/usr/bin/env php + +~~~~~~~~~~ +disabled:2:1