Skip to content

Commit

Permalink
Add Lint/NoSemanticInformation
Browse files Browse the repository at this point in the history
  • Loading branch information
nobodywasishere committed Jan 27, 2025
1 parent e865063 commit 69fc6c9
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/ameba/rule/lint/no_semantic_information.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module Ameba::Rule::Lint
# A rule that reports when there's no semantic information available for a given type.
# This usually happens when there's a file in the codebase not covered by an entrypoint.
#
# YAML configuration example:
#
# ```
# Lint/NoSemanticInformation:
# Enabled: true
# ```
class NoSemanticInformation < Base
properties do
since_version "1.7.0"
description "Reports types that don't have any semantic information available"
severity :warning
end

MSG = "This type doesn't have any semantic information (double check the ameba entrypoints)"

def test(source, context : SemanticContext?)
return if context.nil?

AST::SemanticVisitor.new self, source, context
end

def test(
source,
node : Crystal::ClassDef | Crystal::ModuleDef |
Crystal::LibDef | Crystal::EnumDef,
current_type : Crystal::Type,
)
return if current_type.lookup_type?(node.name)

issue_for node.name, MSG
end
end
end

0 comments on commit 69fc6c9

Please sign in to comment.