commit
49600cc7d9
1 changed files with 40 additions and 38 deletions
|
@ -1,46 +1,48 @@
|
||||||
module HamlLint
|
if defined?(HamlLint)
|
||||||
class Linter::ApplicationNameLinter < Linter
|
module HamlLint
|
||||||
include LinterRegistry
|
class Linter::ApplicationNameLinter < Linter
|
||||||
|
include LinterRegistry
|
||||||
|
|
||||||
FORBIDDEN = 'demarches-simplifiees.fr'
|
FORBIDDEN = 'demarches-simplifiees.fr'
|
||||||
REPLACEMENT = "APPLICATION_NAME"
|
REPLACEMENT = "APPLICATION_NAME"
|
||||||
MSG = 'Hardcoding %s is forbidden, use %s instead'
|
MSG = 'Hardcoding %s is forbidden, use %s instead'
|
||||||
|
|
||||||
def visit_tag(node)
|
def visit_tag(node)
|
||||||
check(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
|
||||||
end
|
|
||||||
|
|
||||||
private
|
def visit_script(node)
|
||||||
|
check(node)
|
||||||
|
end
|
||||||
|
|
||||||
def line_text_for_node(node)
|
def visit_silent_script(node)
|
||||||
document.source_lines[node.line - 1]
|
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
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue