Skip to content
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

Possibility of moving to YARD-style documentation in README #1330

Closed
stephendolan opened this issue Aug 8, 2018 · 24 comments · Fixed by #1553
Closed

Possibility of moving to YARD-style documentation in README #1330

stephendolan opened this issue Aug 8, 2018 · 24 comments · Fixed by #1553

Comments

@stephendolan
Copy link

I find some of the documentation and READMEs in this project relatively difficult to use. For example, in Faker::Lorem:

# Optional arguments: word_count=4, supplemental=false, random_words_to_add=6
# The 'random_words_to_add' argument increases the sentence's word count by a random value within (0..random_words_to_add).
# To specify an exact word count for a sentence, set word_count to the number you want and random_words_to_add equal to 0.
# By default, sentences will have a random number of words within the range (4..10).
Faker::Lorem.sentence #=> "Dolore illum animi et neque accusantium."
Faker::Lorem.sentence(3) #=> "Commodi qui minus deserunt sed vero quia."
Faker::Lorem.sentence(3, true) #=> "Inflammatio denego necessitatibus caelestis autus illum."
Faker::Lorem.sentence(3, false, 4) #=> "Aut voluptatem illum fugit ut sit."
Faker::Lorem.sentence(3, true, 4) #=> "Accusantium tantillus dolorem timor."

There's nothing here specifying what the supplemental parameter does, and there's also no solid indication in the examples. Visiting the code itself isn't any more helpful:

def sentence(word_count = 4, supplemental = false, random_words_to_add = 0)
  words(word_count + rand(random_words_to_add.to_i), supplemental).join(' ').capitalize + locale_period
end

I ended up being able to most easily find the purpose of this parameter on this GitHub issue.

What I would expect in the README:

# Optional arguments: word_count=4, supplemental=false, random_words_to_add=6
# Faker::Lorem.sentence(word_count = 4, supplemental = false, random_words_to_add = 6)
#
# @param [Integer] word_count the number of words to include in the generated sentence.
# @param [Boolean] supplemental whether or not to pull from an additional,  supplemental set of Lorem text.
# @param [Integer] random_words_to_add a number of words between 0 and this value will be added to the generated sentence.
Faker::Lorem.sentence #=> "Dolore illum animi et neque accusantium."
Faker::Lorem.sentence(3) #=> "Commodi qui minus deserunt sed vero quia."
Faker::Lorem.sentence(3, true) #=> "Inflammatio denego necessitatibus caelestis autus illum."
Faker::Lorem.sentence(3, false, 4) #=> "Aut voluptatem illum fugit ut sit."
Faker::Lorem.sentence(3, true, 4) #=> "Accusantium tantillus dolorem timor."
Faker::Lorem.sentence(3, false, 4) #=> "Aut voluptatem illum fugit ut sit."
Faker::Lorem.sentence(3, true, 4) #=> "Accusantium tantillus dolorem timor."

What I would expect in the code:

# Generate a sentence with Lorem Ipsum text.
#
# @param [Integer] word_count the number of words to include in the generated sentence.
# @param [Boolean] supplemental whether or not to pull from an additional,  supplemental set of Lorem text.
# @param [Integer] random_words_to_add a number of words between 0 and this value will be added to the generated sentence.
#
# @return [String] a random sentence generated from Lorem Ipsum text.
def sentence(word_count = 4, supplemental = false, random_words_to_add = 0)
  words(word_count + rand(random_words_to_add.to_i), supplemental).join(' ').capitalize + locale_period
end

I wanted to start a discussion here to see whether or not there's an interest in beginning a larger effort to improve this library's documentation. It is such an excellent source of data that it is a shame to see any of its cool options hidden.

It's also entirely possible that I've missed an additional source of documentation somewhere :)

@Zeragamba
Copy link
Contributor

YARD documentation is supported in RubyMine, and I think VS Code as support for it as well.

@Zeragamba
Copy link
Contributor

Zeragamba commented Feb 15, 2019

