Fix code style issues

This commit is contained in:
Tyler Long
2017-04-13 20:16:38 +08:00
parent dc4edf775d
commit a2ce9e6a54
8 changed files with 233 additions and 230 deletions

1
.gitignore vendored
View File

@@ -13,3 +13,4 @@ test/tmp_*
test/fixtures/samples/*.actual*
dist/*.js
todo.md

View File

@@ -172,7 +172,7 @@ var setClickFun = function (id, functionName) {
var elem = d3.select(element).select('#' + id)
if (elem !== null) {
elem.on('click', function () {
eval(functionName + '(\'' + id + '\')') // jshint ignore:line
window[functionName](id)
})
}
})
@@ -314,7 +314,8 @@ exports.defaultStyle = function () {
*/
exports.addSubGraph = function (list, title) {
function uniq (a) {
var prims = {'boolean': {}, 'number': {}, 'string': {}}, objs = []
var prims = {'boolean': {}, 'number': {}, 'string': {}}
var objs = []
return a.filter(function (item) {
var type = typeof item

View File

@@ -70,7 +70,7 @@ var getStartDate = function (prevTime, dateFormat, str) {
str = str.trim()
// Test for after
var re = /^after\s+([\d\w\-]+)/
var re = /^after\s+([\d\w-]+)/
var afterStatement = re.exec(str.trim())
if (afterStatement !== null) {

View File

@@ -190,9 +190,9 @@ module.exports.draw = function (text, id) {
.attr('font-size', conf.fontSize)
// .attr('font-family',conf.fontFamily)
.attr('x', function (d) {
var startX = timeScale(d.startTime),
endX = timeScale(d.endTime),
textWidth = this.getBBox().width
var startX = timeScale(d.startTime)
var endX = timeScale(d.endTime)
var textWidth = this.getBBox().width
// Check id text width > width of rectangle
if (textWidth > (endX - startX)) {
@@ -211,9 +211,9 @@ module.exports.draw = function (text, id) {
// .attr('text-anchor', 'middle')
.attr('text-height', theBarHeight)
.attr('class', function (d) {
var startX = timeScale(d.startTime),
endX = timeScale(d.endTime),
textWidth = this.getBBox().width
var startX = timeScale(d.startTime)
var endX = timeScale(d.endTime)
var textWidth = this.getBBox().width
var secNum = 0
for (var i = 0; i < categories.length; i++) {
if (d.type === categories[i]) {
@@ -280,11 +280,11 @@ module.exports.draw = function (text, id) {
// Day within a week (not monday)
['%a %d', function (d) {
// return d.getDay() ==1;
return d.getDay() && d.getDate() != 1
return d.getDay() && d.getDate() !== 1
}],
// within a month
['%b %d', function (d) {
return d.getDate() != 1
return d.getDate() !== 1
}],
// Month
['%B', function (d) {
@@ -377,9 +377,10 @@ module.exports.draw = function (text, id) {
.attr('class', 'today')
}
// from this stackexchange question: http://stackoverflow.com/questions/1890203/unique-for-arrays-in-javascript
// from this stackexchange question: http://stackoverflow.com/questions/1890203/unique-for-arrays-in-javascript
function checkUnique (arr) {
var hash = {}, result = []
var hash = {}
var result = []
for (var i = 0, l = arr.length; i < l; ++i) {
if (!hash.hasOwnProperty(arr[i])) { // it works with objects! in FF, at least
hash[arr[i]] = true
@@ -389,17 +390,17 @@ module.exports.draw = function (text, id) {
return result
}
// from this stackexchange question: http://stackoverflow.com/questions/14227981/count-how-many-strings-in-an-array-have-duplicates-in-the-same-array
// from this stackexchange question: http://stackoverflow.com/questions/14227981/count-how-many-strings-in-an-array-have-duplicates-in-the-same-array
function getCounts (arr) {
var i = arr.length, // var to loop over
obj = {} // obj to store results
var i = arr.length // var to loop over
var obj = {} // obj to store results
while (i) {
obj[arr[--i]] = (obj[arr[i]] || 0) + 1 // count occurrences
}
return obj
}
// get specific from everything
// get specific from everything
function getCount (word, arr) {
return getCounts(arr)[word] || 0
}

View File

@@ -24,7 +24,7 @@ function getId () {
function isfastforwardable (currentCommit, otherCommit) {
log.debug('Entering isfastforwardable:', currentCommit.id, otherCommit.id)
while (currentCommit.seq <= otherCommit.seq && currentCommit != otherCommit) {
while (currentCommit.seq <= otherCommit.seq && currentCommit !== otherCommit) {
// only if other branch has more commits
if (otherCommit.parent == null) break
if (Array.isArray(otherCommit.parent)) {
@@ -36,7 +36,7 @@ function isfastforwardable (currentCommit, otherCommit) {
}
}
log.debug(currentCommit.id, otherCommit.id)
return currentCommit.id == otherCommit.id
return currentCommit.id === otherCommit.id
}
function isReachableFrom (currentCommit, otherCommit) {
@@ -118,7 +118,7 @@ exports.reset = function (commitRef) {
log.debug('in reset', commitRef)
var ref = commitRef.split(':')[0]
var parentCount = parseInt(commitRef.split(':')[1])
var commit = ref == 'HEAD' ? head : commits[branches[ref]]
var commit = ref === 'HEAD' ? head : commits[branches[ref]]
log.debug(commit, parentCount)
while (parentCount > 0) {
commit = commits[commit.parent]
@@ -148,7 +148,7 @@ function prettyPrintCommitHistory (commitArr) {
var commit = _.maxBy(commitArr, 'seq')
var line = ''
_.each(commitArr, function (c) {
if (c == commit) {
if (c === commit) {
line += '\t*'
} else {
line += '\t|'
@@ -156,7 +156,7 @@ function prettyPrintCommitHistory (commitArr) {
})
var label = [line, commit.id, commit.seq]
_.each(branches, function (v, k) {
if (v == commit.id) label.push(k)
if (v === commit.id) label.push(k)
})
log.debug(label.join(' '))
if (Array.isArray(commit.parent)) {

View File

@@ -73,9 +73,9 @@ function svgDrawLine (svg, points, colorIdx, interpolate) {
// Pass in the element and its pre-transform coords
function getElementCoords (element, coords) {
coords = coords || element.node().getBBox()
var ctm = element.node().getCTM(),
xn = ctm.e + coords.x * ctm.a,
yn = ctm.f + coords.y * ctm.d
var ctm = element.node().getCTM()
var xn = ctm.e + coords.x * ctm.a
var yn = ctm.f + coords.y * ctm.d
// log.debug(ctm, coords);
return {
left: xn,
@@ -96,7 +96,7 @@ function svgDrawLineForCommits (svg, fromId, toId, direction, color) {
// +--------
// + (fromBbox)
if (fromBbox.left - toBbox.left > config.nodeSpacing) {
var lineStart = { x: fromBbox.left - config.nodeSpacing, y: toBbox.top + toBbox.height / 2}
var lineStart = { x: fromBbox.left - config.nodeSpacing, y: toBbox.top + toBbox.height / 2 }
var lineEnd = { x: toBbox.left + toBbox.width, y: toBbox.top + toBbox.height / 2 }
svgDrawLine(svg, [lineStart, lineEnd], color, 'linear')
svgDrawLine(svg, [
@@ -126,7 +126,7 @@ function svgDrawLineForCommits (svg, fromId, toId, direction, color) {
// |
// + (toBbox)
if (toBbox.top - fromBbox.top > config.nodeSpacing) {
lineStart = { x: toBbox.left + toBbox.width / 2, y: fromBbox.top + fromBbox.height + config.nodeSpacing}
lineStart = { x: toBbox.left + toBbox.width / 2, y: fromBbox.top + fromBbox.height + config.nodeSpacing }
lineEnd = { x: toBbox.left + toBbox.width / 2, y: toBbox.top }
svgDrawLine(svg, [lineStart, lineEnd], color, 'linear')
svgDrawLine(svg, [

View File

@@ -7,14 +7,14 @@ var proxyquire = require('proxyquire')
// var log = require('../../logger').create();
var sq = require('./parser/sequenceDiagram').parser
var newD3
var NewD3
var d3 = {
select: function () {
return new newD3()
return new NewD3()
},
selectAll: function () {
return new newD3()
return new NewD3()
}
}
// var sd = proxyquire('./sequenceRenderer', { './d3': d3 });
@@ -773,10 +773,10 @@ describe('when rendering a sequenceDiagram', function () {
// };
// sq.yy.parseError = parseError;
newD3 = function () {
NewD3 = function () {
var o = {
append: function () {
return newD3()
return NewD3()
},
attr: function () {
return this
@@ -998,10 +998,10 @@ describe('when rendering a sequenceDiagram with actor mirror activated', functio
// };
// sq.yy.parseError = parseError;
newD3 = function () {
NewD3 = function () {
var o = {
append: function () {
return newD3()
return NewD3()
},
attr: function () {
return this

View File

@@ -82,7 +82,7 @@ exports.bounds = {
_self.updateVal(exports.bounds.data, 'startx', startx - n * conf.boxMargin, Math.min)
_self.updateVal(exports.bounds.data, 'stopx', stopx + n * conf.boxMargin, Math.max)
if (!(type == 'activation')) {
if (!(type === 'activation')) {
_self.updateVal(item, 'startx', startx - n * conf.boxMargin, Math.min)
_self.updateVal(item, 'stopx', stopx + n * conf.boxMargin, Math.max)
@@ -308,7 +308,7 @@ module.exports.setConf = function (cnf) {
var actorActivations = function (actor) {
return module.exports.bounds.activations.filter(function (activation) {
return activation.actor == actor
return activation.actor === actor
})
}
@@ -360,7 +360,7 @@ module.exports.draw = function (text, id) {
exports.bounds.insert(activationData.startx, verticalPos - 10, activationData.stopx, verticalPos)
}
var lastMsg
// var lastMsg
// Draw the messages/signals
messages.forEach(function (msg) {
@@ -448,7 +448,7 @@ module.exports.draw = function (text, id) {
break
default:
try {
lastMsg = msg
// lastMsg = msg
exports.bounds.bumpVerticalPos(conf.messageMargin)
var fromBounds = actorFlowVerticaBounds(msg.from)
var toBounds = actorFlowVerticaBounds(msg.to)