Skip to content

Commit

Permalink
Fix some linter messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Mar 9, 2016
1 parent a9c9c5f commit 50c00cc
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 62 deletions.
4 changes: 1 addition & 3 deletions examples/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@ var x = Xray()
x('http://google.com', {
main: 'title',
image: x('https://images.google.com', 'title')
})(function (err, obj) {
console.log(obj); // => { main: 'Google', image: 'Google Images' }
})
})(console.log)
27 changes: 12 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ var assign = require('object-assign')
var cheerio = require('cheerio')
var enstore = require('enstore')
var isUrl = require('is-url')
var Batch = require('batch')
var isArray = Array.isArray
var fs = require('fs')

Expand All @@ -26,13 +25,12 @@ var walk = require('./lib/walk')
*/

var debug = require('debug')('x-ray')
var error = require('debug')('x-ray:error')

/**
* Crawler methods
*/

var methods = [ 'concurrency', 'throttle', 'timeout', 'driver', 'delay', 'limit']
var methods = ['concurrency', 'throttle', 'timeout', 'driver', 'delay', 'limit']

/**
* Export
Expand Down Expand Up @@ -66,7 +64,7 @@ function Xray () {
var stream

function node (source2, fn) {
if (1 == arguments.length) {
if (arguments.length === 1) {
fn = source2
} else {
source = source2
Expand Down Expand Up @@ -169,18 +167,18 @@ function Xray () {

node.html = function ($, fn) {
walk(selector, function (v, k, next) {
if ('string' == typeof v) {
if (typeof v === 'string') {
var value = resolve($, root(scope), v)
return next(null, value)
} else if ('function' == typeof v) {
} else if (typeof v === 'function') {
return v($, function (err, obj) {
if (err) return next(err)
return next(null, obj)
})
} else if (isArray(v)) {
if ('string' == typeof v[0]) {
if (typeof v[0] === 'string') {
return next(null, resolve($, root(scope), v))
} else if ('object' == typeof v[0]) {
} else if (typeof v[0] === 'object') {
var $scope = $.find ? $.find(scope) : $(scope)
var pending = $scope.length
var out = []
Expand Down Expand Up @@ -268,10 +266,10 @@ function Xray () {
*/

function root (selector) {
return ('string' == typeof selector || isArray(selector))
&& !~selector.indexOf('@')
&& !isUrl(selector)
&& selector
return (typeof selector === 'string' || isArray(selector)) &&
!~selector.indexOf('@') &&
!isUrl(selector) &&
selector
}

/**
Expand All @@ -284,8 +282,8 @@ function root (selector) {

function compact (arr) {
return arr.filter(function (val) {
if (null == val) return false
if (undefined !== val.length) return 0 !== val.length
if (!val) return false
if (val.length !== undefined) return val.length !== 0
for (var key in val) if (has.call(val, key)) return true
return false
})
Expand Down Expand Up @@ -330,7 +328,6 @@ function stream_array (stream) {

function stream_object (stream) {
if (!stream) return function () {}
var first = true

return function _stream_object (data, end) {
var json = JSON.stringify(data, true, 2)
Expand Down
4 changes: 2 additions & 2 deletions lib/absolutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function absolute (path, $) {
var remote = parts.protocol + '//' + parts.hostname
// apply <base> tag transformation
var base = $('head').find('base')
if (base.length == 1) {
if (base.length === 1) {
var href = base.attr('href')
if (href) {
remote = href
Expand All @@ -66,7 +66,7 @@ function absolute (path, $) {
return
} else {
var current
if (href && src.indexOf('/') != 0) {
if (href && src.indexOf('/') !== 0) {
current = url.resolve(remote, href)
src = url.resolve(current, src)
} else {
Expand Down
8 changes: 4 additions & 4 deletions lib/highlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* Module Dependencies
*/

