[Pkg-javascript-commits] [d3-tip.js] 06/17: Whitespace and style fixes, with ESLint and CircleCI for future code linting

Sunil Mohan Adapa sunilmohan-guest at moszumanska.debian.org
Thu Dec 8 10:37:11 UTC 2016


This is an automated email from the git hooks/post-receive script.

sunilmohan-guest pushed a commit to branch upstream
in repository d3-tip.js.

commit 1a26f869c6533a8a458a271fe9a2935d4b292b31
Author: Tim van der Horst <tim.vanderhorst at sportsmedglobal.com>
Date:   Wed Aug 24 17:14:50 2016 +1000

    Whitespace and style fixes, with ESLint and CircleCI for future code linting
---
 .editorconfig  |  15 +++++++
 .eslintrc.yaml |  67 ++++++++++++++++++++++++++++++++
 circle.yml     |  10 +++++
 index.js       | 121 ++++++++++++++++++++++++++++++---------------------------
 package.json   |   9 ++++-
 5 files changed, 164 insertions(+), 58 deletions(-)

diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..2eb39a9
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,15 @@
+# EditorConfig is awesome: http://EditorConfig.org
+root = true
+
+[*]
+end_of_line = lf
+indent_style = space
+indent_size = 2
+charset = utf-8
+trim_trailing_whitespace = true
+insert_final_newline = true
+
+# Markdown
+[*.md]
+indent_size = 4
+trim_trailing_whitespace = false
diff --git a/.eslintrc.yaml b/.eslintrc.yaml
new file mode 100644
index 0000000..cf80e67
--- /dev/null
+++ b/.eslintrc.yaml
@@ -0,0 +1,67 @@
+---
+  root: true
+  extends:
+    - airbnb-base/legacy
+  env:
+    browser: true
+    node: true
+    amd: true
+  rules:
+    # Customised whitespace
+    max-len:
+      - 1
+      - 80
+      - 2
+      -
+        ignoreUrls: true
+        ignoreComments: false
+    indent:
+      - 1
+      - 2
+      -
+        SwitchCase: 1
+        VariableDeclarator:
+          var: 2
+          let: 2
+          const: 3
+        outerIIFEBody: 1
+    no-multi-spaces:
+      - 1
+      -
+        exceptions:
+          VariableDeclarator: true
+    key-spacing:
+      - 1
+      -
+        align: value
+    space-before-function-paren:
+      - 1
+      - never
+
+    # Customised to existing code's style
+    semi:
+      - 1
+      - never
+
+    # You don't need this one when you know your operators
+    no-mixed-operators: 0
+
+    # Additional rules
+    func-names: 0
+    no-unused-vars:
+      - 1
+      -
+        vars: all
+        args: all
+        varsIgnorePattern: ^_
+        argsIgnorePattern: ^_
+
+    # Disabled for IE8 support
+    comma-dangle: 0
+
+    # Airbnb rules that were disabled due to too many conflicts
+    # with the existing code style
+    vars-on-top: 0
+    one-var: 0
+    camelcase: 0
+    no-use-before-define: 0
diff --git a/circle.yml b/circle.yml
new file mode 100644
index 0000000..dbbe236
--- /dev/null
+++ b/circle.yml
@@ -0,0 +1,10 @@
+## Customize dependencies
+dependencies:
+  override:
+    - npm prune
+    - npm install
+
+## Customize test command
+test:
+  override:
+    - npm run -s circle:lint
diff --git a/index.js b/index.js
index 35f892c..8c1add3 100644
--- a/index.js
+++ b/index.js
@@ -3,20 +3,22 @@
 //
 // Tooltips for d3.js SVG visualizations
 
