Skip to content

Commit 3c18c8e

Browse files
Fix name check workflows (#1098)
1 parent 11be3a4 commit 3c18c8e

2 files changed

Lines changed: 24 additions & 22 deletions

File tree

scripts/name-check

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,40 +16,39 @@ let { packageFiles, registerExitHandler } = require('./helpers');
1616

1717
registerExitHandler();
1818

19-
let exitCode = 0;
20-
2119
// First 2 arguments are node and script name skip them
2220
// Check if rest has --fix
2321
const fix = process.argv.slice(2).includes('--fix');
2422

2523
const envAssignment = shell.env['ASSIGNMENT'];
26-
if(envAssignment) {
24+
if (envAssignment) {
2725
packageFiles = [`exercises/${envAssignment}/package.json`];
2826
}
2927

3028
// Check if package name in each exercises' package.json is of the format "@exercism/javascript-<exercise>"
31-
packageFiles.forEach(filePath => {
29+
packageFiles.forEach((filePath) => {
3230
const file = JSON.parse(shell.cat(filePath).toString());
3331

3432
const givenName = file['name'];
3533
const exerciseName = filePath.split('/')[2];
3634
const expectedName = `@exercism/javascript-${exerciseName}`;
3735

38-
if(givenName == expectedName) {
36+
if (givenName === expectedName) {
3937
shell.echo(`[Success]: Package name ${givenName} is in correct format`);
4038
return;
4139
}
4240

43-
if(fix) {
41+
if (fix) {
4442
file['name'] = expectedName;
45-
const fileWithFixedName = new shell.ShellString(JSON.stringify(file, undefined, 2) + '\n');
43+
const fileWithFixedName = new shell.ShellString(
44+
JSON.stringify(file, undefined, 2) + '\n'
45+
);
4646
fileWithFixedName.to(filePath);
4747
shell.echo(`[Success]: Fixed package name in ${filePath}`);
48-
}
49-
else {
50-
exitCode = 1;
51-
shell.echo(`[Failure]: Package name in ${filePath} must be ${expectedName}"`);
48+
} else {
49+
shell.echo(
50+
`[Failure]: Package name in ${filePath} must be ${expectedName}"`
51+
);
52+
shell.exit(1);
5253
}
5354
});
54-
55-
shell.exit(exitCode);

scripts/name-uniq

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,19 @@ const { packageFiles, registerExitHandler } = require('./helpers');
1313

1414
registerExitHandler();
1515

16-
let exitCode = 0;
17-
const allNames = packageFiles.map(filePath => JSON.parse(shell.cat(filePath).toString())['name']);
16+
const allNames = packageFiles.map(
17+
(filePath) => JSON.parse(shell.cat(filePath).toString())['name']
18+
);
1819

1920
// Check if all exercises have unique package names
20-
const duplicates = allNames.filter((e, i) => allNames.indexOf(e) !== i)
21-
if(duplicates.length !== 0) {
22-
exitCode = 1
23-
shell.echo(`[Failure] Duplicate package names found: ${duplicates.join(', ')}`);
24-
}
21+
const duplicates = allNames.filter((e, i) => allNames.indexOf(e) !== i);
2522

26-
if(exitCode == 0) {
27-
shell.echo('[Success] All package names are unique.');
23+
if (duplicates.length !== 0) {
24+
shell.echo(
25+
`[Failure] Duplicate package names found: ${duplicates.join(', ')}`
26+
);
27+
shell.exit(1);
2828
}
29+
30+
shell.echo('[Success] All package names are unique.');
31+
shell.exit(1);

0 commit comments

Comments
 (0)