From bc835ae99e9d3e31594e537b015518373ed3fead Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Thu, 25 Apr 2019 13:40:32 -0500 Subject: [PATCH] simplify eslint config --- .eslintrc.json | 21 ++++-- bin/marked | 34 +++++----- docs/demo/demo.js | 58 ++++++++-------- docs/demo/worker.js | 6 +- lib/marked.js | 129 ++++++++++++++++++------------------ test/.eslintrc.json | 13 ---- test/bench.js | 20 +++--- test/helpers/html-differ.js | 2 +- test/helpers/load.js | 10 +-- test/specs/run-spec.js | 8 +-- test/update-specs.js | 10 +-- 11 files changed, 154 insertions(+), 157 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index fea5455ab1..7ac9b5936c 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -2,17 +2,23 @@ "parserOptions": { "ecmaVersion": 5 }, "rules": { "semi": ["error", "always"], - "indent": ["warn", 2, { - "VariableDeclarator": { "var": 2 }, + "indent": ["error", 2, { "SwitchCase": 1, - "outerIIFEBody": 0 + "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 }], - "space-before-function-paren": "off", - "object-curly-spacing": "off", "operator-linebreak": ["error", "before", { "overrides": { "=": "after" } }], "no-cond-assign": "off", "no-useless-escape": "off", - "no-return-assign": "off", "one-var": "off", "no-control-regex": "off", @@ -100,6 +106,7 @@ "no-proto": "error", "no-redeclare": "error", "no-regex-spaces": "error", + "no-return-assign": ["error", "except-parens"], "no-return-await": "error", "no-self-assign": "error", "no-self-compare": "error", @@ -129,6 +136,7 @@ "no-useless-return": "error", "no-whitespace-before-property": "error", "no-with": "error", + "object-curly-spacing": ["error", "always"], "object-property-newline": ["error", { "allowMultiplePropertiesPerLine": true }], "padded-blocks": ["error", { "blocks": "never", "switches": "never", "classes": "never" }], "prefer-promise-reject-errors": "error", @@ -136,6 +144,7 @@ "rest-spread-spacing": ["error", "never"], "semi-spacing": ["error", { "before": false, "after": true }], "space-before-blocks": ["error", "always"], + "space-before-function-paren": ["error", "always"], "space-in-parens": ["error", "never"], "space-infix-ops": "error", "space-unary-ops": ["error", { "words": true, "nonwords": false }], diff --git a/bin/marked b/bin/marked index 307db173b0..c7676d7d2d 100755 --- a/bin/marked +++ b/bin/marked @@ -13,7 +13,7 @@ var fs = require('fs'), * Man Page */ -function help() { +function help () { var spawn = require('child_process').spawn; var options = { @@ -24,15 +24,15 @@ function help() { }; spawn('man', [path.resolve(__dirname, '/../man/marked.1')], options) - .on('error', function() { - fs.readFile(path.resolve(__dirname, '/../man/marked.1.txt'), 'utf8', function(err, data) { + .on('error', function () { + fs.readFile(path.resolve(__dirname, '/../man/marked.1.txt'), 'utf8', function (err, data) { if (err) throw err; console.log(data); }); }); } -function version() { +function version () { var pkg = require('../package.json'); console.log(pkg.version); } @@ -41,7 +41,7 @@ function version() { * Main */ -function main(argv, callback) { +function main (argv, callback) { var files = [], options = {}, input, @@ -51,7 +51,7 @@ function main(argv, callback) { tokens, opt; - function getarg() { + function getarg () { var arg = argv.shift(); if (arg.indexOf('--') === 0) { @@ -65,7 +65,7 @@ function main(argv, callback) { } else if (arg[0] === '-') { if (arg.length > 2) { // e.g. -abc - argv = arg.substring(1).split('').map(function(ch) { + argv = arg.substring(1).split('').map(function (ch) { return '-' + ch; }).concat(argv); arg = argv.shift(); @@ -128,7 +128,7 @@ function main(argv, callback) { } } - function getData(callback) { + function getData (callback) { if (!input) { if (files.length <= 2) { if (string) { @@ -141,7 +141,7 @@ function main(argv, callback) { return fs.readFile(input, 'utf8', callback); } - return getData(function(err, data) { + return getData(function (err, data) { if (err) return callback(err); data = tokens @@ -161,21 +161,21 @@ function main(argv, callback) { * Helpers */ -function getStdin(callback) { +function getStdin (callback) { var stdin = process.stdin, buff = ''; stdin.setEncoding('utf8'); - stdin.on('data', function(data) { + stdin.on('data', function (data) { buff += data; }); - stdin.on('error', function(err) { + stdin.on('error', function (err) { return callback(err); }); - stdin.on('end', function() { + stdin.on('end', function () { return callback(null, buff); }); @@ -186,13 +186,13 @@ function getStdin(callback) { } } -function camelize(text) { - return text.replace(/(\w)-(\w)/g, function(_, a, b) { +function camelize (text) { + return text.replace(/(\w)-(\w)/g, function (_, a, b) { return a + b.toUpperCase(); }); } -function handleError(err) { +function handleError (err) { if (err.code === 'ENOENT') { console.error('marked: output to ' + err.path + ': No such directory'); return process.exit(1); @@ -206,7 +206,7 @@ function handleError(err) { if (!module.parent) { process.title = 'marked'; - main(process.argv.slice(), function(err, code) { + main(process.argv.slice(), function (err, code) { if (err) return handleError(err); return process.exit(code || 0); }); diff --git a/docs/demo/demo.js b/docs/demo/demo.js index a478de4c7c..eb452d0a41 100644 --- a/docs/demo/demo.js +++ b/docs/demo/demo.js @@ -79,7 +79,7 @@ Promise.all([ $mainElem.style.display = 'block'; }); -function setInitialText() { +function setInitialText () { if ('text' in search) { $markdownElem.value = search.text; } else { @@ -93,7 +93,7 @@ function setInitialText() { } } -function setInitialQuickref() { +function setInitialQuickref () { return fetch('./quickref.md') .then(function (res) { return res.text(); }) .then(function (text) { @@ -101,7 +101,7 @@ function setInitialQuickref() { }); } -function setInitialVersion() { +function setInitialVersion () { return fetch('https://data.jsdelivr.com/v1/package/npm/marked') .then(function (res) { return res.json(); @@ -162,7 +162,7 @@ function setInitialVersion() { .then(updateVersion); } -function setInitialOptions() { +function setInitialOptions () { if ('options' in search) { $optionsElem.value = search.options; } else { @@ -170,22 +170,22 @@ function setInitialOptions() { } } -function setInitialOutputType() { +function setInitialOutputType () { if (search.outputType) { $outputTypeElem.value = search.outputType; } } -function handleIframeLoad() { +function handleIframeLoad () { lastInput = ''; inputDirty = true; } -function handleInput() { +function handleInput () { inputDirty = true; }; -function handleVersionChange() { +function handleVersionChange () { if ($markedVerElem.value === 'commit' || $markedVerElem.value === 'pr') { $commitVerElem.style.display = ''; } else { @@ -194,14 +194,14 @@ function handleVersionChange() { } } -function handleClearClick() { +function handleClearClick () { $markdownElem.value = ''; $markedVerElem.value = 'master'; $commitVerElem.style.display = 'none'; updateVersion().then(setDefaultOptions); } -function handleAddVersion(e) { +function handleAddVersion (e) { if (e.which === 13) { switch ($markedVerElem.value) { case 'commit': @@ -236,16 +236,16 @@ function handleAddVersion(e) { } } -function handleInputChange() { +function handleInputChange () { handleChange($inputPanes, $inputTypeElem.value); } -function handleOutputChange() { +function handleOutputChange () { $activeOutputElem = handleChange($panes, $outputTypeElem.value); updateLink(); } -function handleChange(panes, visiblePane) { +function handleChange (panes, visiblePane) { var active = null; for (var i = 0; i < panes.length; i++) { if (panes[i].id === visiblePane) { @@ -258,7 +258,7 @@ function handleChange(panes, visiblePane) { return active; }; -function addCommitVersion(value, text, commit) { +function addCommitVersion (value, text, commit) { if (markedVersions[value]) { return; } @@ -269,7 +269,7 @@ function addCommitVersion(value, text, commit) { $markedVerElem.insertBefore(opt, $markedVerElem.firstChild); } -function getPrCommit(pr) { +function getPrCommit (pr) { return fetch('https://github.com/gitapi/repos/markedjs/marked/pulls/' + pr + '/commits') .then(function (res) { return res.json(); @@ -281,7 +281,7 @@ function getPrCommit(pr) { }); } -function setDefaultOptions() { +function setDefaultOptions () { if (window.Worker) { messageWorker({ task: 'defaults', @@ -293,7 +293,7 @@ function setDefaultOptions() { } } -function setOptions(opts) { +function setOptions (opts) { $optionsElem.value = JSON.stringify( opts, function (key, value) { @@ -304,7 +304,7 @@ function setOptions(opts) { }, ' '); } -function searchToObject() { +function searchToObject () { // modified from https://stackoverflow.com/a/7090123/806777 var pairs = location.search.slice(1).split('&'); var obj = {}; @@ -322,7 +322,7 @@ function searchToObject() { return obj; } -function jsonString(input) { +function jsonString (input) { var output = (input + '') .replace(/\n/g, '\\n') .replace(/\r/g, '\\r') @@ -333,13 +333,13 @@ function jsonString(input) { return '"' + output + '"'; }; -function getScrollSize() { +function getScrollSize () { var e = $activeOutputElem; return e.scrollHeight - e.clientHeight; }; -function getScrollPercent() { +function getScrollPercent () { var size = getScrollSize(); if (size <= 0) { @@ -349,11 +349,11 @@ function getScrollPercent() { return $activeOutputElem.scrollTop / size; }; -function setScrollPercent(percent) { +function setScrollPercent (percent) { $activeOutputElem.scrollTop = percent * getScrollSize(); }; -function updateLink() { +function updateLink () { var outputType = ''; if ($outputTypeElem.value !== 'preview') { outputType = 'outputType=' + $outputTypeElem.value + '&'; @@ -365,7 +365,7 @@ function updateLink() { history.replaceState('', document.title, $permalinkElem.href); } -function updateVersion() { +function updateVersion () { if (window.Worker) { handleInput(); return Promise.resolve(); @@ -390,7 +390,7 @@ function updateVersion() { }).then(handleInput); } -function checkForChanges() { +function checkForChanges () { if (inputDirty && $markedVerElem.value !== 'commit' && $markedVerElem.value !== 'pr' && (typeof marked !== 'undefined' || window.Worker)) { inputDirty = false; @@ -448,7 +448,7 @@ function checkForChanges() { checkChangeTimeout = window.setTimeout(checkForChanges, delayTime); }; -function setResponseTime(ms) { +function setResponseTime (ms) { var amount = ms; var suffix = 'ms'; if (ms > 1000 * 60 * 60) { @@ -464,7 +464,7 @@ function setResponseTime(ms) { $responseTimeElem.textContent = amount + suffix; } -function setParsed(parsed, lexed) { +function setParsed (parsed, lexed) { try { $previewIframe.contentDocument.body.innerHTML = parsed; } catch (ex) {} @@ -472,7 +472,7 @@ function setParsed(parsed, lexed) { $lexerElem.value = lexed; } -function messageWorker(message) { +function messageWorker (message) { if (!markedWorker || markedWorker.working) { if (markedWorker) { clearTimeout(markedWorker.timeout); @@ -525,7 +525,7 @@ function messageWorker(message) { markedWorker.postMessage(message); } -function workerTimeout(seconds) { +function workerTimeout (seconds) { markedWorker.timeout = setTimeout(function () { seconds++; markedWorker.onerror('Marked has taken longer than ' + seconds + ' second' + (seconds > 1 ? 's' : '') + ' to respond...'); diff --git a/docs/demo/worker.js b/docs/demo/worker.js index bdd7addf7f..34020ae875 100644 --- a/docs/demo/worker.js +++ b/docs/demo/worker.js @@ -25,7 +25,7 @@ onmessage = function (e) { } }; -function parse(e) { +function parse (e) { switch (e.data.task) { case 'defaults': @@ -70,7 +70,7 @@ function parse(e) { } } -function jsonString(input) { +function jsonString (input) { var output = (input + '') .replace(/\n/g, '\\n') .replace(/\r/g, '\\r') @@ -81,7 +81,7 @@ function jsonString(input) { return '"' + output + '"'; }; -function loadVersion(ver) { +function loadVersion (ver) { var promise; if (versionCache[ver]) { promise = Promise.resolve(versionCache[ver]); diff --git a/lib/marked.js b/lib/marked.js index 6a9d1494af..a643f060d4 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -4,7 +4,7 @@ * https://github.com/markedjs/marked */ -;(function(root) { +;(function (root) { 'use strict'; /** @@ -133,7 +133,7 @@ block.pedantic = merge({}, block.normal, { * Block Lexer */ -function Lexer(options) { +function Lexer (options) { this.tokens = []; this.tokens.links = Object.create(null); this.options = options || marked.defaults; @@ -160,7 +160,7 @@ Lexer.rules = block; * Static Lex Method */ -Lexer.lex = function(src, options) { +Lexer.lex = function (src, options) { var lexer = new Lexer(options); return lexer.lex(src); }; @@ -169,7 +169,7 @@ Lexer.lex = function(src, options) { * Preprocessing */ -Lexer.prototype.lex = function(src) { +Lexer.prototype.lex = function (src) { src = src .replace(/\r\n|\r/g, '\n') .replace(/\t/g, ' ') @@ -183,7 +183,7 @@ Lexer.prototype.lex = function(src) { * Lexing */ -Lexer.prototype.token = function(src, top) { +Lexer.prototype.token = function (src, top) { src = src.replace(/^ +$/gm, ''); var next, loose, @@ -653,7 +653,7 @@ inline.breaks = merge({}, inline.gfm, { * Inline Lexer & Compiler */ -function InlineLexer(links, options) { +function InlineLexer (links, options) { this.options = options || marked.defaults; this.links = links; this.rules = inline.normal; @@ -685,7 +685,7 @@ InlineLexer.rules = inline; * Static Lexing/Compiling Method */ -InlineLexer.output = function(src, links, options) { +InlineLexer.output = function (src, links, options) { var inline = new InlineLexer(links, options); return inline.output(src); }; @@ -694,7 +694,7 @@ InlineLexer.output = function(src, links, options) { * Lexing/Compiling */ -InlineLexer.prototype.output = function(src) { +InlineLexer.prototype.output = function (src) { var out = '', link, text, @@ -874,7 +874,7 @@ InlineLexer.prototype.output = function(src) { return out; }; -InlineLexer.escapes = function(text) { +InlineLexer.escapes = function (text) { return text ? text.replace(InlineLexer.rules._escapes, '$1') : text; }; @@ -882,7 +882,7 @@ InlineLexer.escapes = function(text) { * Compile Link */ -InlineLexer.prototype.outputLink = function(cap, link) { +InlineLexer.prototype.outputLink = function (cap, link) { var href = link.href, title = link.title ? escape(link.title) : null; @@ -895,7 +895,7 @@ InlineLexer.prototype.outputLink = function(cap, link) { * Smartypants Transformations */ -InlineLexer.prototype.smartypants = function(text) { +InlineLexer.prototype.smartypants = function (text) { if (!this.options.smartypants) return text; return text // em-dashes @@ -918,7 +918,7 @@ InlineLexer.prototype.smartypants = function(text) { * Mangle Links */ -InlineLexer.prototype.mangle = function(text) { +InlineLexer.prototype.mangle = function (text) { if (!this.options.mangle) return text; var out = '', l = text.length, @@ -940,11 +940,11 @@ InlineLexer.prototype.mangle = function(text) { * Renderer */ -function Renderer(options) { +function Renderer (options) { this.options = options || marked.defaults; } -Renderer.prototype.code = function(code, infostring, escaped) { +Renderer.prototype.code = function (code, infostring, escaped) { var lang = (infostring || '').match(/\S*/)[0]; if (this.options.highlight) { var out = this.options.highlight(code, lang); @@ -968,15 +968,15 @@ Renderer.prototype.code = function(code, infostring, escaped) { + '\n'; }; -Renderer.prototype.blockquote = function(quote) { +Renderer.prototype.blockquote = function (quote) { return '
\n' + quote + '
\n'; }; -Renderer.prototype.html = function(html) { +Renderer.prototype.html = function (html) { return html; }; -Renderer.prototype.heading = function(text, level, raw, slugger) { +Renderer.prototype.heading = function (text, level, raw, slugger) { if (this.options.headerIds) { return '' + text + '\n'; }; -Renderer.prototype.hr = function() { +Renderer.prototype.hr = function () { return this.options.xhtml ? '
\n' : '
\n'; }; -Renderer.prototype.list = function(body, ordered, start) { +Renderer.prototype.list = function (body, ordered, start) { var type = ordered ? 'ol' : 'ul', startatt = (ordered && start !== 1) ? (' start="' + start + '"') : ''; return '<' + type + startatt + '>\n' + body + '\n'; }; -Renderer.prototype.listitem = function(text) { +Renderer.prototype.listitem = function (text) { return '
  • ' + text + '
  • \n'; }; -Renderer.prototype.checkbox = function(checked) { +Renderer.prototype.checkbox = function (checked) { return ' '; }; -Renderer.prototype.paragraph = function(text) { +Renderer.prototype.paragraph = function (text) { return '

    ' + text + '

    \n'; }; -Renderer.prototype.table = function(header, body) { +Renderer.prototype.table = function (header, body) { if (body) body = '' + body + ''; return '\n' @@ -1030,11 +1030,11 @@ Renderer.prototype.table = function(header, body) { + '
    \n'; }; -Renderer.prototype.tablerow = function(content) { +Renderer.prototype.tablerow = function (content) { return '\n' + content + '\n'; }; -Renderer.prototype.tablecell = function(content, flags) { +Renderer.prototype.tablecell = function (content, flags) { var type = flags.header ? 'th' : 'td'; var tag = flags.align ? '<' + type + ' align="' + flags.align + '">' @@ -1043,27 +1043,27 @@ Renderer.prototype.tablecell = function(content, flags) { }; // span level renderer -Renderer.prototype.strong = function(text) { +Renderer.prototype.strong = function (text) { return '' + text + ''; }; -Renderer.prototype.em = function(text) { +Renderer.prototype.em = function (text) { return '' + text + ''; }; -Renderer.prototype.codespan = function(text) { +Renderer.prototype.codespan = function (text) { return '' + text + ''; }; -Renderer.prototype.br = function() { +Renderer.prototype.br = function () { return this.options.xhtml ? '
    ' : '
    '; }; -Renderer.prototype.del = function(text) { +Renderer.prototype.del = function (text) { return '' + text + ''; }; -Renderer.prototype.link = function(href, title, text) { +Renderer.prototype.link = function (href, title, text) { href = cleanUrl(this.options.sanitize, this.options.baseUrl, href); if (href === null) { return text; @@ -1076,7 +1076,7 @@ Renderer.prototype.link = function(href, title, text) { return out; }; -Renderer.prototype.image = function(href, title, text) { +Renderer.prototype.image = function (href, title, text) { href = cleanUrl(this.options.sanitize, this.options.baseUrl, href); if (href === null) { return text; @@ -1090,7 +1090,7 @@ Renderer.prototype.image = function(href, title, text) { return out; }; -Renderer.prototype.text = function(text) { +Renderer.prototype.text = function (text) { return text; }; @@ -1099,7 +1099,7 @@ Renderer.prototype.text = function(text) { * returns only the textual part of the token */ -function TextRenderer() {} +function TextRenderer () {} // no need for block level renderers @@ -1112,11 +1112,11 @@ TextRenderer.prototype.text = function (text) { }; TextRenderer.prototype.link = -TextRenderer.prototype.image = function(href, title, text) { +TextRenderer.prototype.image = function (href, title, text) { return '' + text; }; -TextRenderer.prototype.br = function() { +TextRenderer.prototype.br = function () { return ''; }; @@ -1124,7 +1124,7 @@ TextRenderer.prototype.br = function() { * Parsing & Compiling */ -function Parser(options) { +function Parser (options) { this.tokens = []; this.token = null; this.options = options || marked.defaults; @@ -1138,7 +1138,7 @@ function Parser(options) { * Static Parse Method */ -Parser.parse = function(src, options) { +Parser.parse = function (src, options) { var parser = new Parser(options); return parser.parse(src); }; @@ -1147,12 +1147,12 @@ Parser.parse = function(src, options) { * Parse Loop */ -Parser.prototype.parse = function(src) { +Parser.prototype.parse = function (src) { this.inline = new InlineLexer(src.links, this.options); // use an InlineLexer with a TextRenderer to extract pure text this.inlineText = new InlineLexer( src.links, - merge({}, this.options, {renderer: new TextRenderer()}) + merge({}, this.options, { renderer: new TextRenderer() }) ); this.tokens = src.reverse(); @@ -1168,15 +1168,16 @@ Parser.prototype.parse = function(src) { * Next Token */ -Parser.prototype.next = function() { - return this.token = this.tokens.pop(); +Parser.prototype.next = function () { + this.token = this.tokens.pop(); + return this.token; }; /** * Preview Next Token */ -Parser.prototype.peek = function() { +Parser.prototype.peek = function () { return this.tokens[this.tokens.length - 1] || 0; }; @@ -1184,7 +1185,7 @@ Parser.prototype.peek = function() { * Parse Text Tokens */ -Parser.prototype.parseText = function() { +Parser.prototype.parseText = function () { var body = this.token.text; while (this.peek().type === 'text') { @@ -1198,7 +1199,7 @@ Parser.prototype.parseText = function() { * Parse Current Token */ -Parser.prototype.tok = function() { +Parser.prototype.tok = function () { switch (this.token.type) { case 'space': { return ''; @@ -1358,7 +1359,7 @@ Slugger.prototype.slug = function (value) { * Helpers */ -function escape(html, encode) { +function escape (html, encode) { if (encode) { if (escape.escapeTest.test(html)) { return html.replace(escape.escapeReplace, function (ch) { return escape.replacements[ch]; }); @@ -1385,9 +1386,9 @@ escape.replacements = { escape.escapeTestNoEncode = /[<>"']|&(?!#?\w+;)/; escape.escapeReplaceNoEncode = /[<>"']|&(?!#?\w+;)/g; -function unescape(html) { +function unescape (html) { // explicitly match decimal, hex, and named HTML entities - return html.replace(/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig, function(_, n) { + return html.replace(/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig, function (_, n) { n = n.toLowerCase(); if (n === 'colon') return ':'; if (n.charAt(0) === '#') { @@ -1399,23 +1400,23 @@ function unescape(html) { }); } -function edit(regex, opt) { +function edit (regex, opt) { regex = regex.source || regex; opt = opt || ''; return { - replace: function(name, val) { + replace: function (name, val) { val = val.source || val; val = val.replace(/(^|[^\[])\^/g, '$1'); regex = regex.replace(name, val); return this; }, - getRegex: function() { + getRegex: function () { return new RegExp(regex, opt); } }; } -function cleanUrl(sanitize, base, href) { +function cleanUrl (sanitize, base, href) { if (sanitize) { try { var prot = decodeURIComponent(unescape(href)) @@ -1439,7 +1440,7 @@ function cleanUrl(sanitize, base, href) { return href; } -function resolveUrl(base, href) { +function resolveUrl (base, href) { if (!baseUrls[' ' + base]) { // we can ignore everything in base after the last slash of its path component, // but we might need to add _that_ @@ -1463,10 +1464,10 @@ function resolveUrl(base, href) { var baseUrls = {}; var originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i; -function noop() {} +function noop () {} noop.exec = noop; -function merge(obj) { +function merge (obj) { var i = 1, target, key; @@ -1483,7 +1484,7 @@ function merge(obj) { return obj; } -function splitCells(tableRow, count) { +function splitCells (tableRow, count) { // ensure that every cell-delimiting pipe has a space // before it to distinguish it from an escaped pipe var row = tableRow.replace(/\|/g, function (match, offset, str) { @@ -1518,7 +1519,7 @@ function splitCells(tableRow, count) { // Remove trailing 'c's. Equivalent to str.replace(/c*$/, ''). // /c*$/ is vulnerable to REDOS. // invert: Remove suffix of non-c chars instead. Default falsey. -function rtrim(str, c, invert) { +function rtrim (str, c, invert) { if (str.length === 0) { return ''; } @@ -1541,7 +1542,7 @@ function rtrim(str, c, invert) { return str.substr(0, str.length - suffLen); } -function findClosingBracket(str, b) { +function findClosingBracket (str, b) { if (str.indexOf(b[1]) === -1) { return -1; } @@ -1565,7 +1566,7 @@ function findClosingBracket(str, b) { * Marked */ -function marked(src, opt, callback) { +function marked (src, opt, callback) { // throw error in case of non string input if (typeof src === 'undefined' || src === null) { throw new Error('marked(): input parameter is undefined or null'); @@ -1596,7 +1597,7 @@ function marked(src, opt, callback) { pending = tokens.length; - var done = function(err) { + var done = function (err) { if (err) { opt.highlight = highlight; return callback(err); @@ -1626,11 +1627,11 @@ function marked(src, opt, callback) { if (!pending) return done(); for (; i < tokens.length; i++) { - (function(token) { + (function (token) { if (token.type !== 'code') { return --pending || done(); } - return highlight(token.text, token.lang, function(err, code) { + return highlight(token.text, token.lang, function (err, code) { if (err) return done(err); if (code == null || code === token.text) { return --pending || done(); @@ -1663,7 +1664,7 @@ function marked(src, opt, callback) { */ marked.options = -marked.setOptions = function(opt) { +marked.setOptions = function (opt) { merge(marked.defaults, opt); return marked; }; @@ -1715,7 +1716,7 @@ marked.parse = marked; if (typeof module !== 'undefined' && typeof exports === 'object') { module.exports = marked; } else if (typeof define === 'function' && define.amd) { - define(function() { return marked; }); + define(function () { return marked; }); } else { root.marked = marked; } diff --git a/test/.eslintrc.json b/test/.eslintrc.json index 3c9cc1ec59..32bb6c6ca6 100644 --- a/test/.eslintrc.json +++ b/test/.eslintrc.json @@ -3,21 +3,8 @@ "plugins": [ "standard" ], - "parserOptions": { "ecmaVersion": 2018 }, "rules": { "semi": ["error", "always"], - "indent": ["warn", 2, { - "SwitchCase": 1, - "outerIIFEBody": 0 - }], - "space-before-function-paren": "off", - "object-curly-spacing": "off", - "operator-linebreak": ["error", "before", { "overrides": { "=": "after" } }], - "no-cond-assign": "off", - "no-useless-escape": "off", - "no-return-assign": "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 b72c27577c..96f508ff23 100644 --- a/test/bench.js +++ b/test/bench.js @@ -1,13 +1,13 @@ const path = require('path'); const htmlDiffer = require('./helpers/html-differ.js'); -const {loadFiles} = require('./helpers/load.js'); +const { loadFiles } = require('./helpers/load.js'); 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(); @@ -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/html-differ.js b/test/helpers/html-differ.js index 44052be407..7386569903 100644 --- a/test/helpers/html-differ.js +++ b/test/helpers/html-differ.js @@ -1,5 +1,5 @@ const HtmlDiffer = require('@markedjs/html-differ').HtmlDiffer; -const htmlDiffer = new HtmlDiffer({ignoreSelfClosingSlash: true}); +const htmlDiffer = new HtmlDiffer({ ignoreSelfClosingSlash: true }); module.exports = { isEqual: htmlDiffer.isEqual.bind(htmlDiffer), diff --git a/test/helpers/load.js b/test/helpers/load.js index 6a7cd44f13..ef894396d2 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 1f70db1a53..b7d4f70a92 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)); @@ -33,8 +33,8 @@ function runSpecs(title, dir, showCompletionTable, options) { }); } -runSpecs('GFM', './gfm', true, {gfm: true}); -runSpecs('CommonMark', './commonmark', true, {headerIds: false}); -runSpecs('Original', './original', false, {gfm: false}); +runSpecs('GFM', './gfm', true, { gfm: true }); +runSpecs('CommonMark', './commonmark', true, { headerIds: false }); +runSpecs('Original', './original', false, { gfm: false }); runSpecs('New', './new'); runSpecs('Redos', './redos'); diff --git a/test/update-specs.js b/test/update-specs.js index 4994cf4bb0..cb1ac7b05c 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://github.com/raw/commonmark/commonmark.js/master/package.json') .then(res => res.json()) .then(pkg => pkg.version.replace(/^(\d+\.\d+).*$/, '$1')) @@ -20,7 +20,7 @@ function updateCommonmark(dir) { .then(res => res.json()) .then(specs => { specs.forEach(spec => { - const html = marked(spec.markdown, {headerIds: false}); + const html = marked(spec.markdown, { headerIds: false }); if (!htmlDiffer.isEqual(html, spec.html)) { spec.shouldFail = true; } @@ -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)) @@ -64,7 +64,7 @@ function updateGfm(dir) { }) .then(([version, specs]) => { specs.forEach(spec => { - const html = marked(spec.markdown, {gfm: true}); + const html = marked(spec.markdown, { gfm: true }); if (!htmlDiffer.isEqual(html, spec.html)) { spec.shouldFail = true; }