diff --git a/package.json b/package.json index 4ec42c9381c..9afd07587dc 100644 --- a/package.json +++ b/package.json @@ -5,24 +5,24 @@ "test": "script/test" }, "devDependencies": { - "async": "^1.5.2", + "async": "^2.0.0", "glob": "^7.0.5", "ignore": "^3.1.3", "js-yaml": "^3.6.1", - "remark-lint": "^4.2.0", - "remark-parse": "^1.0.0", + "remark-lint": "^5.0.0", + "remark-parse": "^2.0.0", "remark-retext": "^2.0.0", - "remark-stringify": "^1.0.0", - "retext": "^3.0.0", + "remark-stringify": "^2.0.0", "retext-english": "^2.0.0", "retext-equality": "^2.3.2", "retext-quotes": "^1.0.0", - "retext-readability": "^2.0.0", + "retext-readability": "^3.0.0", "retext-repeated-words": "^1.0.0", "retext-sentence-spacing": "^1.0.0", - "retext-simplify": "^2.0.0", - "to-vfile": "^1.0.0", - "unified": "^4.1.2", - "vfile-reporter": "^2.0.0" + "retext-simplify": "^3.0.0", + "to-vfile": "^2.1.0", + "unified": "^5.0.0", + "vfile-reporter": "^3.0.0", + "vfile-statistics": "^1.0.0" } } diff --git a/script/test-prose b/script/test-prose index 1dd2a078133..a57386abb25 100755 --- a/script/test-prose +++ b/script/test-prose @@ -1,95 +1,78 @@ #!/usr/bin/env node -// Retext stuff +// Core var unified = require('unified'); -// Remark stuff +// 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 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', 'utf8')); -var ignore = require('ignore')().add(jekyllConfig["exclude"]) +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(repeated) -var options = { - // https://github.com/wooorm/remark/tree/master/packages/remark-parse#options - "remark": { - "gfm": true, - "footnotes": true - }, +// 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 - "lint": { + .use(lint, { // Headings - "heading-style": "atx", // ## Headings - "first-heading-level": 2, // Page title is h1, so start with h2 - "no-heading-punctuation": false, - "maximum-heading-length": 80, // FIXME: Eventually remove this + headingStyle: 'atx', // ## Headings + firstHeadingLevel: 2, // Page title is h1, so start with h2 + maximumHeadingLength: 80, // FIXME: Eventually remove this // Lists - "list-item-indent": "space", // As the gods intended. - "list-item-spacing": false, - "unordered-list-marker-style": "*", - "ordered-list-marker-style": ".", + listItemIndent: 'space', // As the gods intended. + unorderedListMarkerStyle: '*', + orderedListMarkerStyle: '.', // Misc - "maximum-line-length": false, // turn off line length linting - "emphasis-marker": "_", - "strong-marker": "*", - "blockquote-indentation": 2, - "no-missing-blank-lines": {"exceptTightLists": true}, - }, - "readability": { - "age": 18 - }, - "simplify": { - ignore: [ - "modify", - "contribute", - "previous" - ] - } -}; + emphasisMarker: '_', + strongMarker: '*', + blockquoteIndentation: 2, + noMissingBlankLines: {exceptTightLists: true}, + }) + .use(remark2retext, prose) + .use(stringify); -async.map(ignore.filter(glob.sync("**/*.md")), function(file, callback) { - fs.readFile(file, function(err, contents) { - unified() - .use(parse) - .use(lint, options["lint"]) - .use(remark2retext, unified() - .use(english) - .use(sentenceSpacing, {preferred: 1}) - .use(quotes, {preferred: 'straight'}) - .use(repeated) - // .use(require('retext-simplify'), options["simplify"]) - // .use(require('retext-equality')) - // .use(require('retext-readability'), options["readability"]) - ) - .use(stringify) - .process(contents.toString(), options["remark"], function (err, result) { - result.filename = file; - callback(err, result); - }); +async.map(ignore.filter(glob.sync('**/*.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)); - - var hasErrors = false; - - results.forEach(function(file) { - if(file.messages.length > 0) hasErrors = true; - }); - - if(hasErrors) process.exit(1); + if(statistics(results).total) process.exit(1); });