Ignore comment code when using DVD

I have a Ruby code that looks like this:

# some_string = "{really?}" 

where braces must be part of the string. This line commented on the code I would like to leave there. I also use YARD to document the code, so when I run the yard doc , it (naturally) gives a warning about the impossibility of linking "really."

Is there a way that I can tell YARD to ignore the commented code?

+6
source share
1 answer

Is there a way that I can tell YARD to ignore the commented code?

On the one hand, YARD is documented as supporting Rdoc markup. And Rdoc is documented to support several ways to hide details.

RDoc stops processing comments if it finds a comment line starting with - right after the # character (otherwise, it will be considered as a rule if it has three dashes or more). This can be used to separate the outer from internal comments or to stop the associated comment using a method, class or module. Commenting can be enabled again using the line starting with c ++.

: stopdoc: /: startdoc:
Stop and start adding new documentation items to the current container. For example, if a class has several constants that you don’t want to document, put: stopdoc: before the first and: startdoc: after the last. If you did not specify: startdoc: at the end of the container, disables the documentation for the rest of the current file.

A source

On the other hand, I never convinced Rdoc or YARD to follow this markup. If your luck is better than mine, you can stop reading here.

If you also cannot convince YARD to follow this markup, I think it would be best to shorten this line and send a file with a noticeable commit message - which you can find easily by grepping source control logs.

Finally, rake allows you to freely convert text (code) files. You can write a Rakefile to delete lines before processing them through YARD.

 $ cat silly-ruby-file.src class Something def this_method end def that_method # some_string = "{really?}" # Hide me end end 

I added the text # Hide me ; it’s much easier to filter this particular text than to filter out commented-out lines of arbitrary code.

 $ cat Rakefile task :default => "silly-ruby-file.rb" sh "grep -v '# Hide me' silly-ruby-file.src > silly-ruby-file.rb" 

This tells rake to run grep , copying all lines except those that have the text "# Hide me" in stdout, which redirects to "silly-ruby-file.rb".

+2
source

Source: https://habr.com/ru/post/959198/


All Articles