Skip to content

Conversation

@Kerrick
Copy link

@Kerrick Kerrick commented Jan 22, 2026

I misused :nodoc: and spent time debugging before finding my error. This patch adds a warning for others who might do the same.

The problem:

class Foo
  VISIBLE_CONST = :hello

  # :nodoc:
  HIDDEN_CONST = :bar

  def visible_method
  end
end

I expected only the constant to be hidden. Instead, visible_method also disappeared from my documentation.

The documentation says :nodoc: should be appended inline. This works correctly:

HIDDEN_CONST = :bar # :nodoc:

Since the standalone form is accepted silently but produces surprising results, this patch emits a warning when the pattern is detected.

I am glad to adjust the implementation or wording. If this does not fit RDoc's direction, please close it.


This issue includes creative contributions from Claude (Anthropic).

Using :nodoc: on a separate line before a constant or method causes
the directive to be applied to the containing class instead of the
intended target. This silently drops all subsequent methods from
documentation.

Rather than changing the behavior, this adds a warning so users can
discover the correct inline syntax (e.g., CONST = 1 # :nodoc:).

Co-Authored-By: Claude Opus 4.5 (Thinking) <noreply@anthropic.com>
@tompng
Copy link
Member

tompng commented Jan 22, 2026

Standalone :nodoc: is valid and used correctly. We cant just warn for standalone :nodoc:.

class A
  # :nodoc:

  def undocumented1; end

  def undocumented2; end
end

These :nodoc: are misused, so it can be warned.

class A
  ...

  # :nodoc:
  def f1; end

  # :nodoc:
  # comment for f2

  def f2; end
end

I think checking this is not possible from handle_directive's argument.
Instead of warning, maybe there's an option to change the :nodoc: behavior. I've filed an issue #1578

@Kerrick
Copy link
Author

Kerrick commented Jan 22, 2026

Thank you!

@Kerrick Kerrick closed this Jan 22, 2026
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.

2 participants