Browse Source

make eslint happy

Nils Schneider 9 years ago
parent
commit
3e143435e6
14 changed files with 120 additions and 103 deletions
  1. 0 2
      Gruntfile.js
  2. 1 1
      lib/linklist.js
  3. 19 15
      lib/main.js
  4. 22 22
      lib/map.js
  5. 23 24
      lib/nodelist.js
  6. 18 20
      lib/router.js
  7. 1 1
      lib/sidebar.js
  8. 2 2
      lib/simplenodelist.js
  9. 1 1
      lib/tabs.js
  10. 24 1
      package.json
  11. 2 4
      tasks/build.js
  12. 0 2
      tasks/clean.js
  13. 0 2
      tasks/development.js
  14. 7 6
      tasks/linting.js

+ 0 - 2
Gruntfile.js

@@ -1,5 +1,3 @@
-"use strict"
-
 module.exports = function (grunt) {
   grunt.loadTasks("tasks")
 

+ 1 - 1
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")

+ 19 - 15
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() })
+
   }
 })

+ 22 - 22
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 + "<br><strong>" + showDistance(d) + " / " + showTq(d) + "</strong>")
-       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
 

+ 23 - 24
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)
-      }
-    }
+   }
   }
 })

+ 18 - 20
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) {

+ 1 - 1
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
     }
 

+ 2 - 2
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")

+ 1 - 1
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")

+ 24 - 1
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
+    }
   }
 }

+ 2 - 4
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")
 }

+ 0 - 2
tasks/clean.js

@@ -1,5 +1,3 @@
-"use strict"
-
 module.exports = function (grunt) {
   grunt.config.merge({
     clean: {

+ 0 - 2
tasks/development.js

@@ -1,5 +1,3 @@
-"use strict"
-
 module.exports = function (grunt) {
   grunt.config.merge({
     connect: {

+ 7 - 6
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: {