Closed samhh closed 3 years ago
My guess is that is detecting a missing example in the module documentation (i.e. the very first comment at the top of the module)
Hmm, I hadn't even considered that. Is that desirable behaviour?
@gcanti is correct - the parser is detecting missing documentation at the module level. See here: https://github.com/gcanti/docs-ts/blob/19ca164740a48f6cc2f9557c823e2ab05c9450e9/src/Parser.ts#L755-L759
As a side note, we decided to go this route based on the discussion in #23.
More than happy to discuss further.
Gotcha. I've two pieces of feedback then depending on where we want to go with it:
@gcanti, @gillchristian, @thought2 - do you guys have any opinion on how to solve this issue?
I agree with point 1. (not a desirable behaviour for examples)
Agree, we should not enforce examples on module level docs.
I can work on this tonight. Unless somebody wants to give it a shot.
I'm fine with either way :)
However, I find it somehow appealing to also enforce examples on the module level if this option is enabled. It encourages you think about the module as if you've never heard of it before.
Maybe to put a selection of some representative functions that the module provides into a pipe.
For Array e.g.:
import * as A from 'fp-ts/Array'
import { pipe } from 'fp-ts/function'
const sample : Array<string> = pipe(
[1, 2, 3, 4],
A.filter((n) => n >= 2),
A.map((n) => n.toString())
)
assert.deepStrictEqual(sample, ['3', '2'])
@thought2 - That was my thought process as well. Especially for libraries that can be complex to get started with. A great example would be the port of Haskell's scalpel web scraping library that I have been working on (link for those that are interested in taking a closer look).
However, since @gcanti, @gillchristian, and @samhh feel that this is not the direction to go I am also fine with removing the top-level module requirement for documentation when enforceExamples
is set to true. Hopefully the fact that we are enforcing examples everywhere else in the code when this flag is turned on will encourage devs to put top-level examples as well 😅.
@gillchristian - since I know that the issue needs to be addressed in two places, I am already working on a PR. Should be submitting shortly.
Another option could be to add an extra configuration to enforce module examples separately from the other examples.
Not sure if it's the road we want to go and keep populating the config tho 😬
Repro:
Clone fp-ts-std (and checkout
5870c44
).Add a
docs-ts.json
file with the following contents:Run
yarn docs
(alias fordocs-ts
).The output will be as follows:
I have examples for I think absolutely everything, and they do successfully make it into the generated documentation.
Small modules which could be easier to verify would be
Debug
,IO
, andTask
.