From 7ea56c27683d64ec4a5fad7b2983f803c6e7726d Mon Sep 17 00:00:00 2001 From: Angel Aviel Domaoan <13580338+tenshiAMD@users.noreply.github.com> Date: Fri, 30 Sep 2022 03:51:12 +0800 Subject: [PATCH] fix: resolve format issues in rst --- .../__tests__/__snapshots__/index.js.snap | 44 +++++++++---------- src/generate/index.js | 38 +++++++--------- 2 files changed, 37 insertions(+), 45 deletions(-) diff --git a/src/generate/__tests__/__snapshots__/index.js.snap b/src/generate/__tests__/__snapshots__/index.js.snap index 7278f00..452cca0 100644 --- a/src/generate/__tests__/__snapshots__/index.js.snap +++ b/src/generate/__tests__/__snapshots__/index.js.snap @@ -10,18 +10,18 @@ These people contributed to the project: - +
- - + + -
Kent C. Dodds is awesome!Divjot Singh is awesome!Jeroen Engels is awesome!Divjot Singh is awesome!Jeroen Engels is awesome!
+ @@ -41,12 +41,12 @@ These people contributed to the project: - +
- - + + @@ -58,7 +58,7 @@ These people contributed to the project: -
Kent C. Dodds is awesome!Divjot Singh is awesome!Jeroen Engels is awesome!Divjot Singh is awesome!Jeroen Engels is awesome!
+ @@ -78,24 +78,24 @@ These people contributed to the project: - +
- - - - + + + + - + -
Kent C. Dodds is awesome!Kent C. Dodds is awesome!Kent C. Dodds is awesome!Kent C. Dodds is awesome!Kent C. Dodds is awesome!Kent C. Dodds is awesome!Kent C. Dodds is awesome!Kent C. Dodds is awesome!Kent C. Dodds is awesome!
Kent C. Dodds is awesome!Kent C. Dodds is awesome!Kent C. Dodds is awesome!
+ @@ -115,18 +115,18 @@ These people contributed to the project: - +
- - - - + + + + - + @@ -138,7 +138,7 @@ These people contributed to the project: -
Kent C. Dodds is awesome!Kent C. Dodds is awesome!Kent C. Dodds is awesome!Kent C. Dodds is awesome!Kent C. Dodds is awesome!Kent C. Dodds is awesome!Kent C. Dodds is awesome!Kent C. Dodds is awesome!Kent C. Dodds is awesome!
Kent C. Dodds is awesome!Kent C. Dodds is awesome!Kent C. Dodds is awesome!
+ diff --git a/src/generate/index.js b/src/generate/index.js index 6dac425..03d86d9 100644 --- a/src/generate/index.js +++ b/src/generate/index.js @@ -3,7 +3,7 @@ const formatBadge = require('./format-badge') const formatContributor = require('./format-contributor') function injectListBetweenTags(newContent) { - return function (previousContent) { + return function(previousContent) { const tagToLookFor = `' const startOfOpeningTagIndex = previousContent.indexOf( @@ -24,28 +24,24 @@ function injectListBetweenTags(newContent) { ) { return previousContent } - const startIndent = Math.max( - 0, - previousContent.lastIndexOf('\n', startOfOpeningTagIndex), - ) - const nbSpaces = - startOfOpeningTagIndex - Math.min(startOfOpeningTagIndex, startIndent) + const startIndent = Math.max(0, previousContent.lastIndexOf('\n', startOfOpeningTagIndex)) + const nbSpaces = startOfOpeningTagIndex - Math.min(startOfOpeningTagIndex, startIndent) return [ previousContent.slice(0, endOfOpeningTagIndex + closingTag.length), - '\n', - '\n', - newContent.replace('\n', `\n${' '.repeat(nbSpaces - 1)}`), - '', - '\n', + `\n${ ' '.repeat(nbSpaces - 1) }`, + `\n${ ' '.repeat(nbSpaces - 1) }`, + ' '.repeat(nbSpaces - 1) + newContent.replace('\n', `\n${ ' '.repeat(nbSpaces)}`).replace('', `${' '.repeat(nbSpaces) }`), + `${' '.repeat(nbSpaces - 1) }`, + `\n${ ' '.repeat(nbSpaces - 1) }`, '\n\n', - previousContent.slice(startOfClosingTagIndex), + ' '.repeat(nbSpaces - 1) + previousContent.slice(startOfClosingTagIndex), ].join('') } } function formatLine(contributors) { return `${contributors.join( - '\n ', + '\n ', )}` } @@ -82,7 +78,7 @@ function generateContributorsList(options, contributors) { } function replaceBadge(newContent) { - return function (previousContent) { + return function(previousContent) { const tagToLookFor = `' const startOfOpeningTagIndex = previousContent.indexOf( @@ -103,18 +99,14 @@ function replaceBadge(newContent) { ) { return previousContent } - const startIndent = Math.max( - 0, - previousContent.lastIndexOf('\n', startOfOpeningTagIndex), - ) - const nbSpaces = - startOfOpeningTagIndex - Math.min(startOfOpeningTagIndex, startIndent) + const startIndent = Math.max(0, previousContent.lastIndexOf('\n', startOfOpeningTagIndex)) + const nbSpaces = startOfOpeningTagIndex - Math.min(startOfOpeningTagIndex, startIndent) return [ previousContent.slice(0, endOfOpeningTagIndex + closingTag.length), '\n', - newContent.replace('\n', `\n${' '.repeat(nbSpaces)}`), + ' '.repeat(nbSpaces - 1) + newContent.replace('\n', `\n${ ' '.repeat(nbSpaces)}`), '\n', - previousContent.slice(startOfClosingTagIndex), + ' '.repeat(nbSpaces - 1) + previousContent.slice(startOfClosingTagIndex), ].join('') } }