-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlint.js
63 lines (54 loc) · 1.91 KB
/
lint.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
58
59
60
61
62
63
const fs = require("fs");
const ini = require("ini");
const core = require("@actions/core");
const process = require("process");
const structure = require("./structure.js");
const FilesToLint = fs.readdirSync("./languages/").filter(function(filePath) {
return filePath.toLowerCase().endsWith(".ini");
});
var ExitCode = 0;
FilesToLint.forEach(function(filePath) {
filePath = "./languages/" + filePath;
const Parsed = ini.parse(fs.readFileSync(filePath, 'utf-8'))
let warnings = 0;
let errors = 0;
// Ensure All Sections Defined in `structure`
// exist in the parsed ini file
Object.keys(structure).forEach(function(section) {
if (Parsed[section] == null) {
core.error(`Section '${section}' is required but not found`, { file: filePath });
errors++;
}
});
// Ensure All Sections in parsed ini file `Parsed` are known
Object.keys(Parsed).forEach(function(section) {
if (structure[section] == null) {
core.warning(`Unknown Section '${section}'`, { file: filePath });
warnings++;
} else {
// Ensure All Required Sub-Sections Defined in `structure[section]`
// exist in the parsed ini file
Object.keys(structure[section]).forEach(function(subSection) {
if (structure[section][subSection].required) {
if (Parsed[section][subSection] == null) {
core.error(`Sub-Section '${subSection}' in Section '${section}' is required but not found`, { file: filePath });
errors++;
}
}
});
// Ensure All Sub-Sections in parsed ini file `Parsed[section]` are known
Object.keys(Parsed[section]).forEach(function(subSection) {
if (structure[section][subSection] == null) {
core.warning(`Unknown Sub-Section '${subSection}' in Section '${section}'`, { file: filePath });
warnings++;
}
});
}
});
if (errors == 0) {
core.notice(`Ok (${warnings} ${warnings != 1 ? "Warnings" : "Warning"})`, { file: filePath });
} else {
ExitCode = 1;
}
});
process.exit(ExitCode);