CB-10636 Add JSHint for plugins
diff --git a/.gitignore b/.gitignore
index 52b558e..6964ea0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,7 +12,7 @@
*.swp
*.user
-
+node_modules
diff --git a/.jshintignore b/.jshintignore
new file mode 100644
index 0000000..2ef22fc
--- /dev/null
+++ b/.jshintignore
@@ -0,0 +1 @@
+www/browser/moment.js
diff --git a/.jshintrc b/.jshintrc
new file mode 100644
index 0000000..cf48aac
--- /dev/null
+++ b/.jshintrc
@@ -0,0 +1,16 @@
+{
+ "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
+ }
+}
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"
diff --git a/README.md b/README.md
index 0bce104..5ca8445 100644
--- a/README.md
+++ b/README.md
@@ -17,6 +17,8 @@
# under the License.
-->
+[![Build Status](https://travis-ci.org/apache/cordova-plugin-globalization.svg?branch=master)](https://travis-ci.org/apache/cordova-plugin-globalization)
+
# cordova-plugin-globalization
This plugin obtains information and performs operations specific to the user's
diff --git a/package.json b/package.json
index e7e33b3..4489ed1 100644
--- a/package.json
+++ b/package.json
@@ -36,6 +36,13 @@
"cordova-tizen",
"cordova-blackberry10"
],
+ "scripts": {
+ "test": "npm run jshint",
+ "jshint": "jshint www && jshint src && jshint tests"
+ },
"author": "Apache Software Foundation",
- "license": "Apache-2.0"
+ "license": "Apache-2.0",
+ "devDependencies": {
+ "jshint": "^2.6.0"
+ }
}
diff --git a/src/blackberry10/index.js b/src/blackberry10/index.js
index 7d56740..05fde27 100644
--- a/src/blackberry10/index.js
+++ b/src/blackberry10/index.js
@@ -19,6 +19,8 @@
*
*/
+/* global PluginResult, JNEXT */
+
var g11n;
var globalization = {
diff --git a/src/browser/GlobalizationProxy.js b/src/browser/GlobalizationProxy.js
index d998ca3..1c21a52 100644
--- a/src/browser/GlobalizationProxy.js
+++ b/src/browser/GlobalizationProxy.js
@@ -48,8 +48,8 @@
}
function getWeekDayNames(locale, options) {
- var result = [];
- for (i = 0; i < 7; i++) {
+ var result = [], date;
+ for (var i = 0; i < 7; i++) {
date = new Date(2014, 5, i + 1, 0, 0, 0, 0);
result[i] = date.toLocaleDateString(locale, options);
}
@@ -78,10 +78,11 @@
switch(options.selector) {
case 'date and time': return 'lll';
case 'date': return 'l';
- case 'time': return 'LT'
+ case 'time': return 'LT';
default:
throw selectorError;
}
+ break;
case 'medium':
switch(options.selector) {
case 'date and time': return 'LLL';
@@ -91,6 +92,7 @@
default:
throw selectorError;
}
+ break;
case 'long':
switch(options.selector) {
case 'date and time': return 'llll';
@@ -100,6 +102,7 @@
default:
throw selectorError;
}
+ break;
case 'full':
switch(options.selector) {
case 'date and time': return 'LLLL';
@@ -108,13 +111,14 @@
default:
throw selectorError;
}
+ break;
default:
throw formatLengthError;
}
}
function prepareAndGetDateOptions(options) {
- var options = options || {formatLength:'short', selector:'date and time'};
+ options = options || {formatLength:'short', selector:'date and time'};
options.formatLength = options.formatLength || 'short';
options.selector = options.selector || 'date and time';
@@ -175,7 +179,7 @@
var locale = getCrossPlatformLocale();
if (item === 'months' && type === 'wide') {
- var options = { month: 'long' };
+ options = { month: 'long' };
} else if (item === 'months' && type === 'narrow') {
options = { month: 'short'};
} else if (item === 'days' && type === 'wide') {
@@ -229,7 +233,10 @@
var formatter = new Intl.NumberFormat(getCrossPlatformLocale(), options);
- if (!formatter.hasOwnProperty('resolved')) { fail('Not supported'); return; };
+ if (!formatter.hasOwnProperty('resolved')) {
+ fail('Not supported');
+ return;
+ }
var pattern = formatter.resolved.pattern;
win( {
pattern: pattern,
diff --git a/src/tizen/GlobalizationProxy.js b/src/tizen/GlobalizationProxy.js
index 9e6b981..bfde856 100644
--- a/src/tizen/GlobalizationProxy.js
+++ b/src/tizen/GlobalizationProxy.js
@@ -19,6 +19,8 @@
*
*/
+/* global tizen */
+
var argscheck = require('cordova/argscheck'),
GlobalizationError = require('cordova-plugin-globalization.GlobalizationError');
@@ -114,7 +116,6 @@
* {formatLength:'short'});
*/
dateToString:function(date, successCB, failureCB, options) {
- var dateValue = date.valueOf();
console.log('exec(successCB, failureCB, "Globalization", "dateToString", [{"date": dateValue, "options": options}]);');
var tzdate = null;
@@ -308,7 +309,7 @@
tzdate = new tizen.TZDate(date);
if (tzdate) {
- isDLS = false | (tzdate && tzdate.isDST());
+ isDLS = tzdate && tzdate.isDST();
console.log ("Cordova, globalization, isDayLightSavingsTime, " + isDLS);
diff --git a/src/windows/GlobalizationProxy.js b/src/windows/GlobalizationProxy.js
index 83b64a1..13bdd1e 100644
--- a/src/windows/GlobalizationProxy.js
+++ b/src/windows/GlobalizationProxy.js
@@ -12,6 +12,8 @@
limitations under the License.
*/
+/* global Windows, GlobalizationProxy */
+
var GlobalizationError = require('./GlobalizationError');
var locale = navigator.userLanguage || navigator.language;
@@ -97,7 +99,7 @@
}
default:
throw "The options.type can be 'decimal', 'percent', or 'currency' only";
- };
+ }
}
module.exports = {
@@ -163,10 +165,10 @@
Windows.Globalization.DateTimeFormatting.SecondFormat.none,
[locale]);
- var result = [];
+ var result = [], i, date;
if (item === 'months') {
- for (var i = 0; i < 12; i++) {
- var date = new Date(2014, i, 20, 0, 0, 0, 0);
+ for (i = 0; i < 12; i++) {
+ date = new Date(2014, i, 20, 0, 0, 0, 0);
result[i] = formatter.format(date);
}
} else {
diff --git a/tests/tests.js b/tests/tests.js
index 98fd31d..c395e83 100644
--- a/tests/tests.js
+++ b/tests/tests.js
@@ -19,6 +19,9 @@
*
*/
+/* jshint jasmine: true */
+/* global cordova, GlobalizationError */
+
exports.defineAutoTests = function () {
var isWindowsPhone = cordova.platformId == 'windowsphone',
isWindows = (cordova.platformId === "windows") || (cordova.platformId === "windows8"),
@@ -83,7 +86,7 @@
it("globalization.spec.3 getLocaleName success callback should be called with a Properties object", function (done) {
navigator.globalization.getLocaleName(function (a) {
checkLocaleName(a);
- done()
+ done();
}, fail.bind(null, done));
});
it("globalization.spec.4 getLocaleName return string should have a hyphen", function (done) {
@@ -384,7 +387,7 @@
}, fail.bind(null, done));
});
it("globalization.spec.31 numberToString using type=percent options, should be called with a Properties object", function (done) {
- navigator.globalization.numberToString(.25, function (a) {
+ navigator.globalization.numberToString(0.25, function (a) {
checkNumberToString(a);
done();
}, fail.bind(null, done),
@@ -442,7 +445,7 @@
done();
};
- navigator.globalization.numberToString(.25, function (a) {
+ navigator.globalization.numberToString(0.25, function (a) {
navigator.globalization.stringToNumber(a.value, win, fail.bind(null, done), { type: 'percent' });
}, fail.bind(null, done), { type: 'percent' });
});
diff --git a/www/firefoxos/l10n.js b/www/firefoxos/l10n.js
index 5a735a0..a2cd328 100644
--- a/www/firefoxos/l10n.js
+++ b/www/firefoxos/l10n.js
@@ -19,6 +19,7 @@
*
*/
+/* global unescape */
(function(window, undefined) {
'use strict';
diff --git a/www/firefoxos/l10n_date.js b/www/firefoxos/l10n_date.js
index 8c09d38..dcafba8 100644
--- a/www/firefoxos/l10n_date.js
+++ b/www/firefoxos/l10n_date.js
@@ -19,9 +19,6 @@
*
*/
-
-'use strict';
-
/**
* This lib relies on `l10n.js' to implement localizable date/time strings.
*
@@ -41,6 +38,8 @@
*/
navigator.mozL10n.DateTimeFormat = function(locales, options) {
+ 'use strict';
+
var _ = navigator.mozL10n.get;
// https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Date/toLocaleFormat
diff --git a/www/globalization.js b/www/globalization.js
index 88b3640..aa5f60c 100644
--- a/www/globalization.js
+++ b/www/globalization.js
@@ -20,8 +20,7 @@
*/
var argscheck = require('cordova/argscheck'),
- exec = require('cordova/exec'),
- GlobalizationError = require('./GlobalizationError');
+ exec = require('cordova/exec');
var globalization = {
diff --git a/www/ubuntu/globalization.js b/www/ubuntu/globalization.js
index 51900db..6b423be 100644
--- a/www/ubuntu/globalization.js
+++ b/www/ubuntu/globalization.js
@@ -16,6 +16,9 @@
* under the License.
*
*/
+
+/* global Cordova */
+
var exec = require('cordova/exec');
var argscheck = require('cordova/argscheck');
var GlobalizationError = require('./GlobalizationError');
@@ -158,7 +161,7 @@
getCurrencyPattern: function(currencyCode, successCB, failureCB) {
argscheck.checkArgs('sfF', 'Globalization.getCurrencyPattern', arguments);
- failureCB(new GlobalizationError(GlobalizationError.PATTERN_ERROR, "unimplemented"))
+ failureCB(new GlobalizationError(GlobalizationError.PATTERN_ERROR, "unimplemented"));
//exec(successCB, failureCB, "Globalization", "getCurrencyPattern", [{"currencyCode": currencyCode}]);
}
};