markdown-toc icon indicating copy to clipboard operation
markdown-toc copied to clipboard

Feature Request: Add `--check` flag to show if the tool would make changes

Open bradjc opened this issue 8 years ago • 6 comments

It is very easy to edit a markdown file and change a section heading that would change the TOC, but then forget to re-generate the TOC afterwards. Therefore, adding a check to a continuous integration service like Travis-ci to make sure that TOC are staying in sync would be useful.

I'm imagining adding a --check flag which would cause markdown-toc to return 0 if there are no changes to make, and something else if there are. But really any way to tell if markdown-toc should be run is sufficient.

bradjc avatar Mar 29 '17 17:03 bradjc

Couldn't you just run markdown-toc if the markdown file(s) change? It would probably take the same amount of time to regenerate the toc as it would to reparse the file to check for heading changes.

jonschlinkert avatar Mar 29 '17 18:03 jonschlinkert

I don't think this is about the time it takes, it's solving the problem where people forget to run markdown-toc. CI services shouldn't be pushing commits when they run. rustfmt as an example provides the --diff option, which prints the diff and returns non-zero if it would've changed anything. This is expressly for CI applications.

(I actually think --diff would be better than --check, as it shows what changed, but I could see --check being faster / easier to implement)

ppannuto avatar Apr 04 '17 00:04 ppannuto

where people forget to run markdown-toc

I don't think that's relevant, is it? It sounds like watch is being used. Otherwise, I'm confused at what value this would provide.

jonschlinkert avatar Apr 04 '17 03:04 jonschlinkert

I think we're confusing things a bit here, let's give a concrete example:

I have a repository with some documentation written in markdown.

Someone comes along to improve the documentation, so they click edit in GitHub's web view, which automatically creates a pull request.

I have Travis CI set up on my project, and I want Travis to automatically validate that the edits made update the ToC if needed.

There's no local development environment in this case, or a place for watch (or markdow-toc) to run. The idea of continuous integration in this case is to make sure that the submitter of a change updated the ToC correctly, whether by running markdown-toc or any other means. On Mon, Apr 3, 2017 at 23:03 Jon Schlinkert [email protected] wrote:

where people forget to run markdown-toc

I don't think that's relevant, is it? It sounds like watch is being used. Otherwise, I'm confused at what value this would provide.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/jonschlinkert/markdown-toc/issues/86#issuecomment-291381067, or mute the thread https://github.com/notifications/unsubscribe-auth/AAUt3laWaW1wi23tedn3nAjQdOVYyjYqks5rsbMRgaJpZM4MtU9c .

ppannuto avatar Apr 04 '17 03:04 ppannuto

I think we're confusing things a bit here,

Yes, one of us is lol

jonschlinkert avatar Apr 04 '17 04:04 jonschlinkert