mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Refactor Lint::Documentation
and ignore macro hooks
This commit is contained in:
parent
09fdac6be9
commit
6e5a9a60b3
1 changed files with 32 additions and 10 deletions
|
@ -21,22 +21,44 @@ module Ameba::Rule::Lint
|
||||||
|
|
||||||
MSG = "Missing documentation"
|
MSG = "Missing documentation"
|
||||||
|
|
||||||
|
HOOK_NAMES = %w[
|
||||||
|
inherited
|
||||||
|
included extended
|
||||||
|
method_missing method_added
|
||||||
|
finished
|
||||||
|
]
|
||||||
|
|
||||||
def test(source)
|
def test(source)
|
||||||
DocumentationVisitor.new self, source
|
DocumentationVisitor.new self, source
|
||||||
end
|
end
|
||||||
|
|
||||||
def test(source, node)
|
def test(source, node : Crystal::ClassDef)
|
||||||
|
ignore_classes? || check_missing_doc(source, node)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test(source, node : Crystal::ModuleDef)
|
||||||
|
ignore_modules? || check_missing_doc(source, node)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test(source, node : Crystal::EnumDef)
|
||||||
|
ignore_enums? || check_missing_doc(source, node)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test(source, node : Crystal::Def)
|
||||||
|
ignore_defs? || check_missing_doc(source, node)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test(source, node : Crystal::Macro)
|
||||||
|
return if node.name.in?(HOOK_NAMES)
|
||||||
|
|
||||||
|
ignore_macros? || check_missing_doc(source, node)
|
||||||
|
end
|
||||||
|
|
||||||
|
private def check_missing_doc(source, node)
|
||||||
return unless node.visibility.public?
|
return unless node.visibility.public?
|
||||||
|
return if node.doc.presence
|
||||||
|
|
||||||
case node
|
issue_for(node, MSG)
|
||||||
when Crystal::ClassDef then return if ignore_classes?
|
|
||||||
when Crystal::ModuleDef then return if ignore_modules?
|
|
||||||
when Crystal::EnumDef then return if ignore_enums?
|
|
||||||
when Crystal::Def then return if ignore_defs?
|
|
||||||
when Crystal::Macro then return if ignore_macros?
|
|
||||||
end
|
|
||||||
|
|
||||||
issue_for(node, MSG) unless node.doc.presence
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# :nodoc:
|
# :nodoc:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue