Skip to content
Permalink
Browse files
CB-12895 : added eslint to repo
  • Loading branch information
audreyso committed Sep 27, 2017
1 parent 74a4adc commit c75e8059114255d1dbae1ede398e6626708ee9f3
Showing 37 changed files with 836 additions and 842 deletions.
@@ -0,0 +1 @@
pkg/**
@@ -0,0 +1,10 @@
root: true
extends: semistandard
rules:
indent:
- error
- 4
camelcase: off
padded-blocks: off
operator-linebreak: off
no-throw-literal: off
@@ -15,7 +15,8 @@
"url": "https://issues.apache.org/jira/browse/CB"
},
"scripts": {
"test": "grunt test",
"eslint": "eslint src test pkg",
"test": "grunt test && npm run eslint",
"build": "grunt compile",
"build-browserify": "grunt compile-browserify"
},
@@ -68,6 +69,13 @@
],
"devDependencies": {
"connect": "^3.5.0",
"eslint": "^4.7.2",
"eslint-config-semistandard": "^11.0.0",
"eslint-config-standard": "^10.2.1",
"eslint-plugin-import": "^2.7.0",
"eslint-plugin-node": "^5.1.1",
"eslint-plugin-promise": "^3.5.0",
"eslint-plugin-standard": "^3.0.1",
"grunt": "^1.0.1",
"grunt-contrib-clean": "^1.0.0",
"grunt-contrib-jshint": "^1.0.0",
@@ -32,29 +32,29 @@ var typeMap = {
'O': 'Object'
};

function extractParamName(callee, argIndex) {
function extractParamName (callee, argIndex) {
return (/.*?\((.*?)\)/).exec(callee)[1].split(', ')[argIndex];
}

function checkArgs(spec, functionName, args, opt_callee) {
function checkArgs (spec, functionName, args, opt_callee) {
if (!moduleExports.enableChecks) {
return;
}
var errMsg = null;
var typeName;
for (var i = 0; i < spec.length; ++i) {
var c = spec.charAt(i),
cUpper = c.toUpperCase(),
arg = args[i];
var c = spec.charAt(i);
var cUpper = c.toUpperCase();
var arg = args[i];
// Asterix means allow anything.
if (c == '*') {
if (c === '*') {
continue;
}
typeName = utils.typeName(arg);
if ((arg === null || arg === undefined) && c == cUpper) {
if ((arg === null || arg === undefined) && c === cUpper) {
continue;
}
if (typeName != typeMap[cUpper]) {
if (typeName !== typeMap[cUpper]) {
errMsg = 'Expected ' + typeMap[cUpper];
break;
}
@@ -63,18 +63,17 @@ function checkArgs(spec, functionName, args, opt_callee) {
errMsg += ', but got ' + typeName + '.';
errMsg = 'Wrong type for parameter "' + extractParamName(opt_callee || args.callee, i) + '" of ' + functionName + ': ' + errMsg;
// Don't log when running unit tests.
if (typeof jasmine == 'undefined') {
if (typeof jasmine === 'undefined') {
console.error(errMsg);
}
throw TypeError(errMsg);
}
}

function getValue(value, defaultValue) {
function getValue (value, defaultValue) {
return value === undefined ? defaultValue : value;
}

moduleExports.checkArgs = checkArgs;
moduleExports.getValue = getValue;
moduleExports.enableChecks = true;

@@ -21,58 +21,58 @@

var base64 = exports;

base64.fromArrayBuffer = function(arrayBuffer) {
base64.fromArrayBuffer = function (arrayBuffer) {
var array = new Uint8Array(arrayBuffer);
return uint8ToBase64(array);
};

base64.toArrayBuffer = function(str) {
var decodedStr = typeof atob != 'undefined' ? atob(str) : new Buffer(str,'base64').toString('binary');
base64.toArrayBuffer = function (str) {
var decodedStr = typeof atob !== 'undefined' ? atob(str) : Buffer.from(str, 'base64').toString('binary'); // eslint-disable-line no-undef
var arrayBuffer = new ArrayBuffer(decodedStr.length);
var array = new Uint8Array(arrayBuffer);
for (var i=0, len=decodedStr.length; i < len; i++) {
for (var i = 0, len = decodedStr.length; i < len; i++) {
array[i] = decodedStr.charCodeAt(i);
}
return arrayBuffer;
};

//------------------------------------------------------------------------------
// ------------------------------------------------------------------------------

/* This code is based on the performance tests at http://jsperf.com/b64tests
* This 12-bit-at-a-time algorithm was the best performing version on all
* platforms tested.
*/

var b64_6bit = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
var b64_6bit = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
var b64_12bit;

