CB-10636 Add JSHint for plugins
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/commit/418e904a Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/tree/418e904a Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/diff/418e904a Branch: refs/heads/1.5.x Commit: 418e904a98c0283cfa07fa8ca22997080d0851a4 Parents: afbeab4 Author: daserge <[email protected]> Authored: Thu Feb 25 14:30:21 2016 +0300 Committer: daserge <[email protected]> Committed: Mon Feb 29 11:59:58 2016 +0300 ---------------------------------------------------------------------- .jscsrc | 1 - .jshintrc | 106 +++++-------------------------- .travis.yml | 4 ++ README.md | 2 + package.json | 4 +- src/windows/FileTransferProxy.js | 25 ++++---- www/FileTransfer.js | 6 +- www/blackberry10/.jshintrc | 5 ++ www/blackberry10/FileTransfer.js | 6 +- www/blackberry10/xhrFileTransfer.js | 5 +- www/browser/FileTransfer.js | 32 +++++++--- www/firefoxos/FileTransferProxy.js | 3 +- www/wp7/base64.js | 2 + 13 files changed, 81 insertions(+), 120 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/418e904a/.jscsrc ---------------------------------------------------------------------- diff --git a/.jscsrc b/.jscsrc index 9c04214..2656b94 100644 --- a/.jscsrc +++ b/.jscsrc @@ -1,7 +1,6 @@ { "disallowMixedSpacesAndTabs": true, "disallowTrailingWhitespace": true, - "validateLineBreaks": "CRLF", "validateIndentation": 4, "requireLineFeedAtFileEnd": true, http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/418e904a/.jshintrc ---------------------------------------------------------------------- diff --git a/.jshintrc b/.jshintrc index 52ecff1..93c3c13 100644 --- a/.jshintrc +++ b/.jshintrc @@ -1,91 +1,19 @@ { - // Copied from http://jshint.com/docs/ - - "maxerr" : 50, // {int} Maximum error before stopping - - // Enforcing - "bitwise" : true, // true: Prohibit bitwise operators (&, |, ^, etc.) - "camelcase" : false, // true: Identifiers must be in camelCase - "curly" : true, // true: Require {} for every new block or scope - "eqeqeq" : true, // true: Require triple equals (===) for comparison - "forin" : true, // true: Require filtering for..in loops with obj.hasOwnProperty() - "freeze" : true, // true: prohibits overwriting prototypes of native objects such as Array, Date etc. - "immed" : true, // true: Require immediate invocations to be wrapped in parens e.g. `(function () { } ());` - "latedef" : true, // true: Require variables/functions to be defined before being used - "newcap" : true, // true: Require capitalization of all constructor functions e.g. `new F()` - "noarg" : true, // true: Prohibit use of `arguments.caller` and `arguments.callee` - "noempty" : true, // true: Prohibit use of empty blocks - "nonbsp" : true, // true: Prohibit "non-breaking whitespace" characters. - "nonew" : true, // true: Prohibit use of constructors for side-effects (without assignment) - "plusplus" : true, // true: Prohibit use of `++` and `--` - "quotmark" : false, // Quotation mark consistency: - // false : do nothing (default) - // true : ensure whatever is used is consistent - // "single" : require single quotes - // "double" : require double quotes - "undef" : true, // true: Require all non-global variables to be declared (prevents global leaks) - "unused" : "strict", // Unused variables: - // true : all variables, last function parameter - // "vars" : all variables only - // "strict" : all variables, all function parameters - "strict" : true, // true: Requires all functions run in ES5 Strict Mode - "maxparams" : false, // {int} Max number of formal params allowed per function - "maxdepth" : false, // {int} Max depth of nested blocks (within functions) - "maxstatements" : false, // {int} Max number statements per function - "maxcomplexity" : false, // {int} Max cyclomatic complexity per function - "maxlen" : false, // {int} Max number of characters per line - "varstmt" : false, // true: Disallow any var statements. Only `let` and `const` are allowed. - - // Relaxing - "asi" : false, // true: Tolerate Automatic Semicolon Insertion (no semicolons) - "boss" : false, // true: Tolerate assignments where comparisons would be expected - "debug" : false, // true: Allow debugger statements e.g. browser breakpoints. - "eqnull" : false, // true: Tolerate use of `== null` - "es5" : false, // true: Allow ES5 syntax (ex: getters and setters) - "esnext" : false, // true: Allow ES.next (ES6) syntax (ex: `const`) - "moz" : false, // true: Allow Mozilla specific syntax (extends and overrides esnext features) - // (ex: `for each`, multiple try/catch, function expressionâ¦) - "evil" : false, // true: Tolerate use of `eval` and `new Function()` - "expr" : false, // true: Tolerate `ExpressionStatement` as Programs - "funcscope" : false, // true: Tolerate defining variables inside control statements - "globalstrict" : false, // true: Allow global "use strict" (also enables 'strict') - "iterator" : false, // true: Tolerate using the `__iterator__` property - "lastsemic" : false, // true: Tolerate omitting a semicolon for the last statement of a 1-line block - "laxbreak" : false, // true: Tolerate possibly unsafe line breakings - "laxcomma" : false, // true: Tolerate comma-first style coding - "loopfunc" : false, // true: Tolerate functions being defined in loops - "multistr" : false, // true: Tolerate multi-line strings - "noyield" : false, // true: Tolerate generator functions with no yield statement in them. - "notypeof" : false, // true: Tolerate invalid typeof operator values - "proto" : false, // true: Tolerate using the `__proto__` property - "scripturl" : false, // true: Tolerate script-targeted URLs - "shadow" : false, // true: Allows re-define variables later in code e.g. `var x=1; x=2;` - "sub" : false, // true: Tolerate using `[]` notation when it can still be expressed in dot notation - "supernew" : false, // true: Tolerate `new function () { ... };` and `new Object;` - "validthis" : false, // true: Tolerate using this in a non-constructor function - - // Environments - "browser" : true, // Web Browser (window, document, etc) - "browserify" : false, // Browserify (node.js code in the browser) - "couch" : false, // CouchDB - "devel" : true, // Development/debugging (alert, confirm, etc) - "dojo" : false, // Dojo Toolkit - "jasmine" : true, // Jasmine - "jquery" : false, // jQuery - "mocha" : false, // Mocha - "mootools" : false, // MooTools - "node" : false, // Node.js - "nonstandard" : false, // Widely adopted globals (escape, unescape, etc) - "phantom" : false, // PhantomJS - "prototypejs" : false, // Prototype and Scriptaculous - "qunit" : false, // QUnit - "rhino" : false, // Rhino - "shelljs" : false, // ShellJS - "typed" : false, // Globals for typed array constructions - "worker" : false, // Web Workers - "wsh" : false, // Windows Scripting Host - "yui" : false, // Yahoo User Interface - - // Custom Globals - "globals" : {} // additional predefined global variables + "browser": true + , "devel": true + , "bitwise": true + , "undef": true + , "trailing": true + , "quotmark": false + , "indent": 4 + , "unused": "vars" + , "latedef": "nofunc" + , "globals": { + "module": false, + "exports": false, + "require": false, + "FileTransferError": true, + "FileUploadResult": true, + "resolveLocalFileSystemURI": false + } } http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/418e904a/.travis.yml ---------------------------------------------------------------------- diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..b9af4c5 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,4 @@ +language: node_js +sudo: false +node_js: + - "4.2" http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/418e904a/README.md ---------------------------------------------------------------------- diff --git a/README.md b/README.md index 9b10c60..aee5c11 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,8 @@ # under the License. --> +[](https://travis-ci.org/apache/cordova-plugin-file-transfer) + # cordova-plugin-file-transfer This plugin allows you to upload and download files. http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/418e904a/package.json ---------------------------------------------------------------------- diff --git a/package.json b/package.json index 0551d22..bc9f674 100644 --- a/package.json +++ b/package.json @@ -20,8 +20,8 @@ }, "scripts": { "test": "npm run lint && npm run style", - "style": "node_modules/.bin/jscs tests/tests.js", - "lint": "node_modules/.bin/jshint tests/tests.js" + "lint": "jshint www && jshint src && jshint tests", + "style": "jscs tests/tests.js" }, "repository": { "type": "git", http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/418e904a/src/windows/FileTransferProxy.js ---------------------------------------------------------------------- diff --git a/src/windows/FileTransferProxy.js b/src/windows/FileTransferProxy.js index d5ef9ba..1a506e6 100644 --- a/src/windows/FileTransferProxy.js +++ b/src/windows/FileTransferProxy.js @@ -26,8 +26,7 @@ var FTErr = require('./FileTransferError'), ProgressEvent = require('cordova-plugin-file.ProgressEvent'), FileUploadResult = require('cordova-plugin-file.FileUploadResult'), - FileProxy = require('cordova-plugin-file.FileProxy'), - FileEntry = require('cordova-plugin-file.FileEntry'); + FileProxy = require('cordova-plugin-file.FileProxy'); var appData = Windows.Storage.ApplicationData.current; @@ -35,6 +34,8 @@ var LINE_START = "--"; var LINE_END = "\r\n"; var BOUNDARY = '+++++'; +var fileTransferOps = []; + // Some private helper functions, hidden by the module function cordovaPathToNative(path) { @@ -144,8 +145,6 @@ function doUpload (upload, uploadId, filePath, server, successCallback, errorCal ); } -var fileTransferOps = []; - function FileTransferOperation(state, promise) { this.state = state; this.promise = promise; @@ -178,6 +177,15 @@ exec(win, fail, 'FileTransfer', 'upload', var isMultipart = typeof headers["Content-Type"] === 'undefined'; + function stringToByteArray(str) { + var byteCharacters = atob(str); + var byteNumbers = new Array(byteCharacters.length); + for (var i = 0; i < byteCharacters.length; i++) { + byteNumbers[i] = byteCharacters.charCodeAt(i); + } + return new Uint8Array(byteNumbers); + } + if (!filePath || (typeof filePath !== 'string')) { errorCallback(new FTErr(FTErr.FILE_NOT_FOUND_ERR, null, server)); return; @@ -201,15 +209,6 @@ exec(win, fail, 'FileTransfer', 'upload', var fileDataString = filePath.substr(commaIndex + 1); - function stringToByteArray(str) { - var byteCharacters = atob(str); - var byteNumbers = new Array(byteCharacters.length); - for (var i = 0; i < byteCharacters.length; i++) { - byteNumbers[i] = byteCharacters.charCodeAt(i); - } - return new Uint8Array(byteNumbers); - }; - // setting request headers for uploader var uploader = new Windows.Networking.BackgroundTransfer.BackgroundUploader(); uploader.method = httpMethod; http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/418e904a/www/FileTransfer.js ---------------------------------------------------------------------- diff --git a/www/FileTransfer.js b/www/FileTransfer.js index add97da..80cf91c 100644 --- a/www/FileTransfer.js +++ b/www/FileTransfer.js @@ -19,6 +19,8 @@ * */ +/* global cordova, FileSystem */ + var argscheck = require('cordova/argscheck'), exec = require('cordova/exec'), FileTransferError = require('./FileTransferError'), @@ -156,7 +158,9 @@ FileTransfer.prototype.upload = function(filePath, server, successCallback, erro self.onprogress(newProgressEvent(result)); } } else { - successCallback && successCallback(result); + if (successCallback) { + successCallback(result); + } } }; exec(win, fail, 'FileTransfer', 'upload', [filePath, server, fileKey, fileName, mimeType, params, trustAllHosts, chunkedMode, headers, this._id, httpMethod]); http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/418e904a/www/blackberry10/.jshintrc ---------------------------------------------------------------------- diff --git a/www/blackberry10/.jshintrc b/www/blackberry10/.jshintrc new file mode 100644 index 0000000..85ccb32 --- /dev/null +++ b/www/blackberry10/.jshintrc @@ -0,0 +1,5 @@ +{ + "globals": { + "requestAnimationFrame": true + } +} http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/418e904a/www/blackberry10/FileTransfer.js ---------------------------------------------------------------------- diff --git a/www/blackberry10/FileTransfer.js b/www/blackberry10/FileTransfer.js index f74914a..76e1682 100644 --- a/www/blackberry10/FileTransfer.js +++ b/www/blackberry10/FileTransfer.js @@ -20,7 +20,7 @@ */ var argscheck = require('cordova/argscheck'), - FileTransferError = require('./FileTransferError'); + FileTransferError = require('./FileTransferError'), xhrImpl = require('./BB10XHRImplementation'); @@ -128,7 +128,9 @@ FileTransfer.prototype.upload = function(filePath, server, successCallback, erro self.onprogress(result); } } else { - successCallback && successCallback(result); + if (successCallback) { + successCallback(result); + } } }; xhrImpl.upload(win, fail, [filePath, server, fileKey, fileName, mimeType, params, trustAllHosts, chunkedMode, headers, this._id, httpMethod]); http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/418e904a/www/blackberry10/xhrFileTransfer.js ---------------------------------------------------------------------- diff --git a/www/blackberry10/xhrFileTransfer.js b/www/blackberry10/xhrFileTransfer.js index 7eba7af..53d0d36 100644 --- a/www/blackberry10/xhrFileTransfer.js +++ b/www/blackberry10/xhrFileTransfer.js @@ -19,7 +19,8 @@ * */ -/*global Blob:false */ +/* global Blob:false */ + var cordova = require('cordova'), resolve = cordova.require('cordova-plugin-file.resolveLocalFileSystemURIProxy'), requestAnimationFrame = cordova.require('cordova-plugin-file.bb10RequestAnimationFrame'), @@ -221,7 +222,7 @@ module.exports = { xhr[id].onabort = function (e) { onFail(new FileTransferError(FileTransferError.ABORT_ERR, source, target, xhr[id].status, xhr[id].response)); - } + }; xhr[id].onload = function () { if (xhr[id].readyState === xhr[id].DONE) { http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/418e904a/www/browser/FileTransfer.js ---------------------------------------------------------------------- diff --git a/www/browser/FileTransfer.js b/www/browser/FileTransfer.js index 2146ed1..14868ac 100644 --- a/www/browser/FileTransfer.js +++ b/www/browser/FileTransfer.js @@ -99,7 +99,9 @@ FileTransfer.prototype.upload = function(filePath, server, successCallback, erro // Check if target URL doesn't contain spaces. If contains, it should be escaped first // (see https://github.com/apache/cordova-plugin-file-transfer/blob/master/doc/index.md#upload) if (!checkURL(server)) { - errorCallback && errorCallback(new FileTransferError(FileTransferError.INVALID_URL_ERR, filePath, server)); + if (errorCallback) { + errorCallback(new FileTransferError(FileTransferError.INVALID_URL_ERR, filePath, server)); + } return; } @@ -125,9 +127,13 @@ FileTransfer.prototype.upload = function(filePath, server, successCallback, erro xhr.withCredentials = withCredentials; var fail = errorCallback && function(code, status, response) { - transfers[this._id] && delete transfers[this._id]; + if (transfers[this._id]) { + delete transfers[this._id]; + } var error = new FileTransferError(code, filePath, server, status, response); - errorCallback && errorCallback(error); + if (errorCallback) { + errorCallback(error); + } }; window.resolveLocalFileSystemURL(filePath, function(entry) { @@ -182,7 +188,9 @@ FileTransfer.prototype.upload = function(filePath, server, successCallback, erro }; xhr.upload.onprogress = function (e) { - that.onprogress && that.onprogress(e); + if (that.onprogress) { + that.onprogress(e); + } }; xhr.send(fd); @@ -217,7 +225,9 @@ FileTransfer.prototype.download = function(source, target, successCallback, erro // Check if target URL doesn't contain spaces. If contains, it should be escaped first // (see https://github.com/apache/cordova-plugin-file-transfer/blob/master/doc/index.md#download) if (!checkURL(source)) { - errorCallback && errorCallback(new FileTransferError(FileTransferError.INVALID_URL_ERR, source, target)); + if (errorCallback) { + errorCallback(new FileTransferError(FileTransferError.INVALID_URL_ERR, source, target)); + } return; } @@ -236,7 +246,9 @@ FileTransfer.prototype.download = function(source, target, successCallback, erro var xhr = transfers[this._id] = new XMLHttpRequest(); xhr.withCredentials = withCredentials; var fail = errorCallback && function(code, status, response) { - transfers[that._id] && delete transfers[that._id]; + if (transfers[that._id]) { + delete transfers[that._id]; + } // In XHR GET reqests we're setting response type to Blob // but in case of error we need to raise event with plain text response if (response instanceof Blob) { @@ -268,7 +280,9 @@ FileTransfer.prototype.download = function(source, target, successCallback, erro if (!evt.target.error) { entry.filesystemName = entry.filesystem.name; delete transfers[that._id]; - successCallback && successCallback(entry); + if (successCallback) { + successCallback(entry); + } } else { fail(FileTransferError.FILE_NOT_FOUND_ERR); } @@ -288,7 +302,9 @@ FileTransfer.prototype.download = function(source, target, successCallback, erro }; xhr.onprogress = function (e) { - that.onprogress && that.onprogress(e); + if (that.onprogress) { + that.onprogress(e); + } }; xhr.onerror = function () { http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/418e904a/www/firefoxos/FileTransferProxy.js ---------------------------------------------------------------------- diff --git a/www/firefoxos/FileTransferProxy.js b/www/firefoxos/FileTransferProxy.js index 164da1a..86c46be 100644 --- a/www/firefoxos/FileTransferProxy.js +++ b/www/firefoxos/FileTransferProxy.js @@ -19,8 +19,7 @@ * */ -var cordova = require('cordova'), - FileTransferError = require('./FileTransferError'), +var FileTransferError = require('./FileTransferError'), xhr = {}; function getParentPath(filePath) { http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/418e904a/www/wp7/base64.js ---------------------------------------------------------------------- diff --git a/www/wp7/base64.js b/www/wp7/base64.js index 6c211e7..221e30a 100644 --- a/www/wp7/base64.js +++ b/www/wp7/base64.js @@ -19,6 +19,8 @@ * */ +// jshint ignore: start + var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=', INVALID_CHARACTER_ERR = (function () { // fabricate a suitable error object --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
