-
-
Notifications
You must be signed in to change notification settings - Fork 660
Expand file tree
/
Copy pathlint.mjs
More file actions
65 lines (54 loc) · 1.66 KB
/
lint.mjs
File metadata and controls
65 lines (54 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env node
/**
* Run this script (from root directory):
*
* $ corepack pnpm node scripts/lint.mjs
*
* This runs `eslint` on all sample solutions (and test) files
*/
import path from 'node:path';
import shell from 'shelljs';
import {
registerExitHandler,
prepareAndRun,
assignments as exercises,
shouldPrepare,
} from './helpers.mjs';
registerExitHandler(false);
const assignment = exercises.length === 0 ? exercises[0] : undefined;
// Prepare exercises and cleanup afterwards
shell.env['PREPARE'] =
shell.env['PREPARE'] === undefined || shell.env['PREPARE'];
shell.env['CLEANUP'] =
shell.env['CLEANUP'] === undefined || shell.env['CLEANUP'];
const count = shouldPrepare() ? exercises.length : 'all';
const infoStr = assignment
? `Running lint for ${assignment}...`
: `Running lint for ${count} exercises...`;
const failureStr = '[Failure] Lint check failed!';
shell.mkdir('-p', 'tmp_exercises');
shell.cp('babel.config.js', path.join('tmp_exercises', 'babel.config.js'));
shell.cp('eslint.config.mjs', path.join('tmp_exercises', 'eslint.config.mjs'));
shell.sed(
'-i',
'\\*\\.spec\\.js',
'**/*.spec.js',
path.join('tmp_exercises', 'eslint.config.mjs'),
);
shell.sed(
'-i',
'// <<inject-rules-here>>',
"{ files: ['**/*.spec.js'], rules: { 'no-unused-vars': ['error', { varsIgnorePattern: 'xdescribe|xtest' }] }},",
path.join('tmp_exercises', 'eslint.config.mjs'),
);
// Run lint all at once
prepareAndRun(
'corepack pnpm eslint tmp_exercises -c tmp_exercises/eslint.config.mjs',
infoStr,
failureStr,
);
shell.echo(
assignment
? `[Success] Lint passed for ${assignment}`
: `[Success] Lint passed for ${count} exercises`,
);