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

Correct + make runnable documentation code samples. #1396

Merged
merged 1 commit into from
Apr 13, 2021
Merged

Conversation

cjtenny
Copy link
Collaborator

@cjtenny cjtenny commented Feb 27, 2021

Running all the code samples in the docs through a tolerant markdown snippet parser + execution environment revealed many errors. #1395, #1391, #1380, and this patch's one-line fix in plainmonthday.mjs were all bugs revealed by the documentation code samples. Many of the changes in this patch are slight syntactic changes to make the samples testable and more clear.

Common classes of smaller issues fixed:

  • Examples did not include seconds in string representations
  • Examples contained extra zeroes of precision when not requested
  • Old calling conventions used; arguments needed to be changed
  • Some options bags are now used in dedicated places rather than alongside other methods

Though the documentation tester I wrote isn't included in this patch, because it's messy, one-off, and would be needless work to maintain for auditing every pull request, I'll keep it around for periodic audits of the documentation.

Fixes #921 .

@codecov
Copy link

codecov bot commented Feb 27, 2021

Codecov Report

Merging #1396 (73d9a12) into main (4b18ba5) will decrease coverage by 2.54%.
The diff coverage is 100.00%.

❗ Current head 73d9a12 differs from pull request most recent head ef22c33. Consider uploading reports for the commit ef22c33 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1396      +/-   ##
==========================================
- Coverage   95.65%   93.11%   -2.55%     
==========================================
  Files          19       17       -2     
  Lines       10897    10888       -9     
  Branches     1730     1633      -97     
==========================================
- Hits        10424    10138     -286     
- Misses        469      740     +271     
- Partials        4       10       +6     
Flag Coverage Δ
test262 ?
tests 91.95% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
polyfill/lib/plainmonthday.mjs 83.23% <100.00%> (-7.52%) ⬇️
polyfill/lib/instant.mjs 87.94% <0.00%> (-6.85%) ⬇️
polyfill/lib/plaindate.mjs 89.18% <0.00%> (-6.76%) ⬇️
polyfill/lib/zoneddatetime.mjs 91.60% <0.00%> (-6.28%) ⬇️
polyfill/lib/timezone.mjs 87.41% <0.00%> (-5.97%) ⬇️
polyfill/lib/plainyearmonth.mjs 89.73% <0.00%> (-5.63%) ⬇️
polyfill/lib/plaindatetime.mjs 90.25% <0.00%> (-4.54%) ⬇️
polyfill/lib/plaintime.mjs 92.50% <0.00%> (-4.04%) ⬇️
polyfill/lib/duration.mjs 94.22% <0.00%> (-3.86%) ⬇️
... and 6 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4b18ba5...ef22c33. Read the comment docs.

Copy link
Collaborator

@ptomato ptomato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally, I'm so glad this could be semi-automated!

Long pull request, so long review comments. But most are minor.

docs/ambiguity.md Outdated Show resolved Hide resolved
docs/ambiguity.md Show resolved Hide resolved
docs/README.md Outdated Show resolved Hide resolved
docs/ambiguity.md Outdated Show resolved Hide resolved
docs/balancing.md Outdated Show resolved Hide resolved
docs/zoneddatetime.md Outdated Show resolved Hide resolved
docs/zoneddatetime.md Outdated Show resolved Hide resolved
docs/zoneddatetime.md Outdated Show resolved Hide resolved
docs/zoneddatetime.md Outdated Show resolved Hide resolved
docs/zoneddatetime.md Outdated Show resolved Hide resolved
@cjtenny
Copy link
Collaborator Author

cjtenny commented Apr 8, 2021

Oops, I forgot about this one a while back, sorry for dropping the ball there. Finished the last changes and re-ran everything to catch a few more fixes in rebasing.

I changed every representation to the Node REPL version, which had some annoying effects (lots of 'Temporal.TypeName ' rather than just 'string repr') but overall I think it's more clear and not too bad.

One thing that I had mixed feelings about was using the /* WRONG */ in addition to // => throws...; there are cases where the usage is correct, and it throwing doesn't mean you've done anything wrong. What would you think about removing /* WRONG */ for e.g. those RangeError cases?

@ptomato
Copy link
Collaborator

ptomato commented Apr 8, 2021

Thanks for updating this.

I don't think the Temporal.Foo <...> brackets really add anything to the readability of the docs and I'd still rather keep code results that are Temporal objects as they were, with no brackets and no quotes, but I'm open to being convinced otherwise if you felt strongly about it.

I think it's fine to have /* WRONG */ only on examples that are intentionally wrong.

Otherwise looks good.

@cjtenny
Copy link
Collaborator Author

cjtenny commented Apr 10, 2021

Pushed as two additional commits for easier re-review, will squash before merging

Copy link
Collaborator

@ptomato ptomato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All minor things, feel free to merge after addressing.

docs/duration.md Outdated Show resolved Hide resolved
docs/duration.md Outdated
Usage examples:

TODO FIXME CURRENTLY NOT SPECIFIED, should we remove?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's clear from the note above that DurationFormat is still early stage, and so instead we should just note that the output of the code below is only example output.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, here I thought if I left a big TODO FIXME I'd surely catch it before review, then forgot about it before pushing. I should really install my pre-push hook!

docs/instant.md Outdated Show resolved Hide resolved
docs/instant.md Outdated Show resolved Hide resolved
docs/plainyearmonth.md Outdated Show resolved Hide resolved
polyfill/lib/plainmonthday.mjs Outdated Show resolved Hide resolved
Running all the code samples in the docs through a tolerant markdown snippet parser + execution environment revealed many errors. #1395, #1391, #1380, and this patch's one-line fix in plainmonthday.mjs were all bugs revealed by the documentation code samples. Many of the changes in this patch are slight syntactic changes to make the samples testable and more clear.

Common classes of smaller issues fixed:
- Examples did not include seconds in string representations
- Examples contained extra zeroes of precision when not requested
- Old calling conventions used; arguments needed to be changed
- Some options bags are now used in dedicated places rather than alongside other methods
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.

Scrub docs code samples to make sure they work
2 participants