Skip to content

Commit 4fdef35

Browse files
committed
Refactor code-style
1 parent a406fc1 commit 4fdef35

File tree

2 files changed

+19
-24
lines changed

2 files changed

+19
-24
lines changed

lib/index.js

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
'use strict'
22

3-
/* Dependencies. */
43
var xtend = require('xtend')
54
var defaults = require('./github.json')
65

7-
/* Expose. */
86
module.exports = wrapper
97

108
var own = {}.hasOwnProperty
119

12-
/* Schema. */
1310
var NODES = {
1411
root: {children: all},
1512
doctype: handleDoctype,
@@ -26,7 +23,7 @@ var NODES = {
2623
}
2724
}
2825

29-
/* Sanitize `node`, according to `schema`. */
26+
// Sanitize `node`, according to `schema`.
3027
function wrapper(node, schema) {
3128
var ctx = {type: 'root', children: []}
3229
var replace
@@ -54,7 +51,7 @@ function wrapper(node, schema) {
5451
return replace
5552
}
5653

57-
/* Sanitize `node`. */
54+
// Sanitize `node`.
5855
function one(schema, node, stack) {
5956
var type = node && node.type
6057
var replacement = {type: node.type}
@@ -84,7 +81,7 @@ function one(schema, node, stack) {
8481
if (result === false) {
8582
replace = false
8683

87-
/* Set the non-safe value. */
84+
// Set the non-safe value.
8885
replacement[key] = node[key]
8986
} else if (result !== null && result !== undefined) {
9087
replacement[key] = result
@@ -108,7 +105,7 @@ function one(schema, node, stack) {
108105
return replacement
109106
}
110107

111-
/* Sanitize `children`. */
108+
// Sanitize `children`.
112109
function all(schema, children, node, stack) {
113110
var nodes = children || []
114111
var length = nodes.length || 0
@@ -133,7 +130,7 @@ function all(schema, children, node, stack) {
133130
return results
134131
}
135132

136-
/* Sanitize `properties`. */
133+
// Sanitize `properties`.
137134
function handleProperties(schema, properties, node, stack) {
138135
var name = handleTagName(schema, node.tagName, node, stack)
139136
var attrs = schema.attributes
@@ -170,7 +167,7 @@ function handleProperties(schema, properties, node, stack) {
170167
return result
171168
}
172169

173-
/* Sanitize a property value which is a list. */
170+
// Sanitize a property value which is a list.
174171
function handlePropertyValues(schema, values, prop) {
175172
var length = values.length
176173
var result = []
@@ -188,7 +185,7 @@ function handlePropertyValues(schema, values, prop) {
188185
return result
189186
}
190187

191-
/* Sanitize a property value. */
188+
// Sanitize a property value.
192189
function handlePropertyValue(schema, value, prop) {
193190
if (
194191
typeof value !== 'boolean' &&
@@ -209,7 +206,7 @@ function handlePropertyValue(schema, value, prop) {
209206
return value
210207
}
211208

212-
/* Check whether `value` is a safe URL. */
209+
// Check whether `value` is a safe URL.
213210
function handleProtocol(schema, value, prop) {
214211
var protocols = schema.protocols
215212
var protocol
@@ -266,12 +263,12 @@ function handleProtocol(schema, value, prop) {
266263
return false
267264
}
268265

269-
/* Always return a valid HTML5 doctype. */
266+
// Always return a valid HTML5 doctype.
270267
function handleDoctypeName() {
271268
return 'html'
272269
}
273270

274-
/* Sanitize `tagName`. */
271+
// Sanitize `tagName`.
275272
function handleTagName(schema, tagName, node, stack) {
276273
var name = typeof tagName === 'string' ? tagName : null
277274
var ancestors = schema.ancestors
@@ -284,8 +281,8 @@ function handleTagName(schema, tagName, node, stack) {
284281

285282
ancestors = own.call(ancestors, name) ? ancestors[name] : []
286283

287-
/* Some nodes can break out of their context if they
288-
* don’t have a certain ancestor. */
284+
// Some nodes can break out of their context if they don’t have a certain
285+
// ancestor.
289286
if (ancestors.length !== 0) {
290287
length = ancestors.length + 1
291288
index = -1
@@ -312,17 +309,17 @@ function handleComment(schema) {
312309
return schema.allowComments ? {value: handleValue} : null
313310
}
314311

315-
/* Sanitize `value`. */
312+
// Sanitize `value`.
316313
function handleValue(schema, value) {
317314
return typeof value === 'string' ? value : ''
318315
}
319316

320-
/* Allow `value`. */
317+
// Allow `value`.
321318
function allow(schema, value) {
322319
return value
323320
}
324321

325-
/* Check if `prop` is a data property. */
322+
// Check if `prop` is a data property.
326323
function data(prop) {
327324
return prop.length > 4 && prop.slice(0, 4).toLowerCase() === 'data'
328325
}

test.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict'
22

3-
/* Dependencies. */
43
var test = require('tape')
54
var html = require('hast-util-to-html')
65
var h = require('hastscript')
@@ -12,7 +11,6 @@ var sanitize = require('.')
1211

1312
/* eslint-disable no-script-url, max-params */
1413

15-
/* Tests. */
1614
test('sanitize()', function(t) {
1715
t.test('non-node', function(st) {
1816
st.equal(html(sanitize(true)), '', 'should ignore non-nodes (#1)')
@@ -525,21 +523,21 @@ test('sanitize()', function(t) {
525523
t.end()
526524
})
527525

528-
/* Coverage. */
526+
// Coverage.
529527
toString()
530528

531-
/* Check */
529+
// Check.
532530
function toString() {
533531
return 'alert(1);'
534532
}
535533

536-
/* Test `valid` and `invalid` `url`s in `prop` on `tagName`. */
534+
// Test `valid` and `invalid` `url`s in `prop` on `tagName`.
537535
function testAllURLs(t, tagName, prop, all) {
538536
testURLs(t, tagName, prop, all.valid, true)
539537
testURLs(t, tagName, prop, all.invalid, false)
540538
}
541539

542-
/* Test `valid` `url`s in `prop` on `tagName`. */
540+
// Test `valid` `url`s in `prop` on `tagName`.
543541
function testURLs(t, tagName, prop, urls, valid) {
544542
Object.keys(urls).forEach(function(name) {
545543
var props = {}

0 commit comments

Comments
 (0)