Bug 1267378 - fix eslint errors in css-color.js; r=miker
authorTom Tromey <tom@tromey.com>
Mon, 25 Apr 2016 13:56:04 -0600
changeset 295094 da735eadeed7d047255fd89503a3a47cd93cb456
parent 295093 797e8190073f7e5636786bd344c16c3ffc21eae2
child 295095 678d2aa3a3a65503d9a17a61888b690dcf552d25
push id30219
push usercbook@mozilla.com
push dateThu, 28 Apr 2016 14:14:05 +0000
treeherdermozilla-central@53765e008b97 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmiker
bugs1267378
milestone49.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1267378 - fix eslint errors in css-color.js; r=miker MozReview-Commit-ID: D1MM5Yk9IKv
.eslintignore
devtools/shared/css-color.js
--- a/.eslintignore
+++ b/.eslintignore
@@ -104,16 +104,17 @@ devtools/client/shared/**
 devtools/client/sourceeditor/**
 devtools/client/webaudioeditor/**
 devtools/client/webconsole/**
 !devtools/client/webconsole/panel.js
 !devtools/client/webconsole/jsterm.js
 devtools/client/webide/**
 devtools/server/**
 devtools/shared/*.js
+!devtools/shared/css-color.js
 devtools/shared/*.jsm
 devtools/shared/apps/**
 devtools/shared/client/**
 devtools/shared/discovery/**
 devtools/shared/gcli/**
 devtools/shared/heapsnapshot/**
 devtools/shared/inspector/**
 devtools/shared/layout/**
--- a/devtools/shared/css-color.js
+++ b/devtools/shared/css-color.js
@@ -1,15 +1,15 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
-const {Cc, Ci, Cu} = require("chrome");
+const {Cc, Ci} = require("chrome");
 const Services = require("Services");
 
 const COLOR_UNIT_PREF = "devtools.defaultColorUnit";
 
 const SPECIALVALUES = new Set([
   "currentcolor",
   "initial",
   "inherit",
@@ -30,18 +30,18 @@ const SPECIALVALUES = new Set([
  *   color.valid === true
  *   color.transparent === false // transparent has a special status.
  *   color.name === "red"        // returns hex or rgba when no name available.
  *   color.hex === "#f00"        // returns shortHex when available else returns
  *                                  longHex. If alpha channel is present then we
  *                                  return this.rgba.
  *   color.longHex === "#ff0000" // If alpha channel is present then we return
  *                                  this.rgba.
- *   color.rgb === "rgb(255, 0, 0)" // If alpha channel is present then we return
- *                                     this.rgba.
+ *   color.rgb === "rgb(255, 0, 0)" // If alpha channel is present
+ *                                  // then we return this.rgba.
  *   color.rgba === "rgba(255, 0, 0, 1)"
  *   color.hsl === "hsl(0, 100%, 50%)"
  *   color.hsla === "hsla(0, 100%, 50%, 1)" // If alpha channel is present
  *                                             then we return this.rgba.
  *
  *   color.toString() === "#f00"; // Outputs the color type determined in the
  *                                   COLOR_UNIT_PREF constant (above).
  *   // Color objects can be reused
@@ -123,17 +123,17 @@ CssColor.prototype = {
 
   /**
    * Return true for all transparent values e.g. rgba(0, 0, 0, 0).
    */
   get transparent() {
     try {
       let tuple = this._getRGBATuple();
       return !(tuple.r || tuple.g || tuple.b || tuple.a);
-    } catch(e) {
+    } catch (e) {
       return false;
     }
   },
 
   get specialValue() {
     return SPECIALVALUES.has(this.lowerCased) ? this.authored : null;
   },
 
