summaryrefslogtreecommitdiff
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
parent95b232f2cc9ceb3fe65d2c53d749c28c72c820f5 (diff)
downloadgitlab-ce-c6bf292efba4be34fd832684bd25036354d7336b.tar.gz
Add custom linter for inline JavaScript to haml_lint (!9742)
-rw-r--r--.haml-lint.yml3
-rw-r--r--changelogs/unreleased/restrict-haml-javascript.yml4
-rw-r--r--lib/haml_lint/inline_javascript.rb14
-rw-r--r--lib/tasks/haml-lint.rake1
4 files changed, 22 insertions, 0 deletions
diff --git a/.haml-lint.yml b/.haml-lint.yml
index 372994979b8..32c7de0fb78 100644
--- a/.haml-lint.yml
+++ b/.haml-lint.yml
@@ -41,6 +41,9 @@ linters:
ImplicitDiv:
enabled: true
+ InlineJavaScript:
+ enabled: true
+
InlineStyles:
enabled: false
diff --git a/changelogs/unreleased/restrict-haml-javascript.yml b/changelogs/unreleased/restrict-haml-javascript.yml
new file mode 100644
index 00000000000..3d0a52f416d
--- /dev/null
+++ b/changelogs/unreleased/restrict-haml-javascript.yml
@@ -0,0 +1,4 @@
+---
+title: Add custom linter for inline JavaScript to haml_lint
+merge_request: 9742
+author: winniehell
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