Add custom linter for inline JavaScript to haml_lint (!9742)
This commit is contained in:
parent
95b232f2cc
commit
c6bf292efb
4 changed files with 22 additions and 0 deletions
|
@ -41,6 +41,9 @@ linters:
|
|||
ImplicitDiv:
|
||||
enabled: true
|
||||
|
||||
InlineJavaScript:
|
||||
enabled: true
|
||||
|
||||
InlineStyles:
|
||||
enabled: false
|
||||
|
||||
|
|
4
changelogs/unreleased/restrict-haml-javascript.yml
Normal file
4
changelogs/unreleased/restrict-haml-javascript.yml
Normal file
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
title: Add custom linter for inline JavaScript to haml_lint
|
||||
merge_request: 9742
|
||||
author: winniehell
|
14
lib/haml_lint/inline_javascript.rb
Normal file
14
lib/haml_lint/inline_javascript.rb
Normal file
|
@ -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
|
|
@ -1,5 +1,6 @@
|
|||
unless Rails.env.production?
|
||||
require 'haml_lint/rake_task'
|
||||
require 'haml_lint/inline_javascript'
|
||||
|
||||
HamlLint::RakeTask.new
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue