Skip to content

Commit 8802f34

Browse files
committed
fix: enhance shellcheck integration by dynamically resolving search roots and adding warnings for missing directories
1 parent cca93b1 commit 8802f34

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

src/bin/lint.ts

+24-14
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,14 @@ async function main(argv = process.argv) {
6565
hadFailure = true;
6666
}
6767

68+
const shellcheckDefaultSearchRoots = ['./src', './scripts', './tests'];
69+
const searchRoots = shellcheckDefaultSearchRoots
70+
.map((p) => path.resolve(process.cwd(), p))
71+
.filter((p) => fs.existsSync(p));
72+
6873
// Linting shell scripts (this does not have auto-fixing)
6974
const shellCheckArgs = [
70-
'./src',
71-
'./scripts',
75+
...searchRoots,
7276
'-type',
7377
'f',
7478
'-regextype',
@@ -82,18 +86,24 @@ async function main(argv = process.argv) {
8286
];
8387
if (utils.commandExists('find') && utils.commandExists('shellcheck')) {
8488
console.error('Running shellcheck:');
85-
console.error(' ' + ['find', ...shellCheckArgs].join(' '));
86-
try {
87-
childProcess.execFileSync('find', shellCheckArgs, {
88-
stdio: ['inherit', 'inherit', 'inherit'],
89-
windowsHide: true,
90-
encoding: 'utf-8',
91-
shell: platform === 'win32' ? true : false,
92-
cwd: process.cwd(),
93-
});
94-
} catch (err) {
95-
console.error('Shellcheck failed.' + err);
96-
hadFailure = true;
89+
if (searchRoots.length === 0) {
90+
console.warn(
91+
'No search roots found for shellcheck. Skipping shellcheck.',
92+
);
93+
} else {
94+
console.error(' ' + ['find', ...shellCheckArgs].join(' '));
95+
try {
96+
childProcess.execFileSync('find', shellCheckArgs, {
97+
stdio: ['inherit', 'inherit', 'inherit'],
98+
windowsHide: true,
99+
encoding: 'utf-8',
100+
shell: platform === 'win32' ? true : false,
101+
cwd: process.cwd(),
102+
});
103+
} catch (err) {
104+
console.error('Shellcheck failed. ' + err);
105+
hadFailure = true;
106+
}
97107
}
98108
} else {
99109
console.warn(

0 commit comments

Comments
 (0)