From 3dd58d7a7724a5b1ac8bcbd02f7469455eab9566 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Scott=20Gonz=C3=A1lez?= Date: Wed, 29 Apr 2015 15:12:24 -0400 Subject: [PATCH] Build: Add JSHint for additional linting Ref gh-185 --- .jshintrc | 20 +++++++++++++++++--- Gruntfile.js | 9 ++++++++- package.json | 1 + src/.jshintrc | 21 +++++++++++++++++++++ src/installer.js | 7 ------- src/targeting.js | 4 ++-- src/touch-action.js | 1 - src/touch.js | 3 +-- tests/.jshintrc | 21 +++++++++++++++++++++ tests/unit/capture.js | 2 +- tests/unit/pointermap.js | 3 --- 11 files changed, 72 insertions(+), 20 deletions(-) create mode 100644 src/.jshintrc create mode 100644 tests/.jshintrc diff --git a/.jshintrc b/.jshintrc index 50d29955..c29f1898 100644 --- a/.jshintrc +++ b/.jshintrc @@ -1,7 +1,21 @@ { - "browser": true, + "boss": true, + "curly": true, + "eqeqeq": true, + "eqnull": true, "expr": true, - "predef": [ "define" ], + "immed": true, + "noarg": true, + "smarttabs": true, + "trailing": true, "undef": true, - "unused": true + "unused": true, + + "node": true, + "esnext": true, + + "globals": { + "define": false, + "PointerEvent": true + } } diff --git a/Gruntfile.js b/Gruntfile.js index 687e16e8..996c3421 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,4 +1,5 @@ module.exports = function(grunt) { + grunt.loadNpmTasks('grunt-contrib-jshint'); grunt.loadNpmTasks('grunt-contrib-uglify'); grunt.loadNpmTasks('grunt-git-authors'); grunt.loadNpmTasks('grunt-jscs'); @@ -62,6 +63,12 @@ module.exports = function(grunt) { src: allFiles } } + }, + jshint: { + options: { + jshintrc: true + }, + main: allFiles } }); @@ -96,7 +103,7 @@ module.exports = function(grunt) { }); grunt.registerTask('default', [ 'lint', 'build', 'uglify' ]); - grunt.registerTask('lint', [ 'jscs:lint' ]); + grunt.registerTask('lint', [ 'jscs:lint', 'jshint' ]); grunt.registerTask('test', [ 'intern:pointerevents' ]); grunt.registerTask('ci', [ 'lint', 'build', 'intern:ci' ]); }; diff --git a/package.json b/package.json index 35e59d4f..476d4fd3 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "chai-spies": "^0.5.1", "esperanto": "^0.6.6", "grunt": "~0.4.1", + "grunt-contrib-jshint": "0.11.2", "grunt-contrib-uglify": "^0.4.0", "grunt-git-authors": "^3.0.0", "grunt-jscs": "1.8.0", diff --git a/src/.jshintrc b/src/.jshintrc new file mode 100644 index 00000000..97154530 --- /dev/null +++ b/src/.jshintrc @@ -0,0 +1,21 @@ +{ + "boss": true, + "curly": true, + "eqeqeq": true, + "eqnull": true, + "expr": true, + "immed": true, + "noarg": true, + "smarttabs": true, + "trailing": true, + "undef": true, + "unused": true, + + "browser": true, + "esnext": true, + + "globals": { + "define": false, + "PointerEvent": true + } +} diff --git a/src/installer.js b/src/installer.js index 4eb1d72e..0b279ea3 100644 --- a/src/installer.js +++ b/src/installer.js @@ -111,11 +111,4 @@ Installer.prototype = { } }; -if (!MO) { - Installer.prototype.watchSubtree = function() { - console.warn('PointerEventsPolyfill: MutationObservers not found, ' + - 'touch-action will not be dynamically detected'); - }; -} - export default Installer; diff --git a/src/targeting.js b/src/targeting.js index 743a92a1..84b94d02 100644 --- a/src/targeting.js +++ b/src/targeting.js @@ -35,7 +35,7 @@ export default { searchRoot: function(inRoot, x, y) { if (inRoot) { var t = inRoot.elementFromPoint(x, y); - var st, sr, os; + var st, sr; // is element a shadow host? sr = this.targetingShadow(t); @@ -68,7 +68,7 @@ export default { } // the owner element is expected to be a Document or ShadowRoot - if (s.nodeType != Node.DOCUMENT_NODE && s.nodeType != Node.DOCUMENT_FRAGMENT_NODE) { + if (s.nodeType !== Node.DOCUMENT_NODE && s.nodeType !== Node.DOCUMENT_FRAGMENT_NODE) { s = document; } return s; diff --git a/src/touch-action.js b/src/touch-action.js index ca4e5b58..15c50023 100644 --- a/src/touch-action.js +++ b/src/touch-action.js @@ -23,7 +23,6 @@ var attrib2css = [ var styles = ''; // only install stylesheet if the browser has touch action support -var head = document.head; var hasNativePE = window.PointerEvent || window.MSPointerEvent; // only add shadow selectors if shadowdom is supported diff --git a/src/touch.js b/src/touch.js index 5eb3d210..7654423e 100644 --- a/src/touch.js +++ b/src/touch.js @@ -7,7 +7,6 @@ var captureInfo = dispatcher.captureInfo; var findTarget = targeting.findTarget.bind(targeting); var allShadows = targeting.allShadows.bind(targeting); var pointermap = dispatcher.pointermap; -var touchMap = Array.prototype.map.call.bind(Array.prototype.map); // This should be long enough to ignore compat mouse events made by touch var DEDUP_TIMEOUT = 2500; @@ -261,7 +260,7 @@ var touchEvents = { } }, overDown: function(inPointer) { - var p = pointermap.set(inPointer.pointerId, { + pointermap.set(inPointer.pointerId, { target: inPointer.target, out: inPointer, outTarget: inPointer.target diff --git a/tests/.jshintrc b/tests/.jshintrc new file mode 100644 index 00000000..97154530 --- /dev/null +++ b/tests/.jshintrc @@ -0,0 +1,21 @@ +{ + "boss": true, + "curly": true, + "eqeqeq": true, + "eqnull": true, + "expr": true, + "immed": true, + "noarg": true, + "smarttabs": true, + "trailing": true, + "undef": true, + "unused": true, + + "browser": true, + "esnext": true, + + "globals": { + "define": false, + "PointerEvent": true + } +} diff --git a/tests/unit/capture.js b/tests/unit/capture.js index 6890d5e6..2810f70a 100644 --- a/tests/unit/capture.js +++ b/tests/unit/capture.js @@ -125,7 +125,7 @@ define([ var ids = 0; function wait(e) { ids += e.pointerId; - if (ids == 3) { + if (ids === 3) { pm.clear(); dfd.resolve(); } diff --git a/tests/unit/pointermap.js b/tests/unit/pointermap.js index cd731915..a6ce6e18 100644 --- a/tests/unit/pointermap.js +++ b/tests/unit/pointermap.js @@ -32,9 +32,6 @@ define([ } expect(p.pointers()).to.equal(1); }); - test('PointerMap .get', function() { - var p = new PointerMap(); - }); test('PointerMap .pointers', function() { var p = new PointerMap(); expect(p.pointers).to.be.a('function');