summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorwinniehell <git@winniehell.de>2017-03-06 20:46:52 +0100
committerwinh <winnie@gitlab.com>2017-08-07 11:37:16 +0200
commitc6bf292efba4be34fd832684bd25036354d7336b (patch)
treed9a41626cf149683499fc093c2d8a6cd2d574e20 /lib
parent95b232f2cc9ceb3fe65d2c53d749c28c72c820f5 (diff)
downloadgitlab-ce-c6bf292efba4be34fd832684bd25036354d7336b.tar.gz
Add custom linter for inline JavaScript to haml_lint (!9742)
Diffstat (limited to 'lib')
-rw-r--r--lib/haml_lint/inline_javascript.rb14
-rw-r--r--lib/tasks/haml-lint.rake1
2 files changed, 15 insertions, 0 deletions
diff --git a/lib/haml_lint/inline_javascript.rb b/lib/haml_lint/inline_javascript.rb
new file mode 100644
index 00000000000..f3ddcbb9c95
--- /dev/null
+++ b/lib/haml_lint/inline_javascript.rb
@@ -0,0 +1,14 @@
+require 'haml_lint/haml_visitor'
+require 'haml_lint/linter'
+require 'haml_lint/linter_registry'
+
+module HamlLint
+ class Linter::InlineJavaScript < Linter
+ include 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
+ end
+end
diff --git a/lib/tasks/haml-lint.rake b/lib/tasks/haml-lint.rake
index 609dfaa48e3..ad2d034b0b4 100644
--- a/lib/tasks/haml-lint.rake
+++ b/lib/tasks/haml-lint.rake
@@ -1,5 +1,6 @@
unless Rails.env.production?
require 'haml_lint/rake_task'
+ require 'haml_lint/inline_javascript'
HamlLint::RakeTask.new
end