forked from github/opensource.guide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-prose
executable file
·106 lines (95 loc) · 3.05 KB
/
test-prose
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env node
// Core
var unified = require('unified');
// Remark stuff (markdown)
var parse = require('remark-parse');
var lint = require('remark-lint');
var remark2retext = require('remark-retext');
var stringify = require('remark-stringify');
// Retext stuff (prose)
var english = require('retext-english');
var sentenceSpacing = require('retext-sentence-spacing');
var quotes = require('retext-quotes');
var words = require('retext-words');
var repeated = require('retext-repeated-words');
// Util stuff
var vfile = require('to-vfile');
var statistics = require('vfile-statistics');
var report = require('vfile-reporter');
var glob = require('glob');
var fs = require('fs');
var async = require('async');
var yaml = require('js-yaml');
var jekyllConfig = yaml.safeLoad(fs.readFileSync('_config.yml'));
var ignore = require('ignore')().add(jekyllConfig.exclude)
// Prose checking pipeline
var prose = unified()
.use(english)
.use(sentenceSpacing, {preferred: 1})
.use(quotes, {preferred: 'straight'})
.use(words, {
"patterns": {
"this section": { omit: true },
"next section": { omit: true },
"this guide": { omit: true },
}
})
.use(repeated)
// Check rigorously if `FULL_PROSE_CHECK` is in env.
if(process.env.FULL_PROSE_CHECK) {
prose
.use(require('retext-simplify'), {
ignore: ['modify', 'contribute', 'previous']
})
.use(require('retext-equality'))
.use(require('retext-readability'), {age: 18})
}
// Markdown checking pipeline.
var markdown = unified()
.use(parse)
// https://github.com/wooorm/remark-lint/blob/master/doc/rules.md
.use(lint, {
// Headings
headingStyle: 'atx', // ## Headings
firstHeadingLevel: 2, // Page title is h1, so start with h2
headingIncrement: true,
maximumHeadingLength: 80, // FIXME: Eventually remove this
noDuplicateHeadings: true,
noMultipleToplevelHeadings: true,
// Lists
listItemIndent: 'space', // As the gods intended.
listItemBulletIndent: true,
listItemContentIndent: true,
unorderedListMarkerStyle: '*',
orderedListMarkerStyle: '.',
// Misc
emphasisMarker: '_',
strongMarker: '*',
blockquoteIndentation: 2,
noMissingBlankLines: {exceptTightLists: true},
noConsecutiveBlankLines: true,
finalNewline: true,
noAutoLinkWithoutProtocol: true,
noBlockquoteWithoutCaret: true,
noLiteralUrls: true,
// Mistakes
hardBreakSpaces: true,
noDuplicateDefinitions: true,
noHeadingContentIndent: true,
noInlinePadding: true,
noShortcutReferenceImage: true,
noShortcutReferenceLink: true,
noUndefinedReferences: true,
noUnusedDefinitions: true,
})
.use(remark2retext, prose)
.use(stringify);
async.map(ignore.filter(glob.sync('_articles/**/*.md')), function(filePath, callback) {
vfile.read(filePath, function(err, file) {
if(err) return callback(err);
markdown.process(file, {footnotes: true}, callback);
});
}, function (err, results) {
console.log(report(results));
if(statistics(results).total) process.exit(1);
});