MCPcopy Index your code
hub / github.com/nodejs/node / checkFiles

Function checkFiles

tools/lint-sh.mjs:57–145  ·  view source on GitHub ↗
(...files)

Source from the content-addressed store, hash-verified

55}
56
57async function checkFiles(...files) {
58 const flags = FIX_MODE_ENABLED ? 'r+' : 'r';
59 await Promise.all(
60 files.map(async (file) => {
61 const fd = await fs.open(file, flags);
62 if (await hasInvalidHashBang(fd)) {
63 if (FIX_MODE_ENABLED) {
64 const file = await fd.readFile();
65
66 const fileContent =
67 file[0] === '#'.charCodeAt() ?
68 file.subarray(file.indexOf('\n') + 1) :
69 file;
70
71 const toWrite = Buffer.concat([expectedHashBang, fileContent]);
72 await fd.truncate(toWrite.length);
73 await fd.write(toWrite, 0, toWrite.length, 0);
74 } else {
75 process.exitCode ||= 1;
76 console.error(
77 (process.env.GITHUB_ACTIONS ?
78 `::error file=${file},line=1,col=1::` :
79 'Fixable with --fix: ') +
80 `Invalid hashbang for ${file} (expected /bin/sh).`,
81 );
82 }
83 }
84 await fd.close();
85 }),
86 );
87
88 const stdout = await new Promise((resolve, reject) => {
89 const SHELLCHECK_EXE =
90 process.env.SHELLCHECK ||
91 execSync('command -v ' + (USE_NPX ? 'npx' : SHELLCHECK_EXE_NAME))
92 .toString()
93 .trim();
94 const NPX_OPTIONS = USE_NPX ? [SHELLCHECK_EXE_NAME] : [];
95
96 const shellcheck = spawn(
97 SHELLCHECK_EXE,
98 [
99 ...NPX_OPTIONS,
100 ...SHELLCHECK_OPTIONS,
101 ...(FIX_MODE_ENABLED ?
102 files.map((filePath) => relative(SPAWN_OPTIONS.cwd, filePath)) :
103 files),
104 ],
105 SPAWN_OPTIONS,
106 );
107 shellcheck.once('error', reject);
108
109 let json = '';
110 let childProcess = shellcheck;
111 if (FIX_MODE_ENABLED) {
112 const GIT_EXE =
113 process.env.GIT || execSync('command -v git').toString().trim();
114

Callers 1

lint-sh.mjsFile · 0.70

Calls 15

hasInvalidHashBangFunction · 0.85
execSyncFunction · 0.85
relativeFunction · 0.85
allMethod · 0.80
concatMethod · 0.80
mapMethod · 0.65
openMethod · 0.65
closeMethod · 0.65
parseMethod · 0.65
spawnFunction · 0.50
resolveFunction · 0.50
readFileMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…