-
Notifications
You must be signed in to change notification settings - Fork 0
/
golangci-lint-helper.js
57 lines (43 loc) · 1.35 KB
/
golangci-lint-helper.js
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
#!/usr/bin/env node
const { execSync } = require('child_process');
const path = require('path');
// Check if golangci-lint is installed
try {
execSync('golangci-lint --version', { stdio: 'ignore' });
} catch (error) {
console.error('golangci-lint-helper: golangci-lint is not installed or not found in PATH');
process.exit(1);
}
// Get arguments from command line
let args = process.argv.slice(2);
console.log(`golangci-lint-helper: args ${args.join(' ')}`);
// Check if any arguments provided
if (args.length === 0) {
console.log('golangci-lint-helper: no arguments provided');
process.exit(1);
}
let fix = "";
if (args[0] === '--fix') {
args = args.slice(1);
fix = '--fix';
}
let modules = [];
// Extract unique Go modules from the args which are paths
args.forEach((arg) => {
let modulePath = path.dirname(arg);
// Check if modulePath is not in the modules array
if (!modules.includes(modulePath)) {
modules.push(modulePath);
}
});
console.log(`golangci-lint-helper: got modules ${modules.join(' ')}`);
let exitCode = 0;
for (let module of modules) {
try {
execSync(`golangci-lint run ${fix} ${module}`, { stdio: 'inherit' });
} catch (error) {
console.log(`golangci-lint-helper: error running golangci-lint on module ${module}`);
exitCode = 1;
}
}
process.exit(exitCode);