diff --git a/lib/directive-container.js b/lib/directive-container.js index d27333a..d4d889c 100644 --- a/lib/directive-container.js +++ b/lib/directive-container.js @@ -10,18 +10,18 @@ export const directiveContainer = { concrete: true } -var label = {tokenize: tokenizeLabel, partial: true} -var attributes = {tokenize: tokenizeAttributes, partial: true} +const label = {tokenize: tokenizeLabel, partial: true} +const attributes = {tokenize: tokenizeAttributes, partial: true} function tokenizeDirectiveContainer(effects, ok, nok) { - var self = this + const self = this const tail = self.events[self.events.length - 1] const initialSize = tail && tail[1].type === 'linePrefix' ? tail[2].sliceSerialize(tail[1], true).length : 0 - var sizeOpen = 0 - var previous + let sizeOpen = 0 + let previous return start @@ -114,13 +114,14 @@ function tokenizeDirectiveContainer(effects, ok, nok) { } function chunkStart(code) { - var token - if (code === null) { return after(code) } - token = effects.enter('chunkDocument', {contentType: 'document', previous}) + const token = effects.enter('chunkDocument', { + contentType: 'document', + previous + }) if (previous) previous.next = token previous = token return contentContinue(code) @@ -149,7 +150,7 @@ function tokenizeDirectiveContainer(effects, ok, nok) { } function tokenizeClosingFence(effects, ok, nok) { - var size = 0 + let size = 0 return factorySpace(effects, closingPrefixAfter, 'linePrefix', 4) diff --git a/lib/directive-leaf.js b/lib/directive-leaf.js index 5c5016c..1cbb706 100644 --- a/lib/directive-leaf.js +++ b/lib/directive-leaf.js @@ -8,11 +8,11 @@ export const directiveLeaf = { tokenize: tokenizeDirectiveLeaf } -var label = {tokenize: tokenizeLabel, partial: true} -var attributes = {tokenize: tokenizeAttributes, partial: true} +const label = {tokenize: tokenizeLabel, partial: true} +const attributes = {tokenize: tokenizeAttributes, partial: true} function tokenizeDirectiveLeaf(effects, ok, nok) { - var self = this + const self = this return start diff --git a/lib/directive-text.js b/lib/directive-text.js index 91ba096..d50ab94 100644 --- a/lib/directive-text.js +++ b/lib/directive-text.js @@ -7,8 +7,8 @@ export const directiveText = { previous } -var label = {tokenize: tokenizeLabel, partial: true} -var attributes = {tokenize: tokenizeAttributes, partial: true} +const label = {tokenize: tokenizeLabel, partial: true} +const attributes = {tokenize: tokenizeAttributes, partial: true} function previous(code) { // If there is a previous code, there will always be a tail. @@ -19,7 +19,7 @@ function previous(code) { } function tokenizeDirectiveText(effects, ok, nok) { - var self = this + const self = this return start diff --git a/lib/factory-attributes.js b/lib/factory-attributes.js index 61d1e0c..f674e9e 100644 --- a/lib/factory-attributes.js +++ b/lib/factory-attributes.js @@ -26,8 +26,8 @@ export function factoryAttributes( attributeValueData, disallowEol ) { - var type - var marker + let type + let marker return start diff --git a/lib/factory-label.js b/lib/factory-label.js index 4857c26..015763a 100644 --- a/lib/factory-label.js +++ b/lib/factory-label.js @@ -15,8 +15,8 @@ export function factoryLabel( stringType, disallowEol ) { - var size = 0 - var balance = 0 + let size = 0 + let balance = 0 return start diff --git a/lib/factory-name.js b/lib/factory-name.js index 3fcfb31..07a83d8 100644 --- a/lib/factory-name.js +++ b/lib/factory-name.js @@ -1,7 +1,7 @@ import {asciiAlpha, asciiAlphanumeric} from 'micromark-util-character' export function factoryName(effects, ok, nok, nameType) { - var self = this + const self = this return start diff --git a/lib/html.js b/lib/html.js index 5f3a9a5..d598ad8 100644 --- a/lib/html.js +++ b/lib/html.js @@ -1,9 +1,9 @@ import {decodeEntity} from 'parse-entities/decode-entity.js' -var own = {}.hasOwnProperty +const own = {}.hasOwnProperty export function directiveHtml(options) { - var extensions = options || {} + const extensions = options || {} return { enter: { @@ -65,13 +65,13 @@ export function directiveHtml(options) { } function enter(type) { - var stack = this.getData('directiveStack') + let stack = this.getData('directiveStack') if (!stack) this.setData('directiveStack', (stack = [])) stack.push({type}) } function exitName(token) { - var stack = this.getData('directiveStack') + const stack = this.getData('directiveStack') stack[stack.length - 1].name = this.sliceSerialize(token) } @@ -80,8 +80,8 @@ export function directiveHtml(options) { } function exitLabel() { - var data = this.resume() - var stack = this.getData('directiveStack') + const data = this.resume() + const stack = this.getData('directiveStack') stack[stack.length - 1].label = data } @@ -111,18 +111,18 @@ export function directiveHtml(options) { } function exitAttributeValue(token) { - var attributes = this.getData('directiveAttributes') + const attributes = this.getData('directiveAttributes') attributes[attributes.length - 1][1] = decodeLight( this.sliceSerialize(token) ) } function exitAttributes() { - var stack = this.getData('directiveStack') - var attributes = this.getData('directiveAttributes') - var cleaned = {} - var index = -1 - var attribute + const stack = this.getData('directiveStack') + const attributes = this.getData('directiveAttributes') + const cleaned = {} + let index = -1 + let attribute while (++index < attributes.length) { attribute = attributes[index] @@ -144,23 +144,23 @@ export function directiveHtml(options) { } function exitContainerContent() { - var data = this.resume() - var stack = this.getData('directiveStack') + const data = this.resume() + const stack = this.getData('directiveStack') stack[stack.length - 1].content = data } function exitContainerFence() { - var stack = this.getData('directiveStack') - var directive = stack[stack.length - 1] + const stack = this.getData('directiveStack') + const directive = stack[stack.length - 1] if (!directive.fenceCount) directive.fenceCount = 0 directive.fenceCount++ if (directive.fenceCount === 1) this.setData('slurpOneLineEnding', true) } function exit() { - var directive = this.getData('directiveStack').pop() - var found - var result + const directive = this.getData('directiveStack').pop() + let found + let result if (own.call(extensions, directive.name)) { result = extensions[directive.name].call(this, directive) diff --git a/package.json b/package.json index a7eb62d..5285a01 100644 --- a/package.json +++ b/package.json @@ -63,10 +63,6 @@ "xo": { "prettier": true, "rules": { - "no-var": "off", - "prefer-arrow-callback": "off", - "guard-for-in": "off", - "unicorn/explicit-length-check": "off", "unicorn/no-this-assignment": "off" } }, diff --git a/test/index.js b/test/index.js index e6f1525..140d0a6 100644 --- a/test/index.js +++ b/test/index.js @@ -3,8 +3,10 @@ import {micromark} from 'micromark' import {htmlVoidElements} from 'html-void-elements' import {directive as syntax, directiveHtml as html} from '../index.js' -test('micromark-extension-directive (syntax)', function (t) { - t.test('text', function (t) { +const own = {}.hasOwnProperty + +test('micromark-extension-directive (syntax)', (t) => { + t.test('text', (t) => { t.equal( micromark('\\:a', options()), '

:a

', @@ -362,7 +364,7 @@ test('micromark-extension-directive (syntax)', function (t) { t.end() }) - t.test('leaf', function (t) { + t.test('leaf', (t) => { t.equal(micromark('::b', options()), '', 'should support a directive') t.equal( @@ -696,7 +698,7 @@ test('micromark-extension-directive (syntax)', function (t) { t.end() }) - t.test('container', function (t) { + t.test('container', (t) => { t.equal(micromark(':::b', options()), '', 'should support a directive') t.equal( @@ -1103,7 +1105,7 @@ test('micromark-extension-directive (syntax)', function (t) { t.end() }) -test('micromark-extension-directive (compile)', function (t) { +test('micromark-extension-directive (compile)', (t) => { t.equal( micromark( [ @@ -1179,7 +1181,7 @@ test('micromark-extension-directive (compile)', function (t) { t.end() }) -test('content', function (t) { +test('content', (t) => { t.equal( micromark(':abbr[x\\&y&z]', options({abbr})), '

x&y&z

', @@ -1372,14 +1374,13 @@ function abbr(d) { } function youtube(d) { - var attrs = d.attributes || {} - var v = attrs.v - var list - var prop + const attrs = d.attributes || {} + const v = attrs.v + let prop if (!v) return false - list = [ + const list = [ 'src="https://www.youtube.com/embed/' + this.encode(v) + '"', 'allowfullscreen' ] @@ -1406,17 +1407,19 @@ function youtube(d) { } function h(d) { - var content = d.content || d.label - var attrs = d.attributes || {} - var list = [] - var prop + const content = d.content || d.label + const attrs = d.attributes || {} + const list = [] + let prop for (prop in attrs) { - list.push(this.encode(prop) + '="' + this.encode(attrs[prop]) + '"') + if (own.call(attrs, prop)) { + list.push(this.encode(prop) + '="' + this.encode(attrs[prop]) + '"') + } } this.tag('<' + d.name) - if (list.length) this.tag(' ' + list.join(' ')) + if (list.length > 0) this.tag(' ' + list.join(' ')) this.tag('>') if (content) {