Skip to content

Commit

Permalink
Refactor code-style
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Nov 7, 2018
1 parent 9448c22 commit 60b0ce2
Show file tree
Hide file tree
Showing 30 changed files with 15 additions and 41 deletions.
1 change: 0 additions & 1 deletion lib/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion lib/footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion lib/handlers/blockquote.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
1 change: 0 additions & 1 deletion lib/handlers/break.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')]
}
1 change: 0 additions & 1 deletion lib/handlers/code.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]|$)/)
Expand Down
1 change: 0 additions & 1 deletion lib/handlers/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ module.exports = strikethrough

var all = require('../all')

/* Transform deletions. */
function strikethrough(h, node) {
return h(node, 'del', all(h, node))
}
1 change: 0 additions & 1 deletion lib/handlers/emphasis.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ module.exports = emphasis

var all = require('../all')

/* Transform emphasis. */
function emphasis(h, node) {
return h(node, 'em', all(h, node))
}
1 change: 0 additions & 1 deletion lib/handlers/footnote-reference.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion lib/handlers/footnote.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion lib/handlers/heading.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
3 changes: 1 addition & 2 deletions lib/handlers/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
1 change: 0 additions & 1 deletion lib/handlers/image-reference.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion lib/handlers/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down
2 changes: 1 addition & 1 deletion lib/handlers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
1 change: 0 additions & 1 deletion lib/handlers/inline-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))])
}
1 change: 0 additions & 1 deletion lib/handlers/link-reference.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion lib/handlers/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ var all = require('../all')

module.exports = link

/* Transform a link. */
function link(h, node) {
var props = {href: normalize(node.url)}

Expand Down
3 changes: 1 addition & 2 deletions lib/handlers/list-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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']
}

Expand Down
1 change: 0 additions & 1 deletion lib/handlers/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
1 change: 0 additions & 1 deletion lib/handlers/paragraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
1 change: 0 additions & 1 deletion lib/handlers/root.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))))
}
1 change: 0 additions & 1 deletion lib/handlers/strong.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ module.exports = strong

var all = require('../all')

/* Transform importance. */
function strong(h, node) {
return h(node, 'strong', all(h, node))
}
1 change: 0 additions & 1 deletion lib/handlers/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion lib/handlers/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}
1 change: 0 additions & 1 deletion lib/handlers/thematic-break.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

module.exports = thematicBreak

/* Transform a thematic break / horizontal rule. */
function thematicBreak(h, node) {
return h(node, 'hr')
}
11 changes: 5 additions & 6 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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) &&
Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions lib/one.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -16,20 +16,20 @@ 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 + '`')
}

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 || {}

Expand Down
2 changes: 1 addition & 1 deletion lib/revert.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ']'
Expand Down
4 changes: 2 additions & 2 deletions lib/wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion test/list-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')])])),
Expand Down

0 comments on commit 60b0ce2

Please sign in to comment.