2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-07-28 09:42:27 +02:00
|
|
|
if defined?(HamlLint)
|
|
|
|
module HamlLint
|
|
|
|
class Linter::ApplicationNameLinter < Linter
|
|
|
|
include LinterRegistry
|
2020-07-23 16:10:33 +02:00
|
|
|
|
2024-02-27 18:01:09 +01:00
|
|
|
FORBIDDEN = 'demarches.gouv.fr'
|
2020-07-28 09:42:27 +02:00
|
|
|
REPLACEMENT = "APPLICATION_NAME"
|
|
|
|
MSG = 'Hardcoding %s is forbidden, use %s instead'
|
2020-07-23 16:10:33 +02:00
|
|
|
|
2020-07-28 09:42:27 +02:00
|
|
|
def visit_tag(node)
|
|
|
|
check(node)
|
|
|
|
end
|
2020-07-23 16:10:33 +02:00
|
|
|
|
2020-07-28 09:42:27 +02:00
|
|
|
def visit_script(node)
|
|
|
|
check(node)
|
|
|
|
end
|
2020-07-23 16:10:33 +02:00
|
|
|
|
2020-07-28 09:42:27 +02:00
|
|
|
def visit_silent_script(node)
|
|
|
|
check(node)
|
|
|
|
end
|
2020-07-23 16:10:33 +02:00
|
|
|
|
2020-07-28 09:42:27 +02:00
|
|
|
def visit_plain(node)
|
|
|
|
check(node)
|
|
|
|
end
|
2020-07-23 16:10:33 +02:00
|
|
|
|
2020-07-28 09:42:27 +02:00
|
|
|
def visit_comment(node)
|
|
|
|
check(node)
|
|
|
|
end
|
2020-07-23 16:10:33 +02:00
|
|
|
|
2020-07-28 09:42:27 +02:00
|
|
|
def visit_haml_comment(node)
|
|
|
|
check(node)
|
|
|
|
end
|
2020-07-23 16:10:33 +02:00
|
|
|
|
2020-07-28 09:42:27 +02:00
|
|
|
def check(node)
|
|
|
|
line = line_text_for_node(node)
|
|
|
|
if line.downcase.include?(FORBIDDEN)
|
|
|
|
record_lint(node, format(MSG, FORBIDDEN, REPLACEMENT))
|
|
|
|
end
|
2020-07-23 16:10:33 +02:00
|
|
|
end
|
|
|
|
|
2020-07-28 09:42:27 +02:00
|
|
|
private
|
2020-07-23 16:10:33 +02:00
|
|
|
|
2020-07-28 09:42:27 +02:00
|
|
|
def line_text_for_node(node)
|
|
|
|
document.source_lines[node.line - 1]
|
|
|
|
end
|
2020-07-23 16:10:33 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|