Skip to content

Commit

Permalink
Add ESLint + Fix raised issues
Browse files Browse the repository at this point in the history
  • Loading branch information
j3k0 committed Oct 30, 2014
1 parent c4c1dac commit f31fc68
Show file tree
Hide file tree
Showing 46 changed files with 754 additions and 652 deletions.
18 changes: 18 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"env" : {
"node" : true,
"browser" : true
},
"rules" : {
"strict": 1,
"quotes": 0,
"no-underscore-dangle": 0,
"no-multi-spaces": 0,
"key-spacing": 0,
"curly": 0,
"no-use-before-define": [ 1, "nofunc" ]
},
"globals" : {
"store": true
}
}
9 changes: 9 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"node": true,
"browser": true,
"undef": true,
"globals": {
"store": true,
"cordova": true
}
}
12 changes: 8 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,19 @@ prepare-test-js:
@cp src/js/platforms/*-adapter.js test/tmp/
@#node_modules/.bin/istanbul instrument --no-compact --output test/tmp/store-test.js test/store-test-src.js

jshint: check-jshint
jshint: check-jshint sync-android
@echo "- JSHint"
@node_modules/.bin/jshint src/js/*.js test/js/*.js
@node_modules/.bin/jshint --config .jshintrc src/js/*.js src/js/platforms/*.js test/js/*.js

test-js: jshint prepare-test-js
eslint: jshint
@echo "- ESLint"
@node_modules/.bin/eslint --config .eslintrc src/js/*.js src/js/platforms/*.js test/js/*.js

test-js: jshint eslint prepare-test-js
@echo "- Mocha"
@node_modules/.bin/istanbul test --root test/tmp test/js/run.js

test-js-coverage: jshint prepare-test-js
test-js-coverage: jshint eslint prepare-test-js
@echo "- Mocha / Instanbul"
@node_modules/.bin/istanbul cover --root test/ test/js/run.js
@node_modules/.bin/coveralls < coverage/lcov.info
Expand Down
16 changes: 8 additions & 8 deletions doc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ be contacted to load informations about the registered products: human
readable `title` and `description`, `price`, etc.

This isn't an optional step as some despotic store owners (like Apple) require you
to display information about a product as retrieved from their server: no
to display information about a product as retrieved from their server: no
hard-coding of price and title allowed! This is also convenient for you
as you can change the price of your items knowing that it'll be reflected instantly
on your clients' devices.
Expand All @@ -80,9 +80,9 @@ Let's demonstrate this with an example:
render();
store.when("cc.fovea.test1").updated(render);
}

function render() {

// Get the product from the pool.
var product = store.get("cc.fovea.test1");

Expand All @@ -102,21 +102,21 @@ Let's demonstrate this with an example:
+ "<div class=\"description\">" + product.description + "</div>"
+ "<div class=\"price\">" + product.price + "</div>"
);

// Is this product owned? Give him a special class.
if (product.owned)
$el.addClass("owned");
else
$el.removeClass("owned");

// Is an order for this product in progress? Can't be ordered right now?
if (product.canPurchase)
$el.addClass("can-purchase");
else
$el.removeClass("can-purchase");
}
}

// method called when the view is hidden
function hide() {
// stop monitoring the product
Expand Down Expand Up @@ -387,7 +387,7 @@ A Promise with the following methods:
- `error(function(err){})`
- validation failed, either because of expiry or communication
failure.
- `err` is a [store.Error object](#errors), with a code expected to be
- `err` is a [store.Error object](#errors), with a code expected to be
`store.ERR_PAYMENT_EXPIRED` or `store.ERR_VERIFICATION_FAILED`.


Expand Down Expand Up @@ -904,7 +904,7 @@ Only supports JSON requests.

Options:

* `url`:
* `url`:
* `method`: HTTP method to use (GET, POST, ...)
* `success`: callback(data)
* `error`: callback(statusCode, statusText)
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"homepage": "https://github.com/j3k0/PhoneGap-InAppPurchase-iOS",
"devDependencies": {
"cordova": "^3.6.3-0.2.13",
"eslint": "^0.9.1",
"istanbul": "^0.3.2",
"jshint": "^2.5.6",
"mocha": "^1.21.4",
Expand Down
2 changes: 1 addition & 1 deletion src/js/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ var ERROR_CODES_BASE = 6777000;
/*///*/ store.CONNECTION_FAILED = 6778002;
/*///*/ store.PURCHASE_EXPIRED = 6778003;

}).call(this);
})();
4 changes: 2 additions & 2 deletions src/js/error-callbacks.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function(){
'use strict';

///
///
/// ## *store.error.callbacks* array
///
/// Array of user registered error callbacks.
Expand Down Expand Up @@ -47,4 +47,4 @@ function deferThrow(err) {
setTimeout(function() { throw err; }, 1);
}

}).call(this);
})();
4 changes: 2 additions & 2 deletions src/js/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

///
/// ## <a name="errors"></a>*store.Error* object
///
///
/// All error callbacks takes an `error` object as parameter.

store.Error = function(options) {
Expand Down Expand Up @@ -80,4 +80,4 @@ store.error.unregister = function(cb) {
store.error.callbacks.unregister(cb);
};

}).call(this);
})();
2 changes: 1 addition & 1 deletion src/js/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ store.get = function(id) {
return product;
};

}).call(this);
})();
2 changes: 1 addition & 1 deletion src/js/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ store.log = {
debug: function(o) { log(store.DEBUG, o); }
};

}).call(this);
})();
3 changes: 1 addition & 2 deletions src/js/off.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,4 @@ store.off = function(callback) {
store.error.unregister(callback);
};

}).call(this);

})();
4 changes: 2 additions & 2 deletions src/js/once.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"use strict";