var debug = require('debug')('highlight')
var parse = require('x-ray-parse')
var chalk = require('chalk')
var isArray = Array.isArray
Expand Down Expand Up @@ -58,18 +57,19 @@ function find ($, scope, selector, attr) {
})
return $
} else if (scope) {
var $scope = select($, scope)
$scope = select($, scope)
attribute($scope.find(selector).eq(0), attr)
return $
} else {
var $selector
if (isArray(selector)) {
var $selector = select($, selector[0])
$selector = select($, selector[0])
$selector.map(function (i) {
attribute($selector.eq(i), attr)
})
return $
} else {
var $selector = select($, selector)
$selector = select($, selector)
attribute($selector.eq(0), attr)
return $
}
Expand Down
3 changes: 1 addition & 2 deletions lib/is-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ module.exports = isHTML

function isHTML (str) {
str = (str || '').toString().trim()
return '<' == str[0]
&& '>' == str[str.length - 1]
return str[0] === '<' && str[str.length - 1] === '>'
}
9 changes: 5 additions & 4 deletions lib/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,19 @@ function find ($, scope, selector, attr) {
})
return out
} else if (scope) {
var $scope = select($, scope)
$scope = select($, scope)
return attribute($scope.find(selector).eq(0), attr)
} else {
var $selector
if (isArray(selector)) {
var $selector = select($, selector[0])
var out = []
$selector = select($, selector[0])
out = []
$selector.map(function (i) {
out.push(attribute($selector.eq(i), attr))
})
return out
} else {
var $selector = select($, selector)
$selector = select($, selector)
return attribute($selector.eq(0), attr)
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/walk.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function walk (value, fn, done, key) {
walk(v, fn, function (err, value) {
if (err) return next(err)
// ignore undefined values
if (undefined !== value && '' !== value) {
if (undefined !== value && value !== '') {
out[k] = value
}
next()
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"dependencies": {
"batch": "^0.5.2",
"chalk": "^1.0.0",
"cheerio": "^0.19.0",
"debug": "^2.1.3",
"enstore": "^1.0.1",
"http-context": "^1.1.0",
Expand Down
59 changes: 30 additions & 29 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ describe('Xray()', function () {
x('a', [{ link: '@href' }])(url, function (err, arr) {
if (err) return done(err)
assert.equal(50, arr.length)
assert.deepEqual({ link: 'http://loripsum.net/' }, arr.pop())
assert.deepEqual({ link: 'http://loripsum.net/' }, arr.pop())
assert.deepEqual({ link: 'http://loripsum.net/' }, arr.pop())
assert.deepEqual({ link: 'http://loripsum.net/' }, arr.pop())
assert.deepEqual({ link: 'http://loripsum.net/' }, arr.pop())
assert.deepEqual({ link: 'http://loripsum.net/' }, arr.pop())
assert.deepEqual({ link: 'http://producthunt.com/' }, arr.pop())
done()
})
Expand Down Expand Up @@ -142,13 +142,13 @@ describe('Xray()', function () {

x('.tags', [['li']])($, function (err, arr) {
if (err) return done(err)
assert(3 == arr[0].length)
assert('a' == arr[0][0])
assert('b' == arr[0][1])
assert('c' == arr[0][2])
assert(2 == arr[1].length)
assert('d' == arr[1][0])
assert('e' == arr[1][1])
assert(arr[0].length === 3)
assert(arr[0][0] === 'a')
assert(arr[0][1] === 'b')
assert(arr[0][2] === 'c')
assert(arr[1].length === 2)
assert(arr[1][0] === 'd')
assert(arr[1][1] === 'e')
done()
})
})
Expand All @@ -172,7 +172,7 @@ describe('Xray()', function () {
</ul>
</div>
</div>
*/})
*/}) // eslint-disable-line

var $ = cheerio.load(html)
var x = Xray()
Expand Down Expand Up @@ -202,7 +202,7 @@ describe('Xray()', function () {
}])
})(function (err, obj) {
if (err) return done(err)
assert('mat.io' == obj.title)
assert(obj.title === 'mat.io')

assert.deepEqual({
title: "The 100 Best Children's Books of All Time",
Expand Down Expand Up @@ -231,7 +231,7 @@ describe('Xray()', function () {

x('li.group', [{
title: '.dribbble-img strong',
image: '.dribbble-img [data-src]@data-src',
image: '.dribbble-img [data-src]@data-src'
}]).paginate('.next_page@href').limit(3)
;('https://dribbble.com', function (err, arr) {
if (err) return done(err)
Expand All @@ -255,6 +255,7 @@ describe('Xray()', function () {
}]).paginate('.next_page@href').limit(10)
;(function (err, arr) {
timesCalled++
assert.ifError(err)
assert.equal(1, timesCalled, 'callback was called more than once')
})
})
Expand All @@ -272,13 +273,13 @@ describe('Xray()', function () {
var x = Xray()
x($, '.tags', [['li']]).write().pipe(concat(function (data) {
var arr = JSON.parse(data.toString())
assert(3 == arr[0].length)
assert('a' == arr[0][0])
assert('b' == arr[0][1])
assert('c' == arr[0][2])
assert(2 == arr[1].length)
assert('d' == arr[1][0])
assert('e' == arr[1][1])
assert(arr[0].length === 3)
assert(arr[0][0] === 'a')
assert(arr[0][1] === 'b')
assert(arr[0][2] === 'c')
assert(arr[1].length === 2)
assert(arr[1][0] === 'd')
assert(arr[1][1] === 'e')
done()
}))
})
Expand All @@ -289,7 +290,7 @@ describe('Xray()', function () {

x('https://dribbble.com', 'li.group', [{
title: '.dribbble-img strong',
image: '.dribbble-img [data-src]@data-src',
image: '.dribbble-img [data-src]@data-src'
}]).paginate('.next_page@href').limit(3).write().pipe(concat(function (data) {
var arr = JSON.parse(data.toString())
assert(arr.length, 'array should have a length')
Expand All @@ -311,13 +312,13 @@ describe('Xray()', function () {

x($, '.tags', [['li']]).write(path).on('finish', function () {
var arr = JSON.parse(read(path, 'utf8'))
assert(3 == arr[0].length)
assert('a' == arr[0][0])
assert('b' == arr[0][1])
assert('c' == arr[0][2])
assert(2 == arr[1].length)
assert('d' == arr[1][0])
assert('e' == arr[1][1])
assert(arr[0].length === 3)
assert(arr[0][0] === 'a')
assert(arr[0][1] === 'b')
assert(arr[0][2] === 'c')
assert(arr[1].length === 2)
assert(arr[1][0] === 'd')
assert(arr[1][1] === 'e')
rm(path)
done()
})
Expand All @@ -329,7 +330,7 @@ describe('Xray()', function () {

x('https://dribbble.com', 'li.group', [{
title: '.dribbble-img strong',
image: '.dribbble-img [data-src]@data-src',
image: '.dribbble-img [data-src]@data-src'
}]).paginate('.next_page@href').limit(3).write(path).on('finish', function () {
var arr = JSON.parse(read(path, 'utf8'))
assert(arr.length, 'array should have a length')
Expand Down
1 change: 0 additions & 1 deletion test/params.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

var params = require('../lib/params')
var cheerio = require('cheerio')
var assert = require('assert')

/**
Expand Down

0 comments on commit 50c00cc

Please sign in to comment.