CB-10636 Add JSHint for plugins

This commit is contained in:
daserge
2016-02-25 14:30:21 +03:00
parent afbeab405f
commit 418e904a98
13 changed files with 81 additions and 120 deletions
-1
View File
@@ -1,7 +1,6 @@
{
"disallowMixedSpacesAndTabs": true,
"disallowTrailingWhitespace": true,
"validateLineBreaks": "CRLF",
"validateIndentation": 4,
"requireLineFeedAtFileEnd": true,
+17 -89
View File
@@ -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
}
}
+4
View File
@@ -0,0 +1,4 @@
language: node_js
sudo: false
node_js:
- "4.2"
+2
View File
@@ -17,6 +17,8 @@
# under the License.
-->
[![Build Status](https://travis-ci.org/apache/cordova-plugin-file-transfer.svg?branch=master)](https://travis-ci.org/apache/cordova-plugin-file-transfer)
# cordova-plugin-file-transfer
This plugin allows you to upload and download files.
+2 -2
View File
@@ -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",
+12 -13
View File
@@ -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;
+5 -1
View File
@@ -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]);
+5
View File
@@ -0,0 +1,5 @@
{
"globals": {
"requestAnimationFrame": true
}
}
+4 -2
View File
@@ -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]);
+3 -2
View File
@@ -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) {
+24 -8
View File
@@ -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 () {
+1 -2
View File
@@ -19,8 +19,7 @@
*
*/
var cordova = require('cordova'),
FileTransferError = require('./FileTransferError'),
var FileTransferError = require('./FileTransferError'),
xhr = {};
function getParentPath(filePath) {
+2
View File
@@ -19,6 +19,8 @@
*
*/
// jshint ignore: start
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=',
INVALID_CHARACTER_ERR = (function () {
// fabricate a suitable error object