mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Refactor Lint::Documentation
rule to use a custom visitor
This commit is contained in:
parent
1a9a58b3cd
commit
09fdac6be9
1 changed files with 30 additions and 2 deletions
|
@ -22,10 +22,10 @@ module Ameba::Rule::Lint
|
||||||
MSG = "Missing documentation"
|
MSG = "Missing documentation"
|
||||||
|
|
||||||
def test(source)
|
def test(source)
|
||||||
AST::ScopeVisitor.new self, source
|
DocumentationVisitor.new self, source
|
||||||
end
|
end
|
||||||
|
|
||||||
def test(source, node : Crystal::ClassDef | Crystal::ModuleDef | Crystal::EnumDef | Crystal::Def | Crystal::Macro, scope : AST::Scope)
|
def test(source, node)
|
||||||
return unless node.visibility.public?
|
return unless node.visibility.public?
|
||||||
|
|
||||||
case node
|
case node
|
||||||
|
@ -38,5 +38,33 @@ module Ameba::Rule::Lint
|
||||||
|
|
||||||
issue_for(node, MSG) unless node.doc.presence
|
issue_for(node, MSG) unless node.doc.presence
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# :nodoc:
|
||||||
|
private class DocumentationVisitor < AST::BaseVisitor
|
||||||
|
NODES = {
|
||||||
|
ClassDef,
|
||||||
|
ModuleDef,
|
||||||
|
EnumDef,
|
||||||
|
Def,
|
||||||
|
Macro,
|
||||||
|
}
|
||||||
|
|
||||||
|
@visibility : Crystal::Visibility = :public
|
||||||
|
|
||||||
|
def visit(node : Crystal::VisibilityModifier)
|
||||||
|
@visibility = node.modifier
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
{% for name in NODES %}
|
||||||
|
def visit(node : Crystal::{{ name }})
|
||||||
|
node.visibility = @visibility
|
||||||
|
@visibility = :public
|
||||||
|
|
||||||
|
@rule.test @source, node
|
||||||
|
true
|
||||||
|
end
|
||||||
|
{% end %}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue