ci: add lint for expectations (#11365)

This commit is contained in:
Alex Rudenko 2023-11-13 13:39:24 +01:00 committed by GitHub
parent 915eb7ff4e
commit 02d62be58e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 7 deletions

View File

@ -20,6 +20,7 @@
"lint": "run-s lint:*",
"lint:eslint": "([ \"$CI\" = true ] && eslint --ext js --ext ts --quiet . || eslint --ext js --ext ts .)",
"lint:prettier": "prettier --check .",
"lint:expectations": "node tools/sort-test-expectations.js --lint",
"postinstall": "npm run postinstall --workspaces --if-present",
"prepare": "npm run prepare --workspaces --if-present",
"test": "wireit",

View File

@ -25,6 +25,8 @@ const source = 'test/TestExpectations.json';
const testExpectations = JSON.parse(fs.readFileSync(source, 'utf-8'));
const commitedExpectations = structuredClone(testExpectations);
function getSpecificity(item) {
return (
item.parameters.length +
@ -50,10 +52,21 @@ testExpectations.forEach(item => {
item.platforms.sort();
});
fs.writeFileSync(
source,
prettier.format(JSON.stringify(testExpectations), {
...require(path.join(__dirname, '..', '.prettierrc.cjs')),
parser: 'json',
})
);
if (process.argv.includes('--lint')) {
if (
JSON.stringify(commitedExpectations) !== JSON.stringify(testExpectations)
) {
console.error(
`${source} is not formatted properly. Run 'npm run format:expectations'.`
);
process.exit(1);
}
} else {
fs.writeFileSync(
source,
prettier.format(JSON.stringify(testExpectations), {
...require(path.join(__dirname, '..', '.prettierrc.cjs')),
parser: 'json',
})
);
}