summaryrefslogtreecommitdiff
path: root/haml_lint/inline_javascript.rb
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2019-05-21 19:49:14 -0700
committerStan Hu <stanhu@gmail.com>2019-05-21 19:49:14 -0700
commit27381e22a92453b23f1ed75406970b37d926f1ec (patch)
treebdb46c358c8028493f3e69d8adb2cdaaf2f766fe /haml_lint/inline_javascript.rb
parent0ded86570c10d24ad4fff7e4fcd4b562bcd397fd (diff)
downloadgitlab-ce-27381e22a92453b23f1ed75406970b37d926f1ec.tar.gz
Move files from lib/haml_lint to haml_lintsh-fix-linter-registry-haml
Files in lib will be eager loaded and hence will require haml_lint to be loaded. Since this is only a development dependency, we can't assume this gem will be available in production, so it should never be loaded in production.
Diffstat (limited to 'haml_lint/inline_javascript.rb')
-rw-r--r--haml_lint/inline_javascript.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/haml_lint/inline_javascript.rb b/haml_lint/inline_javascript.rb
new file mode 100644
index 00000000000..da6af92e82b
--- /dev/null
+++ b/haml_lint/inline_javascript.rb
@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+unless Rails.env.production?
+ require_dependency 'haml_lint/haml_visitor'
+ require_dependency 'haml_lint/linter'
+ require_dependency 'haml_lint/linter_registry'
+
+ module HamlLint
+ class Linter::InlineJavaScript < Linter
+ include ::HamlLint::LinterRegistry
+
+ def visit_filter(node)
+ return unless node.filter_type == 'javascript'
+
+ record_lint(node, 'Inline JavaScript is discouraged (https://docs.gitlab.com/ee/development/gotchas.html#do-not-use-inline-javascript-in-views)')
+ end
+
+ def visit_tag(node)
+ return unless node.tag_name == 'script'
+
+ record_lint(node, 'Inline JavaScript is discouraged (https://docs.gitlab.com/ee/development/gotchas.html#do-not-use-inline-javascript-in-views)')
+ end
+ end
+ end
+end