Refactor code-style
This commit is contained in:
parent
cd45dd6c6d
commit
e30accdd27
3 changed files with 23 additions and 33 deletions
4
index.js
4
index.js
|
@ -1,10 +1,10 @@
|
||||||
import {directive} from 'micromark-extension-directive'
|
import {directive} from 'micromark-extension-directive'
|
||||||
import {directiveFromMarkdown, directiveToMarkdown} from 'mdast-util-directive'
|
import {directiveFromMarkdown, directiveToMarkdown} from 'mdast-util-directive'
|
||||||
|
|
||||||
var warningIssued
|
let warningIssued
|
||||||
|
|
||||||
export default function remarkDirective() {
|
export default function remarkDirective() {
|
||||||
var data = this.data()
|
const data = this.data()
|
||||||
|
|
||||||
// Old remark.
|
// Old remark.
|
||||||
/* c8 ignore next 14 */
|
/* c8 ignore next 14 */
|
||||||
|
|
|
@ -45,7 +45,7 @@
|
||||||
"tape": "^5.0.0",
|
"tape": "^5.0.0",
|
||||||
"to-vfile": "^7.0.0",
|
"to-vfile": "^7.0.0",
|
||||||
"unified": "^10.0.0",
|
"unified": "^10.0.0",
|
||||||
"xo": "^0.37.0"
|
"xo": "^0.39.0"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"format": "remark . -qfo --ignore-pattern test/ && prettier . -w --loglevel warn && xo --fix",
|
"format": "remark . -qfo --ignore-pattern test/ && prettier . -w --loglevel warn && xo --fix",
|
||||||
|
@ -64,13 +64,6 @@
|
||||||
},
|
},
|
||||||
"xo": {
|
"xo": {
|
||||||
"prettier": true,
|
"prettier": true,
|
||||||
"esnext": false,
|
|
||||||
"rules": {
|
|
||||||
"no-var": "off",
|
|
||||||
"prefer-arrow-callback": "off",
|
|
||||||
"unicorn/no-array-callback-reference": "off",
|
|
||||||
"unicorn/prefer-optional-catch-binding": "off"
|
|
||||||
},
|
|
||||||
"ignores": [
|
"ignores": [
|
||||||
"types/"
|
"types/"
|
||||||
]
|
]
|
||||||
|
|
|
@ -7,43 +7,40 @@ import {remark} from 'remark'
|
||||||
import {isHidden} from 'is-hidden'
|
import {isHidden} from 'is-hidden'
|
||||||
import directive from '../index.js'
|
import directive from '../index.js'
|
||||||
|
|
||||||
test('directive()', function (t) {
|
test('directive()', (t) => {
|
||||||
t.doesNotThrow(function () {
|
t.doesNotThrow(() => {
|
||||||
remark().use(directive).freeze()
|
remark().use(directive).freeze()
|
||||||
}, 'should not throw if not passed options')
|
}, 'should not throw if not passed options')
|
||||||
|
|
||||||
t.doesNotThrow(function () {
|
t.doesNotThrow(() => {
|
||||||
unified().use(directive).freeze()
|
unified().use(directive).freeze()
|
||||||
}, 'should not throw if without parser or compiler')
|
}, 'should not throw if without parser or compiler')
|
||||||
|
|
||||||
t.end()
|
t.end()
|
||||||
})
|
})
|
||||||
|
|
||||||
test('fixtures', function (t) {
|
test('fixtures', (t) => {
|
||||||
var base = path.join('test', 'fixtures')
|
const base = path.join('test', 'fixtures')
|
||||||
var entries = fs.readdirSync(base).filter((d) => !isHidden(d))
|
const entries = fs.readdirSync(base).filter((d) => !isHidden(d))
|
||||||
|
|
||||||
t.plan(entries.length)
|
t.plan(entries.length)
|
||||||
|
|
||||||
entries.forEach(each)
|
let index = -1
|
||||||
|
while (++index < entries.length) {
|
||||||
function each(fixture) {
|
const fixture = entries[index]
|
||||||
t.test(fixture, function (st) {
|
t.test(fixture, (st) => {
|
||||||
var file = readSync(path.join(base, fixture, 'input.md'))
|
const file = readSync(path.join(base, fixture, 'input.md'))
|
||||||
var input = String(file)
|
const input = String(file)
|
||||||
var outputPath = path.join(base, fixture, 'output.md')
|
const outputPath = path.join(base, fixture, 'output.md')
|
||||||
var treePath = path.join(base, fixture, 'tree.json')
|
const treePath = path.join(base, fixture, 'tree.json')
|
||||||
var proc
|
const proc = remark().use(directive).freeze()
|
||||||
var actual
|
const actual = proc.parse(file)
|
||||||
var output
|
let output
|
||||||
var expected
|
let expected
|
||||||
|
|
||||||
proc = remark().use(directive).freeze()
|
|
||||||
actual = proc.parse(file)
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
expected = JSON.parse(fs.readFileSync(treePath))
|
expected = JSON.parse(fs.readFileSync(treePath))
|
||||||
} catch (_) {
|
} catch {
|
||||||
// New fixture.
|
// New fixture.
|
||||||
fs.writeFileSync(treePath, JSON.stringify(actual, 0, 2) + '\n')
|
fs.writeFileSync(treePath, JSON.stringify(actual, 0, 2) + '\n')
|
||||||
expected = actual
|
expected = actual
|
||||||
|
@ -51,7 +48,7 @@ test('fixtures', function (t) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
output = fs.readFileSync(outputPath, 'utf8')
|
output = fs.readFileSync(outputPath, 'utf8')
|
||||||
} catch (_) {
|
} catch {
|
||||||
output = input
|
output = input
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue