Hacker News new | ask | show | jobs
by Aliabid94 2282 days ago
This is something that I’ve felt is going to become very hot - some way of ensuring that documentation never goes stale. In the same vein as tests needing to pass before merging a commit, ensuring documentation is up to date when commiting. Looking forward to hearing more!
1 comments

Rust has a feature that somewhat provides this - doctests[1]. Rust doc comments begin with `///` and will be parsed as markdown when generating documentation. If there are codeblocks in the documentation comments, they will be run with all other tests and the test runner will report if the blocks fail to compile or if they error at runtime.

So if the API changes, the example code in the documentation will fail to compile.

[1] https://doc.rust-lang.org/rustdoc/documentation-tests.html

For anyone looking for something similar with JS, we wrote doctest-js: https://github.com/supabase/doctest-js

It allows you to write Unit Tests using JSDoc

It won't necessarily stop your documentation from building but offers another good reason to document your code