From 3e143435e6d878b517a31c8e201c2a9128c4e96e Mon Sep 17 00:00:00 2001 From: Nils Schneider Date: Sun, 29 Mar 2015 16:14:10 +0200 Subject: [PATCH] make eslint happy --- Gruntfile.js | 2 -- lib/linklist.js | 2 +- lib/main.js | 34 +++++++++++++++++-------------- lib/map.js | 44 ++++++++++++++++++++-------------------- lib/nodelist.js | 47 +++++++++++++++++++++---------------------- lib/router.js | 38 +++++++++++++++++----------------- lib/sidebar.js | 2 +- lib/simplenodelist.js | 4 ++-- lib/tabs.js | 2 +- package.json | 25 ++++++++++++++++++++++- tasks/build.js | 6 ++---- tasks/clean.js | 2 -- tasks/development.js | 2 -- tasks/linting.js | 13 ++++++------ 14 files changed, 120 insertions(+), 103 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index fa4be60..be42044 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,5 +1,3 @@ -"use strict" - module.exports = function (grunt) { grunt.loadTasks("tasks") diff --git a/lib/linklist.js b/lib/linklist.js index 97fe9f4..e500ded 100644 --- a/lib/linklist.js +++ b/lib/linklist.js @@ -9,7 +9,7 @@ define(["tablesort", "tablesort.numeric"], function (Tablesort) { } self.setData = function (links) { - if (links.length == 0) + if (links.length === 0) return var h2 = document.createElement("h2") diff --git a/lib/main.js b/lib/main.js index b66bccd..464bf7a 100644 --- a/lib/main.js +++ b/lib/main.js @@ -1,14 +1,14 @@ -define(["config", "moment", "chroma-js", "router", "map", "sidebar", "tabs", "container", "meshstats", "linklist", "nodelist", "simplenodelist", "infobox/main"], -function (config, moment, chroma, Router, Map, Sidebar, Tabs, Container, Meshstats, Linklist, Nodelist, SimpleNodelist, Infobox) { +define(["config", "moment", "chroma-js", "router", "map", "sidebar", "tabs", "container", "meshstats", "linklist", "nodelist", "simplenodelist", "infobox/main", "leaflet"], +function (config, moment, chroma, Router, Map, Sidebar, Tabs, Container, Meshstats, Linklist, Nodelist, SimpleNodelist, Infobox, L) { return function () { var linklist, lostnodeslist, map, meshstats, newnodeslist, nodelist, router function createGUI() { moment.locale("de") - router = new Router(config) + router = new Router() - var linkScale = chroma.scale(chroma.interpolate.bezier(['green', 'yellow', 'red'])).domain([1, 5]) + var linkScale = chroma.scale(chroma.interpolate.bezier(["green", "yellow", "red"])).domain([1, 5]) var sidebar = new Sidebar(document.body) var infobox = new Infobox(config, sidebar, router) var tabs = new Tabs() @@ -36,16 +36,7 @@ function (config, moment, chroma, Router, Map, Sidebar, Tabs, Container, Meshsta router.addTarget(map) } - var urls = [ config.dataPath + 'nodes.json', - config.dataPath + 'graph.json' - ] - - Promise.all(urls.map(getJSON)) - .then(function (d) { createGUI(); return d }) - .then(handle_data) - .then(function () { router.start() }) - - function handle_data(data) { + function handleData(data) { var nodedict = data[0] var nodes = Object.keys(nodedict.nodes).map(function (key) { return nodedict.nodes[key] }) @@ -59,7 +50,7 @@ function (config, moment, chroma, Router, Map, Sidebar, Tabs, Container, Meshsta }) var now = moment() - var age = moment(now).subtract(14, 'days') + var age = moment(now).subtract(14, "days") var newnodes = limit("firstseen", age, sortByKey("firstseen", nodes).filter(online)) var lostnodes = limit("lastseen", age, sortByKey("lastseen", nodes).filter(offline)) @@ -116,5 +107,18 @@ function (config, moment, chroma, Router, Map, Sidebar, Tabs, Container, Meshsta lostnodeslist.setData(lostnodes) router.setData(nodes, links) } + + var urls = [ config.dataPath + "nodes.json", + config.dataPath + "graph.json" + ] + + Promise.all(urls.map(getJSON)) + .then(function (d) { + createGUI() + return d + }) + .then(handleData) + .then(function () { router.start() }) + } }) diff --git a/lib/map.js b/lib/map.js index a295000..17bad63 100644 --- a/lib/map.js +++ b/lib/map.js @@ -10,7 +10,7 @@ define(["leaflet", "moment", "leaflet.label"], function (L, moment) { m.setStyle(iconFunc(d)) } - m.on('click', router.node(d)) + m.on("click", router.node(d)) m.bindLabel(d.nodeinfo.hostname) dict[d.nodeinfo.node_id] = m @@ -38,7 +38,7 @@ define(["leaflet", "moment", "leaflet.label"], function (L, moment) { } line.bindLabel(d.source.node.nodeinfo.hostname + " – " + d.target.node.nodeinfo.hostname + "
" + showDistance(d) + " / " + showTq(d) + "") - line.on('click', router.link(d)) + line.on("click", router.link(d)) dict[linkId(d)] = line @@ -60,7 +60,7 @@ define(["leaflet", "moment", "leaflet.label"], function (L, moment) { var self = this var el = document.createElement("div") - el.classList.add("map") + el.classList.add("map") self.div = el var map = L.map(el, options) @@ -88,17 +88,17 @@ define(["leaflet", "moment", "leaflet.label"], function (L, moment) { var nodesOffline = subtract(nodes.filter(offline), lostnodes) var markersOnline = nodesOnline.filter(has_location) - .map(mkMarker(nodeDict, function (d) { return iconOnline }, router)) + .map(mkMarker(nodeDict, function () { return iconOnline }, router)) var markersOffline = nodesOffline.filter(has_location) - .map(mkMarker(nodeDict, function (d) { return iconOffline }, router)) + .map(mkMarker(nodeDict, function () { return iconOffline }, router)) var markersNew = newnodes.filter(has_location) - .map(mkMarker(nodeDict, function (d) { return iconNew }, router)) + .map(mkMarker(nodeDict, function () { return iconNew }, router)) var markersLost = lostnodes.filter(has_location) .map(mkMarker(nodeDict, function (d) { - if (d.lastseen.isAfter(moment(now).subtract(3, 'days'))) + if (d.lastseen.isAfter(moment(now).subtract(3, "days"))) return iconAlert return iconLost @@ -110,6 +110,20 @@ define(["leaflet", "moment", "leaflet.label"], function (L, moment) { groupLost = L.featureGroup(markersLost).addTo(map) } + function resetMarkerStyles(nodes, links) { + Object.keys(nodes).forEach( function (d) { + nodes[d].resetStyle() + }) + + Object.keys(links).forEach( function (d) { + links[d].resetStyle() + }) + } + + function setView(bounds) { + map.fitBounds(bounds, {paddingTopLeft: [sidebar.getWidth(), 0]}) + } + function resetView() { resetMarkerStyles(nodeDict, linkDict) @@ -127,24 +141,10 @@ define(["leaflet", "moment", "leaflet.label"], function (L, moment) { setView(bounds) } - function setView(bounds) { - map.fitBounds(bounds, {paddingTopLeft: [sidebar.getWidth(), 0]}) - } - - function resetMarkerStyles(nodes, links) { - Object.keys(nodes).forEach( function (d) { - nodes[d].resetStyle() - }) - - Object.keys(links).forEach( function (d) { - links[d].resetStyle() - }) - } - function goto(dict, id) { var m = dict[id] if (m === undefined) - return + return undefined var bounds diff --git a/lib/nodelist.js b/lib/nodelist.js index 68869ab..298464e 100644 --- a/lib/nodelist.js +++ b/lib/nodelist.js @@ -1,15 +1,34 @@ define(["tablesort", "tablesort.numeric"], function (Tablesort) { return function(router) { + function showUptime(el, now, d) { + var uptime + if (d.flags.online && "uptime" in d.statistics) + uptime = Math.round(d.statistics.uptime / 3600) + else if (!d.flags.online && "lastseen" in d) + uptime = Math.round(-(now - d.lastseen) / 3600000) + + var s = "" + + if (uptime !== undefined) + if (Math.abs(uptime) >= 24) + s = Math.round(uptime / 24) + "d" + else + s = uptime + "h" + + el.textContent = s + el.setAttribute("data-sort", uptime !== undefined ? -uptime : 0) + } + var self = this var el - self.render = function (d) { + self.render = function (d) { el = document.createElement("div") d.appendChild(el) } self.setData = function (now, nodes) { - if (nodes.length == 0) + if (nodes.length === 0) return var h2 = document.createElement("h2") @@ -60,7 +79,7 @@ define(["tablesort", "tablesort.numeric"], function (Tablesort) { } var td2 = document.createElement("td") - showUptime(td2, d) + showUptime(td2, now, d) row.appendChild(td2) var td3 = document.createElement("td") @@ -75,26 +94,6 @@ define(["tablesort", "tablesort.numeric"], function (Tablesort) { new Tablesort(table) el.appendChild(table) - - function showUptime(el, d) { - var uptime - if (d.flags.online && "uptime" in d.statistics) - uptime = Math.round(d.statistics.uptime / 3600) - else if (!d.flags.online && "lastseen" in d) - uptime = Math.round(-(now - d.lastseen) / 3600000) - - var s = "" - - if (uptime !== undefined) { - if (Math.abs(uptime) >= 24) - s = Math.round(uptime/24) + "d" - else - s = uptime + "h" - } - - el.textContent = s - el.setAttribute("data-sort", uptime !== undefined ? -uptime : 0) - } - } + } } }) diff --git a/lib/router.js b/lib/router.js index 25be296..303805d 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1,9 +1,23 @@ define(function () { - return function (config) { + return function () { var objects = { nodes: {}, links: {} } var targets = [] var self = this + function saveState(d) { + var s = "#!" + + if (d) { + if ("node" in d) + s += "n:" + d.node.nodeinfo.node_id + + if ("link" in d) + s += "l:" + linkId(d.link) + } + + window.history.pushState(s, undefined, s) + } + function resetView(push) { push = trueDefault(push) @@ -27,20 +41,6 @@ define(function () { }) } - function saveState(d) { - var s = "#!" - - if (d) { - if ("node" in d) - s += "n:" + d.node.nodeinfo.node_id - - if ("link" in d) - s += "l:" + linkId(d.link) - } - - window.history.pushState(s, undefined, s) - } - function loadState(s) { if (!s) return false @@ -49,9 +49,10 @@ define(function () { return false var args = s.slice(2).split(":") + var id if (args[0] === "n") { - var id = args[1] + id = args[1] if (id in objects.nodes) { gotoNode(objects.nodes[id]) @@ -60,7 +61,7 @@ define(function () { } if (args[0] === "l") { - var id = args[1] + id = args[1] if (id in objects.links) { gotoLink(objects.links[id]) @@ -102,9 +103,6 @@ define(function () { saveState() } - self.addMarkers = function (d) { - markers = d - } self.addTarget = function (d) { targets.push(d) } self.setData = function (nodes, links) { diff --git a/lib/sidebar.js b/lib/sidebar.js index e356584..2a153e6 100644 --- a/lib/sidebar.js +++ b/lib/sidebar.js @@ -19,7 +19,7 @@ define([], function () { sidebar.appendChild(container) self.getWidth = function () { - var small = window.matchMedia("(max-width: 60em)"); + var small = window.matchMedia("(max-width: 60em)") return small.matches ? 0 : sidebar.offsetWidth } diff --git a/lib/simplenodelist.js b/lib/simplenodelist.js index 5302319..80b8dae 100644 --- a/lib/simplenodelist.js +++ b/lib/simplenodelist.js @@ -3,13 +3,13 @@ define(["moment"], function (moment) { var self = this var el - self.render = function (d) { + self.render = function (d) { el = document.createElement("div") d.appendChild(el) } self.setData = function (list) { - if (list.length == 0) + if (list.length === 0) return var h2 = document.createElement("h2") diff --git a/lib/tabs.js b/lib/tabs.js index a4d500c..17f80c7 100644 --- a/lib/tabs.js +++ b/lib/tabs.js @@ -7,7 +7,7 @@ define([], function () { var container = document.createElement("div") - function switchTab(ev) { + function switchTab() { for (var i = 0; i < tabs.children.length; i++) { var el = tabs.children[i] el.classList.remove("visible") diff --git a/package.json b/package.json index ffb7085..4af7708 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,29 @@ "grunt-contrib-requirejs": "^0.4.4", "grunt-contrib-uglify": "^0.5.1", "grunt-contrib-watch": "^0.6.1", - "grunt-eslint": "^1.1.0" + "grunt-eslint": "^10.0.0" + }, + "eslintConfig": { + "env": { + "browser": true, + "amd": true, + "es6": true, + "node": true + }, + "globals": { + "getJSON": false, + "has_location": false, + "limit": false, + "linkId": false, + "offline": false, + "one": false, + "online": false, + "showDistance": false, + "showTq": false, + "sortByKey": false, + "subtract": false, + "sum": false, + "trueDefault": false + } } } diff --git a/tasks/build.js b/tasks/build.js index f91634c..4fc62ce 100644 --- a/tasks/build.js +++ b/tasks/build.js @@ -1,5 +1,3 @@ -"use strict" - module.exports = function(grunt) { grunt.config.merge({ copy: { @@ -31,7 +29,7 @@ module.exports = function(grunt) { ], expand: true, dest: "build/", - cwd: "bower_components/ionicons/", + cwd: "bower_components/ionicons/" } }, cssmin: { @@ -61,5 +59,5 @@ module.exports = function(grunt) { grunt.loadNpmTasks("grunt-contrib-copy") grunt.loadNpmTasks("grunt-contrib-requirejs") - grunt.loadNpmTasks('grunt-contrib-cssmin') + grunt.loadNpmTasks("grunt-contrib-cssmin") } diff --git a/tasks/clean.js b/tasks/clean.js index 7e99509..989ef08 100644 --- a/tasks/clean.js +++ b/tasks/clean.js @@ -1,5 +1,3 @@ -"use strict" - module.exports = function (grunt) { grunt.config.merge({ clean: { diff --git a/tasks/development.js b/tasks/development.js index 30f3749..10f3edf 100644 --- a/tasks/development.js +++ b/tasks/development.js @@ -1,5 +1,3 @@ -"use strict" - module.exports = function (grunt) { grunt.config.merge({ connect: { diff --git a/tasks/linting.js b/tasks/linting.js index 2380155..fac4eef 100644 --- a/tasks/linting.js +++ b/tasks/linting.js @@ -1,5 +1,3 @@ -"use strict" - module.exports = function (grunt) { grunt.config.merge({ checkDependencies: { @@ -15,10 +13,13 @@ module.exports = function (grunt) { }, eslint: { options: { - rule: { - semi: [2, "never"], - strict: [2, "never"], - curly: [2, "multi"] + rules: { + "semi": [2, "never"], + "curly": [2, "multi"], + "strict": [2, "never"], + "no-multi-spaces": 0, + "no-new": 0, + "no-shadow": 0 } }, sources: {