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,8 +1,8 @@
Template.headerTitle.events({
'click .js-open-archived-board': function() {
Modal.open('archivedBoards')
}
})
'click .js-open-archived-board'() {
Modal.open('archivedBoards');
},
});
BlazeComponent.extendComponent({
template() {
@ -10,26 +10,26 @@ BlazeComponent.extendComponent({
},
onCreated() {
this.subscribe('archivedBoards')
this.subscribe('archivedBoards');
},
archivedBoards() {
return Boards.find({ archived: true }, {
sort: ['title']
})
sort: ['title'],
});
},
events() {
return [{
'click .js-restore-board': function() {
let boardId = this.currentData()._id
'click .js-restore-board'() {
const boardId = this.currentData()._id;
Boards.update(boardId, {
$set: {
archived: false
}
})
Utils.goBoardId(boardId)
}
}]
archived: false,
},
});
Utils.goBoardId(boardId);
},
}];
},
}).register('archivedBoards')
}).register('archivedBoards');

View file

@ -1,11 +1,11 @@
var subManager = new SubsManager();
const subManager = new SubsManager();
BlazeComponent.extendComponent({
template: function() {
template() {
return 'board';
},
onCreated: function() {
onCreated() {
this.draggingActive = new ReactiveVar(false);
this.showOverlay = new ReactiveVar(false);
this.isBoardReady = new ReactiveVar(false);
@ -15,15 +15,15 @@ BlazeComponent.extendComponent({
// XXX The boardId should be readed from some sort the component "props",
// unfortunatly, Blaze doesn't have this notion.
this.autorun(() => {
let currentBoardId = Session.get('currentBoard');
if (! currentBoardId)
const currentBoardId = Session.get('currentBoard');
if (!currentBoardId)
return;
var handle = subManager.subscribe('board', currentBoardId);
const handle = subManager.subscribe('board', currentBoardId);
Tracker.nonreactive(() => {
Tracker.autorun(() => {
this.isBoardReady.set(handle.ready());
})
})
});
});
});
this._isDragging = false;
@ -33,52 +33,52 @@ BlazeComponent.extendComponent({
this.mouseHasEnterCardDetails = false;
},
openNewListForm: function() {
openNewListForm() {
this.componentChildren('addListForm')[0].open();
},
// XXX Flow components allow us to avoid creating these two setter methods by
// exposing a public API to modify the component state. We need to investigate
// best practices here.
setIsDragging: function(bool) {
setIsDragging(bool) {
this.draggingActive.set(bool);
},
scrollLeft: function(position = 0) {
scrollLeft(position = 0) {
this.$('.js-lists').animate({
scrollLeft: position
scrollLeft: position,
});
},
currentCardIsInThisList: function() {
var currentCard = Cards.findOne(Session.get('currentCard'));
var listId = this.currentData()._id;
currentCardIsInThisList() {
const currentCard = Cards.findOne(Session.get('currentCard'));
const listId = this.currentData()._id;
return currentCard && currentCard.listId === listId;
},
events: function() {
events() {
return [{
// XXX The board-overlay div should probably be moved to the parent
// component.
'mouseenter .board-overlay': function() {
'mouseenter .board-overlay'() {
if (this.mouseHasEnterCardDetails) {
this.showOverlay.set(false);
}
},
// Click-and-drag action
'mousedown .board-canvas': function(evt) {
'mousedown .board-canvas'(evt) {
if ($(evt.target).closest('a,.js-list-header').length === 0) {
this._isDragging = true;
this._lastDragPositionX = evt.clientX;
}
},
'mouseup': function(evt) {
'mouseup'() {
if (this._isDragging) {
this._isDragging = false;
}
},
'mousemove': function(evt) {
'mousemove'(evt) {
if (this._isDragging) {
// Update the canvas position
this.listsDom.scrollLeft -= evt.clientX - this._lastDragPositionX;
@ -91,40 +91,40 @@ BlazeComponent.extendComponent({
EscapeActions.executeUpTo('popup-close');
EscapeActions.preventNextClick();
}
}
},
}];
}
},
}).register('board');
Template.boardBody.onRendered(function() {
var self = BlazeComponent.getComponentForElement(this.firstNode);
const self = BlazeComponent.getComponentForElement(this.firstNode);
self.listsDom = this.find('.js-lists');
if (! Session.get('currentCard')) {
if (!Session.get('currentCard')) {
self.scrollLeft();
}
// We want to animate the card details window closing. We rely on CSS
// transition for the actual animation.
self.listsDom._uihooks = {
removeElement: function(node) {
var removeNode = _.once(function() {
removeElement(node) {
const removeNode = _.once(() => {
node.parentNode.removeChild(node);
});
if ($(node).hasClass('js-card-details')) {
$(node).css({
flexBasis: 0,
padding: 0
padding: 0,
});
$(self.listsDom).one(CSSEvents.transitionend, removeNode);
} else {
removeNode();
}
}
},
};
if (! Meteor.user() || ! Meteor.user().isBoardMember())
if (!Meteor.user() || !Meteor.user().isBoardMember())
return;
self.$(self.listsDom).sortable({
@ -134,63 +134,63 @@ Template.boardBody.onRendered(function() {
items: '.js-list:not(.js-list-composer)',
placeholder: 'list placeholder',
distance: 7,
start: function(evt, ui) {
start(evt, ui) {
ui.placeholder.height(ui.helper.height());
Popup.close();
},
stop: function() {
stop() {
self.$('.js-lists').find('.js-list:not(.js-list-composer)').each(
function(i, list) {
var data = Blaze.getData(list);
(i, list) => {
const data = Blaze.getData(list);
Lists.update(data._id, {
$set: {
sort: i
}
sort: i,
},
});
}
);
}
},
});
// Disable drag-dropping while in multi-selection mode
self.autorun(function() {
self.autorun(() => {
self.$(self.listsDom).sortable('option', 'disabled',
MultiSelection.isActive());
});
// If there is no data in the board (ie, no lists) we autofocus the list
// creation form by clicking on the corresponding element.
var currentBoard = Boards.findOne(Session.get('currentBoard'));
const currentBoard = Boards.findOne(Session.get('currentBoard'));
if (currentBoard.lists().count() === 0) {
self.openNewListForm();
}
});
BlazeComponent.extendComponent({
template: function() {
template() {
return 'addListForm';
},
// Proxy
open: function() {
open() {
this.componentChildren('inlinedForm')[0].open();
},
events: function() {
events() {
return [{
submit: function(evt) {
submit(evt) {
evt.preventDefault();
var title = this.find('.list-name-input');
const title = this.find('.list-name-input');
if ($.trim(title.value)) {
Lists.insert({
title: title.value,
boardId: Session.get('currentBoard'),
sort: $('.list').length
sort: $('.list').length,
});
title.value = '';
}
}
},
}];
}
},
}).register('addListForm');

View file

@ -1,143 +1,143 @@
Template.boardMenuPopup.events({
'click .js-rename-board': Popup.open('boardChangeTitle'),
'click .js-open-archives': function() {
'click .js-open-archives'() {
Sidebar.setView('archives');
Popup.close();
},
'click .js-change-board-color': Popup.open('boardChangeColor'),
'click .js-change-language': Popup.open('changeLanguage'),
'click .js-archive-board ': Popup.afterConfirm('archiveBoard', function() {
var boardId = Session.get('currentBoard');
'click .js-archive-board ': Popup.afterConfirm('archiveBoard', () => {
const boardId = Session.get('currentBoard');
Boards.update(boardId, { $set: { archived: true }});
// XXX We should have some kind of notification on top of the page to
// confirm that the board was successfully archived.
FlowRouter.go('home');
})
}),
});
Template.boardChangeTitlePopup.events({
submit: function(evt, t) {
var title = t.$('.js-board-name').val().trim();
submit(evt, tpl) {
const title = tpl.$('.js-board-name').val().trim();
if (title) {
Boards.update(this._id, {
$set: {
title: title
}
title,
},
});
Popup.close();
}
evt.preventDefault();
}
},
});
BlazeComponent.extendComponent({
template: function() {
template() {
return 'headerBoard';
},
isStarred: function() {
var boardId = Session.get('currentBoard');
var user = Meteor.user();
isStarred() {
const boardId = Session.get('currentBoard');
const user = Meteor.user();
return user && user.hasStarred(boardId);
},
// Only show the star counter if the number of star is greater than 2
showStarCounter: function() {
var currentBoard = this.currentData();
showStarCounter() {
const currentBoard = this.currentData();
return currentBoard && currentBoard.stars >= 2;
},
events: function() {
events() {
return [{
'click .js-edit-board-title': Popup.open('boardChangeTitle'),
'click .js-star-board': function() {
'click .js-star-board'() {
Meteor.user().toggleBoardStar(Session.get('currentBoard'));
},
'click .js-open-board-menu': Popup.open('boardMenu'),
'click .js-change-visibility': Popup.open('boardChangeVisibility'),
'click .js-open-filter-view': function() {
'click .js-open-filter-view'() {
Sidebar.setView('filter');
},
'click .js-filter-reset': function(evt) {
'click .js-filter-reset'(evt) {
evt.stopPropagation();
Sidebar.setView();
Filter.reset();
},
'click .js-multiselection-activate': function() {
var currentCard = Session.get('currentCard');
'click .js-multiselection-activate'() {
const currentCard = Session.get('currentCard');
MultiSelection.activate();
if (currentCard) {
MultiSelection.add(currentCard);
}
},
'click .js-multiselection-reset': function(evt) {
'click .js-multiselection-reset'(evt) {
evt.stopPropagation();
MultiSelection.disable();
}
},
}];
}
},
}).register('headerBoard');
BlazeComponent.extendComponent({
template: function() {
template() {
return 'boardChangeColorPopup';
},
backgroundColors: function() {
backgroundColors() {
return Boards.simpleSchema()._schema.color.allowedValues;
},
isSelected: function() {
var currentBoard = Boards.findOne(Session.get('currentBoard'));
isSelected() {
const currentBoard = Boards.findOne(Session.get('currentBoard'));
return currentBoard.color === this.currentData().toString();
},
events: function() {
events() {
return [{
'click .js-select-background': function(evt) {
var currentBoardId = Session.get('currentBoard');
'click .js-select-background'(evt) {
const currentBoardId = Session.get('currentBoard');
Boards.update(currentBoardId, {
$set: {
color: this.currentData().toString()
}
color: this.currentData().toString(),
},
});
evt.preventDefault();
}
},
}];
}
},
}).register('boardChangeColorPopup');
BlazeComponent.extendComponent({
template: function() {
template() {
return 'createBoardPopup';
},
onCreated: function() {
onCreated() {
this.visibilityMenuIsOpen = new ReactiveVar(false);
this.visibility = new ReactiveVar('private');
},
visibilityCheck: function() {
visibilityCheck() {
return this.currentData() === this.visibility.get();
},
setVisibility: function(visibility) {
setVisibility(visibility) {
this.visibility.set(visibility);
this.visibilityMenuIsOpen.set(false);
},
toogleVisibilityMenu: function() {
this.visibilityMenuIsOpen.set(! this.visibilityMenuIsOpen.get());
toogleVisibilityMenu() {
this.visibilityMenuIsOpen.set(!this.visibilityMenuIsOpen.get());
},
onSubmit: function(evt) {
onSubmit(evt) {
evt.preventDefault();
var title = this.find('.js-new-board-title').value;
var visibility = this.visibility.get();
const title = this.find('.js-new-board-title').value;
const visibility = this.visibility.get();
var boardId = Boards.insert({
title: title,
permission: visibility
const boardId = Boards.insert({
title,
permission: visibility,
});
Utils.goBoardId(boardId);
@ -146,39 +146,39 @@ BlazeComponent.extendComponent({
Meteor.user().toggleBoardStar(boardId);
},
events: function() {
events() {
return [{
'click .js-select-visibility': function() {
'click .js-select-visibility'() {
this.setVisibility(this.currentData());
},
'click .js-change-visibility': this.toogleVisibilityMenu,
submit: this.onSubmit
submit: this.onSubmit,
}];
}
},
}).register('createBoardPopup');
BlazeComponent.extendComponent({
template: function() {
template() {
return 'boardChangeVisibilityPopup';
},
visibilityCheck: function() {
var currentBoard = Boards.findOne(Session.get('currentBoard'));
visibilityCheck() {
const currentBoard = Boards.findOne(Session.get('currentBoard'));
return this.currentData() === currentBoard.permission;
},
selectBoardVisibility: function() {
selectBoardVisibility() {
Boards.update(Session.get('currentBoard'), {
$set: {
permission: this.currentData()
}
permission: this.currentData(),
},
});
Popup.close();
},
events: function() {
events() {
return [{
'click .js-select-visibility': this.selectBoardVisibility
'click .js-select-visibility': this.selectBoardVisibility,
}];
}
},
}).register('boardChangeVisibilityPopup');

View file

@ -1,30 +1,30 @@
BlazeComponent.extendComponent({
template: function() {
template() {
return 'boardList';
},
boards: function() {
boards() {
return Boards.find({
archived: false,
'members.userId': Meteor.userId()
'members.userId': Meteor.userId(),
}, {
sort: ['title']
sort: ['title'],
});
},
isStarred: function() {
var user = Meteor.user();
isStarred() {
const user = Meteor.user();
return user && user.hasStarred(this.currentData()._id);
},
events: function() {
events() {
return [{
'click .js-add-board': Popup.open('createBoard'),
'click .js-star-board': function(evt) {
var boardId = this.currentData()._id;
'click .js-star-board'(evt) {
const boardId = this.currentData()._id;
Meteor.user().toggleBoardStar(boardId);
evt.preventDefault();
}
},
}];
}
},
}).register('boardList');