Skip to content

Commit c9acf5e

Browse files
committed
Add eslint to project
Closes #524
1 parent 245db60 commit c9acf5e

File tree

6 files changed

+41
-17
lines changed

6 files changed

+41
-17
lines changed

.eslintrc

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{ "extends": "eslint:recommended",
2+
"env": {
3+
"browser": true,
4+
"jquery": true
5+
},
6+
"rules": {
7+
"eqeqeq": "warn",
8+
"no-eval": "error",
9+
"no-extra-parens": "error",
10+
"no-implicit-globals": "error",
11+
"no-trailing-spaces": "error",
12+
"no-unused-expressions": "error",
13+
"semi": ["error", "never"]
14+
}
15+
}

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

jquery.pjax.js

+18-14
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ function pjax(options) {
253253

254254
// If $.pjax.defaults.version is a function, invoke it first.
255255
// Otherwise it can be a static string.
256-
var currentVersion = (typeof $.pjax.defaults.version === 'function') ?
256+
var currentVersion = typeof $.pjax.defaults.version === 'function' ?
257257
$.pjax.defaults.version() :
258258
$.pjax.defaults.version
259259

@@ -299,7 +299,7 @@ function pjax(options) {
299299
if (blurFocus) {
300300
try {
301301
document.activeElement.blur()
302-
} catch (e) { }
302+
} catch (e) { /* ignore */ }
303303
}
304304

305305
if (container.title) document.title = container.title
@@ -492,7 +492,7 @@ function onPjaxPopstate(event) {
492492

493493
// Force reflow/relayout before the browser tries to restore the
494494
// scroll position.
495-
container[0].offsetHeight
495+
container[0].offsetHeight // eslint-disable-line no-unused-expressions
496496
} else {
497497
locationReplace(location.href)
498498
}
@@ -566,7 +566,7 @@ function cloneContents(container) {
566566
// Unmark script tags as already being eval'd so they can get executed again
567567
// when restored from cache. HAXX: Uses jQuery internal method.
568568
cloned.find('script').each(function(){
569-
if (!this.src) jQuery._data(this, 'globalEval', false)
569+
if (!this.src) $._data(this, 'globalEval', false)
570570
})
571571
return cloned.contents()
572572
}
@@ -665,13 +665,14 @@ function extractContainer(data, xhr, options) {
665665
var serverUrl = xhr.getResponseHeader('X-PJAX-URL')
666666
obj.url = serverUrl ? stripInternalParams(parseURL(serverUrl)) : options.requestUrl
667667

668+
var $head, $body
668669
// Attempt to parse response html into elements
669670
if (fullDocument) {
670-
var $body = $(parseHTML(data.match(/<body[^>]*>([\s\S.]*)<\/body>/i)[0]))
671+
$body = $(parseHTML(data.match(/<body[^>]*>([\s\S.]*)<\/body>/i)[0]))
671672
var head = data.match(/<head[^>]*>([\s\S.]*)<\/head>/i)
672-
var $head = head != null ? $(parseHTML(head[0])) : $body
673+
$head = head != null ? $(parseHTML(head[0])) : $body
673674
} else {
674-
var $head = $body = $(parseHTML(data))
675+
$head = $body = $(parseHTML(data))
675676
}
676677

677678
// If response data is empty, return fast
@@ -683,12 +684,11 @@ function extractContainer(data, xhr, options) {
683684
obj.title = findAll($head, 'title').last().text()
684685

685686
if (options.fragment) {
687+
var $fragment = $body
686688
// If they specified a fragment, look for it in the response
687689
// and pull it out.
688-
if (options.fragment === 'body') {
689-
var $fragment = $body
690-
} else {
691-
var $fragment = findAll($body, options.fragment).first()
690+
if (options.fragment !== 'body') {
691+
$fragment = findAll($fragment, options.fragment).first()
692692
}
693693

694694
if ($fragment.length) {
@@ -797,8 +797,8 @@ function cachePop(direction, id, value) {
797797
}
798798

799799
pushStack.push(id)
800-
if (id = popStack.pop())
801-
delete cacheMapping[id]
800+
id = popStack.pop()
801+
if (id) delete cacheMapping[id]
802802

803803
// Trim whichever stack we just pushed to to max cache length.
804804
trimCacheStack(pushStack, pjax.defaults.maxCacheLength)
@@ -894,6 +894,10 @@ $.support.pjax =
894894
// pushState isn't reliable on iOS until 5.
895895
!navigator.userAgent.match(/((iPod|iPhone|iPad).+\bOS\s+[1-4]\D|WebApps\/.+CFNetwork)/)
896896

897-
$.support.pjax ? enable() : disable()
897+
if ($.support.pjax) {
898+
enable()
899+
} else {
900+
disable()
901+
}
898902

899903
})(jQuery)

package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,8 @@
1212
"files" : [
1313
"LICENSE",
1414
"jquery.pjax.js"
15-
]
15+
],
16+
"devDependencies": {
17+
"eslint": "^3.19.0"
18+
}
1619
}

script/bootstrap

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env bash
22
set -e
33

4+
npm install
45
bundle install
56

67
if phantom_version="$(phantomjs --version)"; then

script/test

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env bash
22
set -e
33

4+
./node_modules/.bin/eslint *.js
5+
46
port=3999
57
script/server -p "$port" &>/dev/null &
68
pid=$!
@@ -11,8 +13,6 @@ while ! lsof -i :$port >/dev/null; do
1113
sleep .05
1214
done
1315

14-
[ -z "$CI" ] || echo "PhantomJS $(phantomjs --version)"
15-
1616
phantomjs ./test/run-qunit.js \
1717
"http://localhost:$port/?jquery=3.2" \
1818
"http://localhost:$port/?jquery=2.2" \

0 commit comments

Comments
 (0)