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 4ae28f4 commit 64a1b87
Show file tree
Hide file tree
Showing 35 changed files with 1,175 additions and 882 deletions.
13 changes: 13 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -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.

12 changes: 7 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
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,9 +27,9 @@ DIRS = $(BUILD_DIR)

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

all: unit-test
all: unit-test lint

bench: test
bench: unit-test lint
@src/bench.js

lib/version.js: package.json
Expand All @@ -42,8 +42,6 @@ test: unit-test browser-test browser-test-amd

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 @@ -55,6 +53,10 @@ browser-test-amd: $(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 graphlib

Expand Down
6 changes: 3 additions & 3 deletions lib/alg/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ var _ = require("../lodash");
module.exports = components;

function components(g) {
var visited = {},
cmpts = [],
cmpt;
var visited = {};
var cmpts = [];
var cmpt;

function dfs(v) {
if (_.has(visited, v)) return;
Expand Down
4 changes: 2 additions & 2 deletions lib/alg/dfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ function dfs(g, vs, order) {

var navigation = (g.isDirected() ? g.successors : g.neighbors).bind(g);

var acc = [],
visited = {};
var acc = [];
var visited = {};
_.each(vs, function(v) {
if (!g.hasNode(v)) {
throw new Error("Graph does not have node: " + v);
Expand Down
4 changes: 2 additions & 2 deletions lib/alg/dijkstra-all.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var dijkstra = require("./dijkstra"),
_ = require("../lodash");
var dijkstra = require("./dijkstra");
var _ = require("../lodash");

module.exports = dijkstraAll;

Expand Down
22 changes: 11 additions & 11 deletions lib/alg/dijkstra.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
var _ = require("../lodash"),
PriorityQueue = require("../data/priority-queue");
var _ = require("../lodash");
var PriorityQueue = require("../data/priority-queue");

module.exports = dijkstra;

var DEFAULT_WEIGHT_FUNC = _.constant(1);

function dijkstra(g, source, weightFn, edgeFn) {
return runDijkstra(g, String(source),
weightFn || DEFAULT_WEIGHT_FUNC,
edgeFn || function(v) { return g.outEdges(v); });
weightFn || DEFAULT_WEIGHT_FUNC,
edgeFn || function(v) { return g.outEdges(v); });
}

function runDijkstra(g, source, weightFn, edgeFn) {
var results = {},
pq = new PriorityQueue(),
v, vEntry;
var results = {};
var pq = new PriorityQueue();
var v, vEntry;

var updateNeighbors = function(edge) {
var w = edge.v !== v ? edge.v : edge.w,
wEntry = results[w],
weight = weightFn(edge),
distance = vEntry.distance + weight;
var w = edge.v !== v ? edge.v : edge.w;
var wEntry = results[w];
var weight = weightFn(edge);
var distance = vEntry.distance + weight;

if (weight < 0) {
throw new Error("dijkstra does not allow negative edge weights. " +
Expand Down
4 changes: 2 additions & 2 deletions lib/alg/find-cycles.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var _ = require("../lodash"),
tarjan = require("./tarjan");
var _ = require("../lodash");
var tarjan = require("./tarjan");

module.exports = findCycles;

Expand Down
12 changes: 6 additions & 6 deletions lib/alg/floyd-warshall.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ var DEFAULT_WEIGHT_FUNC = _.constant(1);

function floydWarshall(g, weightFn, edgeFn) {
return runFloydWarshall(g,
weightFn || DEFAULT_WEIGHT_FUNC,
edgeFn || function(v) { return g.outEdges(v); });
weightFn || DEFAULT_WEIGHT_FUNC,
edgeFn || function(v) { return g.outEdges(v); });
}

function runFloydWarshall(g, weightFn, edgeFn) {
var results = {},
nodes = g.nodes();
var results = {};
var nodes = g.nodes();

nodes.forEach(function(v) {
results[v] = {};
Expand All @@ -23,8 +23,8 @@ function runFloydWarshall(g, weightFn, edgeFn) {
}
});
edgeFn(v).forEach(function(edge) {
var w = edge.v === v ? edge.w : edge.v,
d = weightFn(edge);
var w = edge.v === v ? edge.w : edge.v;
var d = weightFn(edge);
results[v][w] = { distance: d, predecessor: v };
});
});
Expand Down
18 changes: 9 additions & 9 deletions lib/alg/prim.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
var _ = require("../lodash"),
Graph = require("../graph"),
PriorityQueue = require("../data/priority-queue");
var _ = require("../lodash");
var Graph = require("../graph");
var PriorityQueue = require("../data/priority-queue");

module.exports = prim;

function prim(g, weightFunc) {
var result = new Graph(),
parents = {},
pq = new PriorityQueue(),
v;
var result = new Graph();
var parents = {};
var pq = new PriorityQueue();
var v;

function updateNeighbors(edge) {
var w = edge.v === v ? edge.w : edge.v,
pri = pq.priority(w);
var w = edge.v === v ? edge.w : edge.v;
var pri = pq.priority(w);
if (pri !== undefined) {
var edgeWeight = weightFunc(edge);
if (edgeWeight < pri) {
Expand Down
12 changes: 6 additions & 6 deletions lib/alg/tarjan.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ var _ = require("../lodash");
module.exports = tarjan;

function tarjan(g) {
var index = 0,
stack = [],
visited = {}, // node id -> { onStack, lowlink, index }
results = [];
var index = 0;
var stack = [];
var visited = {}; // node id -> { onStack, lowlink, index }
var results = [];

function dfs(v) {
var entry = visited[v] = {
Expand All @@ -26,8 +26,8 @@ function tarjan(g) {
});

if (entry.lowlink === entry.index) {
var cmpt = [],
w;
var cmpt = [];
var w;
do {
w = stack.pop();
visited[w].onStack = false;
Expand Down
6 changes: 3 additions & 3 deletions lib/alg/topsort.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ module.exports = topsort;
topsort.CycleException = CycleException;

function topsort(g) {
var visited = {},
stack = {},
results = [];
var visited = {};
var stack = {};
var results = [];

function visit(node) {
if (_.has(stack, node)) {
Expand Down
6 changes: 3 additions & 3 deletions lib/data/priority-queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ PriorityQueue.prototype.decrease = function(key, priority) {

PriorityQueue.prototype._heapify = function(i) {
var arr = this._arr;
var l = 2 * i,
r = l + 1,
largest = i;
var l = 2 * i;
var r = l + 1;
var largest = i;
if (l < arr.length) {
largest = arr[l].priority < arr[largest].priority ? l : largest;
if (r < arr.length) {
Expand Down
34 changes: 17 additions & 17 deletions lib/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ var _ = require("./lodash");

module.exports = Graph;

var DEFAULT_EDGE_NAME = "\x00",
GRAPH_NODE = "\x00",
EDGE_KEY_DELIM = "\x01";
var DEFAULT_EDGE_NAME = "\x00";
var GRAPH_NODE = "\x00";
var EDGE_KEY_DELIM = "\x01";

// Implementation notes:
//
Expand Down Expand Up @@ -204,8 +204,8 @@ Graph.prototype.setParent = function(v, parent) {
// Coerce parent to string
parent += "";
for (var ancestor = parent;
!_.isUndefined(ancestor);
ancestor = this.parent(ancestor)) {
!_.isUndefined(ancestor);
ancestor = this.parent(ancestor)) {
if (ancestor === v) {
throw new Error("Setting " + parent+ " as parent of " + v +
" would create a cycle");
Expand Down Expand Up @@ -346,8 +346,8 @@ Graph.prototype.edges = function() {
};

Graph.prototype.setPath = function(vs, value) {
var self = this,
args = arguments;
var self = this;
var args = arguments;
_.reduce(vs, function(v, w) {
if (args.length > 1) {
self.setEdge(v, w, value);
Expand All @@ -364,9 +364,9 @@ Graph.prototype.setPath = function(vs, value) {
* setEdge({ v, w, [name] }, [value])
*/
Graph.prototype.setEdge = function() {
var v, w, name, value,
valueSpecified = false,
arg0 = arguments[0];
var v, w, name, value;
var valueSpecified = false;
var arg0 = arguments[0];

if (typeof arg0 === "object" && arg0 !== null && "v" in arg0) {
v = arg0.v;
Expand Down Expand Up @@ -428,23 +428,23 @@ Graph.prototype.setEdge = function() {

Graph.prototype.edge = function(v, w, name) {
var e = (arguments.length === 1
? edgeObjToId(this._isDirected, arguments[0])
: edgeArgsToId(this._isDirected, v, w, name));
? edgeObjToId(this._isDirected, arguments[0])
: edgeArgsToId(this._isDirected, v, w, name));
return this._edgeLabels[e];
};

Graph.prototype.hasEdge = function(v, w, name) {
var e = (arguments.length === 1
? edgeObjToId(this._isDirected, arguments[0])
: edgeArgsToId(this._isDirected, v, w, name));
? edgeObjToId(this._isDirected, arguments[0])
: edgeArgsToId(this._isDirected, v, w, name));
return _.has(this._edgeLabels, e);
};

Graph.prototype.removeEdge = function(v, w, name) {
var e = (arguments.length === 1
? edgeObjToId(this._isDirected, arguments[0])
: edgeArgsToId(this._isDirected, v, w, name)),
edge = this._edgeObjs[e];
? edgeObjToId(this._isDirected, arguments[0])
: edgeArgsToId(this._isDirected, v, w, name));
var edge = this._edgeObjs[e];
if (edge) {
v = edge.v;
w = edge.w;
Expand Down
14 changes: 7 additions & 7 deletions lib/json.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var _ = require("./lodash"),
Graph = require("./graph");
var _ = require("./lodash");
var Graph = require("./graph");

module.exports = {
write: write,
Expand All @@ -24,9 +24,9 @@ function write(g) {

function writeNodes(g) {
return _.map(g.nodes(), function(v) {
var nodeValue = g.node(v),
parent = g.parent(v),
node = { v: v };
var nodeValue = g.node(v);
var parent = g.parent(v);
var node = { v: v };
if (!_.isUndefined(nodeValue)) {
node.value = nodeValue;
}
Expand All @@ -39,8 +39,8 @@ function writeNodes(g) {

function writeEdges(g) {
return _.map(g.edges(), function(e) {
var edgeValue = g.edge(e),
edge = { v: e.v, w: e.w };
var edgeValue = g.edge(e);
var edge = { v: e.v, w: e.w };
if (!_.isUndefined(e.name)) {
edge.name = e.name;
}
Expand Down
4 changes: 3 additions & 1 deletion lib/lodash.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ if (typeof require === "function") {
union: require("lodash/union"),
values: require("lodash/values")
};
} catch (e) {}
} catch (e) {
// continue regardless of error
}
}

if (!lodash) {
Expand Down
Loading

0 comments on commit 64a1b87

Please sign in to comment.