Skip to content

Allow instance variable annotations between class members - #3183

Open
ksss wants to merge 2 commits into
ruby:masterfrom
ksss:inline-ivar-between-members
Open

ksss wants to merge 2 commits into
ruby:masterfrom
ksss:inline-ivar-between-members

Conversation

@ksss

@ksss ksss commented Sep 29, 2026 •

Copy link
Copy Markdown
Collaborator

Fix #3175

Summary

Instance variable annotations written between class/module members were reported as unused. Only the ones before the first member or after the last member worked.

class Foo
  def a
  end

  # @rbs @x: Integer    # <- Unused inline rbs annotation

  def b
  end

  # @rbs @y: String     # <- works
end

Why

visit_class_or_module_body reports comments enclosed in the child nodes of the class/module node as unused. The body is a single StatementsNode spanning from the first statement to the last one, so every comment between statements was treated as enclosed. This change looks into each statement of the body instead.

A class body with rescue/ensure (BeginNode) is left as before.

Also added a note to docs/inline.md that the declarations need a blank line before the following member, since a comment block directly above a def/attr_* belongs to that member.

🤖 Generated with Claude Code

ksss and others added 2 commits September 29, 2026 22:55
Comments between the first and the last statement of a class/module body were
treated as enclosed in the body `StatementsNode`, and reported as unused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

InlineParser: @rbs @ivar annotation is reported as unused unless it is the first thing in the class body

1 participant