Skip to content

Commit

Permalink
Lint cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
nicjansma committed Sep 9, 2017
1 parent 69befd4 commit 93f2a21
Show file tree
Hide file tree
Showing 8 changed files with 226 additions and 326 deletions.
104 changes: 3 additions & 101 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,114 +1,16 @@
{
"extends": "nicjansma",
"env": {
"browser": true,
"node": true,
"browser": true,
"amd": true
},
"rules": {
//
// v1.0 rules
//
"camelcase": 2,
"comma-spacing": 2,
"consistent-return": 2,
"curly": [2, "all"],
"dot-notation": [2, { "allowKeywords": true }],
"eol-last": 2,
"eqeqeq": 2,
"key-spacing": [2, { "beforeColon": false, "afterColon": true }],
"new-cap": 2,
"new-parens": 2,
"no-alert": 2,
"no-array-constructor": 2,
"no-caller": 2,
"no-catch-shadow": 2,
"no-eval": 2,
"no-extend-native": 2,
"no-extra-bind": 2,
"no-extra-parens": [2, "functions"],
"no-implied-eval": 2,
"no-iterator": 2,
"no-label-var": 2,
"no-labels": 2,
"no-lone-blocks": 2,
"no-loop-func": 2,
"no-multi-spaces": 2,
"no-multi-str": 2,
"no-native-reassign": 2,
"no-new": 2,
"no-new-func": 2,
"no-new-object": 2,
"no-new-wrappers": 2,
"no-octal-escape": 2,
"no-process-exit": 2,
"no-proto": 2,
"no-return-assign": 2,
"no-script-url": 2,
"no-sequences": 2,
"no-shadow": 2,
"no-shadow-restricted-names": 2,
"no-spaced-func": 2,
"no-trailing-spaces": 2,
"no-undef-init": 2,
"no-unused-expressions": 2,
"no-use-before-define": 2,
"no-with": 2,
"quotes": [2, "double"],
"semi": 2,
"semi-spacing": [2, {"before": false, "after": true}],
"space-infix-ops": 2,
"keyword-spacing": 2,
"space-unary-ops": [2, { "words": true, "nonwords": false }],
"strict": [2, "function"],
"yoda": [2, "never"],
//
// enabled over default
//
"valid-jsdoc": [1, {
"requireReturn": false,
"prefer": {
"return": "returns"
}
}],
"guard-for-in": 2,
"no-div-regex": 2,
"no-eq-null": 2,
"no-floating-decimal": 2,
"no-self-compare": 2,
"no-void": 2,
"radix": 2,
"wrap-iife": 2,
"no-mixed-requires": 2,
"no-new-require": 2,
"no-path-concat": 2,
"brace-style": [2, "1tbs", { "allowSingleLine": false }],
"comma-style": [2, "last"],
"consistent-this": [2, "that"],
"no-inline-comments": 2,
"no-multiple-empty-lines": [1, {"max": 1}],
"no-nested-ternary": 2,
"space-before-function-paren": [2, "never"],
"space-before-blocks": 1,
"space-in-parens": 1,
"spaced-comment": 1,
"max-len": [1, 120, 4],
"array-callback-return": 2,
"no-confusing-arrow": 2,
"no-empty-function": 2,
"no-extra-label": 2,
"no-implicit-globals": 2,
"no-new-symbol": 2,
"no-self-assign": 2,
"no-unused-labels": 2,
"no-useless-constructor": 2,
"no-whitespace-before-property": 2,
"indent": ["error", 4],

//
// Disabled
//

// disabled for use of _jQuery
"no-underscore-dangle": 0
}
}
}
2 changes: 1 addition & 1 deletion dist/resourcetiming-compression.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(function(root) {
(function() {
"use strict";

var gulp = require("gulp");
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"devDependencies": {
"commander": "^2.9.0",
"eslint": "^3.12.2",
"eslint-config-nicjansma": "^1.0.2",
"expect.js": "^0.3.1",
"gulp": "^3.9.1",
"gulp-eslint": "^3.0.1",
Expand Down
61 changes: 29 additions & 32 deletions src/resourcetiming-compression.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,12 @@
} else if (typeof node === "string") {
// this is a leaf, but we need to go further, so convert it into a branch
cur = cur[letter] = { "|": node };
} else if (i === (letters.length - 1)) {
// this is the end of our key, and we've hit an existing node. Add our timings.
cur[letter]["|"] = value;
} else {
if (i === (letters.length - 1)) {
// this is the end of our key, and we've hit an existing node. Add our timings.
cur[letter]["|"] = value;
} else {
// continue onwards
cur = cur[letter];
}
// continue onwards
cur = cur[letter];
}
}
}
Expand Down Expand Up @@ -211,17 +209,17 @@
topNode = {};
topNode[node] = cur[node];
return topNode;
} else {
// other nodes we return name and value separately
return { name: node, value: cur[node] };
}

// other nodes we return name and value separately
return { name: node, value: cur[node] };
} else if (top) {
// top node with more than 1 child, return it as-is
return cur;
} else {
// more than two nodes and not the top, we can't compress any more
return false;
}

