diff --git a/test/.eslintrc.json b/test/.eslintrc.json index 32bb6c6c..eea8f0fd 100644 --- a/test/.eslintrc.json +++ b/test/.eslintrc.json @@ -5,6 +5,26 @@ ], "rules": { "semi": ["error", "always"], + "indent": ["error", 2, { + "SwitchCase": 1, + "VariableDeclarator": { "var": 2 }, + "outerIIFEBody": 0, + "MemberExpression": 1, + "FunctionDeclaration": { "parameters": 1, "body": 1 }, + "FunctionExpression": { "parameters": 1, "body": 1 }, + "CallExpression": { "arguments": 1 }, + "ArrayExpression": 1, + "ObjectExpression": 1, + "ImportDeclaration": 1, + "flatTernaryExpressions": false, + "ignoreComments": false + }], + "operator-linebreak": ["error", "before", { "overrides": { "=": "after" } }], + "space-before-function-paren": ["error", "never"], + "no-cond-assign": "off", + "no-useless-escape": "off", + "one-var": "off", + "no-control-regex": "off", "prefer-const": "error", "no-var": "error" }, diff --git a/test/bench.js b/test/bench.js index 96f508ff..26ede38a 100644 --- a/test/bench.js +++ b/test/bench.js @@ -7,7 +7,7 @@ let marked = require('../'); /** * Load specs */ -function load () { +function load() { const dir = path.resolve(__dirname, './specs/commonmark'); const sections = loadFiles(dir); let specs = []; @@ -22,7 +22,7 @@ function load () { /** * Run all benchmarks */ -function runBench (options) { +function runBench(options) { options = options || {}; const specs = load(); @@ -73,7 +73,7 @@ function runBench (options) { const commonmark = require('commonmark'); const parser = new commonmark.Parser(); const writer = new commonmark.HtmlRenderer(); - return function (text) { + return function(text) { return writer.render(parser.parse(text)); }; })()); @@ -101,7 +101,7 @@ function runBench (options) { } } -function bench (name, specs, engine) { +function bench(name, specs, engine) { const before = process.hrtime(); for (let i = 0; i < 1e3; i++) { for (const spec of specs) { @@ -127,7 +127,7 @@ function bench (name, specs, engine) { /** * A simple one-time benchmark */ -function time (options) { +function time(options) { options = options || {}; const specs = load(); if (options.marked) { @@ -139,13 +139,13 @@ function time (options) { /** * Argument Parsing */ -function parseArg (argv) { +function parseArg(argv) { argv = argv.slice(2); const options = {}; const orphans = []; - function getarg () { + function getarg() { let arg = argv.shift(); if (arg.indexOf('--') === 0) { @@ -222,14 +222,14 @@ function parseArg (argv) { /** * Helpers */ -function camelize (text) { +function camelize(text) { return text.replace(/(\w)-(\w)/g, (_, a, b) => a + b.toUpperCase()); } /** * Main */ -function main (argv) { +function main(argv) { const opt = parseArg(argv); if (opt.minified) { @@ -246,7 +246,7 @@ function main (argv) { /** * returns time to millisecond granularity */ -function prettyElapsedTime (hrtimeElapsed) { +function prettyElapsedTime(hrtimeElapsed) { const seconds = hrtimeElapsed[0]; const frac = Math.round(hrtimeElapsed[1] / 1e3) / 1e3; return seconds * 1e3 + frac; diff --git a/test/helpers/load.js b/test/helpers/load.js index 17f6925f..20ee43aa 100644 --- a/test/helpers/load.js +++ b/test/helpers/load.js @@ -4,12 +4,12 @@ const fs = require('fs'); const path = require('path'); const fm = require('front-matter'); -function node4Polyfills () { +function node4Polyfills() { // https://github.com/uxitten/polyfill/blob/master/string.polyfill.js // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padEnd if (!String.prototype.padEnd) { // eslint-disable-next-line no-extend-native - String.prototype.padEnd = function padEnd (targetLength, padString) { + String.prototype.padEnd = function padEnd(targetLength, padString) { targetLength = targetLength >> 0; // floor if number or convert non-number to 0; padString = String((typeof padString !== 'undefined' ? padString : ' ')); if (this.length > targetLength) { @@ -28,7 +28,7 @@ function node4Polyfills () { // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart if (!String.prototype.padStart) { // eslint-disable-next-line no-extend-native - String.prototype.padStart = function padStart (targetLength, padString) { + String.prototype.padStart = function padStart(targetLength, padString) { targetLength = targetLength >> 0; // truncate if number, or convert non-number to 0; padString = String(typeof padString !== 'undefined' ? padString : ' '); if (this.length >= targetLength) { @@ -45,7 +45,7 @@ function node4Polyfills () { } node4Polyfills(); -function outputCompletionTable (title, specs) { +function outputCompletionTable(title, specs) { let longestName = 0; let maxSpecs = 0; @@ -67,7 +67,7 @@ function outputCompletionTable (title, specs) { console.log(); } -function loadFiles (dir) { +function loadFiles(dir) { const files = fs.readdirSync(dir); return files.reduce((obj, file) => { diff --git a/test/specs/run-spec.js b/test/specs/run-spec.js index 307a9182..a6a2b82e 100644 --- a/test/specs/run-spec.js +++ b/test/specs/run-spec.js @@ -1,7 +1,7 @@ const path = require('path'); const load = require('../helpers/load.js'); -function runSpecs (title, dir, showCompletionTable, options) { +function runSpecs(title, dir, showCompletionTable, options) { options = options || {}; const specs = load.loadFiles(path.resolve(__dirname, dir)); diff --git a/test/update-specs.js b/test/update-specs.js index cb1ac7b0..2e586435 100644 --- a/test/update-specs.js +++ b/test/update-specs.js @@ -5,13 +5,13 @@ const htmlDiffer = require('./helpers/html-differ.js'); const fs = require('fs'); const path = require('path'); -function removeFiles (dir) { +function removeFiles(dir) { fs.readdirSync(dir).forEach(file => { fs.unlinkSync(path.join(dir, file)); }); } -function updateCommonmark (dir) { +function updateCommonmark(dir) { return fetch('https://raw.githubusercontent.com/commonmark/commonmark.js/master/package.json') .then(res => res.json()) .then(pkg => pkg.version.replace(/^(\d+\.\d+).*$/, '$1')) @@ -35,7 +35,7 @@ function updateCommonmark (dir) { }); } -function updateGfm (dir) { +function updateGfm(dir) { return fetch('https://github.github.com/gfm/') .then(res => res.text()) .then(html => cheerio.load(html))