-
Notifications
You must be signed in to change notification settings - Fork 19
/
lintFiles.js
74 lines (67 loc) · 2.04 KB
/
lintFiles.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
64
65
66
67
68
69
70
71
72
73
74
var merge = require('merge');
module.exports = function(tree, options) {
var passes = [];
var failures = [];
options = merge({ containsCode : false, files : {} }, options);
var resolveRelevance = function (feature) {
return (!feature.relevant || feature.relevant === true || feature.relevant());
};
var files = {
'Contributing document': /^contributing/i,
'Readme document': /^readme/i,
'License document': /^(licen[cs]e|copying)/i,
'Code of Conduct':/^CODEOFCONDUCT|CODE-OF-CONDUCT|CODE_OF_CONDUCT/i,
'Changelog document': /^(change(s|log)|history|news)/i,
'.gitignore file': /.gitignore/,
'Test suite': {
type: 'tree',
path: /(spec|tests?)/i,
relevant: function () {
return options.containsCode;
}
}
};
files = merge(files, options.files);
var pointKeys = Object.keys(files);
pointKeys.forEach(function(p) {
var passed = false;
var i;
for (i = tree.length - 1; i >= 0; i--) {
if (typeof files[p].shouldExist === 'boolean') {
if (files[p].type && files[p].path) {
if (resolveRelevance(files[p]) && (files[p].path.test(tree[i].path) === files[p].shouldExist)) {
passed = true;
break;
}
} else if (files[p].test(tree[i].path) === files[p].shouldExist) {
passed = true;
break;
}
} else if (files[p].type && files[p].path) {
if (resolveRelevance(files[p]) && files[p].path.test(tree[i].path)) {
passed = true;
break;
}
} else if (files[p].test(tree[i].path)) {
passed = true;
break;
}
}
// If something should not exist, and there's nothing in the tree then of
// COURSE it doesn't exist
if (tree.length === 0 && typeof files[p].shouldExist === 'boolean') {
passed = true;
}
if (passed) {
passes.push({ message : p });
// Is this confusing? Either there's no opinion about relevancy, or it's a function.
// If no opinion, failures. If function, use that to determine.
} else if (!files[p].relevant || files[p].relevant(tree)) {
failures.push({ message : p });
}
});
return {
passes: passes,
failures: failures
};
};