-
-
Notifications
You must be signed in to change notification settings - Fork 398
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to skip comment /modeline ? #484
Comments
2 newlines will do it. YARD won't pick up comments with more than 2 blank lines between the comment and object declaration. |
Thanks, that work indeed. I thought something like that would work (and I think I tried it too, but apparently not) but couldn't find anything in the doc. Thanks again |
It would be nice if one could configure YARD to ignore comments with even one blank line, since adding two blank lines starts a fight with Rubocop. |
@dmolesUC3 seems like that's an issue to open with Rubocop, then. :) |
Not exactly. I can configure Rubocop to allow any number of blank lines or an arbitrary fixed number of blank lines, but there's no way to tell it 'allow only one blank line unless the extra blank line is there to trick YARD into ignoring the above comment'. |
(And frankly I'd rather not have the extra blank line for YARD's sake, either.) |
@dmolesUC3 it still sounds like a feature request for Rubocop. If that project's goal is to enforce existing code conventions, then it should enforce existing code conventions. Blank lines for documentation is one of these existing code conventions-- YARD has been around for more than 8 years now, and this syntax has always been enforced. Quite explicitly: YARD will not add syntax to ignore comments. You can read about why in a lot of different places:
I'm sure there are more examples out there. |
I wonder if we're talking past each other? I'm not asking for Speaking as a newcomer, the fact that there aren't any blank lines in (most of? any of?) the documentation examples makes the existing behavior far from obvious. Writing this... # This is my class
#
# @!attribute [rw] some_attribute
# @return [SomeType] something or other
# @!attribute [rw] some_other_attribute
# @return [SomeType] something or other
# ...(etc.)
class MyClass < MyOtherClass
# ------------------------------------------------------------
# Attributes
attr_reader :some_attribute
attr_reader :some_other_attribute
# etc...
# ------------------------------------------------------------
# Initializer
# Creates a new {MyClass}
#
# @param whatever [Thing] etc.
def initialize(whatever:)
# ...
end
# ------------------------------------------------------------
# Overrides
# ... etc.
end ...it took me a good fifteen minutes to figure out why |
The problem is that for YARD to do the thing you're wanting, we would have to have a feature that would effectively work like a
This won't happen either. This is actually against convention as well. I'm not sure who is spreading the idea that people should use The actual convention is: "document your # This is my class
class MyClass < MyOtherClass
# @return [SomeType] something or other
attr_reader :some_attribute
# @return [SomeType] something or other
attr_reader :some_other_attribute I'll probably have to pour through our existing docs and make sure to update this accordingly. YARD docs are obviously not making this clear enough, we've had a few users trip up over this recently. a FAQ / other entries would probably clarify. The other convention, which I think RuboCop is correct in [coincidentally] yelling at you about, is "don't have superfluous line comments" # ------------------------------------------------------------
# Attributes Is unnecessary and a bad code documentation strategy, IMO. If you find yourself needing visual separation between your different class features, you're probably throwing too much data into one file. |
Okay. Part of the docs problem might be that it's easy to hit the deprecated The And while I can see how a simple I'm new to Ruby, so maybe At any rate, it looks like I can get what I want -- superfluous line comments and all -- by documenting the accessors directly, so long as I don't have any |
No, I take that back, I do have an occasional use for |
Seems like the
attr_* are NOT out of style, they are very much still the convention. We should have examples for this, I agree.
You can document attr_writers too. Just like any method, you can use # @overload value=(val)
# @param val [String] the value to set
attr_writer :value |
Both myself and my co-workers have also found it confusing that 2 (rather than 1) blank lines are needed to separate comment from a code object to not have it treated as documentation. Rather than having to deal with this recurring confusion, it actually seems simpler to monkey patch YARD to have it behave as expected. module YardRubyParserExt
private
raise NoMethodError unless YARD::Parser::Ruby::RipperParser.private_method_defined?(:add_comment)
def add_comment(line, node = nil, *args)
# YARD requires 2 empty lines between a comment and a node to consider the
# comment to not be documenting the node. Instead, we only require a single
# empty line, which seems to be behaviour developers expect.
if node && line < node.line - 1
node = nil
end
super(line, node, *args)
end
end
YARD::Parser::Ruby::RipperParser.prepend(YardRubyParserExt) Obviously having YARD be configurable would be preferred. |
@dylanahsmith you can refer to RDoc (example) for creating this formatting convention that YARD must be able to support. I think a few developers believe that this is the expected behavior because of it.
I suppose this could be configurable, but I'd be more curious as to what your use case is. Stray comments that are not associated with any object should be pretty rare IMO, and the most typical case would likely be VIM/emacs type header comments at the top of files, which could be handled differently than a generalized newline monkeypatch. Specifically, you could write a plugin to ignore specific comment lines by their formatting. Writing a custom DocstringParser (by subclassing and pre-processing # place this in some .rb file and load with `--load file.rb` or package as a plugin
class IgnoreVIMDirectiveDocstringParser < YARD::DocstringParser
def parse_content(content)
super(content.sub(/\Avi:.*$/, ''))
end
end
YARD::Docstring.default_parser = IgnoreVIMDirectiveDocstringParser The above requires no monkeypatching. |
These comments are meant to give an overview of the internals of the code. These are details that aren't meant to be shown in the documented public interface for the code. When these comments are placed above a namespace module that is documented elsewhere, then they would override the documentation for that module. |
I'd still be curious to see a more concrete example of the use case here. Most of the times I have seen this type of thing, I am really looking at something that is effectively still documentation, just for a different audience. Configuring data for different audiences is something YARD can do by adding an # @internal
# Internal information about this module ...
module Foo
end That way you can still decide to show that information when generating documentation for internal audiences (your private API docs). Alternatively if this is too much overhead, you can just move your comments under the declaration rather than on top, where ideally they are closer to the internals they are describing: module Foo
# Internal information about this module ...
# document the class
class Bar; end
end |
How can I make yard skip comment at the beginning of a file ?
here is my probleme :
I have a file defining module A
and then another file using module A as a namespace with a modeline
The modeline (the first comment line) override the doc of module A. The solution I found so far is to add a dummy object between the comment and module A like
I don't like it, because I'm pretty sure this '1' will be removed by other people modifying this file.
Any idea ?
The text was updated successfully, but these errors were encountered: