added a custom haml linter in order to avoid hardcoding application name
This commit is contained in:
parent
3340a2b091
commit
4cfe41ce25
2 changed files with 52 additions and 0 deletions
|
@ -1,4 +1,10 @@
|
|||
require:
|
||||
- './lib/linters/application_name_linter.rb'
|
||||
|
||||
linters:
|
||||
ApplicationNameLinter:
|
||||
enabled: true
|
||||
|
||||
AlignmentTabs:
|
||||
enabled: true
|
||||
|
||||
|
|
46
lib/linters/application_name_linter.rb
Normal file
46
lib/linters/application_name_linter.rb
Normal file
|
@ -0,0 +1,46 @@
|
|||
module HamlLint
|
||||
class Linter::ApplicationNameLinter < Linter
|
||||
include LinterRegistry
|
||||
|
||||
FORBIDDEN = 'demarches-simplifiees.fr'
|
||||
REPLACEMENT = "APPLICATION_NAME"
|
||||
MSG = 'Hardcoding %s is forbidden, use %s instead'
|
||||
|
||||
def visit_tag(node)
|
||||
check(node)
|
||||
end
|
||||
|
||||
def visit_script(node)
|
||||
check(node)
|
||||
end
|
||||
|
||||
def visit_silent_script(node)
|
||||
check(node)
|
||||
end
|
||||
|
||||
def visit_plain(node)
|
||||
check(node)
|
||||
end
|
||||
|
||||
def visit_comment(node)
|
||||
check(node)
|
||||
end
|
||||
|
||||
def visit_haml_comment(node)
|
||||
check(node)
|
||||
end
|
||||
|
||||
def check(node)
|
||||
line = line_text_for_node(node)
|
||||
if line.downcase.include?(FORBIDDEN)
|
||||
record_lint(node, format(MSG, FORBIDDEN, REPLACEMENT))
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def line_text_for_node(node)
|
||||
document.source_lines[node.line - 1]
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue