Skip to content

Commit 40af676

Browse files
committed
Refactor code-style
1 parent a840260 commit 40af676

File tree

3 files changed

+38
-41
lines changed

3 files changed

+38
-41
lines changed

index.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import gfmTableToMarkdown from 'mdast-util-gfm-table/to-markdown.js'
77
import gfmTaskListItemFromMarkdown from 'mdast-util-gfm-task-list-item/from-markdown.js'
88
import gfmTaskListItemToMarkdown from 'mdast-util-gfm-task-list-item/to-markdown.js'
99

10-
var own = {}.hasOwnProperty
10+
const own = {}.hasOwnProperty
1111

1212
export const gfmFromMarkdown = configure([
1313
gfmAutolinkLiteralFromMarkdown,
@@ -28,9 +28,9 @@ export function gfmToMarkdown(options) {
2828
}
2929

3030
function configure(extensions) {
31-
var config = {transforms: [], canContainEols: []}
32-
var length = extensions.length
33-
var index = -1
31+
const config = {transforms: [], canContainEols: []}
32+
const length = extensions.length
33+
let index = -1
3434

3535
while (++index < length) {
3636
extension(config, extensions[index])
@@ -40,18 +40,20 @@ function configure(extensions) {
4040
}
4141

4242
function extension(config, extension) {
43-
var key
44-
var left
45-
var right
43+
let key
44+
let left
45+
let right
4646

4747
for (key in extension) {
48-
left = own.call(config, key) ? config[key] : (config[key] = {})
49-
right = extension[key]
50-
51-
if (key === 'canContainEols' || key === 'transforms') {
52-
config[key] = [].concat(left, right)
53-
} else {
54-
Object.assign(left, right)
48+
if (own.call(extension, key)) {
49+
left = own.call(config, key) ? config[key] : (config[key] = {})
50+
right = extension[key]
51+
52+
if (key === 'canContainEols' || key === 'transforms') {
53+
config[key] = [].concat(left, right)
54+
} else {
55+
Object.assign(left, right)
56+
}
5557
}
5658
}
5759
}

package.json

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,7 @@
7373
"trailingComma": "none"
7474
},
7575
"xo": {
76-
"prettier": true,
77-
"rules": {
78-
"no-var": "off",
79-
"prefer-arrow-callback": "off",
80-
"guard-for-in": "off",
81-
"unicorn/prefer-optional-catch-binding": "off"
82-
}
76+
"prettier": true
8377
},
8478
"remarkConfig": {
8579
"plugins": [

test/index.js

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,46 +11,47 @@ import {gfmFromMarkdown, gfmToMarkdown} from '../index.js'
1111

1212
const spec = JSON.parse(fs.readFileSync(path.join('test', 'spec.json')))
1313

14-
test('markdown -> mdast', function (t) {
14+
test('markdown -> mdast', (t) => {
1515
const files = spec.filter(
1616
(example) => !/disallowed raw html/i.test(example.category)
1717
)
1818
let index = -1
1919

2020
while (++index < files.length) {
2121
const example = files[index]
22-
var category = Slugger.slug(example.category)
23-
var name = index + '-' + category
24-
var fixtureHtmlPath = path.join('test', name + '.html')
25-
var fixtureMarkdownPath = path.join('test', name + '.md')
26-
var fixtureHtml
27-
var fixtureMarkdown
28-
var mdast
29-
var html
30-
var md
31-
32-
mdast = fromMarkdown(example.input, {
22+
const category = Slugger.slug(example.category)
23+
const name = index + '-' + category
24+
const fixtureHtmlPath = path.join('test', name + '.html')
25+
const fixtureMarkdownPath = path.join('test', name + '.md')
26+
27+
const mdast = fromMarkdown(example.input, {
3328
extensions: [gfm()],
3429
mdastExtensions: [gfmFromMarkdown]
3530
})
3631

37-
html = toHtml(toHast(mdast, {allowDangerousHtml: true, commonmark: true}), {
38-
allowDangerousHtml: true,
39-
entities: {useNamedReferences: true},
40-
closeSelfClosing: true
41-
})
32+
const html = toHtml(
33+
toHast(mdast, {allowDangerousHtml: true, commonmark: true}),
34+
{
35+
allowDangerousHtml: true,
36+
entities: {useNamedReferences: true},
37+
closeSelfClosing: true
38+
}
39+
)
40+
41+
let fixtureHtml
42+
let fixtureMarkdown
4243

4344
try {
4445
fixtureHtml = String(fs.readFileSync(fixtureHtmlPath))
45-
} catch (_) {
46+
} catch {
4647
fixtureHtml = example.output.slice(0, -1)
4748
}
4849

49-
md = toMarkdown(mdast, {extensions: [gfmToMarkdown()]})
50+
const md = toMarkdown(mdast, {extensions: [gfmToMarkdown()]})
5051

5152
try {
5253
fixtureMarkdown = String(fs.readFileSync(fixtureMarkdownPath))
53-
} catch (_) {
54+
} catch {
5455
fixtureMarkdown = md
5556
fs.writeFileSync(fixtureMarkdownPath, fixtureMarkdown)
5657
}

0 commit comments

Comments
 (0)