From 0e1a2d6858a63b50c54a09ed4cfef0158922b328 Mon Sep 17 00:00:00 2001 From: Josh <36625023+JoshuaBrest@users.noreply.github.com> Date: Sun, 12 May 2024 01:17:59 -0700 Subject: [PATCH] Test invalid lint via amongus + add trailing new line --- scripts/generate.mjs | 30 ++++++++++++++++++------------ scripts/lint.mjs | 19 +++++++++++++++++-- src/game-support/among-us.md | 3 ++- 3 files changed, 37 insertions(+), 15 deletions(-) diff --git a/scripts/generate.mjs b/scripts/generate.mjs index 1f4cf31..7f32b87 100755 --- a/scripts/generate.mjs +++ b/scripts/generate.mjs @@ -169,12 +169,18 @@ export const generateGameMetadata = async () => { * @returns {string} */ export const generateLinks = links => { - return '\n' + links - .map(link => { - return ` - [${markdownEscape(link.game.title)}](/game-support/${encodeURIComponent(basename(link.path))})`; - }) - .join('\n') + '\n'; -} + return ( + '\n' + + links + .map(link => { + return ` - [${markdownEscape( + link.game.title + )}](/game-support/${encodeURIComponent(basename(link.path))})`; + }) + .join('\n') + + '\n' + ); +}; /** * Generate the games.json file. @@ -207,7 +213,7 @@ export const generateGamesJson = links => { null, 2 ); -} +}; /** * Main function. @@ -220,7 +226,6 @@ const main = async () => { return 1; } - // Get the SUMMARY.md file /** * @type {[string, null] | [null, Error]} @@ -237,9 +242,8 @@ const main = async () => { } // Get the start and end of the SUMMARY.md file - const [summarySections, summarySectionsError] = sectionsGetStartAndEnd( - summaryFile - ); + const [summarySections, summarySectionsError] = + sectionsGetStartAndEnd(summaryFile); if (summarySectionsError) { logging.error('Failed to find start and end sections in SUMMARY.md.'); return 1; @@ -286,4 +290,6 @@ const main = async () => { return 0; }; -main().then(code => process.exit(code)); +// Check if this is the file that is being run +if (process.argv[1] === new URL(import.meta.url).pathname) + main().then(code => process.exit(code)); diff --git a/scripts/lint.mjs b/scripts/lint.mjs index bdddfb5..798df3c 100755 --- a/scripts/lint.mjs +++ b/scripts/lint.mjs @@ -268,6 +268,17 @@ const lintMarkdownFile = async file => { ); } } + + // There should be a trailing newline with no content + if (lineIndexes[lineIndexes.length - 1] !== content.length) { + logLintViolation( + 'warning', + file, + lineIndexes.length, + 1, + 'File should end with a newline.' + ); + } }; /** @@ -314,7 +325,10 @@ const main = async () => { } else if (!gameDataError) { const [start, end] = summarySections; // Slice at these indexes to get the content between the sections - const contentBetweenSections = summaryFile.slice(start + SCRIPT_GENERATE_START.length, end); + const contentBetweenSections = summaryFile.slice( + start + SCRIPT_GENERATE_START.length, + end + ); // Check if the content between the sections is up to date const expectedContent = generateLinks(gameData); if (contentBetweenSections !== expectedContent) { @@ -339,4 +353,5 @@ const main = async () => { return 0; }; -main().then(code => process.exit(code)); +if (process.argv[1] === new URL(import.meta.url).pathname) + main().then(code => process.exit(code)); diff --git a/src/game-support/among-us.md b/src/game-support/among-us.md index f142869..cbe7558 100644 --- a/src/game-support/among-us.md +++ b/src/game-support/among-us.md @@ -1,9 +1,10 @@ # Among Us - +a {{#template ../templates/rating.md status=Gold installs=Yes opens=Yes}} > [!NOTE] > This game has an iPad Mac port through the App Store. {{#template ../templates/steam.md id=945360}} +a \ No newline at end of file