var b64_12bitTable = function() {
var b64_12bitTable = function () {
b64_12bit = [];
for (var i=0; i<64; i++) {
for (var j=0; j<64; j++) {
b64_12bit[i*64+j] = b64_6bit[i] + b64_6bit[j];
for (var i = 0; i < 64; i++) {
for (var j = 0; j < 64; j++) {
b64_12bit[i * 64 + j] = b64_6bit[i] + b64_6bit[j];
}
}
b64_12bitTable = function() { return b64_12bit; };
b64_12bitTable = function () { return b64_12bit; };
return b64_12bit;
};

function uint8ToBase64(rawData) {
function uint8ToBase64 (rawData) {
var numBytes = rawData.byteLength;
var output="";
var output = '';
var segment;
var table = b64_12bitTable();
for (var i=0;i<numBytes-2;i+=3) {
segment = (rawData[i] << 16) + (rawData[i+1] << 8) + rawData[i+2];
for (var i = 0; i < numBytes - 2; i += 3) {
segment = (rawData[i] << 16) + (rawData[i + 1] << 8) + rawData[i + 2];
output += table[segment >> 12];
output += table[segment & 0xfff];
}
if (numBytes - i == 2) {
segment = (rawData[i] << 16) + (rawData[i+1] << 8);
if (numBytes - i === 2) {
segment = (rawData[i] << 16) + (rawData[i + 1] << 8);
output += table[segment >> 12];
output += b64_6bit[(segment & 0xfff) >> 6];
output += '=';
} else if (numBytes - i == 1) {
} else if (numBytes - i === 1) {
segment = (rawData[i] << 16);
output += table[segment >> 12];
output += '==';
@@ -21,15 +21,15 @@

var utils = require('cordova/utils');

function each(objects, func, context) {
function each (objects, func, context) {
for (var prop in objects) {
if (objects.hasOwnProperty(prop)) {
func.apply(context, [objects[prop], prop]);
}
}
}

function clobber(obj, key, value) {
function clobber (obj, key, value) {
exports.replaceHookForTesting(obj, key);
var needsProperty = false;
try {
@@ -39,15 +39,15 @@ function clobber(obj, key, value) {
}
// Getters can only be overridden by getters.
if (needsProperty || obj[key] !== value) {
utils.defineGetter(obj, key, function() {
utils.defineGetter(obj, key, function () {
return value;
});
}
}

function assignOrWrapInDeprecateGetter(obj, key, value, message) {
function assignOrWrapInDeprecateGetter (obj, key, value, message) {
if (message) {
utils.defineGetter(obj, key, function() {
utils.defineGetter(obj, key, function () {
console.log(message);
delete obj[key];
clobber(obj, key, value);
@@ -58,7 +58,7 @@ function assignOrWrapInDeprecateGetter(obj, key, value, message) {
}
}

function include(parent, objects, clobber, merge) {
function include (parent, objects, clobber, merge) {
each(objects, function (obj, key) {
try {
var result = obj.path ? require(obj.path) : {};
@@ -78,7 +78,7 @@ function include(parent, objects, clobber, merge) {
result = parent[key];
} else {
// Overwrite if not currently defined.
if (typeof parent[key] == 'undefined') {
if (typeof parent[key] === 'undefined') {
assignOrWrapInDeprecateGetter(parent, key, result, obj.deprecated);
} else {
// Set result to what already exists, so we can build children into it if they exist.
@@ -89,7 +89,7 @@ function include(parent, objects, clobber, merge) {
if (obj.children) {
include(result, obj.children, clobber, merge);
}
} catch(e) {
} catch (e) {
utils.alert('Exception building Cordova JS globals: ' + e + ' for key "' + key + '"');
}
});
@@ -102,7 +102,7 @@ function include(parent, objects, clobber, merge) {
* @param target Object to merge properties into.
* @param src Object to merge properties from.
*/
function recursiveMerge(target, src) {
function recursiveMerge (target, src) {
for (var prop in src) {
if (src.hasOwnProperty(prop)) {
if (target.prototype && target.prototype.constructor === target) {
@@ -119,15 +119,15 @@ function recursiveMerge(target, src) {
}
}

exports.buildIntoButDoNotClobber = function(objects, target) {
exports.buildIntoButDoNotClobber = function (objects, target) {
include(target, objects, false, false);
};
exports.buildIntoAndClobber = function(objects, target) {
exports.buildIntoAndClobber = function (objects, target) {
include(target, objects, true, false);
};
exports.buildIntoAndMerge = function(objects, target) {
exports.buildIntoAndMerge = function (objects, target) {
include(target, objects, true, true);
};
exports.recursiveMerge = recursiveMerge;
exports.assignOrWrapInDeprecateGetter = assignOrWrapInDeprecateGetter;
exports.replaceHookForTesting = function() {};
exports.replaceHookForTesting = function () {};

0 comments on commit c75e805

Please sign in to comment.