From b3851817ecd59b039f2c2228d08a1c6fd8e60d60 Mon Sep 17 00:00:00 2001 From: Maxime Quandalle Date: Thu, 3 Sep 2015 23:12:46 +0200 Subject: 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). --- client/lib/utils.js | 66 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 29 deletions(-) (limited to 'client/lib/utils.js') diff --git a/client/lib/utils.js b/client/lib/utils.js index c6a9adc5..0cd93419 100644 --- a/client/lib/utils.js +++ b/client/lib/utils.js @@ -1,62 +1,70 @@ Utils = { // XXX We should remove these two methods - goBoardId: function(_id) { - var board = Boards.findOne(_id); + goBoardId(_id) { + const board = Boards.findOne(_id); return board && FlowRouter.go('board', { id: board._id, - slug: board.slug + slug: board.slug, }); }, - goCardId: function(_id) { - var card = Cards.findOne(_id); - var board = Boards.findOne(card.boardId); + goCardId(_id) { + const card = Cards.findOne(_id); + const board = Boards.findOne(card.boardId); return board && FlowRouter.go('card', { cardId: card._id, boardId: board._id, - slug: board.slug + slug: board.slug, }); }, - capitalize: function(string) { + capitalize(string) { return string.charAt(0).toUpperCase() + string.slice(1); }, - getLabelIndex: function(boardId, labelId) { - var board = Boards.findOne(boardId); - var labels = {}; - _.each(board.labels, function(a, b) { + getLabelIndex(boardId, labelId) { + const board = Boards.findOne(boardId); + const labels = {}; + _.each(board.labels, (a, b) => { labels[a._id] = b; }); return { index: labels[labelId], - key: function(key) { - return 'labels.' + labels[labelId] + '.' + key; - } + key(key) { + return `labels.${labels[labelId]}.${key}`; + }, }; }, // Determine the new sort index - calculateIndex: function(prevCardDomElement, nextCardDomElement, nCards) { - nCards = nCards || 1; - + calculateIndex(prevCardDomElement, nextCardDomElement, nCards = 1) { + let base, increment; // If we drop the card to an empty column - if (! prevCardDomElement && ! nextCardDomElement) { - return {base: 0, increment: 1}; + if (!prevCardDomElement && !nextCardDomElement) { + base = 0; + increment = 1; // If we drop the card in the first position - } else if (! prevCardDomElement) { - return {base: Blaze.getData(nextCardDomElement).sort - 1, increment: -1}; + } else if (!prevCardDomElement) { + base = Blaze.getData(nextCardDomElement).sort - 1; + increment = -1; // If we drop the card in the last position - } else if (! nextCardDomElement) { - return {base: Blaze.getData(prevCardDomElement).sort + 1, increment: 1}; + } else if (!nextCardDomElement) { + base = Blaze.getData(prevCardDomElement).sort + 1; + increment = 1; } // In the general case take the average of the previous and next element // sort indexes. else { - var prevSortIndex = Blaze.getData(prevCardDomElement).sort; - var nextSortIndex = Blaze.getData(nextCardDomElement).sort; - var increment = (nextSortIndex - prevSortIndex) / (nCards + 1); - return {base: prevSortIndex + increment, increment: increment}; + const prevSortIndex = Blaze.getData(prevCardDomElement).sort; + const nextSortIndex = Blaze.getData(nextCardDomElement).sort; + increment = (nextSortIndex - prevSortIndex) / (nCards + 1); + base = prevSortIndex + increment; } - } + // XXX Return a generator that yield values instead of a base with a + // increment number. + return { + base, + increment, + }; + }, }; -- cgit v1.2.3-1-g7c22