Refactor code-style

This commit is contained in:
Titus Wormer 2021-08-05 15:47:49 +02:00
parent cd45dd6c6d
commit e30accdd27
No known key found for this signature in database
GPG key ID: E6E581152ED04E2E
3 changed files with 23 additions and 33 deletions

View file

@ -1,10 +1,10 @@
import {directive} from 'micromark-extension-directive'
import {directiveFromMarkdown, directiveToMarkdown} from 'mdast-util-directive'
var warningIssued
let warningIssued
export default function remarkDirective() {
var data = this.data()
const data = this.data()
// Old remark.
/* c8 ignore next 14 */

View file

@ -45,7 +45,7 @@
"tape": "^5.0.0",
"to-vfile": "^7.0.0",
"unified": "^10.0.0",
"xo": "^0.37.0"
"xo": "^0.39.0"
},
"scripts": {
"format": "remark . -qfo --ignore-pattern test/ && prettier . -w --loglevel warn && xo --fix",
@ -64,13 +64,6 @@
},
"xo": {
"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": [
"types/"
]

View file

@ -7,43 +7,40 @@ import {remark} from 'remark'
import {isHidden} from 'is-hidden'
import directive from '../index.js'
test('directive()', function (t) {
t.doesNotThrow(function () {
test('directive()', (t) => {
t.doesNotThrow(() => {
remark().use(directive).freeze()
}, 'should not throw if not passed options')
t.doesNotThrow(function () {
t.doesNotThrow(() => {
unified().use(directive).freeze()
}, 'should not throw if without parser or compiler')
t.end()
})
test('fixtures', function (t) {
var base = path.join('test', 'fixtures')
var entries = fs.readdirSync(base).filter((d) => !isHidden(d))
test('fixtures', (t) => {
const base = path.join('test', 'fixtures')
const entries = fs.readdirSync(base).filter((d) => !isHidden(d))
t.plan(entries.length)
entries.forEach(each)
function each(fixture) {
t.test(fixture, function (st) {
var file = readSync(path.join(base, fixture, 'input.md'))
var input = String(file)
var outputPath = path.join(base, fixture, 'output.md')
var treePath = path.join(base, fixture, 'tree.json')
var proc
var actual
var output
var expected
proc = remark().use(directive).freeze()
actual = proc.parse(file)
let index = -1
while (++index < entries.length) {
const fixture = entries[index]
t.test(fixture, (st) => {
const file = readSync(path.join(base, fixture, 'input.md'))
const input = String(file)
const outputPath = path.join(base, fixture, 'output.md')
const treePath = path.join(base, fixture, 'tree.json')
const proc = remark().use(directive).freeze()
const actual = proc.parse(file)
let output
let expected
try {
expected = JSON.parse(fs.readFileSync(treePath))
} catch (_) {
} catch {
// New fixture.
fs.writeFileSync(treePath, JSON.stringify(actual, 0, 2) + '\n')
expected = actual
@ -51,7 +48,7 @@ test('fixtures', function (t) {
try {
output = fs.readFileSync(outputPath, 'utf8')
} catch (_) {
} catch {
output = input
}