Skip to content

Commit 93c3d26

Browse files
committed
Refactor code-style
1 parent 3d14647 commit 93c3d26

File tree

3 files changed

+40
-47
lines changed

3 files changed

+40
-47
lines changed

index.js

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import {findAndReplace} from 'mdast-util-find-and-replace'
33
import unicodePunctuation from 'micromark/dist/character/unicode-punctuation.js'
44
import unicodeWhitespace from 'micromark/dist/character/unicode-whitespace.js'
55

6-
var inConstruct = 'phrasing'
7-
var notInConstruct = ['autolink', 'link', 'image', 'label']
6+
const inConstruct = 'phrasing'
7+
const notInConstruct = ['autolink', 'link', 'image', 'label']
88

99
export const gfmAutolinkLiteralFromMarkdown = {
1010
transforms: [transformGfmAutolinkLiterals],
@@ -78,10 +78,9 @@ function transformGfmAutolinkLiterals(tree) {
7878
)
7979
}
8080

81+
// eslint-disable-next-line max-params
8182
function findUrl($0, protocol, domain, path, match) {
82-
var prefix = ''
83-
var parts
84-
var result
83+
let prefix = ''
8584

8685
// Not an expected previous character.
8786
if (!previous(match)) {
@@ -99,11 +98,11 @@ function findUrl($0, protocol, domain, path, match) {
9998
return false
10099
}
101100

102-
parts = splitUrl(domain + path)
101+
const parts = splitUrl(domain + path)
103102

104103
if (!parts[0]) return false
105104

106-
result = {
105+
let result = {
107106
type: 'link',
108107
title: null,
109108
url: prefix + protocol + parts[0],
@@ -132,7 +131,7 @@ function findEmail($0, atext, label, match) {
132131
}
133132

134133
function isCorrectDomain(domain) {
135-
var parts = domain.split('.')
134+
const parts = domain.split('.')
136135

137136
if (
138137
parts.length < 2 ||
@@ -150,10 +149,10 @@ function isCorrectDomain(domain) {
150149
}
151150

152151
function splitUrl(url) {
153-
var trail = /[!"&'),.:;<>?\]}]+$/.exec(url)
154-
var closingParenIndex
155-
var openingParens
156-
var closingParens
152+
let trail = /[!"&'),.:;<>?\]}]+$/.exec(url)
153+
let closingParenIndex
154+
let openingParens
155+
let closingParens
157156

158157
if (trail) {
159158
url = url.slice(0, trail.index)
@@ -174,9 +173,11 @@ function splitUrl(url) {
174173
}
175174

176175
function previous(match, email) {
177-
var code = match.input.charCodeAt(match.index - 1)
176+
const code = match.input.charCodeAt(match.index - 1)
178177
return (
179-
(code !== code || unicodeWhitespace(code) || unicodePunctuation(code)) &&
178+
(match.index === 0 ||
179+
unicodeWhitespace(code) ||
180+
unicodePunctuation(code)) &&
180181
(!email || code !== 47)
181182
)
182183
}

package.json

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,7 @@
6868
"trailingComma": "none"
6969
},
7070
"xo": {
71-
"prettier": true,
72-
"prettier": true,
73-
"rules": {
74-
"no-var": "off",
75-
"prefer-arrow-callback": "off",
76-
"max-params": "off",
77-
"no-self-compare": "off",
78-
"unicorn/no-array-for-each": "off",
79-
"unicorn/prefer-includes": "off",
80-
"unicorn/prefer-optional-catch-binding": "off"
81-
}
71+
"prettier": true
8272
},
8373
"remarkConfig": {
8474
"plugins": [

test/index.js

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
gfmAutolinkLiteralToMarkdown
1212
} from '../index.js'
1313

14-
test('markdown -> mdast', function (t) {
14+
test('markdown -> mdast', (t) => {
1515
t.deepEqual(
1616
fromMarkdown(
1717
'www.example.com, https://example.com, and contact@example.com.',
@@ -170,7 +170,7 @@ test('markdown -> mdast', function (t) {
170170
t.end()
171171
})
172172

173-
test('mdast -> markdown', function (t) {
173+
test('mdast -> markdown', (t) => {
174174
t.deepEqual(
175175
toMarkdown(
176176
{
@@ -363,28 +363,30 @@ test('mdast -> markdown', function (t) {
363363
'should not escape colons in image (resource) labels'
364364
)
365365

366-
fs.readdirSync('test')
367-
.filter((d) => path.extname(d) === '.md')
368-
.forEach((d) => {
369-
var stem = path.basename(d, '.md')
370-
var actual = toHtml(
371-
toHast(
372-
fromMarkdown(fs.readFileSync(path.join('test', d)), {
373-
extensions: [gfmAutolinkLiteral],
374-
mdastExtensions: [gfmAutolinkLiteralFromMarkdown]
375-
}),
376-
{allowDangerousHtml: true}
377-
),
378-
{allowDangerousHtml: true, entities: {useNamedReferences: true}}
379-
)
380-
var expected = String(fs.readFileSync(path.join('test', stem + '.html')))
366+
const files = fs.readdirSync('test').filter((d) => path.extname(d) === '.md')
367+
let index = -1
381368

382-
if (actual.charCodeAt(actual.length - 1) !== 10) {
383-
actual += '\n'
384-
}
369+
while (++index < files.length) {
370+
const d = files[index]
371+
const stem = path.basename(d, '.md')
372+
let actual = toHtml(
373+
toHast(
374+
fromMarkdown(fs.readFileSync(path.join('test', d)), {
375+
extensions: [gfmAutolinkLiteral],
376+
mdastExtensions: [gfmAutolinkLiteralFromMarkdown]
377+
}),
378+
{allowDangerousHtml: true}
379+
),
380+
{allowDangerousHtml: true, entities: {useNamedReferences: true}}
381+
)
382+
const expected = String(fs.readFileSync(path.join('test', stem + '.html')))
383+
384+
if (actual.charCodeAt(actual.length - 1) !== 10) {
385+
actual += '\n'
386+
}
385387

386-
t.deepEqual(actual, expected, stem)
387-
})
388+
t.deepEqual(actual, expected, stem)
389+
}
388390

389391
t.end()
390392
})

0 commit comments

Comments
 (0)