/// ## <a name="once"></a>*store.once(query)*
///
///
/// Identical to [`store.when`](#when), but the callback will be called only once.
/// After being called, the callback will be unregistered.
store.once = function(query, action, callback) {
Expand All @@ -25,4 +25,4 @@ store.once = function(query, action, callback) {

store.once.unregister = store.when.unregister;

}).call(this);
})();
9 changes: 4 additions & 5 deletions src/js/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var callbackId = 0;
/// Initiate the purchase of a product.
///
/// The `product` argument can be either:
///
///
/// - the `store.Product` object
/// - the product `id`
/// - the product `alias`
Expand All @@ -23,9 +23,8 @@ var callbackId = 0;
///
store.order = function(pid) {

var that = this;
var p = pid;

if (typeof pid === "string") {
p = store.products.byId[pid] || store.products.byAlias[pid];
if (!p) {
Expand Down Expand Up @@ -75,7 +74,7 @@ store.order = function(pid) {
if (!localCallback.error)
return;
done();
cb(p);
cb(err);
});
return this;
}
Expand All @@ -97,4 +96,4 @@ store.order.unregister = function(cb) {
}
};

}).call(this);
})();
14 changes: 7 additions & 7 deletions src/js/platforms/android-adapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
(function() {
"use strict";

var initialized = false;
var skus = [];

store.when("refreshed", function() {
if (!initialized) init();
});
Expand All @@ -9,10 +12,7 @@ store.when("re-refreshed", function() {
iabGetPurchases();
});

var initialized = false;
var skus = [];

var init = function () {
function init() {
if (initialized) return;
initialized = true;

Expand All @@ -30,7 +30,7 @@ var init = function () {
showLog: store.verbosity >= store.DEBUG ? true : false
},
skus);
};
}

function iabReady() {
store.log.debug("android -> ready");
Expand Down Expand Up @@ -225,7 +225,7 @@ store.when("product", "finished", function(product) {
function(err, code) { // error
// can't finish.
store.error({
code: code || ERR_UNKNOWN,
code: code || store.ERR_UNKNOWN,
message: err
});
},
Expand All @@ -236,4 +236,4 @@ store.when("product", "finished", function(product) {
}
});

}).call(this);
})();
52 changes: 27 additions & 25 deletions src/js/platforms/android-bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Copyright (C) 2012-2013 by Guillaume Charhon
* Modifications 10/16/2013 by Brian Thurlow
*/
/*global cordova */

(function() {
"use strict";
Expand All @@ -21,38 +22,39 @@ InAppBilling.prototype.init = function (success, fail, options, skus) {
this.options = {
showLog: options.showLog !== false
};

if (this.options.showLog) {
log('setup ok');
}

var hasSKUs = false;
//Optional Load SKUs to Inventory.
if(typeof skus !== "undefined"){
if (typeof skus === "string") {
skus = [skus];
}
if (skus.length > 0) {
if (typeof skus[0] !== 'string') {
var msg = 'invalid productIds: ' + JSON.stringify(skus);
if (this.options.showLog) {
log(msg);
}
skus = [skus];
}
if (skus.length > 0) {
if (typeof skus[0] !== 'string') {
var msg = 'invalid productIds: ' + JSON.stringify(skus);
if (this.options.showLog) {
log(msg);
}
fail(msg, store.ERR_INVALID_PRODUCT_ID);
return;
}
if (this.options.showLog) {
log('load ' + JSON.stringify(skus));
}
return;
}
if (this.options.showLog) {
log('load ' + JSON.stringify(skus));
}
hasSKUs = true;
}
}
}

if(hasSKUs){
return cordova.exec(success, errorCb(fail), "InAppBillingPlugin", "init", [skus]);
}else {

if (hasSKUs) {
cordova.exec(success, errorCb(fail), "InAppBillingPlugin", "init", [skus]);
}
else {
//No SKUs
return cordova.exec(success, errorCb(fail), "InAppBillingPlugin", "init", []);
cordova.exec(success, errorCb(fail), "InAppBillingPlugin", "init", []);
}
};
InAppBilling.prototype.getPurchases = function (success, fail) {
Expand Down Expand Up @@ -89,7 +91,7 @@ InAppBilling.prototype.getProductDetails = function (success, fail, skus) {
if (this.options.showLog) {
log('getProductDetails called!');
}

if (typeof skus === "string") {
skus = [skus];
}
Expand All @@ -104,9 +106,9 @@ InAppBilling.prototype.getProductDetails = function (success, fail, skus) {
return;
}
if (this.options.showLog) {
log('load ' + JSON.stringify(skus));
log('load ' + JSON.stringify(skus));
}
return cordova.exec(success, errorCb(fail), "InAppBillingPlugin", "getProductDetails", [skus]);
cordova.exec(success, errorCb(fail), "InAppBillingPlugin", "getProductDetails", [skus]);
}
};

Expand Down Expand Up @@ -140,4 +142,4 @@ window.inappbilling = new InAppBilling();
try { store.android = window.inappbilling; }
catch (e) {}

}).call(this);
})();
Loading

0 comments on commit f31fc68

Please sign in to comment.