SourceDocs icon indicating copy to clipboard operation
SourceDocs copied to clipboard

Calculate Documentation Percentage

Open leogdion opened this issue 5 years ago • 7 comments

I know some documentation tools have the ability to return the percentage documented. I'd love something like this to include in my CI along with SourceDocs. I am more than willing to help as well and add this feature. Where would something like this be calculated and added?

leogdion avatar Dec 09 '20 14:12 leogdion

Hi @leogdion, thank you for the suggestion. This is an interesting topic, and feature.

Where to calculate the percentage will depend on your definition:

  • Should the total percentage be in the README file?
  • Should it be on each document file?
  • Maybe we would want a sourcedocs percentage command that prints the total percentage without generating any other output?

In terms of calculation, SourceDocs loads all entities (classes, methods, etc) from code, whether they are documented or not. We could count the number of entities that have documentation and calculate the percentage. The best place to do that would probably be in MarkdownIndex.swift.

eneko avatar Dec 11 '20 00:12 eneko

I was thinking something fairly simple:

  • Maybe we would want a sourcedocs percentage command that prints the total percentage without generating any other output?

In other words just output the value with the command output (not included in any markdown files). My intention is to include it as part of my pre-commit hook or CI to ensure my documentation is up to certain threshold similar to how I can use swift-test-codecov in my pre-commit hook to ensure my test code coverage is fulfilled.

Feel free to look at how I do this with MistKit and code coverage. I'm going to look at MarkdownIndex.swift and see what I can do there.

Thanks for the pointers!

leogdion avatar Dec 11 '20 13:12 leogdion

Nice. That would be a great tool, for sure. It might require some good amount of refactoring, to separate the documentation extraction logic from the markdown generation (right now it's all tangled together 🙈).

If you want to look into it, I would recommend starting by adding a new command, then running the SourceKitten calls to parse the source files and load documentation. Feel free to duplicate any code, if you want to go this route, we can tidy it up later.

eneko avatar Dec 11 '20 20:12 eneko

I posted #65 Let me know if it needs any further fixes.

leogdion avatar Dec 14 '20 01:12 leogdion

Will take a look, thanks

eneko avatar Dec 14 '20 18:12 eneko

Cool! Let me know if you have any questions.

leogdion avatar Dec 28 '20 00:12 leogdion

Hi @leogdion, just left you a comment on the PR. please try pulling the latest changes from the main branch (master branch is no longer used).

If you don't mind, and have the time, it would be nice to clean up the command, specially all the parameters (arguments) not being used or needed for this command. Instead, you can pass default values to the documentation generator.

eneko avatar Dec 28 '20 05:12 eneko