Skip to content

Commit

Permalink
Update lodash and ESLint
Browse files Browse the repository at this point in the history
  • Loading branch information
lutzroeder committed Feb 16, 2019
1 parent 5cbd6ed commit ec3fd32
Show file tree
Hide file tree
Showing 57 changed files with 1,915 additions and 1,638 deletions.
13 changes: 13 additions & 0 deletions .eslintrc.json
@@ -0,0 +1,13 @@
{
"env": {
"browser": true,
"node": true,
"mocha": true
},
"extends": "eslint:recommended",
"rules": {
"indent": [ "error", 2 ],
"linebreak-style": [ "error", "unix" ],
"semi": [ "error", "always" ]
}
}
6 changes: 0 additions & 6 deletions .jscsrc

This file was deleted.

10 changes: 6 additions & 4 deletions Makefile
Expand Up @@ -4,7 +4,7 @@ NPM = npm
BROWSERIFY = ./node_modules/browserify/bin/cmd.js
ISTANBUL = ./node_modules/istanbul/lib/cli.js
JSHINT = ./node_modules/jshint/bin/jshint
JSCS = ./node_modules/jscs/bin/jscs
ESLINT = ./node_modules/eslint/bin/eslint.js
KARMA = ./node_modules/karma/bin/karma
MOCHA = ./node_modules/mocha/bin/_mocha
UGLIFY = ./node_modules/uglify-js/bin/uglifyjs
Expand All @@ -27,7 +27,7 @@ DIRS = $(BUILD_DIR)

.PHONY: all bench clean browser-test unit-test test dist

all: unit-test
all: unit-test lint

bench: test
@src/bench.js
Expand All @@ -42,8 +42,6 @@ test: unit-test browser-test

unit-test: $(SRC_FILES) $(TEST_FILES) node_modules | $(BUILD_DIR)
@$(ISTANBUL) cover $(ISTANBUL_OPTS) $(MOCHA) --dir $(COVERAGE_DIR) -- $(MOCHA_OPTS) $(TEST_FILES) || $(MOCHA) $(MOCHA_OPTS) $(TEST_FILES)
@$(JSHINT) $(JSHINT_OPTS) $(filter-out node_modules, $?)
@$(JSCS) $(filter-out node_modules, $?)

browser-test: $(BUILD_DIR)/$(MOD).js $(BUILD_DIR)/$(MOD).core.js
$(KARMA) start --single-run $(KARMA_OPTS)
Expand All @@ -52,6 +50,10 @@ browser-test: $(BUILD_DIR)/$(MOD).js $(BUILD_DIR)/$(MOD).core.js
bower.json: package.json src/release/make-bower.json.js
@src/release/make-bower.json.js > $@

lint:
@$(JSHINT) $(JSHINT_OPTS) $(filter-out node_modules, $?)
@$(ESLINT) $(SRC_FILES) $(TEST_FILES)

$(BUILD_DIR)/$(MOD).js: index.js $(SRC_FILES) | unit-test
@$(BROWSERIFY) $< > $@ -s dagre

Expand Down
14 changes: 7 additions & 7 deletions lib/acyclic.js
@@ -1,7 +1,7 @@
"use strict";

var _ = require("./lodash"),
greedyFAS = require("./greedy-fas");
var _ = require("./lodash");
var greedyFAS = require("./greedy-fas");

