/
license.js
47 lines (39 loc) · 1.17 KB
/
license.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
'use strict';
const find = require('unist-util-find');
const findAllAfter = require('unist-util-find-all-after');
const rule = require('unified-lint-rule');
const toString = require('mdast-util-to-string');
const visit = require('unist-util-visit');
module.exports = rule('remark-lint:awesome/license', (ast, file) => {
const license = find(ast, node => (
node.type === 'heading' &&
(toString(node) === 'Licence' || toString(node) === 'License')
));
if (!license) {
file.message('Missing License section', ast);
return;
}
if (license.depth !== 2) {
file.message('License section must be at heading depth 2', ast);
return;
}
const headingsPost = findAllAfter(ast, license, {
type: 'heading'
});
if (headingsPost.length > 0) {
file.message('License must be the last section', headingsPost[0]);
return;
}
const children = findAllAfter(ast, license, () => true);
const content = {type: 'root', children};
const value = toString(content);
if (!value) {
file.message('License must not be empty', license);
}
visit(content, 'image', node => {
if (/\.png/i.test(node.url)) {
file.message('License image must be SVG', node);
return false;
}
});
});