From 60b0ce2f3d4b47cc1b92a240dbeedf33a022fb09 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Wed, 7 Nov 2018 22:07:11 +0100 Subject: [PATCH] Refactor code-style --- lib/all.js | 1 - lib/footer.js | 1 - lib/handlers/blockquote.js | 1 - lib/handlers/break.js | 1 - lib/handlers/code.js | 1 - lib/handlers/delete.js | 1 - lib/handlers/emphasis.js | 1 - lib/handlers/footnote-reference.js | 1 - lib/handlers/footnote.js | 1 - lib/handlers/heading.js | 1 - lib/handlers/html.js | 3 +-- lib/handlers/image-reference.js | 1 - lib/handlers/image.js | 1 - lib/handlers/index.js | 2 +- lib/handlers/inline-code.js | 1 - lib/handlers/link-reference.js | 1 - lib/handlers/link.js | 1 - lib/handlers/list-item.js | 3 +-- lib/handlers/list.js | 1 - lib/handlers/paragraph.js | 1 - lib/handlers/root.js | 1 - lib/handlers/strong.js | 1 - lib/handlers/table.js | 1 - lib/handlers/text.js | 1 - lib/handlers/thematic-break.js | 1 - lib/index.js | 11 +++++------ lib/one.js | 8 ++++---- lib/revert.js | 2 +- lib/wrap.js | 4 ++-- test/list-item.js | 1 - 30 files changed, 15 insertions(+), 41 deletions(-) diff --git a/lib/all.js b/lib/all.js index 942a8b7..ced06ea 100644 --- a/lib/all.js +++ b/lib/all.js @@ -5,7 +5,6 @@ module.exports = all var trim = require('trim') var one = require('./one') -/* Transform the children of `parent`. */ function all(h, parent) { var nodes = parent.children || [] var length = nodes.length diff --git a/lib/footer.js b/lib/footer.js index 53b108e..3b5619b 100644 --- a/lib/footer.js +++ b/lib/footer.js @@ -6,7 +6,6 @@ var thematicBreak = require('./handlers/thematic-break') var list = require('./handlers/list') var wrap = require('./wrap') -/* Transform all footnote definitions, if any. */ function generateFootnotes(h) { var footnotes = h.footnotes var length = footnotes.length diff --git a/lib/handlers/blockquote.js b/lib/handlers/blockquote.js index c844e8d..e192c93 100644 --- a/lib/handlers/blockquote.js +++ b/lib/handlers/blockquote.js @@ -5,7 +5,6 @@ module.exports = blockquote var wrap = require('../wrap') var all = require('../all') -/* Transform a block quote. */ function blockquote(h, node) { return h(node, 'blockquote', wrap(all(h, node), true)) } diff --git a/lib/handlers/break.js b/lib/handlers/break.js index db276bf..8970da4 100644 --- a/lib/handlers/break.js +++ b/lib/handlers/break.js @@ -4,7 +4,6 @@ module.exports = hardBreak var u = require('unist-builder') -/* Transform an inline break. */ function hardBreak(h, node) { return [h(node, 'br'), u('text', '\n')] } diff --git a/lib/handlers/code.js b/lib/handlers/code.js index 70e23bb..59e818a 100644 --- a/lib/handlers/code.js +++ b/lib/handlers/code.js @@ -5,7 +5,6 @@ module.exports = code var detab = require('detab') var u = require('unist-builder') -/* Transform a code block. */ function code(h, node) { var value = node.value ? detab(node.value + '\n') : '' var lang = node.lang && node.lang.match(/^[^ \t]+(?=[ \t]|$)/) diff --git a/lib/handlers/delete.js b/lib/handlers/delete.js index 31a2f61..518c9e5 100644 --- a/lib/handlers/delete.js +++ b/lib/handlers/delete.js @@ -4,7 +4,6 @@ module.exports = strikethrough var all = require('../all') -/* Transform deletions. */ function strikethrough(h, node) { return h(node, 'del', all(h, node)) } diff --git a/lib/handlers/emphasis.js b/lib/handlers/emphasis.js index 6e74ea0..e9114d6 100644 --- a/lib/handlers/emphasis.js +++ b/lib/handlers/emphasis.js @@ -4,7 +4,6 @@ module.exports = emphasis var all = require('../all') -/* Transform emphasis. */ function emphasis(h, node) { return h(node, 'em', all(h, node)) } diff --git a/lib/handlers/footnote-reference.js b/lib/handlers/footnote-reference.js index d946e8a..8f7825c 100644 --- a/lib/handlers/footnote-reference.js +++ b/lib/handlers/footnote-reference.js @@ -4,7 +4,6 @@ module.exports = footnoteReference var u = require('unist-builder') -/* Transform a reference to a footnote. */ function footnoteReference(h, node) { var identifier = node.identifier diff --git a/lib/handlers/footnote.js b/lib/handlers/footnote.js index 7825994..9136c6b 100644 --- a/lib/handlers/footnote.js +++ b/lib/handlers/footnote.js @@ -4,7 +4,6 @@ module.exports = footnote var footnoteReference = require('./footnote-reference') -/* Transform an inline footnote. */ function footnote(h, node) { var identifiers = [] var identifier = 1 diff --git a/lib/handlers/heading.js b/lib/handlers/heading.js index 902a9a8..d28ecaa 100644 --- a/lib/handlers/heading.js +++ b/lib/handlers/heading.js @@ -4,7 +4,6 @@ module.exports = heading var all = require('../all') -/* Transform a heading. */ function heading(h, node) { return h(node, 'h' + node.depth, all(h, node)) } diff --git a/lib/handlers/html.js b/lib/handlers/html.js index db5cd9d..d6be09c 100644 --- a/lib/handlers/html.js +++ b/lib/handlers/html.js @@ -4,8 +4,7 @@ module.exports = html var u = require('unist-builder') -/* Return either a `raw` node, in dangerous mode, or - * nothing. */ +// Return either a `raw` node, in dangerous mode, or nothing. function html(h, node) { return h.dangerous ? h.augment(node, u('raw', node.value)) : null } diff --git a/lib/handlers/image-reference.js b/lib/handlers/image-reference.js index 9e0ee33..084570c 100644 --- a/lib/handlers/image-reference.js +++ b/lib/handlers/image-reference.js @@ -5,7 +5,6 @@ module.exports = imageReference var normalize = require('mdurl/encode') var revert = require('../revert') -/* Transform a reference to an image. */ function imageReference(h, node) { var def = h.definition(node.identifier) var props diff --git a/lib/handlers/image.js b/lib/handlers/image.js index c05da6a..029d91a 100644 --- a/lib/handlers/image.js +++ b/lib/handlers/image.js @@ -4,7 +4,6 @@ var normalize = require('mdurl/encode') module.exports = image -/* Transform an image. */ function image(h, node) { var props = {src: normalize(node.url), alt: node.alt} diff --git a/lib/handlers/index.js b/lib/handlers/index.js index f9181f0..24ec328 100644 --- a/lib/handlers/index.js +++ b/lib/handlers/index.js @@ -29,7 +29,7 @@ module.exports = { footnoteDefinition: ignore } -/* Return nothing for nodes which are ignored. */ +// Return nothing for nodes which are ignored. function ignore() { return null } diff --git a/lib/handlers/inline-code.js b/lib/handlers/inline-code.js index 7fa4454..986de52 100644 --- a/lib/handlers/inline-code.js +++ b/lib/handlers/inline-code.js @@ -5,7 +5,6 @@ module.exports = inlineCode var collapse = require('collapse-white-space') var u = require('unist-builder') -/* Transform inline code. */ function inlineCode(h, node) { return h(node, 'code', [u('text', collapse(node.value))]) } diff --git a/lib/handlers/link-reference.js b/lib/handlers/link-reference.js index bd3dab1..0c810da 100644 --- a/lib/handlers/link-reference.js +++ b/lib/handlers/link-reference.js @@ -6,7 +6,6 @@ var normalize = require('mdurl/encode') var revert = require('../revert') var all = require('../all') -/* Transform a reference to a link. */ function linkReference(h, node) { var def = h.definition(node.identifier) var props diff --git a/lib/handlers/link.js b/lib/handlers/link.js index e811351..7e1b781 100644 --- a/lib/handlers/link.js +++ b/lib/handlers/link.js @@ -5,7 +5,6 @@ var all = require('../all') module.exports = link -/* Transform a link. */ function link(h, node) { var props = {href: normalize(node.url)} diff --git a/lib/handlers/list-item.js b/lib/handlers/list-item.js index c8a9112..e325894 100644 --- a/lib/handlers/list-item.js +++ b/lib/handlers/list-item.js @@ -6,7 +6,6 @@ var u = require('unist-builder') var wrap = require('../wrap') var all = require('../all') -/* Transform a list-item. */ function listItem(h, node, parent) { var children = node.children var head = children[0] @@ -44,7 +43,7 @@ function listItem(h, node, parent) { }) ) - /* According to github-markdown-css, this class hides bullet. */ + // According to github-markdown-css, this class hides bullet. props.className = ['task-list-item'] } diff --git a/lib/handlers/list.js b/lib/handlers/list.js index 42a9aa6..50629a9 100644 --- a/lib/handlers/list.js +++ b/lib/handlers/list.js @@ -5,7 +5,6 @@ module.exports = list var wrap = require('../wrap') var all = require('../all') -/* Transform a list. */ function list(h, node) { var props = {} var name = node.ordered ? 'ol' : 'ul' diff --git a/lib/handlers/paragraph.js b/lib/handlers/paragraph.js index ef3dcd6..389e7ab 100644 --- a/lib/handlers/paragraph.js +++ b/lib/handlers/paragraph.js @@ -4,7 +4,6 @@ module.exports = paragraph var all = require('../all') -/* Transform a paragraph. */ function paragraph(h, node) { return h(node, 'p', all(h, node)) } diff --git a/lib/handlers/root.js b/lib/handlers/root.js index fcfe7f6..8d2f5c7 100644 --- a/lib/handlers/root.js +++ b/lib/handlers/root.js @@ -6,7 +6,6 @@ var u = require('unist-builder') var wrap = require('../wrap') var all = require('../all') -/* Transform a `root`. */ function root(h, node) { return h.augment(node, u('root', wrap(all(h, node)))) } diff --git a/lib/handlers/strong.js b/lib/handlers/strong.js index 90387e8..fc3e45c 100644 --- a/lib/handlers/strong.js +++ b/lib/handlers/strong.js @@ -4,7 +4,6 @@ module.exports = strong var all = require('../all') -/* Transform importance. */ function strong(h, node) { return h(node, 'strong', all(h, node)) } diff --git a/lib/handlers/table.js b/lib/handlers/table.js index af445bd..b9f8ea0 100644 --- a/lib/handlers/table.js +++ b/lib/handlers/table.js @@ -6,7 +6,6 @@ var position = require('unist-util-position') var wrap = require('../wrap') var all = require('../all') -/* Transform a table. */ function table(h, node) { var rows = node.children var index = rows.length diff --git a/lib/handlers/text.js b/lib/handlers/text.js index 7cc67d7..6975fd6 100644 --- a/lib/handlers/text.js +++ b/lib/handlers/text.js @@ -5,7 +5,6 @@ module.exports = text var u = require('unist-builder') var trimLines = require('trim-lines') -/* Transform text. */ function text(h, node) { return h.augment(node, u('text', trimLines(node.value))) } diff --git a/lib/handlers/thematic-break.js b/lib/handlers/thematic-break.js index 53c049d..e83a451 100644 --- a/lib/handlers/thematic-break.js +++ b/lib/handlers/thematic-break.js @@ -2,7 +2,6 @@ module.exports = thematicBreak -/* Transform a thematic break / horizontal rule. */ function thematicBreak(h, node) { return h(node, 'hr') } diff --git a/lib/index.js b/lib/index.js index 5d040ab..2bcd972 100644 --- a/lib/index.js +++ b/lib/index.js @@ -12,7 +12,7 @@ var one = require('./one') var footer = require('./footer') var handlers = require('./handlers') -/* Factory to transform. */ +// Factory to transform. function factory(tree, options) { var settings = options || {} var dangerous = settings.allowDangerousHTML @@ -27,13 +27,12 @@ function factory(tree, options) { return h - /* Finalise the created `right`, a hast node, from - * `left`, an mdast node. */ + // Finalise the created `right`, a hast node, from `left`, an mdast node. function augment(left, right) { var data var ctx - /* Handle `data.hName`, `data.hProperties, `hChildren`. */ + // Handle `data.hName`, `data.hProperties, `hChildren`. if (left && 'data' in left) { data = left.data @@ -62,7 +61,7 @@ function factory(tree, options) { return right } - /* Create an element for a `node`. */ + // Create an element for a `node`. function h(node, tagName, props, children) { if ( (children === undefined || children === null) && @@ -86,7 +85,7 @@ function factory(tree, options) { } } -/* Transform `tree`, which is an mdast node, to a hast node. */ +// Transform `tree`, which is an mdast node, to a hast node. function toHast(tree, options) { var h = factory(tree, options) var node = one(h, tree) diff --git a/lib/one.js b/lib/one.js index 0125f0c..f73e51c 100644 --- a/lib/one.js +++ b/lib/one.js @@ -7,7 +7,7 @@ var all = require('./all') var own = {}.hasOwnProperty -/* Transform an unknown node. */ +// Transform an unknown node. function unknown(h, node) { if (text(node)) { return h.augment(node, u('text', node.value)) @@ -16,12 +16,12 @@ function unknown(h, node) { return h(node, 'div', all(h, node)) } -/* Visit a node. */ +// Visit a node. function one(h, node, parent) { var type = node && node.type var fn = own.call(h.handlers, type) ? h.handlers[type] : null - /* Fail on non-nodes. */ + // Fail on non-nodes. if (!type) { throw new Error('Expected node, got `' + node + '`') } @@ -29,7 +29,7 @@ function one(h, node, parent) { return (typeof fn === 'function' ? fn : unknown)(h, node, parent) } -/* Check if the node should be renderered a text node. */ +// Check if the node should be renderered a text node. function text(node) { var data = node.data || {} diff --git a/lib/revert.js b/lib/revert.js index 032bf4a..82b68ce 100644 --- a/lib/revert.js +++ b/lib/revert.js @@ -5,7 +5,7 @@ module.exports = revert var u = require('unist-builder') var all = require('./all') -/* Return the content of a reference without definition as markdown. */ +// Return the content of a reference without definition as markdown. function revert(h, node) { var subtype = node.referenceType var suffix = ']' diff --git a/lib/wrap.js b/lib/wrap.js index b4cfaa5..5a22d96 100644 --- a/lib/wrap.js +++ b/lib/wrap.js @@ -4,8 +4,8 @@ module.exports = wrap var u = require('unist-builder') -/* Wrap `nodes` with newlines between each entry. - * Optionally adds newlines at the start and end. */ +// Wrap `nodes` with newlines between each entry. Optionally adds newlines at +// the start and end. function wrap(nodes, loose) { var result = [] var index = -1 diff --git a/test/list-item.js b/test/list-item.js index f0393da..4f3f1b7 100644 --- a/test/list-item.js +++ b/test/list-item.js @@ -4,7 +4,6 @@ var test = require('tape') var u = require('unist-builder') var to = require('..') -/* Tests. */ test('ListItem', function(t) { t.deepEqual( to(u('listItem', [u('paragraph', [u('text', 'november')])])),