I've started to add YARD style docs. an example can be seen here:

@stympy
Copy link
Contributor

stympy commented Feb 15, 2019

I really like this. Who's willing to take up the challenge of converting all the docs? :)

@stephendolan
Copy link
Author

I don't think that there necessarily needs to be a conversion effort to move all of the documentation immediately, though that would certainly be the dream :).

I was more envisioning a discussion here about which YARD documentation elements should be required, how/where to go about documenting those in the CONTRIBUTING.md, and then how to go about enforcing those documentation requirements for every new pull request before it is allowed to be merged.

@Zeragamba
Copy link
Contributor

Zeragamba commented Feb 15, 2019

I agree with that, we can ask existing/new pull requests that haven't been merged yet to include YARD doc blocks.

An full example would be:

##
# @return [string] A hex string
#
# @param length [integer] Length of the string
# @param upcase [boolean] Upcase the letters 
#
# @example Faker::Example.hex
#   "d6964ad8b71d46a62e5e64cd00b9e476"
#   "955b1fdf9971cda5745604ab081cc61d"
#   "73d3dc6fa0ba67911024d61eb6c1e382"
# @example Faker::Example.hex(length: 10)
#   "170b43193e"
#   "181450a4ae"
#   "d7b0a72da6"
# @example Faker::Example.hex(upcase: true)
#   "4BE0CB215BE62A06306BF21872EA9603"
#   "8A73D1E0BB69E3A5388EA0E340A0B0D9"
#   "F0C078EECFFCA394336F93B54D6CDE24"
#
# @faker.version next
def hex(length: 32, upcase: false)

@Zeragamba
Copy link
Contributor

I know that YARD also allows for us to specify our own CSS for the documentation, so we could so some fancy things with that, but i haven't yet delved into that.

@stephendolan
Copy link
Author

A few comments on the proposed format provided by @SpyMaster356 :

  1. @param length [integer] Length of the string should probably be @param length [Integer] the length of the string (note the lower case description and capitalized data type). Making explicit where we wish to depart from the style laid out in the Tags documentation for YARD will be necessary to maintain consistency.

  2. What's the intended use of the @faker.version tag? Just want to make sure it's actually relevant for the people who will be reviewing the documentation. Personally, what version a function was introduced in wouldn't be of interest to me as an end user.

  3. I firmly believe in having a summary statement at the top of all YARD docs, even if that summary statement is repetitive. I would probably have added something to the top of your comment along the lines of "Produces a random string of hexadecimal characters.". I find that it makes the end documentation even more consistent and easier to parse.

Without summary:
screen shot 2019-02-15 at 11 19 17 am

With summary:
screen shot 2019-02-15 at 11 19 12 am

@Zeragamba
Copy link
Contributor

  1. I didn't know there was a suggested format for tags. I think we should adhere to that as much as possible . However, when i was poking around with it, i was running into the issue where [String] was resolving to Faker::String instead of standard lib's String. Do you know if there is a way to force Yard to pick the standard lib one?

  2. In the current markdown docs, there is often a line "Available since version 1.9.0" or similar, and i think it would be good to keep that for users that have locked down their version of faker.

  3. Nearly all the methods are going to be single line "produce a random this", "produce a random that", so i don't know if a summary is completely needed. We could drop the description on the @return tag to remove the duplication.

@stephendolan
Copy link
Author

I'm not sure about the String resolution issue off the top of my head, but maybe prefixing it like ::String would pull it out of the Faker namespace.

Everything else makes perfect sense to me and I agree with your approach, for whatever that's worth to the group :)

@Zeragamba
Copy link
Contributor

So an updated example:

