FIX: JSHint wasn't validating ES6 files, this fixes a bunch of errors.

This commit is contained in:
Robin Ward 2015-02-10 17:20:16 -05:00
parent d5712e43cf
commit cf3582bedb
25 changed files with 9410 additions and 57913 deletions

View File

@ -3,12 +3,12 @@ export default Em.ObjectController.extend({
disableSave: false,
currentPage: function() {
if (this.get("user_count") == 0) { return 0; }
if (this.get("user_count") === 0) { return 0; }
return Math.floor(this.get("offset") / this.get("limit")) + 1;
}.property("limit", "offset", "user_count"),
totalPages: function() {
if (this.get("user_count") == 0) { return 0; }
if (this.get("user_count") === 0) { return 0; }
return Math.floor(this.get("user_count") / this.get("limit")) + 1;
}.property("limit", "user_count"),

View File

@ -4,19 +4,19 @@ export default Ember.ArrayController.extend(Discourse.Presence, {
loading: false,
actions: {
clearBlock: function(row){
clearBlock(row){
row.clearBlock().then(function(){
// feeling lazy
window.location.reload();
});
},
exportScreenedEmailList: function(subject) {
exportScreenedEmailList() {
Discourse.ExportCsv.exportScreenedEmailList().then(outputExportResult);
}
},
show: function() {
show() {
var self = this;
self.set('loading', true);
Discourse.ScreenedEmail.findAll().then(function(result) {

View File

@ -15,15 +15,15 @@ export default Ember.ArrayController.extend(Discourse.Presence, {
}, 250).observes("filter"),
actions: {
recordAdded: function(arg) {
recordAdded(arg) {
this.get("model").unshiftObject(arg);
},
rollUp: function() {
var self = this;
rollUp() {
const self = this;
return bootbox.confirm(I18n.t("admin.logs.screened_ips.roll_up_confirm"), I18n.t("no_value"), I18n.t("yes_value"), function (confirmed) {
if (confirmed) {
self.set("loading", true)
self.set("loading", true);
return Discourse.ScreenedIpAddress.rollUp().then(function(results) {
if (results && results.subnets) {
if (results.subnets.length > 0) {
@ -39,7 +39,7 @@ export default Ember.ArrayController.extend(Discourse.Presence, {
});
},
exportScreenedIpList: function(subject) {
exportScreenedIpList() {
Discourse.ExportCsv.exportScreenedIpList().then(outputExportResult);
}
}

View File

@ -3,8 +3,8 @@ import { outputExportResult } from 'discourse/lib/export-result';
export default Ember.ArrayController.extend(Discourse.Presence, {
loading: false,
show: function() {
var self = this;
show() {
const self = this;
self.set('loading', true);
Discourse.ScreenedUrl.findAll().then(function(result) {
self.set('model', result);
@ -13,7 +13,7 @@ export default Ember.ArrayController.extend(Discourse.Presence, {
},
actions: {
exportScreenedUrlList: function(subject) {
exportScreenedUrlList() {
Discourse.ExportCsv.exportScreenedUrlList().then(outputExportResult);
}
}

View File

@ -2,4 +2,4 @@ export default Discourse.Route.extend({
redirect: function() {
this.transitionTo("adminGroupsType", "custom");
}
})
});

View File

@ -1,17 +1,17 @@
export default Discourse.Route.extend({
model: function(params) {
model(params) {
return Discourse.Group.findAll().then(function(groups) {
return groups.filterBy("type", params.type);
});
},
actions: {
newGroup: function() {
var self = this;
newGroup() {
const self = this;
this.transitionTo("adminGroupsType", "custom").then(function() {
var group = Discourse.Group.create({ automatic: false, visible: true });
self.transitionTo("adminGroup", group);
})
});
}
}
});

View File

@ -3,16 +3,11 @@ import TextField from 'discourse/components/text-field';
/**
Same as text-field, but with special features for a password input.
Be sure to test on a variety of browsers and operating systems when changing this logic.
@class PasswordFieldView
@extends Discourse.TextFieldView
@namespace Discourse
@module Discourse
**/
export default TextField.extend({
canToggle: false,
keyPress: function(e) {
keyPress(e) {
if ((e.which >= 65 && e.which <= 90 && !e.shiftKey) || (e.which >= 97 && e.which <= 122 && e.shiftKey)) {
this.set('canToggle', true);
this.set('capsLockOn', true);
@ -22,17 +17,17 @@ export default TextField.extend({
}
},
keyUp: function(e) {
if (e.which == 20 && this.get('canToggle')) {
keyUp(e) {
if (e.which === 20 && this.get('canToggle')) {
this.toggleProperty('capsLockOn');
}
},
focusOut: function(e) {
focusOut() {
this.set('capsLockOn', false);
},
focusIn: function() {
focusIn() {
this.set('canToggle', false); // can't know the state of caps lock yet. keyPress will figure it out.
}
});

View File

@ -62,7 +62,7 @@ export default DiscourseController.extend({
this.set('model.loading', true);
var composer = this;
return Discourse.Post.load(postId).then(function(post) {
var quote = Discourse.Quote.build(post, post.get("raw"))
var quote = Discourse.Quote.build(post, post.get("raw"));
composer.appendBlockAtCursor(quote);
composer.set('model.loading', false);
});

View File

@ -81,7 +81,7 @@ export default ObjectController.extend(ModalFunctionality, {
if (opts) params = $.extend(params, opts);
this.send('hideModal');
postAction.act(params).then(function(result) {
postAction.act(params).then(function() {
self.send('closeModal');
}, function(errors) {
self.send('closeModal');

View File

@ -1,7 +1,6 @@
/* global assetPath:true */
import DiscourseController from 'discourse/controllers/controller';
/*global assetPath:true */
export default DiscourseController.extend({
needs: ['topic', 'composer'],
@ -55,7 +54,7 @@ export default DiscourseController.extend({
// create a marker element
var markerElement = document.createElement("span");
// containing a single invisible character
markerElement.appendChild(document.createTextNode("\ufeff"));
markerElement.appendChild(document.createTextNode("\u{feff}"));
// collapse the range at the beginning/end of the selection
range.collapse(!Discourse.Mobile.isMobileDevice);

View File

@ -1,7 +1,7 @@
import ObjectController from 'discourse/controllers/object';
// Handles displaying of a topic as a list item
export default Ember.ObjectController.extend({
export default ObjectController.extend({
needs: ['discovery/topics'],
canStar: Em.computed.alias('controllers.discovery/topics.currentUser.id'),

View File

@ -2,6 +2,6 @@ export default Ember.ObjectController.extend({
needs: ["application"],
_showFooter: function() {
this.set("controllers.application.showFooter", !this.get("canLoadMore"))
this.set("controllers.application.showFooter", !this.get("canLoadMore"));
}.observes("canLoadMore")
});

View File

@ -1,7 +1,7 @@
import registerUnbound from 'discourse/helpers/register-unbound';
function renderRaw(template, templateName, params) {
params.parent = params.parent || this;
function renderRaw(ctx, template, templateName, params) {
params.parent = params.parent || ctx;
if (!params.view) {
var viewClass = Discourse.__container__.lookupFactory('view:' + templateName);
@ -20,7 +20,5 @@ registerUnbound('raw', function(templateName, params) {
return;
}
return renderRaw.call(this, template, templateName, params);
return renderRaw(this, template, templateName, params);
});
export { renderRaw };

View File

@ -1,18 +1,17 @@
var get = Discourse.EmberCompatHandlebars.get;
const get = Discourse.EmberCompatHandlebars.get;
export function resolveParams(options) {
var params = {},
hash = options.hash;
function resolveParams(ctx, options) {
let params = {};
const hash = options.hash;
if (hash) {
var self = this;
if (options.hashTypes) {
Ember.keys(hash).forEach(function(k) {
var type = options.hashTypes[k];
const type = options.hashTypes[k];
if (type === "STRING") {
params[k] = hash[k];
} else if (type === "ID") {
params[k] = get(self, hash[k], options);
params[k] = get(ctx, hash[k], options);
}
});
} else {
@ -24,12 +23,10 @@ export function resolveParams(options) {
export default function registerUnbound(name, fn) {
Handlebars.registerHelper(name, function(property, options) {
if (options.types && options.types[0] === "ID") {
property = get(this, property, options);
}
var params = resolveParams.call(this, options);
return fn.apply(this,[property, params]);
return fn.call(this, property, resolveParams(this, options));
});
}

View File

@ -1,6 +1,6 @@
import registerUnbound from 'discourse/helpers/register-unbound';
var safe = Handlebars.SafeString;
const Safe = Handlebars.SafeString;
registerUnbound('user-status', function(user) {
if (!user) { return; }
@ -10,11 +10,11 @@ registerUnbound('user-status', function(user) {
if(Discourse.User.currentProp("admin") || Discourse.User.currentProp("moderator")) {
if(user.get('admin')) {
var adminDesc = I18n.t('user.admin', {user: name});
return new safe('<i class="fa fa-shield" title="' + adminDesc + '" alt="' + adminDesc + '"></i>');
return new Safe('<i class="fa fa-shield" title="' + adminDesc + '" alt="' + adminDesc + '"></i>');
}
}
if(user.get('moderator')){
var modDesc = I18n.t('user.moderator', {user: name});
return new safe('<i class="fa fa-shield" title="' + modDesc + '" alt="' + modDesc + '"></i>');
return new Safe('<i class="fa fa-shield" title="' + modDesc + '" alt="' + modDesc + '"></i>');
}
});

View File

@ -8,7 +8,7 @@ export default {
initialize: function () {
if (!Discourse.MessageBus) { return; }
Discourse.MessageBus.subscribe("/logout", function (user_id) {
Discourse.MessageBus.subscribe("/logout", function () {
var refresher = function() {
var redirect = Discourse.SiteSettings.logout_redirect;
if(redirect.length === 0){
@ -17,7 +17,7 @@ export default {
window.location.href = redirect;
}
};
bootbox.dialog(I18n.t("logout"), {label: I18n.t("refresh"), callback: refresher}, {onEscape: refresher, backdrop: 'static'})
bootbox.dialog(I18n.t("logout"), {label: I18n.t("refresh"), callback: refresher}, {onEscape: refresher, backdrop: 'static'});
});
}
};

View File

@ -1,11 +1,10 @@
export default Ember.Object.extend(Ember.Evented);
var id = 1;
function newKey() {
return "_view_app_event_" + (id++);
}
export function createViewListener(eventName, cb) {
function createViewListener(eventName, cb) {
var extension = {};
extension[newKey()] = function() {
this.appEvents.on(eventName, this, cb);
@ -18,6 +17,9 @@ export function createViewListener(eventName, cb) {
return extension;
}
export function listenForViewEvent(viewClass, eventName, cb) {
function listenForViewEvent(viewClass, eventName, cb) {
viewClass.reopen(createViewListener(eventName, cb));
}
export { listenForViewEvent, createViewListener };
export default Ember.Object.extend(Ember.Evented);

View File

@ -270,7 +270,7 @@ export default function(options) {
updateAutoComplete(options.dataSource(""));
}
} else if ((completeStart !== null) && (e.charCode !== 0)) {
caretPosition = Discourse.Utilities.caretPosition(me[0]),
caretPosition = Discourse.Utilities.caretPosition(me[0]);
term = me.val().substring(completeStart + (options.key ? 1 : 0), caretPosition);
term += String.fromCharCode(e.charCode);
updateAutoComplete(options.dataSource(term));

View File

@ -136,7 +136,7 @@ var bindEvents = function(page,offset){
$('.emoji-page a').click(function(){
var title = $(this).attr('title');
trackEmojiUsage(title)
trackEmojiUsage(title);
composerController.appendTextAtCursor(":" + title + ":", {space: true});
closeSelector();
return false;

View File

@ -13,4 +13,4 @@ export default Em.Mixin.create({
return true;
}
}
})
});

View File

@ -21,7 +21,7 @@ var TopicRoute = Discourse.Route.extend(ShowFooter, {
cat = model.get('category');
// Only display uncategorized in the title tag if it was renamed
if (cat && !(cat.get('isUncategorizedCategory') && cat.get('name').toLowerCase() == "uncategorized")) {
if (cat && !(cat.get('isUncategorizedCategory') && cat.get('name').toLowerCase() === "uncategorized")) {
var catName = cat.get('name'),
parentCategory = cat.get('parentCategory');
@ -96,7 +96,6 @@ var TopicRoute = Discourse.Route.extend(ShowFooter, {
// Use replaceState to update the URL once it changes
postChangedRoute: function(currentPost) {
// do nothing if we are transitioning to another route
if (isTransitioning || Discourse.TopicRoute.disableReplaceState) { return; }

View File

@ -30,7 +30,7 @@ export default Discourse.View.extend({
position: "absolute",
top: location.top - $this.innerHeight() + 5,
left: location.left,
})
});
break;
}
case "fixed": {
@ -38,7 +38,7 @@ export default Discourse.View.extend({
position: "fixed",
top: location.top,
left: location.left - $this.innerWidth(),
})
});
break;
}
}

View File

@ -99,8 +99,16 @@ module Tilt
# Include JS code for JSHint
unless Rails.env.production?
req_path = "/assets/#{scope.logical_path}.js"
@output << "\nwindow.__jshintSrc = window.__jshintSrc || {}; window.__jshintSrc['#{req_path}'] = #{source.to_json};\n"
if scope.pathname.to_s =~ /js\.es6/
extension = "js.es6"
elsif scope.pathname.to_s =~ /\.es6/
extension = "es6"
else
extension = "js"
end
req_path = "/assets/#{scope.logical_path}.#{extension}"
@output << "\nwindow.__jshintSrc = window.__jshintSrc || {}; window.__jshintSrc['#{req_path}'] = #{data.to_json};\n"
end
@output

View File

@ -1,38 +1,17 @@
module("JSHint");
var qHint = function(name, sourceFile, options, globals) {
if (sourceFile === undefined || typeof(sourceFile) == "object") {
// jsHintTest('file.js', [options])
globals = options;
options = sourceFile;
sourceFile = name;
}
<%= "const JSHINT_OPTS = #{File.read(File.join(Rails.root, '.jshintrc'))};" %>
var qHint = function(name, sourceFile) {
return asyncTestDiscourse(name, function() {
if (typeof window.__jshintSrc !== "undefined") {
var src = window.__jshintSrc[sourceFile];
if (src) {
start();
qHint.validateFile(src, options, globals);
qHint.validateFile(src, JSHINT_OPTS);
return;
}
}
console.warn("Using AJAX for JSHint " + sourceFile);
qHint.sendRequest(sourceFile, function(req) {
start();
if (req.status == 200) {
var text = req.responseText;
qHint.validateFile(text, options, globals);
} else {
ok(false, "HTTP error " + req.status +
" while fetching " + sourceFile);
}
});
});
};
@ -100,6 +79,7 @@ qHint.sendRequest = function (url, callback) {
req.send();
};
<%
TO_IGNORE = File.read("#{Rails.root}/.jshintignore").split("\n")
@ -115,7 +95,7 @@ qHint.sendRequest = function (url, callback) {
end
depend_on filename
result << "qHint('#{filename}', '/assets/#{filename}', #{File.read(File.join(Rails.root, '.jshintrc'))});\n" if ok
result << "qHint('#{filename}', '/assets/#{filename}', JSHINT_OPTS);\n" if ok
end
result
@ -124,5 +104,5 @@ qHint.sendRequest = function (url, callback) {
<%= jshint("#{Rails.root}/test/**/*.js", "test/javascripts/") %>
<%= jshint("#{Rails.root}/app/assets/javascripts/**/*.js", "app/assets/javascripts/") %>
<%= jshint("#{Rails.root}/app/assets/javascripts/**/*.es6", "app/assets/javascripts/") %>

File diff suppressed because one or more lines are too long