Enforce a consistent ES6 coding style

Replace the old (and broken) jshint + jscsrc by eslint and configure
it to support some of the ES6 features.

The command `eslint` currently has one error which is a bug that was
discovered by its static analysis and should be fixed (usage of a
dead object).
This commit is contained in:
Maxime Quandalle 2015-09-03 23:12:46 +02:00
parent 039cfe7edf
commit b3851817ec
60 changed files with 1604 additions and 1692 deletions

View file

@ -1,136 +1,136 @@
var labelColors;
Meteor.startup(function() {
let labelColors;
Meteor.startup(() => {
labelColors = Boards.simpleSchema()._schema['labels.$.color'].allowedValues;
});
BlazeComponent.extendComponent({
template: function() {
template() {
return 'formLabel';
},
onCreated: function() {
onCreated() {
this.currentColor = new ReactiveVar(this.data().color);
},
labels: function() {
return _.map(labelColors, function(color) {
return { color: color, name: '' };
labels() {
return _.map(labelColors, (color) => {
return { color, name: '' };
});
},
isSelected: function(color) {
isSelected(color) {
return this.currentColor.get() === color;
},
events: function() {
events() {
return [{
'click .js-palette-color': function() {
'click .js-palette-color'() {
this.currentColor.set(this.currentData().color);
}
},
}];
}
},
}).register('formLabel');
Template.createLabelPopup.helpers({
// This is the default color for a new label. We search the first color that
// is not already used in the board (although it's not a problem if two
// labels have the same color).
defaultColor: function() {
var labels = Boards.findOne(Session.get('currentBoard')).labels;
var usedColors = _.pluck(labels, 'color');
var availableColors = _.difference(labelColors, usedColors);
defaultColor() {
const labels = Boards.findOne(Session.get('currentBoard')).labels;
const usedColors = _.pluck(labels, 'color');
const availableColors = _.difference(labelColors, usedColors);
return availableColors.length > 1 ? availableColors[0] : labelColors[0];
}
},
});
Template.cardLabelsPopup.events({
'click .js-select-label': function(evt) {
var cardId = Template.parentData(2).data._id;
var labelId = this._id;
var operation;
'click .js-select-label'(evt) {
const cardId = Template.parentData(2).data._id;
const labelId = this._id;
let operation;
if (Cards.find({ _id: cardId, labelIds: labelId}).count() === 0)
operation = '$addToSet';
else
operation = '$pull';
var query = {};
query[operation] = {
labelIds: labelId
};
Cards.update(cardId, query);
Cards.update(cardId, {
[operation]: {
labelIds: labelId,
},
});
evt.preventDefault();
},
'click .js-edit-label': Popup.open('editLabel'),
'click .js-add-label': Popup.open('createLabel')
'click .js-add-label': Popup.open('createLabel'),
});
Template.formLabel.events({
'click .js-palette-color': function(evt) {
var $this = $(evt.currentTarget);
'click .js-palette-color'(evt) {
const $this = $(evt.currentTarget);
// hide selected ll colors
$('.js-palette-select').addClass('hide');
// show select color
$this.find('.js-palette-select').removeClass('hide');
}
},
});
Template.createLabelPopup.events({
// Create the new label
'submit .create-label': function(evt, tpl) {
var name = tpl.$('#labelName').val().trim();
var boardId = Session.get('currentBoard');
var color = Blaze.getData(tpl.find('.fa-check')).color;
'submit .create-label'(evt, tpl) {
const name = tpl.$('#labelName').val().trim();
const boardId = Session.get('currentBoard');
const color = Blaze.getData(tpl.find('.fa-check')).color;
Boards.update(boardId, {
$push: {
labels: {
name,
color,
_id: Random.id(6),
name: name,
color: color
}
}
},
},
});
Popup.back();
evt.preventDefault();
}
},
});
Template.editLabelPopup.events({
'click .js-delete-label': Popup.afterConfirm('deleteLabel', function() {
var boardId = Session.get('currentBoard');
const boardId = Session.get('currentBoard');
Boards.update(boardId, {
$pull: {
labels: {
_id: this._id
}
}
_id: this._id,
},
},
});
Popup.back(2);
}),
'submit .edit-label': function(evt, tpl) {
'submit .edit-label'(evt, tpl) {
evt.preventDefault();
var name = tpl.$('#labelName').val().trim();
var boardId = Session.get('currentBoard');
var getLabel = Utils.getLabelIndex(boardId, this._id);
var color = Blaze.getData(tpl.find('.fa-check')).color;
const name = tpl.$('#labelName').val().trim();
const boardId = Session.get('currentBoard');
const getLabel = Utils.getLabelIndex(boardId, this._id);
const color = Blaze.getData(tpl.find('.fa-check')).color;
var $set = {};
$set[getLabel.key('name')] = name;
$set[getLabel.key('color')] = color;
Boards.update(boardId, { $set: $set });
Boards.update(boardId, {
$set: {
[getLabel.key('name')]: name,
[getLabel.key('color')]: color,
},
});
Popup.back();
}
},
});
Template.cardLabelsPopup.helpers({
isLabelSelected: function(cardId) {
isLabelSelected(cardId) {
return _.contains(Cards.findOne(cardId).labelIds, this._id);
}
},
});