Skip to content

Commit

Permalink
Add eslint to project
Browse files Browse the repository at this point in the history
  • Loading branch information
mislav committed May 20, 2017
1 parent 245db60 commit c9acf5e
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 17 deletions.
15 changes: 15 additions & 0 deletions .eslintrc
@@ -0,0 +1,15 @@
{ "extends": "eslint:recommended",
"env": {
"browser": true,
"jquery": true
},
"rules": {
"eqeqeq": "warn",
"no-eval": "error",
"no-extra-parens": "error",
"no-implicit-globals": "error",
"no-trailing-spaces": "error",
"no-unused-expressions": "error",
"semi": ["error", "never"]
}
}
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
node_modules/
32 changes: 18 additions & 14 deletions jquery.pjax.js
Expand Up @@ -253,7 +253,7 @@ function pjax(options) {

// If $.pjax.defaults.version is a function, invoke it first.
// Otherwise it can be a static string.
var currentVersion = (typeof $.pjax.defaults.version === 'function') ?
var currentVersion = typeof $.pjax.defaults.version === 'function' ?
$.pjax.defaults.version() :
$.pjax.defaults.version

Expand Down Expand Up @@ -299,7 +299,7 @@ function pjax(options) {
if (blurFocus) {
try {
document.activeElement.blur()
} catch (e) { }
} catch (e) { /* ignore */ }
}

if (container.title) document.title = container.title
Expand Down Expand Up @@ -492,7 +492,7 @@ function onPjaxPopstate(event) {

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

var $head, $body
// Attempt to parse response html into elements
if (fullDocument) {
var $body = $(parseHTML(data.match(/<body[^>]*>([\s\S.]*)<\/body>/i)[0]))
$body = $(parseHTML(data.match(/<body[^>]*>([\s\S.]*)<\/body>/i)[0]))
var head = data.match(/<head[^>]*>([\s\S.]*)<\/head>/i)
var $head = head != null ? $(parseHTML(head[0])) : $body
$head = head != null ? $(parseHTML(head[0])) : $body
} else {
var $head = $body = $(parseHTML(data))
$head = $body = $(parseHTML(data))
}

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

if (options.fragment) {
var $fragment = $body
// If they specified a fragment, look for it in the response
// and pull it out.
if (options.fragment === 'body') {
var $fragment = $body
} else {
var $fragment = findAll($body, options.fragment).first()
if (options.fragment !== 'body') {
$fragment = findAll($fragment, options.fragment).first()
}

if ($fragment.length) {
Expand Down Expand Up @@ -797,8 +797,8 @@ function cachePop(direction, id, value) {
}

pushStack.push(id)
if (id = popStack.pop())
delete cacheMapping[id]
id = popStack.pop()
if (id) delete cacheMapping[id]

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

$.support.pjax ? enable() : disable()
if ($.support.pjax) {
enable()
} else {
disable()
}

})(jQuery)
5 changes: 4 additions & 1 deletion package.json
Expand Up @@ -12,5 +12,8 @@
"files" : [
"LICENSE",
"jquery.pjax.js"
]
],
"devDependencies": {
"eslint": "^3.19.0"
}
}
1 change: 1 addition & 0 deletions script/bootstrap
@@ -1,6 +1,7 @@
#!/usr/bin/env bash
set -e

npm install
bundle install

if phantom_version="$(phantomjs --version)"; then
Expand Down
4 changes: 2 additions & 2 deletions script/test
@@ -1,6 +1,8 @@
#!/usr/bin/env bash
set -e

./node_modules/.bin/eslint *.js

port=3999
script/server -p "$port" &>/dev/null &
pid=$!
Expand All @@ -11,8 +13,6 @@ while ! lsof -i :$port >/dev/null; do
sleep .05
done

[ -z "$CI" ] || echo "PhantomJS $(phantomjs --version)"

phantomjs ./test/run-qunit.js \
"http://localhost:$port/?jquery=3.2" \
"http://localhost:$port/?jquery=2.2" \
Expand Down

0 comments on commit c9acf5e

Please sign in to comment.