]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Add a linter rule for inline HTML
authorJoshua Spence <josh@joshuaspence.com>
Thu, 13 Aug 2015 21:41:41 +0000 (07:41 +1000)
committerJoshua Spence <josh@joshuaspence.com>
Thu, 13 Aug 2015 21:41:41 +0000 (07:41 +1000)
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

src/__phutil_library_map__.php
src/lint/linter/ArcanistInlineHTMLXHPASTLinterRule.php [new file with mode: 0644]
src/lint/linter/__tests__/xhpast/inline-html.lint-test [new file with mode: 0644]

index 70f871738afb943fe6f9158d769043dc341cd2c9..97a653f0c107f9a6a43552a2089015f9a989f8c0 100644 (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',
diff --git a/src/lint/linter/ArcanistInlineHTMLXHPASTLinterRule.php b/src/lint/linter/ArcanistInlineHTMLXHPASTLinterRule.php
new file mode 100644 (file)
index 0000000..3cb758a
--- /dev/null
@@ -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.'));
+    }
+  }
+
+}
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 (file)
index 0000000..13cdd0d
--- /dev/null
@@ -0,0 +1,4 @@
+#!/usr/bin/env php
+<html>
+~~~~~~~~~~
+disabled:2:1