Skip to content

Commit 8853818

Browse files
authoredOct 12, 2020
Forbid License, Licence and Contribute sections (#123)
1 parent 881805c commit 8853818

File tree

15 files changed

+27
-101
lines changed

15 files changed

+27
-101
lines changed
 

‎rules/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module.exports = [
66
require('./contributing'),
77
require('./git-repo-age'),
88
require('./github'),
9-
/// require('./license'),
9+
require('./license'),
1010
require('./list-item'),
1111
require('./no-ci-badge'),
1212
require('./spell-check'),

‎rules/license.js

+2-34
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,15 @@
11
'use strict';
22
const find = require('unist-util-find');
3-
const findAllAfter = require('unist-util-find-all-after');
43
const rule = require('unified-lint-rule');
54
const toString = require('mdast-util-to-string');
6-
const visit = require('unist-util-visit');
75

86
module.exports = rule('remark-lint:awesome-license', (ast, file) => {
97
const license = find(ast, node => (
108
node.type === 'heading' &&
119
(toString(node) === 'Licence' || toString(node) === 'License')
1210
));
1311

14-
if (!license) {
15-
file.message('Missing License section', ast);
16-
return;
12+
if (license) {
13+
file.message('Forbidden license section found', ast);
1714
}
18-
19-
if (license.depth !== 2) {
20-
file.message('License section must be at heading depth 2', license);
21-
return;
22-
}
23-
24-
const headingsPost = findAllAfter(ast, license, {
25-
type: 'heading'
26-
});
27-
28-
if (headingsPost.length > 0) {
29-
file.message('License must be the last section', headingsPost[0]);
30-
return;
31-
}
32-
33-
const children = findAllAfter(ast, license, () => true);
34-
const content = {type: 'root', children};
35-
const value = toString(content);
36-
37-
if (!value) {
38-
file.message('License must not be empty', license);
39-
}
40-
41-
visit(content, 'image', node => {
42-
if (/\.png/i.test(node.url)) {
43-
file.message('License image must be SVG', node);
44-
return false;
45-
}
46-
});
4715
});

‎rules/toc.js

-3
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ const slugger = new GitHubSlugger();
1313
const maxListItemDepth = 1;
1414

1515
const sectionHeadingBlacklist = new Set([
16-
'Contribute',
1716
'Contributing',
18-
'Licence',
19-
'License',
2017
'Footnotes'
2118
]);
2219

‎test/fixtures/license/error0.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88

99
non-empty
1010

11-
## LICENSE
11+
## Licence
1212

13-
This is an invalid license section.
13+
Licence section is forbidden.

‎test/fixtures/license/error2.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
## License
88

9-
This license is invalid because it is not the last section.
9+
License section is forbidden, even if first section.
1010

1111
## Foo
1212

‎test/fixtures/license/error3.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ non-empty
1010

1111
# License
1212

13-
This license is invalid because its heading should be at depth 2.
13+
License is forbidden even at depth 1.

‎test/fixtures/license/error4.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
[![CC4](https://mirrors.creativecommons.org/presskit/buttons/88x31/png/by.png)](https://creativecommons.org/licenses/by/4.0/)
44

5-
This license is invalid because it points to a png instead of an svg.
5+
License is forbidden even if ut has images.

‎test/fixtures/license/success0.md

+1-7
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,4 @@
66

77
## Foo
88

9-
This license section below is 100% valid.
10-
11-
## License
12-
13-
[![CC0](https://mirrors.creativecommons.org/presskit/buttons/88x31/svg/cc-zero.svg)](https://creativecommons.org/publicdomain/zero/1.0/)
14-
15-
To the extent possible under law, [Sindre Sorhus](https://sindresorhus.com) has waived all copyright and related or neighboring rights to this work.
9+
This list is 100% valid because it has no license section.

‎test/fixtures/toc/0.md

-4
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ non-empty
3434

3535
non-empty
3636

37-
## License
38-
39-
non-empty
40-
4137
## Footnotes
4238

4339
non-empty

‎test/fixtures/toc/1.md

+1-5
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,7 @@ non-empty
3434

3535
non-empty
3636

37-
## Contribute
38-
39-
non-empty
40-
41-
## Licence
37+
## Contributing
4238

4339
non-empty
4440

‎test/fixtures/toc/2.md

+1-5
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,7 @@ non-empty
3434

3535
non-empty
3636

37-
## License
38-
39-
non-empty
40-
41-
## Contribute
37+
## Contributing
4238

4339
non-empty
4440

‎test/fixtures/toc/3.md

+1-5
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ non-empty
3535

3636
non-empty
3737

38-
## Licence
39-
40-
non-empty
41-
42-
## Contribute
38+
## Contributing
4339

4440
non-empty

‎test/fixtures/toc/4.md

+1-5
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,6 @@ non-empty
4848

4949
non-empty
5050

51-
## Contribute
52-
53-
non-empty
54-
55-
## Licence
51+
## Contributing
5652

5753
non-empty

‎test/fixtures/toc/5.md

-8
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,10 @@
66

77
## Foo
88

9-
## Contribute
10-
11-
This section should be ignored.
12-
139
## Contributing
1410

1511
This section should be ignored.
1612

17-
## License
18-
19-
This section should be ignored.
20-
2113
## Footnotes
2214

2315
This section should be ignored.

‎test/rules/license.js

+14-19
Original file line numberDiff line numberDiff line change
@@ -4,66 +4,61 @@ import lint from '../_lint';
44
const config = {
55
plugins: [
66
require('remark-lint'),
7-
/// require('remark-lint-no-empty-sections'),
87
require('../../rules/license')
98
]
109
};
1110

12-
test('license - missing', async t => {
11+
test('licence - forbidden section', async t => {
1312
const messages = await lint({config, filename: 'test/fixtures/license/error0.md'});
1413
t.deepEqual(messages, [
1514
{
1615
line: 1,
1716
ruleId: 'awesome-license',
18-
message: 'Missing License section'
17+
message: 'Forbidden license section found'
1918
}
2019
]);
2120
});
2221

23-
test('license - empty', async t => {
22+
test('license - forbidden empty section', async t => {
2423
const messages = await lint({config, filename: 'test/fixtures/license/error1.md'});
2524
t.deepEqual(messages, [
26-
// {
27-
// ruleId: 'no-empty-sections',
28-
// message: 'Remove empty section: "License"'
29-
// },
3025
{
31-
line: 11,
26+
line: 1,
3227
ruleId: 'awesome-license',
33-
message: 'License must not be empty'
28+
message: 'Forbidden license section found'
3429
}
3530
]);
3631
});
3732

38-
test('license - not last section', async t => {
33+
test('license - forbidden last section', async t => {
3934
const messages = await lint({config, filename: 'test/fixtures/license/error2.md'});
4035
t.deepEqual(messages, [
4136
{
42-
line: 11,
37+
line: 1,
4338
ruleId: 'awesome-license',
44-
message: 'License must be the last section'
39+
message: 'Forbidden license section found'
4540
}
4641
]);
4742
});
4843

49-
test('license - incorrect heading depth', async t => {
44+
test('license - forbidden heading depth section', async t => {
5045
const messages = await lint({config, filename: 'test/fixtures/license/error3.md'});
5146
t.deepEqual(messages, [
5247
{
53-
line: 11,
48+
line: 1,
5449
ruleId: 'awesome-license',
55-
message: 'License section must be at heading depth 2'
50+
message: 'Forbidden license section found'
5651
}
5752
]);
5853
});
5954

60-
test('license - png image', async t => {
55+
test('license - forbidden image section', async t => {
6156
const messages = await lint({config, filename: 'test/fixtures/license/error4.md'});
6257
t.deepEqual(messages, [
6358
{
64-
line: 3,
59+
line: 1,
6560
ruleId: 'awesome-license',
66-
message: 'License image must be SVG'
61+
message: 'Forbidden license section found'
6762
}
6863
]);
6964
});

0 commit comments

Comments
 (0)
Please sign in to comment.