-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Forbid License, Licence and Contribute sections (#123)
- Loading branch information
Showing
15 changed files
with
27 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,15 @@ | ||
'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) { | ||
file.message('Forbidden license section found', ast); | ||
} | ||
|
||
if (license.depth !== 2) { | ||
file.message('License section must be at heading depth 2', license); | ||
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; | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,6 @@ | |
|
||
non-empty | ||
|
||
## LICENSE | ||
## Licence | ||
|
||
This is an invalid license section. | ||
Licence section is forbidden. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,10 +34,6 @@ non-empty | |
|
||
non-empty | ||
|
||
## License | ||
|
||
non-empty | ||
|
||
## Footnotes | ||
|
||
non-empty |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,11 +34,7 @@ non-empty | |
|
||
non-empty | ||
|
||
## Contribute | ||
|
||
non-empty | ||
|
||
## Licence | ||
## Contributing | ||
|
||
non-empty | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,11 +34,7 @@ non-empty | |
|
||
non-empty | ||
|
||
## License | ||
|
||
non-empty | ||
|
||
## Contribute | ||
## Contributing | ||
|
||
non-empty | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,10 +35,6 @@ non-empty | |
|
||
non-empty | ||
|
||
## Licence | ||
|
||
non-empty | ||
|
||
## Contribute | ||
## Contributing | ||
|
||
non-empty |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,10 +48,6 @@ non-empty | |
|
||
non-empty | ||
|
||
## Contribute | ||
|
||
non-empty | ||
|
||
## Licence | ||
## Contributing | ||
|
||
non-empty |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters