-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·37 lines (31 loc) · 947 Bytes
/
index.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
#!/usr/bin/env node
const fs = require('fs-extra');
const { program } = require('commander');
program
.version('1.0.4')
.description('Ensure there is an empty line at the end of a file')
.arguments('<files...>')
.action((files) => {
let hasError = false;
files.forEach((file) => {
try {
const content = fs.readFileSync(file, 'utf8');
const lines = content.split('\n');
const lastLine = lines[lines.length - 1];
if (lastLine.length === 0) {
console.log(`Empty line found at the end of ${file}`);
} else {
console.error(`Error: Missing empty line at the end of ${file}`);
hasError = true;
}
} catch (err) {
console.error(`Error: Failed to read file ${file}`);
console.error(err);
hasError = true;
}
});
if (hasError) {
process.exit(1);
}
});
program.parse(process.argv);