Introducing sphinx-js, a better way to document large JavaScript projects
hacks.mozilla.org
hacks.mozilla.org
- One, like this and JSDoc, is structured documenting of the code interface. It’s a reference tool.
- Two, is a more free form documenting of intent. Commented source code tools like Docco serve this well.
Both are useful in different situations and don’t replace each other. For 3rd party tools the former is more useful, for internal - the latter.
Unfortunately the parsers for each are usually mutually incompatible and I really wish there was a tool that supported both.
For example, these are the reference docs to a package I used to maintain: http://django-tidings.readthedocs.io/en/latest/reference.htm.... They're entirely extracted from the source.
However, most of the other pages in that manual are written expressly for new users, organized to teach. The magic of Sphinx is that those introductory pages can link effortlessly back into the reference docs. There are many examples on http://django-tidings.readthedocs.io/en/latest/introduction.....
And it doesn't stop at linking; you can also embed extracted docs into the midst of a contextualized explanation. See https://mozilla.github.io/fathom/optimization.html, which is JS code and so uses sphinx-js.
I missed all that power from the Python world; that's why I ported some of it to the nascent JS ecosystem.
Which is fine of course, but it doesn't really help with the latter case as anything other than a secondary concern. That's great when your primary usage is as a reference but suffers the same problem as JSDoc/etc when it isn't.
But it's a better form of what it's doing, for sure.
Here's a comment of mine from a while ago describing how Mozilla's old "Bonsai" tool worked:
There exists for example esdoc [1] which is capable of compiling together written documents with generated documentation. I've just implemented this for two work projects with the return of many thanks from my team.
That said I will also check out sphinx-js because we also maintain python projects and already use sphinx for those.
Overview
Design
Installation
Usage
Tutorial
Configuration
Example
Advanced
FAQ
Changelog
You can't add more. And, as far as I can tell (the documentation I can find is silent on the point), those pages are islands, with no ability to call content out of the code. (I'd love to be shown wrong. Did you find otherwise?) However, I do applaud esdoc's better support for more modern JS features!You can also link between written docs and API docs, though it is a bit manual/hacky (you need to know the rendered file paths).
[1]https://elixir-lang.org/getting-started/mix-otp/docs-tests-a...
Sphinx also has additional doc testing methods that let you test the code examples in your actual docs: http://www.sphinx-doc.org/en/stable/ext/doctest.html
Here's an example:
##Examples
iex> user = Repo.insert!(%MyApp.User{id: 1, some_state: "whatever"})
...> {:ok, user} = MyApp.Users.DataTransformer.transform_with_effects(user)
...> Repo.one(where: MyApp.User.id == 1).some_state
"new state"Or to put it another way, the way to learn how to use Clojure's Spec is not from the names of functions in the Clojure Spec source code. It's from reading blogs and watching videos and listening to podcasts and reading the documentation. And the bar for Clojure Spec is pretty low. It just has to be better than JavaDoc.
More seriously, keeping comments up to date is hard, but there's no alternative if you want to maintain a public API.