-(function (root, factory) {
+(function(root, factory) {
   if (typeof define === 'function' && define.amd) {
     // AMD. Register as an anonymous module with d3 as a dependency.
     define(['d3'], factory)
   } else if (typeof module === 'object' && module.exports) {
+    /* eslint-disable global-require */
     // CommonJS
     var d3 = require('d3')
     module.exports = factory(d3)
+    /* eslint-enable global-require */
   } else {
     // Browser global.
+    // eslint-disable-next-line no-param-reassign
     root.d3.tip = factory(root.d3)
   }
-}(this, function (d3) {
-
+}(this, function(d3) {
   // Public - contructs a new tooltip
   //
   // Returns a tip
@@ -41,7 +43,7 @@
     // Returns a tip
     tip.show = function() {
       var args = Array.prototype.slice.call(arguments)
-      if(args[args.length - 1] instanceof SVGElement) target = args.pop()
+      if (args[args.length - 1] instanceof SVGElement) target = args.pop()
 
       var content = html.apply(this, args),
           poffset = offset.apply(this, args),
@@ -49,20 +51,22 @@
           nodel   = getNodeEl(),
           i       = directions.length,
           coords,
-          scrollTop  = document.documentElement.scrollTop || document.body.scrollTop,
-          scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft
+          scrollTop  = document.documentElement.scrollTop ||
+            document.body.scrollTop,
+          scrollLeft = document.documentElement.scrollLeft ||
+            document.body.scrollLeft
 
       nodel.html(content)
         .style('opacity', 1).style('pointer-events', 'all')
 
-      while(i--) nodel.classed(directions[i], false)
+      while (i--) nodel.classed(directions[i], false)
       coords = direction_callbacks.get(dir).apply(this)
       nodel.classed(dir, true)
-      	.style('top', (coords.top +  poffset[0]) + scrollTop + 'px')
-      	.style('left', (coords.left + poffset[1]) + scrollLeft + 'px')
+        .style('top', (coords.top + poffset[0]) + scrollTop + 'px')
+        .style('left', (coords.left + poffset[1]) + scrollLeft + 'px')
 
-      return tip;
-    };
+      return tip
+    }
 
     // Public - hide the tooltip
     //
@@ -73,37 +77,37 @@
       return tip
     }
 
-    // Public: Proxy attr calls to the d3 tip container.  Sets or gets attribute value.
+    // Public: Proxy attr calls to the d3 tip container.
+    // Sets or gets attribute value.
     //
     // n - name of the attribute
     // v - value of the attribute
     //
     // Returns tip or attribute value
-    tip.attr = function(n, v) {
+    tip.attr = function(n, _v) {
       if (arguments.length < 2 && typeof n === 'string') {
         return getNodeEl().attr(n)
-      } else {
-        var args =  Array.prototype.slice.call(arguments)
-        d3.selection.prototype.attr.apply(getNodeEl(), args)
       }
 
+      var args =  Array.prototype.slice.call(arguments)
+      d3.selection.prototype.attr.apply(getNodeEl(), args)
       return tip
     }
 
-    // Public: Proxy style calls to the d3 tip container.  Sets or gets a style value.
+    // Public: Proxy style calls to the d3 tip container.
+    // Sets or gets a style value.
     //
     // n - name of the property
     // v - value of the property
     //
     // Returns tip or style property value
-    tip.style = function(n, v) {
+    tip.style = function(n, _v) {
       if (arguments.length < 2 && typeof n === 'string') {
         return getNodeEl().style(n)
-      } else {
-        var args = Array.prototype.slice.call(arguments)
-        d3.selection.prototype.style.apply(getNodeEl(), args)
       }
 
+      var args = Array.prototype.slice.call(arguments)
+      d3.selection.prototype.style.apply(getNodeEl(), args)
       return tip
     }
 
@@ -148,11 +152,11 @@
     //
     // Returns a tip
     tip.destroy = function() {
-      if(node) {
-        getNodeEl().remove();
-        node = null;
+      if (node) {
+        getNodeEl().remove()
+        node = null
       }
-      return tip;
+      return tip
     }
 
     function d3_tip_direction() { return 'n' }
@@ -160,17 +164,16 @@
     function d3_tip_html() { return ' ' }
 
     var direction_callbacks = d3.map({
-      n:  direction_n,
-      s:  direction_s,
-      e:  direction_e,
-      w:  direction_w,
-      nw: direction_nw,
-      ne: direction_ne,
-      sw: direction_sw,
-      se: direction_se
-    }),
-
-    directions = direction_callbacks.keys()
+          n:  direction_n,
+          s:  direction_s,
+          e:  direction_e,
+          w:  direction_w,
+          nw: direction_nw,
+          ne: direction_ne,
+          sw: direction_sw,
+          se: direction_se
+        }),
+        directions = direction_callbacks.keys()
 
     function direction_n() {
       var bbox = getScreenBBox()
@@ -237,11 +240,15 @@
     }
 
     function initNode() {
-      var node = d3.select(document.createElement('div'));
-      node.style('position', 'absolute').style('top', 0).style('opacity', 0)
-      	.style('pointer-events', 'none').style('box-sizing', 'border-box')
-
-      return node.node()
+      var div = d3.select(document.createElement('div'))
+      div
+        .style('position', 'absolute')
+        .style('top', 0)
+        .style('opacity', 0)
+        .style('pointer-events', 'none')
+        .style('box-sizing', 'border-box')
+
+      return div.node()
     }
 
     function getSVGNode(element) {
@@ -252,19 +259,19 @@
     }
 
     function getNodeEl() {
-      if(node === null) {
-        node = initNode();
+      if (node == null) {
+        node = initNode()
         // re-add node to DOM
-        document.body.appendChild(node);
-      };
-      return d3.select(node);
+        document.body.appendChild(node)
+      }
+      return d3.select(node)
     }
 
     // Private - gets the screen coordinates of a shape
     //
     // Given a shape on the screen, will return an SVGPoint for the directions
-    // n(north), s(south), e(east), w(west), ne(northeast), se(southeast), nw(northwest),
-    // sw(southwest).
+    // n(north), s(south), e(east), w(west), ne(northeast), se(southeast),
+    // nw(northwest), sw(southwest).
     //
     //    +-+-+
     //    |   |
@@ -274,10 +281,10 @@
     //
     // Returns an Object {n, s, e, w, nw, sw, ne, se}
     function getScreenBBox() {
-      var targetel   = target || d3.event.target;
+      var targetel   = target || d3.event.target
 
-      while ('undefined' === typeof targetel.getScreenCTM && 'undefined' === targetel.parentNode) {
-          targetel = targetel.parentNode;
+      while (targetel.getScreenCTM == null && targetel.parentNode == null) {
+        targetel = targetel.parentNode
       }
 
       var bbox       = {},
@@ -298,7 +305,7 @@
       point.x -= width
       bbox.sw = point.matrixTransform(matrix)
       point.y -= height / 2
-      bbox.w  = point.matrixTransform(matrix)
+      bbox.w = point.matrixTransform(matrix)
       point.x += width
       bbox.e = point.matrixTransform(matrix)
       point.x -= width / 2
@@ -309,15 +316,15 @@
 
       return bbox
     }
-    
+
     // Private - replace D3JS 3.X d3.functor() function
     function functor(v) {
-    	return typeof v === "function" ? v : function() {
+      return typeof v === 'function' ? v : function() {
         return v
-    	}
+      }
     }
 
     return tip
-  };
-
+  }
+// eslint-disable-next-line semi
 }));
diff --git a/package.json b/package.json
index ffc5a5a..023ec1c 100644
--- a/package.json
+++ b/package.json
@@ -9,7 +9,9 @@
     "example": "examples"
   },
   "scripts": {
-    "test": "echo \"Error: no test specified\" && exit 1"
+    "test": "echo \"Error: no test specified\" && exit 1",
+    "lint": "eslint .",
+    "circle:lint": "npm run -s lint -- --max-warnings 0 -f junit -o $CIRCLE_TEST_REPORTS/eslint/junit.xml"
   },
   "repository": {
     "type": "git",
@@ -26,5 +28,10 @@
   "homepage": "https://github.com/Caged/d3-tip",
   "dependencies": {
     "d3": "^4.2"
+  },
+  "devDependencies": {
+    "eslint": "^3.3.1",
+    "eslint-config-airbnb-base": "^5.0.3",
+    "eslint-plugin-import": "^1.14.0"
   }
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/d3-tip.js.git



More information about the Pkg-javascript-commits mailing list