// more than two nodes and not the top, we can't compress any more
return false;
};

/**
Expand Down Expand Up @@ -256,6 +254,7 @@
* @returns {number} navigationStart time, or 0 if not accessible
*/
ResourceTimingCompression.getNavStartTime = function(frame) {
/* eslint no-unused-vars: ["error", { "varsIgnorePattern": "frameLoc" }] */
var navStart = 0, frameLoc;

if (!frame) {
Expand Down Expand Up @@ -460,9 +459,9 @@
ResourceTimingCompression.toBase36 = function(n) {
if (typeof n === "number" && n !== 0) {
return n.toString(36);
} else {
return typeof n === "string" ? n : "";
}

return typeof n === "string" ? n : "";
};

/**
Expand Down Expand Up @@ -660,9 +659,9 @@

// change everything to base36 and remove any trailing ,s
return sizes.map(this.toBase36).join(",").replace(/,+$/, "");
} else {
return "";
}

return "";
};

/**
Expand Down Expand Up @@ -830,22 +829,20 @@
// if this entry already exists, add a pipe as a separator
if (results[url] !== undefined) {
results[url] += "|" + data;
} else if (visibleEntries[url] !== undefined) {
// For the first time we see this URL, add resource dimensions if we have them
// We use * as an additional separator to indicate it is not a new resource entry
// The following characters will not be URL encoded:
// *!-.()~_ but - and . are special to number representation so we don't use them
// After the *, the type of special data (ResourceTiming = 0) is added
results[url] =
SPECIAL_DATA_PREFIX +
SPECIAL_DATA_DIMENSION_TYPE +
visibleEntries[url].map(this.toBase36).join(",").replace(/,+$/, "")
+ "|"
+ data;
} else {
// for the first time we see this URL, add resource dimensions if we have them
if (visibleEntries[url] !== undefined) {
// We use * as an additional separator to indicate it is not a new resource entry
// The following characters will not be URL encoded:
// *!-.()~_ but - and . are special to number representation so we don't use them
// After the *, the type of special data (ResourceTiming = 0) is added
results[url] =
SPECIAL_DATA_PREFIX +
SPECIAL_DATA_DIMENSION_TYPE +
visibleEntries[url].map(this.toBase36).join(",").replace(/,+$/, "")
+ "|"
+ data;
} else {
results[url] = data;
}
results[url] = data;
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/resourcetiming-decompression.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,8 @@
}

// Find indices of cells that were affected by our resource.
var low = this.searchSortedFirst(cells, {ts: startTime}, getTs);
var up = this.searchSortedLast(cells, {ts: responseEnd}, getTs);
var low = this.searchSortedFirst(cells, { ts: startTime }, getTs);
var up = this.searchSortedLast(cells, { ts: responseEnd }, getTs);

var tot = 0.0;

Expand Down Expand Up @@ -525,9 +525,9 @@
ResourceTimingDecompression.getInitiatorTypeFromIndex = function(index) {
if (this.REV_INITIATOR_TYPES.hasOwnProperty(index)) {
return this.REV_INITIATOR_TYPES[index];
} else {
return "other";
}

return "other";
};

/**
Expand Down
26 changes: 13 additions & 13 deletions test/test-resourcetiming-compression.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
//
describe(".convertToTrie()", function() {
it("should convert a single node", function() {
var data = {"abc": "abc"};
var data = { "abc": "abc" };
var expected = {
"a": {
"b": {
Expand All @@ -89,7 +89,7 @@
});

it("should convert a two-node tree whose nodes don't intersect", function() {
var data = {"abc": "abc", "xyz": "xyz"};
var data = { "abc": "abc", "xyz": "xyz" };
var expected = {
"a": {
"b": {
Expand All @@ -106,7 +106,7 @@
});

it("should convert a complex tree", function() {
var data = {"abc": "abc", "abcd": "abcd", "ab": "ab"};
var data = { "abc": "abc", "abcd": "abcd", "ab": "ab" };
var expected = {
"a": {
"b": {
Expand All @@ -127,7 +127,7 @@
//
describe(".optimizeTrie()", function() {
it("should optimize a single-node tree", function() {
var data = {"abc": "abc"};
var data = { "abc": "abc" };
var expected = {
"abc": "abc"
};
Expand All @@ -138,7 +138,7 @@
});

it("should optimize a simple tree", function() {
var data = {"abc": "abc", "xyz": "xyz"};
var data = { "abc": "abc", "xyz": "xyz" };
var expected = {
"abc": "abc",
"xyz": "xyz"
Expand All @@ -150,7 +150,7 @@
});

it("should optimize a complex tree", function() {
var data = {"abc": "abc", "abcd": "abcd", "ab": "ab"};
var data = { "abc": "abc", "abcd": "abcd", "ab": "ab" };
var expected = {
"ab":
{
Expand Down Expand Up @@ -355,8 +355,8 @@
describe("accumulateServerTimingEntries()", function() {
it("Should increment our count collector", function() {
var serverTimingCollection = {};
ResourceTimingCompression.accumulateServerTimingEntries(serverTimingCollection, [{name: "n1", description: "d1"}, {name: "n2", description: "d1"}]);
ResourceTimingCompression.accumulateServerTimingEntries(serverTimingCollection, [{name: "n2", description: "d1"}, {name: "n2", description: "d2"}]);
ResourceTimingCompression.accumulateServerTimingEntries(serverTimingCollection, [{ name: "n1", description: "d1" }, { name: "n2", description: "d1" }]);
ResourceTimingCompression.accumulateServerTimingEntries(serverTimingCollection, [{ name: "n2", description: "d1" }, { name: "n2", description: "d2" }]);

expect(serverTimingCollection).to.eql({
n1: {
Expand Down Expand Up @@ -396,9 +396,9 @@
}
}
})).to.eql([
["m2", "d2a", "d2b"],
["m1", "d1"],
["m0"]
["m2", "d2a", "d2b"],
["m1", "d1"],
["m0"]
]);
});
it("Should special case exactly one empty description", function() {
Expand All @@ -418,8 +418,8 @@
describe("indexServerTiming", function() {
it("Should index a lookup", function() {
expect(ResourceTimingCompression.indexServerTiming([
["metric0", "d1"],
["metric1", "d2a", "d2b"]
["metric0", "d1"],
["metric1", "d2a", "d2b"]
])).to.eql({
metric0: {
index: 0,
Expand Down
Loading

0 comments on commit 93f2a21

Please sign in to comment.