Skip to content

Commit c6bf292

Browse files
winniehellwinh
authored and
winh
committed
Add custom linter for inline JavaScript to haml_lint (!9742)
1 parent 95b232f commit c6bf292

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

.haml-lint.yml

+3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ linters:
4141
ImplicitDiv:
4242
enabled: true
4343

44+
InlineJavaScript:
45+
enabled: true
46+
4447
InlineStyles:
4548
enabled: false
4649

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
title: Add custom linter for inline JavaScript to haml_lint
3+
merge_request: 9742
4+
author: winniehell

lib/haml_lint/inline_javascript.rb

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
require 'haml_lint/haml_visitor'
2+
require 'haml_lint/linter'
3+
require 'haml_lint/linter_registry'
4+
5+
module HamlLint
6+
class Linter::InlineJavaScript < Linter
7+
include LinterRegistry
8+
9+
def visit_filter(node)
10+
return unless node.filter_type == 'javascript'
11+
record_lint(node, 'Inline JavaScript is discouraged (https://docs.gitlab.com/ee/development/gotchas.html#do-not-use-inline-javascript-in-views)')
12+
end
13+
end
14+
end

lib/tasks/haml-lint.rake

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
unless Rails.env.production?
22
require 'haml_lint/rake_task'
3+
require 'haml_lint/inline_javascript'
34

45
HamlLint::RakeTask.new
56
end

0 commit comments

Comments
 (0)