@@ -146,17 +146,17 @@ CssColor.prototype = {
     try {
       let tuple = this._getRGBATuple();
 
       if (tuple.a !== 1) {
         return this.rgb;
       }
       let {r, g, b} = tuple;
       return DOMUtils.rgbToColorName(r, g, b);
-    } catch(e) {
+    } catch (e) {
       return this.hex;
     }
   },
 
   get hex() {
     let invalidOrSpecialValue = this._getInvalidOrSpecialValue();
     if (invalidOrSpecialValue !== false) {
       return invalidOrSpecialValue;
@@ -179,17 +179,18 @@ CssColor.prototype = {
     if (invalidOrSpecialValue !== false) {
       return invalidOrSpecialValue;
     }
     if (this.hasAlpha) {
       return this.rgba;
     }
 
     let tuple = this._getRGBATuple();
-    return "#" + ((1 << 24) + (tuple.r << 16) + (tuple.g << 8) + (tuple.b << 0)).toString(16).substr(-6);
+    return "#" + ((1 << 24) + (tuple.r << 16) + (tuple.g << 8) +
+                  (tuple.b << 0)).toString(16).substr(-6);
   },
 
   get rgb() {
     let invalidOrSpecialValue = this._getInvalidOrSpecialValue();
     if (invalidOrSpecialValue !== false) {
       return invalidOrSpecialValue;
     }
     if (!this.hasAlpha) {
@@ -205,17 +206,17 @@ CssColor.prototype = {
 
   get rgba() {
     let invalidOrSpecialValue = this._getInvalidOrSpecialValue();
     if (invalidOrSpecialValue !== false) {
       return invalidOrSpecialValue;
     }
     if (this.lowerCased.startsWith("rgba(")) {
       // The color is valid and begins with rgba(.
-        return this.authored;
+      return this.authored;
     }
     let components = this._getRGBATuple();
     return "rgba(" + components.r + ", " +
                      components.g + ", " +
                      components.b + ", " +
                      components.a + ")";
   },
 
@@ -306,17 +307,17 @@ CssColor.prototype = {
   },
 
   /**
    * Return a string representing a color of type defined in COLOR_UNIT_PREF.
    */
   toString: function() {
     let color;
 
-    switch(this.colorUnit) {
+    switch (this.colorUnit) {
       case CssColor.COLORUNIT.authored:
         color = this.authored;
         break;
       case CssColor.COLORUNIT.hex:
         color = this.hex;
         break;
       case CssColor.COLORUNIT.hsl:
         color = this.hsl;
@@ -353,22 +354,21 @@ CssColor.prototype = {
 
   _hsl: function(maybeAlpha) {
     if (this.lowerCased.startsWith("hsl(") && maybeAlpha === undefined) {
       // We can use it as-is.
       return this.authored;
     }
 
     let {r, g, b} = this._getRGBATuple();
-    let [h,s,l] = rgbToHsl([r,g,b]);
+    let [h, s, l] = rgbToHsl([r, g, b]);
     if (maybeAlpha !== undefined) {
       return "hsla(" + h + ", " + s + "%, " + l + "%, " + maybeAlpha + ")";
-    } else {
-      return "hsl(" + h + ", " + s + "%, " + l + "%)";
     }
+    return "hsl(" + h + ", " + s + "%, " + l + "%)";
   },
 
   /**
    * This method allows comparison of CssColor objects using ===.
    */
   valueOf: function() {
     return this.rgba;
   },
@@ -377,34 +377,34 @@ CssColor.prototype = {
 /**
  * Convert rgb value to hsl
  *
  * @param {array} rgb
  *         Array of rgb values
  * @return {array}
  *         Array of hsl values.
  */
-function rgbToHsl([r,g,b]) {
+function rgbToHsl([r, g, b]) {
   r = r / 255;
   g = g / 255;
   b = b / 255;
 
   let max = Math.max(r, g, b);
   let min = Math.min(r, g, b);
   let h;
   let s;
   let l = (max + min) / 2;
 
-  if (max == min){
+  if (max == min) {
     h = s = 0;
   } else {
     let d = max - min;
     s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
 
-    switch(max) {
+    switch (max) {
       case r:
         h = ((g - b) / d) % 6;
         break;
       case g:
         h = (b - r) / d + 2;
         break;
       case b:
         h = (r - g) / d + 4;
@@ -464,11 +464,11 @@ function classifyColor(value) {
   } else if (value.startsWith("hsl(") || value.startsWith("hsla(")) {
     return CssColor.COLORUNIT.hsl;
   } else if (/^#[0-9a-f]+$/.exec(value)) {
     return CssColor.COLORUNIT.hex;
   }
   return CssColor.COLORUNIT.name;
 }
 
-loader.lazyGetter(this, "DOMUtils", function () {
+loader.lazyGetter(this, "DOMUtils", function() {
   return Cc["@mozilla.org/inspector/dom-utils;1"].getService(Ci.inIDOMUtils);
 });