From 678a0061d54ebaa672b21155b4af682d50182c82 Mon Sep 17 00:00:00 2001 From: Petri Lehtinen Date: Tue, 13 Aug 2019 12:52:04 +0300 Subject: [PATCH] Don't transform files whose TOC is unchanged Looking at the code, this was always the intention, but there was a small bug in the logic that this patch fixes. This is helpful e.g. to check in CI that all TOCs have been updated, like this: doctoc --stdout . | grep -q "should be updated" && echo "TOCs are out of date!" --- lib/transform.js | 2 +- test/fixtures/readme-with-code.md | 5 +---- test/fixtures/readme-with-custom-title.md | 4 +--- test/fixtures/readme-with-weird-headers.md | 3 +-- 4 files changed, 4 insertions(+), 10 deletions(-) diff --git a/lib/transform.js b/lib/transform.js index 5b1370d..5344192 100644 --- a/lib/transform.js +++ b/lib/transform.js @@ -152,7 +152,7 @@ exports = module.exports = function transform(content, mode, maxHeaderLevel, tit var wrappedToc = start + '\n' + toc + '\n' + end; - if (currentToc === toc) return { transformed: false }; + if (currentToc === wrappedToc) return { transformed: false }; var data = updateSection(lines.join('\n'), wrappedToc, matchesStart, matchesEnd, true); return { transformed : true, data : data, toc: toc, wrappedToc: wrappedToc }; diff --git a/test/fixtures/readme-with-code.md b/test/fixtures/readme-with-code.md index 6f6c315..e05cd67 100644 --- a/test/fixtures/readme-with-code.md +++ b/test/fixtures/readme-with-code.md @@ -4,10 +4,7 @@ README to test doctoc with edge-case headers. ## Table of Contents -- [Single Backticks](#single-backticks) -- [Multiple Backticks](#multiple-backticks) -- [code tag](#code-tag) -- [pre tag](#pre-tag) +Out of date diff --git a/test/fixtures/readme-with-custom-title.md b/test/fixtures/readme-with-custom-title.md index 2534d7f..a4adeed 100644 --- a/test/fixtures/readme-with-custom-title.md +++ b/test/fixtures/readme-with-custom-title.md @@ -6,9 +6,7 @@ README to test doctoc with user-specified titles. ## Table of Contents -- [Installation](#installation) -- [API](#api) -- [License](#license) +Out of date diff --git a/test/fixtures/readme-with-weird-headers.md b/test/fixtures/readme-with-weird-headers.md index 9465cfd..36dd1db 100644 --- a/test/fixtures/readme-with-weird-headers.md +++ b/test/fixtures/readme-with-weird-headers.md @@ -4,8 +4,7 @@ README to test doctoc with edge-case headers. ## Table of Contents -- [hasOwnProperty](#hasownproperty) -- [something else](#something-else) +Out of date