Skip to content

Commit

Permalink
Test invalid lint via amongus + add trailing new line
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaBrest committed May 12, 2024
1 parent e542c7a commit 0e1a2d6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 15 deletions.
30 changes: 18 additions & 12 deletions scripts/generate.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -207,7 +213,7 @@ export const generateGamesJson = links => {
null,
2
);
}
};

/**
* Main function.
Expand All @@ -220,7 +226,6 @@ const main = async () => {
return 1;
}


// Get the SUMMARY.md file
/**
* @type {[string, null] | [null, Error]}
Expand All @@ -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;
Expand Down Expand Up @@ -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));
19 changes: 17 additions & 2 deletions scripts/lint.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
);
}
};

/**
Expand Down Expand Up @@ -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) {
Expand All @@ -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));
3 changes: 2 additions & 1 deletion src/game-support/among-us.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Among Us
<!-- script:Aliases [] -->

a

Check warning on line 3 in src/game-support/among-us.md

View workflow job for this annotation

GitHub Actions / lint

Line before review metadata should be empty.
{{#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

Check warning on line 10 in src/game-support/among-us.md

View workflow job for this annotation

GitHub Actions / lint

File should end with a newline.

0 comments on commit 0e1a2d6

Please sign in to comment.