module.exports = {
run: run,
Expand All @@ -10,8 +10,8 @@ module.exports = {

function run(g) {
var fas = (g.graph().acyclicer === "greedy"
? greedyFAS(g, weightFn(g))
: dfsFAS(g));
? greedyFAS(g, weightFn(g))
: dfsFAS(g));
_.forEach(fas, function(e) {
var label = g.edge(e);
g.removeEdge(e);
Expand All @@ -28,9 +28,9 @@ function run(g) {
}

function dfsFAS(g) {
var fas = [],
stack = {},
visited = {};
var fas = [];
var stack = {};
var visited = {};

function dfs(v) {
if (_.has(visited, v)) {
Expand Down
18 changes: 9 additions & 9 deletions lib/add-border-segments.js
@@ -1,12 +1,12 @@
var _ = require("./lodash"),
util = require("./util");
var _ = require("./lodash");
var util = require("./util");

module.exports = addBorderSegments;

function addBorderSegments(g) {
function dfs(v) {
var children = g.children(v),
node = g.node(v);
var children = g.children(v);
var node = g.node(v);
if (children.length) {
_.forEach(children, dfs);
}
Expand All @@ -15,8 +15,8 @@ function addBorderSegments(g) {
node.borderLeft = [];
node.borderRight = [];
for (var rank = node.minRank, maxRank = node.maxRank + 1;
rank < maxRank;
++rank) {
rank < maxRank;
++rank) {
addBorderNode(g, "borderLeft", "_bl", v, node, rank);
addBorderNode(g, "borderRight", "_br", v, node, rank);
}
Expand All @@ -27,9 +27,9 @@ function addBorderSegments(g) {
}

function addBorderNode(g, prop, prefix, sg, sgNode, rank) {
var label = { width: 0, height: 0, rank: rank, borderType: prop },
prev = sgNode[prop][rank - 1],
curr = util.addDummyNode(g, "border", label, prefix);
var label = { width: 0, height: 0, rank: rank, borderType: prop };
var prev = sgNode[prop][rank - 1];
var curr = util.addDummyNode(g, "border", label, prefix);
sgNode[prop][rank] = curr;
g.setParent(curr, sg);
if (prev) {
Expand Down
10 changes: 5 additions & 5 deletions lib/data/list.js
Expand Up @@ -12,8 +12,8 @@ function List() {
}

List.prototype.dequeue = function() {
var sentinel = this._sentinel,
entry = sentinel._prev;
var sentinel = this._sentinel;
var entry = sentinel._prev;
if (entry !== sentinel) {
unlink(entry);
return entry;
Expand All @@ -32,9 +32,9 @@ List.prototype.enqueue = function(entry) {
};

List.prototype.toString = function() {
var strs = [],
sentinel = this._sentinel,
curr = sentinel._prev;
var strs = [];
var sentinel = this._sentinel;
var curr = sentinel._prev;
while (curr !== sentinel) {
strs.push(JSON.stringify(curr, filterOutLinks));
curr = curr._prev;
Expand Down
6 changes: 3 additions & 3 deletions lib/debug.js
@@ -1,6 +1,6 @@
var _ = require("./lodash"),
util = require("./util"),
Graph = require("./graphlib").Graph;
var _ = require("./lodash");
var util = require("./util");
var Graph = require("./graphlib").Graph;

module.exports = {
debugOrdering: debugOrdering
Expand Down
4 changes: 3 additions & 1 deletion lib/graphlib.js
Expand Up @@ -5,7 +5,9 @@ var graphlib;
if (typeof require === "function") {
try {
graphlib = require("graphlib");
} catch (e) {}
} catch (e) {
// continue regardless of error
}
}

if (!graphlib) {
Expand Down
34 changes: 17 additions & 17 deletions lib/greedy-fas.js
@@ -1,6 +1,6 @@
var _ = require("./lodash"),
Graph = require("./graphlib").Graph,
List = require("./data/list");
var _ = require("./lodash");
var Graph = require("./graphlib").Graph;
var List = require("./data/list");

/*
* A greedy heuristic for finding a feedback arc set for a graph. A feedback
Expand All @@ -27,9 +27,9 @@ function greedyFAS(g, weightFn) {
}

function doGreedyFAS(g, buckets, zeroIdx) {
var results = [],
sources = buckets[buckets.length - 1],
sinks = buckets[0];
var results = [];
var sources = buckets[buckets.length - 1];
var sinks = buckets[0];

var entry;
while (g.nodeCount()) {
Expand All @@ -53,8 +53,8 @@ function removeNode(g, buckets, zeroIdx, entry, collectPredecessors) {
var results = collectPredecessors ? [] : undefined;

_.forEach(g.inEdges(entry.v), function(edge) {
var weight = g.edge(edge),
uEntry = g.node(edge.v);
var weight = g.edge(edge);
var uEntry = g.node(edge.v);

if (collectPredecessors) {
results.push({ v: edge.v, w: edge.w });
Expand All @@ -65,9 +65,9 @@ function removeNode(g, buckets, zeroIdx, entry, collectPredecessors) {
});

_.forEach(g.outEdges(entry.v), function(edge) {
var weight = g.edge(edge),
w = edge.w,
wEntry = g.node(w);
var weight = g.edge(edge);
var w = edge.w;
var wEntry = g.node(w);
wEntry["in"] -= weight;
assignBucket(buckets, zeroIdx, wEntry);
});
Expand All @@ -78,9 +78,9 @@ function removeNode(g, buckets, zeroIdx, entry, collectPredecessors) {
}

function buildState(g, weightFn) {
var fasGraph = new Graph(),
maxIn = 0,
maxOut = 0;
var fasGraph = new Graph();
var maxIn = 0;
var maxOut = 0;

_.forEach(g.nodes(), function(v) {
fasGraph.setNode(v, { v: v, "in": 0, out: 0 });
Expand All @@ -89,9 +89,9 @@ function buildState(g, weightFn) {
// Aggregate weights on nodes, but also sum the weights across multi-edges
// into a single edge for the fasGraph.
_.forEach(g.edges(), function(e) {
var prevWeight = fasGraph.edge(e.v, e.w) || 0,
weight = weightFn(e),
edgeWeight = prevWeight + weight;
var prevWeight = fasGraph.edge(e.v, e.w) || 0;
var weight = weightFn(e);
var edgeWeight = prevWeight + weight;
fasGraph.setEdge(e.v, e.w, edgeWeight);
maxOut = Math.max(maxOut, fasGraph.node(e.v).out += weight);
maxIn = Math.max(maxIn, fasGraph.node(e.w)["in"] += weight);
Expand Down

0 comments on commit ec3fd32

Please sign in to comment.