##
# Produces a random hexadecimal string
#
# @return [string]
#
# @param length [integer] Length of the string
# @param upcase [boolean] Upcase the letters 
#
# @example Faker::Example.hex
#   "d6964ad8b71d46a62e5e64cd00b9e476"
#   "955b1fdf9971cda5745604ab081cc61d"
#   "73d3dc6fa0ba67911024d61eb6c1e382"
# @example Faker::Example.hex(length: 10)
#   "170b43193e"
#   "181450a4ae"
#   "d7b0a72da6"
# @example Faker::Example.hex(upcase: true)
#   "4BE0CB215BE62A06306BF21872EA9603"
#   "8A73D1E0BB69E3A5388EA0E340A0B0D9"
#   "F0C078EECFFCA394336F93B54D6CDE24"
#
# @faker.version next
def hex(length: 32, upcase: false)

@Zeragamba
Copy link
Contributor

One thing that we should discuss is the number of examples that are required.

A few ideas for that:

  1. Require 1 example for each usage
  2. Require 3 examples for each usage (unless it's always the same result, eg Faker::Placeholdit.image)
  3. Require 3 examples for the primary usage, and 1 for each of the secondary usages

@stympy
Copy link
Contributor

stympy commented Feb 15, 2019

I'm fine with requiring just one example and encouraging examples for optional arguments.

@stephendolan
Copy link
Author

I don't think anything more than 1 example showing the main use case should be required (of course, the more the better). The @param and @return tags should be detailed enough to inform users about the various uses on their own, and is where the focus should be placed during documentation review.

@Zeragamba
Copy link
Contributor

For me, I think each usage should have at least one example, as that can speak more about what will be generated. But generally @param and the summary should be enough in most cases.

@Zeragamba
Copy link
Contributor

Oh cool, Rubocop has a documentation cop, we could make use of that once all the methods are documented.

@stephendolan
Copy link
Author

When utilizing YARD for documentation, I've found the yard stats command that comes with the gem to be very helpful as well. You can use some simple command line tools to ensure that your documentation percentage doesn't drop.

It seems like we've got enough of a start here to open up a pull request. Does it make sense to include these guidelines in CONTRIBUTING.md, or is it worth having something like a DOCUMENTATION.md document that can be linked from CONTRIBUTING.md?

@Zeragamba
Copy link
Contributor

To me, having the new documentation style as part of CONTRIBUTING.md makes the most sense to me. And looking at the file, it actually doesn't mention documentation at all >.<

Adding the check to ensure that the documentation level doesn't drop (btw, currently sits at 7% excluding lib/faker/deprecate) would be good to have from the start.

Sounds good to you @stympy?

@stympy
Copy link
Contributor

stympy commented Feb 15, 2019

That works for me.

@Zeragamba
Copy link
Contributor

@stephendolan i've already started a bit on my fork here: https://github.com/SpyMaster356/faker/tree/yard-powered-docs

@stephendolan
Copy link
Author

Just so I'm clear @SpyMaster356 , are you submitting the initial pull request, or should I?

@Zeragamba
Copy link
Contributor

We could work off of my fork as it's already got Yard added, and some basic setup done. Up to you, as you opened this thread.

On another note, using ::String for the type didn't fix the name-spacing issue, and it looks like even YARD has a similar issue: https://www.rubydoc.info/gems/yard/String

@Zeragamba
Copy link
Contributor

Should i open the pull request @stephendolan?

@stephendolan
Copy link
Author

I'm happy to open one, @SpyMaster356 . It will just be the week of March 8th before I can devote the time to getting it done correctly. If we'd like to see progress before then, someone else will have to open the PR.

We've got a big release at work this week, followed by a big vacation for me :D.

@Zeragamba
Copy link
Contributor

Have fun on the vacation. I'll open a PR for the stuff i have on my fork.

vbrazo pushed a commit that referenced this issue Sep 11, 2019
* install Yard

* add some basic docs to test with

* and go go gadget yard

* Revert "and go go gadget yard"

This reverts commit b2c8000.

* use square brackets not braces

* fully document Faker::Blockchain

* exclude deprecated methods

* add version numbers to blockchain

* update documentation to match what was discussed in #1330

* remove class level @faker.version from docs

* update CONTRIBUTING.md

* add documentation to Alphanumeric

* consistently use braces for types

* document the Books namespace

* add doc url

* Add yard docs for Faker::Blockchain::Tezos.block

* update docs for named params

* convert back to [] for types
Although YARD supports any kind of bracket for the Typing, square brackets are
used in the documentation. For those contributing, and unfamiliar with YARD, it
would be best that our documentation matches the same style as that in YARD's
tutorials and documentation.

* document Faker::Creature::Animal

* document Faker::Creature::Cat

* document Faker::Creature::Dog

* document Faker::Creature::Horse

* Update lib/faker/default/alphanumeric.rb

Co-Authored-By: Connor Shea <[email protected]>

* Update lib/faker/creature/dog.rb

Co-Authored-By: Connor Shea <[email protected]>

* document Faker::Game

* document Faker::Games::HalfLife

* document Faker::Games::Zelda

* document Faker::Games::SuperSmashBros

* document Faker::TvShows::BreakingBad

* Document Faker::Games::ElderScrolls

* document Faker::Gender

* document Faker::House

* document Faker::ProgrammingLanguage

* document Faker::Source

* Update some of the docs to use examples without titles.

* Update a few more docs to use examples without titles.

* Update more docs to use title-less examples.

* document Faker::Boolean

* document Faker::Avatar

* document Faker::Games::Fallout

* document Faker::Games::Overwatch

* document Faker::Hacker

* Fix a method description.

* Remove trailing whitespace.

* document Faker::App

* Add faker version for BreakingBad methods.

* Add faker version to Zelda methods.

* document Faker::Artist

* Merge the examples for semantic_version in app.rb.

* Add faker versions for elder_scrolls.rb and fallout.rb.

Some of the Elder Scrolls methods were added after others, in 1.9.0.

* Update version tags in Elder Scrolls and Fallout.

* Clean up docs

Co-Authored-By: Connor Shea <[email protected]>
Update CONTRIBUTING.md to match new example format
install Yard


and go go gadget yard


Revert "and go go gadget yard"

This reverts commit b2c8000.

fully document Faker::Blockchain


exclude deprecated methods


add version numbers to blockchain


update documentation to match what was discussed in #1330


remove class level @faker.version from docs

update CONTRIBUTING.md

update existing yard docs


clean up some of the docs

* fix line ending issues
michebble pushed a commit to michebble/faker that referenced this issue Feb 16, 2020
* install Yard

* add some basic docs to test with

* and go go gadget yard

* Revert "and go go gadget yard"

This reverts commit b2c8000.

* use square brackets not braces

* fully document Faker::Blockchain

* exclude deprecated methods

* add version numbers to blockchain

* update documentation to match what was discussed in faker-ruby#1330

* remove class level @faker.version from docs

* update CONTRIBUTING.md

* add documentation to Alphanumeric

* consistently use braces for types

* document the Books namespace

* add doc url

* Add yard docs for Faker::Blockchain::Tezos.block

* update docs for named params

* convert back to [] for types
Although YARD supports any kind of bracket for the Typing, square brackets are
used in the documentation. For those contributing, and unfamiliar with YARD, it
would be best that our documentation matches the same style as that in YARD's
tutorials and documentation.

* document Faker::Creature::Animal

* document Faker::Creature::Cat

* document Faker::Creature::Dog

* document Faker::Creature::Horse

* Update lib/faker/default/alphanumeric.rb

Co-Authored-By: Connor Shea <[email protected]>

* Update lib/faker/creature/dog.rb

Co-Authored-By: Connor Shea <[email protected]>

* document Faker::Game

* document Faker::Games::HalfLife

* document Faker::Games::Zelda

* document Faker::Games::SuperSmashBros

* document Faker::TvShows::BreakingBad

* Document Faker::Games::ElderScrolls

* document Faker::Gender

* document Faker::House

* document Faker::ProgrammingLanguage

* document Faker::Source

* Update some of the docs to use examples without titles.

* Update a few more docs to use examples without titles.

* Update more docs to use title-less examples.

* document Faker::Boolean

* document Faker::Avatar

* document Faker::Games::Fallout

* document Faker::Games::Overwatch

* document Faker::Hacker

* Fix a method description.

* Remove trailing whitespace.

* document Faker::App

* Add faker version for BreakingBad methods.

* Add faker version to Zelda methods.

* document Faker::Artist

* Merge the examples for semantic_version in app.rb.

* Add faker versions for elder_scrolls.rb and fallout.rb.

Some of the Elder Scrolls methods were added after others, in 1.9.0.

* Update version tags in Elder Scrolls and Fallout.

* Clean up docs

Co-Authored-By: Connor Shea <[email protected]>
Update CONTRIBUTING.md to match new example format
install Yard


and go go gadget yard


Revert "and go go gadget yard"

This reverts commit b2c8000.

fully document Faker::Blockchain


exclude deprecated methods


add version numbers to blockchain


update documentation to match what was discussed in faker-ruby#1330


remove class level @faker.version from docs

update CONTRIBUTING.md

update existing yard docs


clean up some of the docs

* fix line ending issues
davidmorton0 pushed a commit to davidmorton0/faker that referenced this issue Jul 12, 2021
* install Yard

* add some basic docs to test with

* and go go gadget yard

* Revert "and go go gadget yard"

This reverts commit b2c8000.

* use square brackets not braces

* fully document Faker::Blockchain

* exclude deprecated methods

* add version numbers to blockchain

* update documentation to match what was discussed in faker-ruby#1330

* remove class level @faker.version from docs

* update CONTRIBUTING.md

* add documentation to Alphanumeric

* consistently use braces for types

* document the Books namespace

* add doc url

* Add yard docs for Faker::Blockchain::Tezos.block

* update docs for named params

* convert back to [] for types
Although YARD supports any kind of bracket for the Typing, square brackets are
used in the documentation. For those contributing, and unfamiliar with YARD, it
would be best that our documentation matches the same style as that in YARD's
tutorials and documentation.

* document Faker::Creature::Animal

* document Faker::Creature::Cat

* document Faker::Creature::Dog

* document Faker::Creature::Horse

* Update lib/faker/default/alphanumeric.rb

Co-Authored-By: Connor Shea <[email protected]>

* Update lib/faker/creature/dog.rb

Co-Authored-By: Connor Shea <[email protected]>

* document Faker::Game

* document Faker::Games::HalfLife

* document Faker::Games::Zelda

* document Faker::Games::SuperSmashBros

* document Faker::TvShows::BreakingBad

* Document Faker::Games::ElderScrolls

* document Faker::Gender

* document Faker::House

* document Faker::ProgrammingLanguage

* document Faker::Source

* Update some of the docs to use examples without titles.

* Update a few more docs to use examples without titles.

* Update more docs to use title-less examples.

* document Faker::Boolean

* document Faker::Avatar

* document Faker::Games::Fallout

* document Faker::Games::Overwatch

* document Faker::Hacker

* Fix a method description.

* Remove trailing whitespace.

* document Faker::App

* Add faker version for BreakingBad methods.

* Add faker version to Zelda methods.

* document Faker::Artist

* Merge the examples for semantic_version in app.rb.

* Add faker versions for elder_scrolls.rb and fallout.rb.

Some of the Elder Scrolls methods were added after others, in 1.9.0.

* Update version tags in Elder Scrolls and Fallout.

* Clean up docs

Co-Authored-By: Connor Shea <[email protected]>
Update CONTRIBUTING.md to match new example format
install Yard


and go go gadget yard


Revert "and go go gadget yard"

This reverts commit b2c8000.

fully document Faker::Blockchain


exclude deprecated methods


add version numbers to blockchain


update documentation to match what was discussed in faker-ruby#1330


remove class level @faker.version from docs

update CONTRIBUTING.md

update existing yard docs


clean up some of the docs

* fix line ending issues
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants