diff options
-rw-r--r-- | .haml-lint.yml | 3 | ||||
-rw-r--r-- | changelogs/unreleased/restrict-haml-javascript.yml | 4 | ||||
-rw-r--r-- | lib/haml_lint/inline_javascript.rb | 14 | ||||
-rw-r--r-- | lib/tasks/haml-lint.rake | 1 |
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 |