Merge pull request #2104 from nschonni/additional-jshinting

Additional jshinting
This commit is contained in:
Régis Hanol 2014-03-11 09:20:04 +01:00
commit d25081ce07
8 changed files with 75 additions and 75 deletions

View file

@ -1,15 +1,8 @@
app/assets/javascripts/defer/html-sanitizer-bundle.js
app/assets/javascripts/locales/
lib/autospec/run-qunit.js
lib/headless-ember.js
lib/javascripts/locale/
lib/javascripts/messageformat.js
lib/javascripts/moment.js
lib/javascripts/moment_locale/
public/javascripts/
spec/phantom_js/smoke_test.js
test/javascripts/helpers/assertions.js
test/javascripts/helpers/parse_html.js
test/javascripts/helpers/qunit_helpers.js
test/javascripts/test_helper.js
vendor/

View file

@ -1,3 +1,5 @@
/*global I18n:true */
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function (searchElement, fromIndex) {
@ -52,7 +54,7 @@ I18n.fallbackRules = {};
I18n.pluralizationRules = {
en: function (n) {
return n == 0 ? ["zero", "none", "other"] : n == 1 ? "one" : "other";
return n === 0 ? ["zero", "none", "other"] : n === 1 ? "one" : "other";
}
};
@ -60,8 +62,8 @@ I18n.getFallbacks = function(locale) {
if (locale === I18n.defaultLocale) {
return [];
} else if (!I18n.fallbackRules[locale]) {
var rules = []
, components = locale.split("-");
var rules = [],
components = locale.split("-");
for (var l = 1; l < components.length; l++) {
rules.push(components.slice(0, l).join("-"));
@ -73,23 +75,23 @@ I18n.getFallbacks = function(locale) {
}
return I18n.fallbackRules[locale];
}
};
I18n.isValidNode = function(obj, node, undefined) {
return obj[node] !== null && obj[node] !== undefined;
};
I18n.lookup = function(scope, options) {
var options = options || {}
, lookupInitialScope = scope
, translations = this.prepareOptions(I18n.translations)
, locale = options.locale || I18n.currentLocale()
, messages = translations[locale] || {}
, options = this.prepareOptions(options)
, currentScope
;
options = options || {};
var lookupInitialScope = scope,
translations = this.prepareOptions(I18n.translations),
locale = options.locale || I18n.currentLocale(),
messages = translations[locale] || {},
currentScope;
if (typeof(scope) == "object") {
options = this.prepareOptions(options);
if (typeof scope === "object") {
scope = scope.join(this.defaultSeparator);
}
@ -130,10 +132,9 @@ I18n.lookup = function(scope, options) {
// #=> {name: "John Doe", role: "user"}
//
I18n.prepareOptions = function() {
var options = {}
, opts
, count = arguments.length
;
var options = {},
opts,
count = arguments.length;
for (var i = 0; i < count; i++) {
opts = arguments[i];
@ -154,11 +155,10 @@ I18n.prepareOptions = function() {
I18n.interpolate = function(message, options) {
options = this.prepareOptions(options);
var matches = message.match(this.PLACEHOLDER)
, placeholder
, value
, name
;
var matches = message.match(this.PLACEHOLDER),
placeholder,
value,
name;
if (!matches) {
return message;
@ -185,8 +185,8 @@ I18n.translate = function(scope, options) {
var translation = this.lookup(scope, options);
try {
if (typeof(translation) == "object") {
if (typeof(options.count) == "number") {
if (typeof translation === "object") {
if (typeof options.count === "number") {
return this.pluralize(options.count, scope, options);
} else {
return translation;
@ -221,9 +221,9 @@ I18n.parseDate = function(date) {
var matches, convertedDate;
// we have a date, so just return it.
if (typeof(date) == "object") {
if (typeof date === "object") {
return date;
};
}
// it matches the following formats:
// yyyy-mm-dd
@ -247,14 +247,14 @@ I18n.parseDate = function(date) {
} else {
convertedDate = new Date(matches[1], matches[2], matches[3], matches[4], matches[5], matches[6]);
}
} else if (typeof(date) == "number") {
} else if (typeof date === "number") {
// UNIX timestamp
convertedDate = new Date();
convertedDate.setTime(date);
} else if (date.match(/\d+ \d+:\d+:\d+ [+-]\d+ \d+/)) {
// a valid javascript format with timezone info
convertedDate = new Date();
convertedDate.setTime(Date.parse(date))
convertedDate.setTime(Date.parse(date));
} else {
// an arbitrary javascript string
convertedDate = new Date();
@ -265,9 +265,8 @@ I18n.parseDate = function(date) {
};
I18n.toTime = function(scope, d) {
var date = this.parseDate(d)
, format = this.lookup(scope)
;
var date = this.parseDate(d),
format = this.lookup(scope);
if (date.toString().match(/invalid/i)) {
return date.toString();
@ -289,20 +288,19 @@ I18n.strftime = function(date, format) {
options.meridian = options.meridian || ["AM", "PM"];
var weekDay = date.getDay()
, day = date.getDate()
, year = date.getFullYear()
, month = date.getMonth() + 1
, hour = date.getHours()
, hour12 = hour
, meridian = hour > 11 ? 1 : 0
, secs = date.getSeconds()
, mins = date.getMinutes()
, offset = date.getTimezoneOffset()
, absOffsetHours = Math.floor(Math.abs(offset / 60))
, absOffsetMinutes = Math.abs(offset) - (absOffsetHours * 60)
, timezoneoffset = (offset > 0 ? "-" : "+") + (absOffsetHours.toString().length < 2 ? "0" + absOffsetHours : absOffsetHours) + (absOffsetMinutes.toString().length < 2 ? "0" + absOffsetMinutes : absOffsetMinutes)
;
var weekDay = date.getDay(),
day = date.getDate(),
year = date.getFullYear(),
month = date.getMonth() + 1,
hour = date.getHours(),
hour12 = hour,
meridian = hour > 11 ? 1 : 0,
secs = date.getSeconds(),
mins = date.getMinutes(),
offset = date.getTimezoneOffset(),
absOffsetHours = Math.floor(Math.abs(offset / 60)),
absOffsetMinutes = Math.abs(offset) - (absOffsetHours * 60),
timezoneoffset = (offset > 0 ? "-" : "+") + (absOffsetHours.toString().length < 2 ? "0" + absOffsetHours : absOffsetHours) + (absOffsetMinutes.toString().length < 2 ? "0" + absOffsetMinutes : absOffsetMinutes);
if (hour12 > 12) {
hour12 = hour12 - 12;
@ -350,13 +348,12 @@ I18n.toNumber = function(number, options) {
{precision: 3, separator: ".", delimiter: ",", strip_insignificant_zeros: false}
);
var negative = number < 0
, string = Math.abs(number).toFixed(options.precision).toString()
, parts = string.split(".")
, precision
, buffer = []
, formattedNumber
;
var negative = number < 0,
string = Math.abs(number).toFixed(options.precision).toString(),
parts = string.split("."),
precision,
buffer = [],
formattedNumber;
number = parts[0];
precision = parts[1];
@ -378,8 +375,8 @@ I18n.toNumber = function(number, options) {
if (options.strip_insignificant_zeros) {
var regex = {
separator: new RegExp(options.separator.replace(/\./, "\\.") + "$")
, zeros: /0+$/
separator: new RegExp(options.separator.replace(/\./, "\\.") + "$"),
zeros: /0+$/
};
formattedNumber = formattedNumber
@ -409,12 +406,11 @@ I18n.toCurrency = function(number, options) {
};
I18n.toHumanSize = function(number, options) {
var kb = 1024
, size = number
, iterations = 0
, unit
, precision
;
var kb = 1024,
size = number,
iterations = 0,
unit,
precision;
while (size >= kb && iterations < 4) {
size = size / kb;
@ -480,7 +476,7 @@ I18n.pluralize = function(count, scope, options) {
var pluralizer = this.pluralizer(this.currentLocale());
var key = pluralizer(Math.abs(count));
var keys = ((typeof key == "object") && (key instanceof Array)) ? key : [key];
var keys = ((typeof key === "object") && (key instanceof Array)) ? key : [key];
var message = this.findAndTranslateValidNode(keys, translation);
if (message == null) message = this.missingTranslation(scope, keys[0]);

View file

@ -1,6 +1,8 @@
/*jshint devel:true, phantom:true */
/*global QUnit, ANSI */
// THIS FILE IS CALLED BY "qunit_runner.rb" IN AUTOSPEC
if (phantom.args.length != 1) {
if (phantom.args.length !== 1) {
console.log("Usage: " + phantom.scriptName + " <URL>");
phantom.exit(1);
}
@ -95,7 +97,7 @@ function colorizer() {
return colorCode + text + colorEnd;
}
};
};
}
function logQUnit() {
@ -144,10 +146,10 @@ function logQUnit() {
// display failures
if (Object.keys(errors).length > 0) {
console.log("Failures:\n");
for (m in errors) {
for (var m in errors) {
var module = errors[m];
console.log("Module Failed: " + ANSI.highlight(m, "red"));
for (t in module) {
for (var t in module) {
var test = module[t];
console.log(" Test Failed: " + t);
for (var a = 0; a < test.length; a++) {
@ -172,4 +174,4 @@ function logQUnit() {
window.qunitResult = context;
});
};
}

View file

@ -1,3 +1,5 @@
/*global Element:true, document:true, window:true, $:true, jQuery:true */
/*exported precompileEmberHandlebars, $, jQuery */
// DOM
var Element = {};
Element.firstChild = function () { return Element; };
@ -11,8 +13,10 @@ this.document = document;
var console = window.console = {};
console.log = console.info = console.warn = console.error = function(){};
/*jshint -W120 */
// jQuery
var $ = jQuery = window.jQuery = function() { return jQuery; };
/*jshint +W120*/
jQuery.ready = function() { return jQuery; };
jQuery.inArray = function() { return jQuery; };
jQuery.event = {

View file

@ -1,3 +1,4 @@
/* exported exists, count, present, blank, containsInstance, not */
// Test helpers
function exists(selector) {
return !!count(selector);

View file

@ -1,3 +1,5 @@
/* global Tautologistics */
/* exported parseHTML */
function parseHTML(rawHtml) {
var builder = new Tautologistics.NodeHtmlParser.HtmlBuilder(),
parser = new Tautologistics.NodeHtmlParser.Parser(builder);

View file

@ -1,3 +1,5 @@
/* global asyncTest */
/* exported integration, testController, controllerFor, asyncTestDiscourse, fixture */
function integration(name, lifecycle) {
module("Integration: " + name, {
setup: function() {
@ -27,7 +29,7 @@ function testController(klass, model) {
}
function controllerFor(controller, model) {
var controller = Discourse.__container__.lookup('controller:' + controller);
controller = Discourse.__container__.lookup('controller:' + controller);
if (model) { controller.set('model', model ); }
return controller;
}

View file

@ -1,5 +1,5 @@
/*jshint maxlen:250 */
/*global count:true find:true document:true equal:true sinon:true */
/*global document, sinon, console, QUnit */
//= require env