Skip to content

Commit

Permalink
Refactor code-style
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Jul 31, 2021
1 parent 78c5056 commit ecba958
Show file tree
Hide file tree
Showing 84 changed files with 552 additions and 624 deletions.
21 changes: 2 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"unified": "^10.0.0",
"unist-builder": "^3.0.0",
"vfile-find-down": "^6.0.0",
"xo": "^0.38.0"
"xo": "^0.39.0"
},
"scripts": {
"postinstall": "lerna bootstrap --no-ci",
Expand All @@ -71,24 +71,7 @@
"trailingComma": "none"
},
"xo": {
"prettier": true,
"esnext": false,
"rules": {
"eqeqeq": [
2,
"allow-null"
],
"guard-for-in": "off",
"no-eq-null": "off",
"unicorn/no-array-callback-reference": "off",
"unicorn/no-array-push-push": "off",
"unicorn/no-array-for-each": "off",
"prefer-exponentiation-operator": "off",
"unicorn/explicit-length-check": "off",
"unicorn/no-fn-reference-in-iterator": "off",
"unicorn/prefer-includes": "off",
"unicorn/prefer-optional-catch-binding": "off"
}
"prettier": true
},
"remarkConfig": {
"plugins": [
Expand Down
4 changes: 2 additions & 2 deletions packages/hast-util-from-string/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
*/

export function fromString(node, d) {
var value = d == null ? '' : String(d)
const value = d === undefined || d === null ? '' : String(d)

if ('children' in node) {
node.children = []

if (value) {
node.children.push({type: 'text', value: value})
node.children.push({type: 'text', value})
}
} else {
node.value = value
Expand Down
2 changes: 1 addition & 1 deletion packages/hast-util-from-string/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import test from 'tape'
import {u} from 'unist-builder'
import {fromString} from './index.js'

test('hast-util-from-string', function (t) {
test('hast-util-from-string', (t) => {
t.deepEqual(
fromString(u('text'), 'foo'),
u('text', 'foo'),
Expand Down
15 changes: 5 additions & 10 deletions packages/hast-util-is-body-ok-link/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,9 @@
import {isElement} from 'hast-util-is-element'
import {hasProperty} from 'hast-util-has-property'

var list = ['pingback', 'prefetch', 'stylesheet']
const list = new Set(['pingback', 'prefetch', 'stylesheet'])

export function isBodyOkLink(node) {
var length
var index
var rel

if (!isElement(node, 'link')) {
return false
}
Expand All @@ -40,16 +36,15 @@ export function isBodyOkLink(node) {
return true
}

rel = (node.properties || {}).rel || []
length = rel.length
index = -1
const rel = (node.properties || {}).rel || []
let index = -1

if (rel.length === 0) {
return false
}

while (++index < length) {
if (list.indexOf(rel[index]) === -1) {
while (++index < rel.length) {
if (!list.has(rel[index])) {
return false
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/hast-util-is-body-ok-link/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {u} from 'unist-builder'
import {h} from 'hastscript'
import {isBodyOkLink} from './index.js'

test('isBodyOkLink', function (t) {
test('isBodyOkLink', (t) => {
t.equal(
isBodyOkLink(h('link', {itemProp: 'foo'})),
true,
Expand Down
2 changes: 1 addition & 1 deletion packages/hast-util-is-conditional-comment/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* conditional comments.
*/

var re = /^\[if[ \t\f\n\r]+[^\]]+]|<!\[endif]$/
const re = /^\[if[ \t\f\n\r]+[^\]]+]|<!\[endif]$/

export function isConditionalComment(node) {
return node && node.type === 'comment' && re.test(node.value)
Expand Down
12 changes: 8 additions & 4 deletions packages/hast-util-is-conditional-comment/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import {u} from 'unist-builder'
import {h} from 'hastscript'
import {isConditionalComment} from './index.js'

test('hast-util-is-conditional-comment', function (t) {
;[
test('hast-util-is-conditional-comment', (t) => {
const fixtures = [
'[if IE]>…<![endif]',
'[if IE 6]>…<![endif]',
'[if IE 7]>…<![endif]',
Expand All @@ -16,13 +16,17 @@ test('hast-util-is-conditional-comment', function (t) {
'[if gt IE 6]>…<![endif]',
'[if !IE]>',
'<![endif]'
].forEach(function (d) {
]
let index = -1

while (++index < fixtures.length) {
const d = fixtures[index]
t.equal(
isConditionalComment(u('comment', d)),
true,
'yes - <!--' + d + '-->'
)
})
}

t.equal(
isConditionalComment(u('comments', 'foo')),
Expand Down
12 changes: 4 additions & 8 deletions packages/hast-util-is-css-link/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,18 @@
*/

export function isCssLink(node) {
var props
var rel
var type

if (!node || node.tagName !== 'link') {
return false
}

props = node.properties || {}
rel = props.rel
const props = node.properties || {}
const rel = props.rel

if (!rel || !rel.indexOf || rel.indexOf('stylesheet') === -1) {
if (!rel || !rel.indexOf || !rel.includes('stylesheet')) {
return false
}

type = String(props.type || '')
const type = String(props.type || '')
.trim()
.toLowerCase()

Expand Down
2 changes: 1 addition & 1 deletion packages/hast-util-is-css-link/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {u} from 'unist-builder'
import {h} from 'hastscript'
import {isCssLink} from './index.js'

test('hast-util-is-css-link', function (t) {
test('hast-util-is-css-link', (t) => {
t.equal(
isCssLink(h('link', {rel: ['stylesheet']})),
true,
Expand Down
10 changes: 6 additions & 4 deletions packages/hast-util-is-css-style/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
*/

export function isCssStyle(node) {
var value

if (!node || node.tagName !== 'style') {
return false
}

value = (node.properties || {}).type
const value = (node.properties || {}).type

return value == null || String(value).trim().toLowerCase() === 'text/css'
return (
value === undefined ||
value === null ||
String(value).trim().toLowerCase() === 'text/css'
)
}
2 changes: 1 addition & 1 deletion packages/hast-util-is-css-style/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {u} from 'unist-builder'
import {h} from 'hastscript'
import {isCssStyle} from './index.js'

test('hast-util-is-css-style', function (t) {
test('hast-util-is-css-style', (t) => {
t.equal(isCssStyle(h('style')), true, 'yes - a `style` node')
t.equal(
isCssStyle(h('style', {type: null})),
Expand Down
2 changes: 1 addition & 1 deletion packages/hast-util-is-event-handler/test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import test from 'tape'
import {isEventHandler} from './index.js'

test('hast-util-is-event-handler', function (t) {
test('hast-util-is-event-handler', (t) => {
t.ok(isEventHandler('oncut'), 'oncut')
t.ok(isEventHandler('onend'), 'onend')
t.ok(isEventHandler('onpushsubscriptionchange'), 'pushsubscriptionchange')
Expand Down
10 changes: 4 additions & 6 deletions packages/hast-util-is-javascript/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import {hasProperty} from 'hast-util-has-property'
import {isElement} from 'hast-util-is-element'

const mime = [
const mime = new Set([
'application/ecmascript',
'application/javascript',
'application/x-ecmascript',
Expand All @@ -43,7 +43,7 @@ const mime = [
'text/livescript',
'text/x-ecmascript',
'text/x-javascript'
]
])

// Check node.
export function isJavaScript(node) {
Expand All @@ -62,13 +62,11 @@ export function isJavaScript(node) {

// Check one value.
function check(d, prefix) {
var value

if (typeof d !== 'string') {
return false
}

value = d.split(';', 1)[0].trim().toLowerCase()
const value = d.split(';', 1)[0].trim().toLowerCase()

return value === '' || mime.indexOf((prefix || '') + value) !== -1
return value === '' || mime.has((prefix || '') + value)
}
2 changes: 1 addition & 1 deletion packages/hast-util-is-javascript/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {u} from 'unist-builder'
import {h} from 'hastscript'
import {isJavaScript} from './index.js'

test('hast-util-is-javascript', function (t) {
test('hast-util-is-javascript', (t) => {
t.ok(isJavaScript(h('script')), 'yes - for `script`')
t.ok(
isJavaScript(h('script', {src: 'index.js'})),
Expand Down
9 changes: 4 additions & 5 deletions packages/hast-util-to-string/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,11 @@ function one(node) {
}

function all(node) {
var children = node.children
var length = children.length
var index = -1
var result = []
const children = node.children
let index = -1
const result = []

while (++index < length) {
while (++index < children.length) {
result[index] = one(children[index])
}

Expand Down
2 changes: 1 addition & 1 deletion packages/hast-util-to-string/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import test from 'tape'
import {u} from 'unist-builder'
import {toString} from './index.js'

test('hast-util-to-string', function (t) {
test('hast-util-to-string', (t) => {
t.deepEqual(toString(u('comment', 'foo')), 'foo', 'should stringify comments')

t.deepEqual(toString(u('text', 'foo')), 'foo', 'should stringify texts')
Expand Down
15 changes: 6 additions & 9 deletions packages/rehype-concat-css-style/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function rehypeConcatCssStyle() {
}

function transform(tree) {
var matches = []
const matches = []

visit(tree, 'element', visitor)

Expand All @@ -35,17 +35,14 @@ function transform(tree) {
}

function concat() {
var length = matches.length
var index = -1
var contents = []
var match
var siblings
let index = -1
const contents = []

while (++index < length) {
match = matches[index]
while (++index < matches.length) {
const match = matches[index]

if (index) {
siblings = match[0].children
const siblings = match[0].children
siblings.splice(siblings.indexOf(match[1]), 1)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/rehype-concat-css-style/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {u} from 'unist-builder'
import {h} from 'hastscript'
import min from './index.js'

test('rehype-concat-css-style', function (t) {
test('rehype-concat-css-style', (t) => {
t.deepEqual(
rehype()
.use(min)
Expand Down
15 changes: 6 additions & 9 deletions packages/rehype-concat-javascript/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function rehypeConcatJavaScript() {
}

function transform(tree) {
var matches = []
const matches = []

visit(tree, 'element', visitor)

Expand All @@ -35,17 +35,14 @@ function transform(tree) {
}

function concat() {
var length = matches.length
var index = -1
var contents = []
var match
var siblings
let index = -1
const contents = []

while (++index < length) {
match = matches[index]
while (++index < matches.length) {
const match = matches[index]

if (index) {
siblings = match[0].children
const siblings = match[0].children
siblings.splice(siblings.indexOf(match[1]), 1)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/rehype-concat-javascript/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {u} from 'unist-builder'
import {h} from 'hastscript'
import min from './index.js'

test('rehype-concat-javascript', function (t) {
test('rehype-concat-javascript', (t) => {
t.deepEqual(
rehype()
.use(min)
Expand Down

0 comments on commit ecba958

Please sign in to comment.