Skip to content

Instantly share code, notes, and snippets.

@gr0uch
Last active August 29, 2015 14:13
Show Gist options
  • Save gr0uch/25626bab7c952fa03da7 to your computer and use it in GitHub Desktop.
Save gr0uch/25626bab7c952fa03da7 to your computer and use it in GitHub Desktop.
Idea: JS documentation tool

There are not enough tools in the JS ecosystem for generating docs from source code. There is dox which seems to be popular, but it is not very configurable and a bit limited in functionality in that has no lexical understanding of code. The gold standard is jsdoc but it still has its own shortcomings. It is also rigid in its expectations of input, and outputs JSON in a predefined way. I want to write a new tool that instruments code so that it has an understanding of what is being documented, and modular serializers for inputs and outputs.

Example input, JSDoc style:

App.UsersController = Framework.ArrayController.extend({
  /**
   * Get a list of inactive users.
   *
   * @public
   * @param {Number} threshold in seconds for what is considered inactive
   * @return {Array}
   */
  getInactiveUsers (threshold) { ... }
});

Many current implementations identify the comment block and then run a regular expression on the following line, without understanding the context it is in. This might be interpreted incorrectly as documentation of an anonymous function, but more importantly it misses the ArrayController.extend context. It may also not understand ES6 syntax (omitted function keyword) because their regular expressions do not account for it or their code instrumentation tool doesn't parse ES6. Moreover, they don't offer much extensibility, in that you are generally limited to JSDoc format, and implementations differ.

What I would expect as JSON output:

{
  "context": {
    "type": "method",
    "name": "getInactiveUsers",
    "scope": "Framework.ArrayController.extend"
  },
  "description": {
    "text": "Get a list of inactive users.",
    "tags": [
      {"tag": "public"},
      {"tag": "param", "name": "threshold", "type": "Number", "description": "in seconds for what is considered inactive"},
      {"tag": "return", "type": "Array"}
    ]
  }
}

The above is just one example, the idea is that the output can be user defined function, so it could output XML if you're a masochist.

Naming ideas: doccer (rhymes with soccer), docchi (rhymes with gnocchi)

@gr0uch
Copy link
Author

gr0uch commented Jan 27, 2015

Implementation wise, i think mashing together acorn with doctrine would be a good start.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment