Add eslint and hound

This commit is contained in:
Antoine Vandecreme 2017-01-08 15:52:57 +01:00
parent 537c3d04c1
commit de25b68b43
24 changed files with 721 additions and 97 deletions

285
.eslintrc.hound.json Normal file
View File

@ -0,0 +1,285 @@
{
"env": {
"browser": true
},
"extends": "eslint:recommended",
"rules": {
"indent": [
"error",
4
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"double"
],
"semi": [
"error",
"always"
],
"no-unused-vars": [
"error",
{
"args": "none"
}
],
"block-scoped-var": [
"error"
],
"consistent-return": [
"error"
],
"curly": [
"error",
"all"
],
"eqeqeq": [
"error"
],
"no-eval": [
"error"
],
"no-implicit-globals": [
"error"
],
"no-implied-eval": [
"error"
],
"no-invalid-this": [
"error"
],
"no-multi-spaces": [
"error",
{
"exceptions": {
"Property": true,
"VariableDeclarator": true,
"AssignmentExpression": true
}
}
],
"no-new-wrappers": [
"error"
],
"no-new": [
"error"
],
"no-return-assign": [
"error"
],
"no-self-compare": [
"error"
],
"no-unmodified-loop-condition": [
"error"
],
"no-unused-expressions": [
"error"
],
"no-useless-call": [
"error"
],
"no-useless-concat": [
"error"
],
"no-useless-escape": [
"error"
],
"no-useless-return": [
"error"
],
"no-with": [
"error"
],
"radix": [
"error"
],
"yoda": [
"error"
],
"no-undef-init": [
"error"
],
"no-use-before-define": [
"error",
{
"functions": false
}
],
"array-bracket-spacing": [
"error",
"never"
],
"block-spacing": [
"error"
],
"brace-style": [
"error"
],
"camelcase": [
"error"
],
"comma-spacing": [
"error"
],
"comma-style": [
"error"
],
"computed-property-spacing": [
"error"
],
"consistent-this": [
"error",
"self"
],
"eol-last": [
"error"
],
"func-call-spacing": [
"error"
],
"func-name-matching": [
"error"
],
"key-spacing": [
"error",
{
"mode": "minimum"
}
],
"keyword-spacing": [
"error"
],
"max-len": [
"error",
80
],
"max-statements-per-line": [
"error",
{
"max": 1
}
],
"new-cap": [
"error"
],
"new-parens": [
"error"
],
"no-array-constructor": [
"error"
],
"no-mixed-operators": [
"error",
{
"groups": [
[
"&",
"|",
"^",
"~",
"<<",
">>",
">>>"
],
[
"==",
"!=",
"===",
"!==",
">",
">=",
"<",
"<="
],
[
"&&",
"||"
],
[
"in",
"instanceof"
]
]
}
],
"no-new-object": [
"error"
],
"no-tabs": [
"error"
],
"no-trailing-spaces": [
"error"
],
"no-unneeded-ternary": [
"error"
],
"no-whitespace-before-property": [
"error"
],
"object-curly-spacing": [
"error",
"always"
],
"one-var-declaration-per-line": [
"error"
],
"one-var": [
"error",
"never"
],
"operator-assignment": [
"error"
],
"operator-linebreak": [
"error",
"after"
],
"quote-props": [
"error",
"as-needed"
],
"semi-spacing": [
"error"
],
"space-before-blocks": [
"error"
],
"space-before-function-paren": [
"error",
"never"
],
"space-in-parens": [
"error",
"never"
],
"space-infix-ops": [
"error"
],
"space-unary-ops": [
"error",
{
"words": false,
"nonwords": false
}
],
"unicode-bom": [
"error"
],
"no-caller": [
"error"
],
"no-loop-func": [
"error"
]
},
"globals": {
"OpenSeadragon": true,
"define": false,
"module": false
}
}

285
.eslintrc.json Normal file
View File

@ -0,0 +1,285 @@
{
"env": {
"browser": true
},
"extends": "eslint:recommended",
"rules": {
"indent": [
"off",
4
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"off",
"double"
],
"semi": [
"error",
"always"
],
"no-unused-vars": [
"error",
{
"args": "none"
}
],
"block-scoped-var": [
"error"
],
"consistent-return": [
"off"
],
"curly": [
"error",
"all"
],
"eqeqeq": [
"off"
],
"no-eval": [
"error"
],
"no-implicit-globals": [
"error"
],
"no-implied-eval": [
"error"
],
"no-invalid-this": [
"error"
],
"no-multi-spaces": [
"error",
{
"exceptions": {
"Property": true,
"VariableDeclarator": true,
"AssignmentExpression": true
}
}
],
"no-new-wrappers": [
"error"
],
"no-new": [
"error"
],
"no-return-assign": [
"error"
],
"no-self-compare": [
"error"
],
"no-unmodified-loop-condition": [
"error"
],
"no-unused-expressions": [
"error"
],
"no-useless-call": [
"error"
],
"no-useless-concat": [
"error"
],
"no-useless-escape": [
"off"
],
"no-useless-return": [
"error"
],
"no-with": [
"error"
],
"radix": [
"error"
],
"yoda": [
"off"
],
"no-undef-init": [
"error"
],
"no-use-before-define": [
"error",
{
"functions": false
}
],
"array-bracket-spacing": [
"off",
"never"
],
"block-spacing": [
"off"
],
"brace-style": [
"off"
],
"camelcase": [
"error"
],
"comma-spacing": [
"error"
],
"comma-style": [
"error"
],
"computed-property-spacing": [
"off"
],
"consistent-this": [
"off",
"self"
],
"eol-last": [
"error"
],
"func-call-spacing": [
"error"
],
"func-name-matching": [
"error"
],
"key-spacing": [
"error",
{
"mode": "minimum"
}
],
"keyword-spacing": [
"off"
],
"max-len": [
"off",
80
],
"max-statements-per-line": [
"error",
{
"max": 1
}
],
"new-cap": [
"error"
],
"new-parens": [
"error"
],
"no-array-constructor": [
"error"
],
"no-mixed-operators": [
"error",
{
"groups": [
[
"&",
"|",
"^",
"~",
"<<",
">>",
">>>"
],
[
"==",
"!=",
"===",
"!==",
">",
">=",
"<",
"<="
],
[
"&&",
"||"
],
[
"in",
"instanceof"
]
]
}
],
"no-new-object": [
"error"
],
"no-tabs": [
"error"
],
"no-trailing-spaces": [
"error"
],
"no-unneeded-ternary": [
"error"
],
"no-whitespace-before-property": [
"error"
],
"object-curly-spacing": [
"off",
"always"
],
"one-var-declaration-per-line": [
"error"
],
"one-var": [
"off",
"never"
],
"operator-assignment": [
"error"
],
"operator-linebreak": [
"error",
"after"
],
"quote-props": [
"off",
"as-needed"
],
"semi-spacing": [
"error"
],
"space-before-blocks": [
"off"
],
"space-before-function-paren": [
"off",
"never"
],
"space-in-parens": [
"off",
"never"
],
"space-infix-ops": [
"error"
],
"space-unary-ops": [
"error",
{
"words": false,
"nonwords": false
}
],
"unicode-bom": [
"error"
],
"no-caller": [
"error"
],
"no-loop-func": [
"error"
]
},
"globals": {
"OpenSeadragon": true,
"define": false,
"module": false
}
}

6
.hound.yml Normal file
View File

@ -0,0 +1,6 @@
jshint:
config_file: .jshintrc
eslint:
enabled: true
config_file: .eslintrc.hound.json

View File

@ -11,6 +11,7 @@ module.exports = function(grunt) {
grunt.loadNpmTasks("grunt-contrib-connect");
grunt.loadNpmTasks("grunt-contrib-watch");
grunt.loadNpmTasks("grunt-contrib-clean");
grunt.loadNpmTasks("grunt-eslint");
grunt.loadNpmTasks("grunt-git-describe");
grunt.loadNpmTasks('grunt-text-replace');
@ -194,6 +195,12 @@ module.exports = function(grunt) {
beforeconcat: sources,
afterconcat: [ distribution ]
},
eslint: {
options: {
configFile: '.eslintrc.json'
},
target: sources
},
"git-describe": {
build: {}
}
@ -266,7 +273,7 @@ module.exports = function(grunt) {
// Cleans out the build folder and builds the code and images into it, checking lint.
grunt.registerTask("build", [
"clean:build", "jshint:beforeconcat", "git-describe", "concat", "jshint:afterconcat",
"uglify", "replace:cleanPaths", "copy:build"
"eslint", "uglify", "replace:cleanPaths", "copy:build"
]);
// ----------

View File

@ -24,6 +24,7 @@
"grunt-contrib-uglify": "^2.0.0",
"grunt-contrib-watch": "^0.6.1",
"grunt-git-describe": "^2.3.2",
"grunt-eslint": "^19.0.0",
"grunt-qunit-istanbul": "^0.6.0",
"grunt-text-replace": "^0.4.0",
"qunitjs": "^1.20.0"

View File

@ -45,6 +45,7 @@
*/
$.IIIFTileSource = function( options ){
/* eslint-disable camelcase */
$.extend( true, this, options );
@ -400,7 +401,9 @@ $.extend( $.IIIFTileSource.prototype, $.TileSource.prototype, /** @lends OpenSea
height: options.sizes[i].height
});
}
return levels.sort(function(a,b){return a.width - b.width;});
return levels.sort(function(a, b) {
return a.width - b.width;
});
}

View File

@ -160,6 +160,7 @@
* @memberof OpenSeadragon.MouseTracker#
*/
this.dblClickDistThreshold = options.dblClickDistThreshold || $.DEFAULT_SETTINGS.dblClickDistThreshold;
/*eslint-disable no-multi-spaces*/
this.userData = options.userData || null;
this.stopDelay = options.stopDelay || 50;
@ -182,6 +183,7 @@
this.keyHandler = options.keyHandler || null;
this.focusHandler = options.focusHandler || null;
this.blurHandler = options.blurHandler || null;
/*eslint-enable no-multi-spaces*/
//Store private properties in a scope sealed hash map
var _this = this;
@ -1370,6 +1372,7 @@
eventParams = getCaptureEventParams( tracker, $.MouseTracker.havePointerEvents ? 'pointerevent' : pointerType );
// We emulate mouse capture by hanging listeners on the document object.
// (Note we listen on the capture phase so the captured handlers will get called first)
// eslint-disable-next-line no-use-before-define
if (isInIframe && canAccessEvents(window.top)) {
$.addEvent(
window.top,
@ -1413,6 +1416,7 @@
eventParams = getCaptureEventParams( tracker, $.MouseTracker.havePointerEvents ? 'pointerevent' : pointerType );
// We emulate mouse capture by hanging listeners on the document object.
// (Note we listen on the capture phase so the captured handlers will get called first)
// eslint-disable-next-line no-use-before-define
if (isInIframe && canAccessEvents(window.top)) {
$.removeEvent(
window.top,
@ -1703,7 +1707,7 @@
// Calculate deltaY
if ( $.MouseTracker.wheelEventName == "mousewheel" ) {
simulatedEvent.deltaY = - 1 / $.DEFAULT_SETTINGS.pixelsPerWheelLine * event.wheelDelta;
simulatedEvent.deltaY = -event.wheelDelta / $.DEFAULT_SETTINGS.pixelsPerWheelLine;
} else {
simulatedEvent.deltaY = event.detail;
}
@ -2207,10 +2211,7 @@
* @inner
*/
function onTouchCancel( tracker, event ) {
var i,
touchCount = event.changedTouches.length,
gPoints = [],
pointsList = tracker.getActivePointersListByType( 'touch' );
var pointsList = tracker.getActivePointersListByType('touch');
abortTouchContacts( tracker, event, pointsList );
}
@ -2565,8 +2566,7 @@
* Gesture points associated with the event.
*/
function updatePointersExit( tracker, event, gPoints ) {
var delegate = THIS[ tracker.hash ],
pointsList = tracker.getActivePointersListByType( gPoints[ 0 ].type ),
var pointsList = tracker.getActivePointersListByType(gPoints[0].type),
i,
gPointCount = gPoints.length,
curGPoint,
@ -2801,7 +2801,6 @@
var delegate = THIS[ tracker.hash ],
pointsList = tracker.getActivePointersListByType( gPoints[ 0 ].type ),
propagate,
insideElementReleased,
releasePoint,
releaseTime,
i,

View File

@ -859,7 +859,7 @@ function OpenSeadragon( options ){
try {
// We test if the canvas is tainted by retrieving data from it.
// An exception will be raised if the canvas is tainted.
var data = canvas.getContext('2d').getImageData(0, 0, 1, 1);
canvas.getContext('2d').getImageData(0, 0, 1, 1);
} catch (e) {
isTainted = true;
}
@ -1026,10 +1026,46 @@ function OpenSeadragon( options ){
dblClickDistThreshold: 20,
springStiffness: 6.5,
animationTime: 1.2,
gestureSettingsMouse: { scrollToZoom: true, clickToZoom: true, dblClickToZoom: false, pinchToZoom: false, flickEnabled: false, flickMinSpeed: 120, flickMomentum: 0.25, pinchRotate: false },
gestureSettingsTouch: { scrollToZoom: false, clickToZoom: false, dblClickToZoom: true, pinchToZoom: true, flickEnabled: true, flickMinSpeed: 120, flickMomentum: 0.25, pinchRotate: false },
gestureSettingsPen: { scrollToZoom: false, clickToZoom: true, dblClickToZoom: false, pinchToZoom: false, flickEnabled: false, flickMinSpeed: 120, flickMomentum: 0.25, pinchRotate: false },
gestureSettingsUnknown: { scrollToZoom: false, clickToZoom: false, dblClickToZoom: true, pinchToZoom: true, flickEnabled: true, flickMinSpeed: 120, flickMomentum: 0.25, pinchRotate: false },
gestureSettingsMouse: {
scrollToZoom: true,
clickToZoom: true,
dblClickToZoom: false,
pinchToZoom: false,
flickEnabled: false,
flickMinSpeed: 120,
flickMomentum: 0.25,
pinchRotate: false
},
gestureSettingsTouch: {
scrollToZoom: false,
clickToZoom: false,
dblClickToZoom: true,
pinchToZoom: true,
flickEnabled: true,
flickMinSpeed: 120,
flickMomentum: 0.25,
pinchRotate: false
},
gestureSettingsPen: {
scrollToZoom: false,
clickToZoom: true,
dblClickToZoom: false,
pinchToZoom: false,
flickEnabled: false,
flickMinSpeed: 120,
flickMomentum: 0.25,
pinchRotate: false
},
gestureSettingsUnknown: {
scrollToZoom: false,
clickToZoom: false,
dblClickToZoom: true,
pinchToZoom: true,
flickEnabled: true,
flickMinSpeed: 120,
flickMomentum: 0.25,
pinchRotate: false
},
zoomPerClick: 2,
zoomPerScroll: 1.2,
zoomPerSecond: 1.0,
@ -1675,7 +1711,9 @@ function OpenSeadragon( options ){
if (Date.now) {
$.now = Date.now;
} else {
$.now = function() { return new Date().getTime(); };
$.now = function() {
return new Date().getTime();
};
}
return $.now();
@ -2012,6 +2050,7 @@ function OpenSeadragon( options ){
* @returns {String} The value of the url parameter or null if no param matches.
*/
getUrlParameter: function( key ) {
// eslint-disable-next-line no-use-before-define
var value = URLPARAMS[ key ];
return value ? value : null;
},
@ -2332,6 +2371,7 @@ function OpenSeadragon( options ){
// Should only be used by IE8 in non standards mode
$.parseJSON = function(string) {
/*jshint evil:true*/
//eslint-disable-next-line no-eval
return eval('(' + string + ')');
};
}
@ -2347,6 +2387,7 @@ function OpenSeadragon( options ){
*/
imageFormatSupported: function( extension ) {
extension = extension ? extension : "";
// eslint-disable-next-line no-use-before-define
return !!FILEFORMATS[ extension.toLowerCase() ];
}
@ -2383,8 +2424,7 @@ function OpenSeadragon( options ){
(function() {
//A small auto-executing routine to determine the browser vendor,
//version and supporting feature sets.
var app = navigator.appName,
ver = navigator.appVersion,
var ver = navigator.appVersion,
ua = navigator.userAgent,
regex;
@ -2406,7 +2446,7 @@ function OpenSeadragon( options ){
}
break;
case "Netscape":
if( !!window.addEventListener ){
if (window.addEventListener) {
if ( ua.indexOf( "Firefox" ) >= 0 ) {
$.Browser.vendor = $.BROWSERS.FIREFOX;
$.Browser.version = parseFloat(

View File

@ -592,6 +592,4 @@ function onKeyPress( event ) {
}
}
}(OpenSeadragon));

View File

@ -268,7 +268,7 @@ $.Viewer = function( options ) {
this.innerTracker = new $.MouseTracker({
element: this.canvas,
startDisabled: this.mouseNavEnabled ? false : true,
startDisabled: !this.mouseNavEnabled,
clickTimeThreshold: this.clickTimeThreshold,
clickDistThreshold: this.clickDistThreshold,
dblClickTimeThreshold: this.dblClickTimeThreshold,
@ -291,7 +291,7 @@ $.Viewer = function( options ) {
this.outerTracker = new $.MouseTracker({
element: this.container,
startDisabled: this.mouseNavEnabled ? false : true,
startDisabled: !this.mouseNavEnabled,
clickTimeThreshold: this.clickTimeThreshold,
clickDistThreshold: this.clickDistThreshold,
dblClickTimeThreshold: this.dblClickTimeThreshold,
@ -869,7 +869,6 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
bodyStyle = body.style,
docStyle = document.documentElement.style,
_this = this,
hash,
nodes,
i;
@ -1032,8 +1031,8 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
var pageScroll = $.getPageScroll();
restoreScrollCounter++;
if (restoreScrollCounter < 10 &&
pageScroll.x !== _this.pageScroll.x ||
pageScroll.y !== _this.pageScroll.y ) {
(pageScroll.x !== _this.pageScroll.x ||
pageScroll.y !== _this.pageScroll.y)) {
$.requestAnimationFrame( restoreScroll );
}
};

View File

@ -212,7 +212,8 @@ $.extend( $.World.prototype, $.EventSource.prototype, /** @lends OpenSeadragon.W
// We need to make sure any pending images are canceled so the world items don't get messed up
this.viewer._cancelPendingImages();
var item;
for (var i = 0; i < this._items.length; i++) {
var i;
for (i = 0; i < this._items.length; i++) {
item = this._items[i];
item.removeHandler('bounds-change', this._delegatedFigureSizes);
item.removeHandler('clip-change', this._delegatedFigureSizes);