From 6efa287c4ec85ceacf7c199fc6892767d7c7b715 Mon Sep 17 00:00:00 2001 From: Jeff Avallone Date: Wed, 27 Jul 2016 11:00:17 -0400 Subject: [PATCH] Fixing lint warning that came with the new version of JSCS Also some other minor code cleanup --- src/js/parser/javascript.js | 2 +- src/js/parser/javascript/charset_range.js | 2 +- src/js/parser/javascript/escape.js | 4 ++-- src/js/parser/javascript/match.js | 10 +++------- src/js/parser/javascript/match_fragment.js | 15 +++++++-------- src/js/parser/javascript/node.js | 14 +++++++------- src/js/parser/javascript/regexp.js | 8 ++++---- src/js/parser/javascript/repeat.js | 4 ++-- src/js/parser/javascript/root.js | 6 ++---- src/js/parser/javascript/subexp.js | 2 +- src/js/regexper.js | 13 +++++-------- 11 files changed, 35 insertions(+), 45 deletions(-) diff --git a/src/js/parser/javascript.js b/src/js/parser/javascript.js index 75c5221..ec236c0 100644 --- a/src/js/parser/javascript.js +++ b/src/js/parser/javascript.js @@ -78,7 +78,7 @@ export default class Parser { // Render the parsed expression to an SVG. render() { - var svg = Snap(this.container.querySelector('svg')); + let svg = Snap(this.container.querySelector('svg')); return this.parsed.render(svg.group()) // Once rendering is complete, the rendered expression is positioned and diff --git a/src/js/parser/javascript/charset_range.js b/src/js/parser/javascript/charset_range.js index a330091..d0f5376 100644 --- a/src/js/parser/javascript/charset_range.js +++ b/src/js/parser/javascript/charset_range.js @@ -9,7 +9,7 @@ export default { // Renders the charset range into the currently set container _render() { - var contents = [ + let contents = [ this.first, this.container.text(0, 0, '-'), this.last diff --git a/src/js/parser/javascript/escape.js b/src/js/parser/javascript/escape.js index 783ac1a..2faeb6e 100644 --- a/src/js/parser/javascript/escape.js +++ b/src/js/parser/javascript/escape.js @@ -30,7 +30,7 @@ export default { }, setup() { - var addHex; + let addHex; // The escape code. For an escape such as `\b` it would be "b". this.code = this.properties.esc.properties.code.textValue; @@ -69,7 +69,7 @@ export default { 7: ['Back reference (group = 7)', -1, false], 8: ['Back reference (group = 8)', -1, false], 9: ['Back reference (group = 9)', -1, false], - 0() { + 0: function() { if (this.arg) { return [`octal: ${this.arg}`, parseInt(this.arg, 8), true]; } else { diff --git a/src/js/parser/javascript/match.js b/src/js/parser/javascript/match.js index c951b23..597c643 100644 --- a/src/js/parser/javascript/match.js +++ b/src/js/parser/javascript/match.js @@ -29,13 +29,9 @@ export default { // Renders the match into the currently set container. _render() { - var partPromises, - items; - // Render each of the match fragments. - partPromises = _.map(this.parts, part => part.render(this.container.group())); - - items = _(partPromises).compact().value(); + let partPromises = _.map(this.parts, part => part.render(this.container.group())), + items = _(partPromises).compact().value(); // Handle the situation where a regular expression of `()` is rendered. // This leads to a Match node with no fragments. Something must be rendered @@ -66,7 +62,7 @@ export default { // Returns an array of SVG path strings between each item. // - __items__ - Array of SVG elements or nodes. connectorPaths(items) { - var prev, next; + let prev, next; prev = util.normalizeBBox(_.first(items).getBBox()); return _.map(items.slice(1), item => { diff --git a/src/js/parser/javascript/match_fragment.js b/src/js/parser/javascript/match_fragment.js index 4464e3e..1d02807 100644 --- a/src/js/parser/javascript/match_fragment.js +++ b/src/js/parser/javascript/match_fragment.js @@ -52,22 +52,21 @@ export default { // Renders label for the loop path indicating how many times the content may // be matched. loopLabel() { - var labelStr = this.repeat.label, - tooltipStr = this.repeat.tooltip, - label, tooltip, labelBox, box; + let labelStr = this.repeat.label, + tooltipStr = this.repeat.tooltip; if (labelStr) { - label = this.container.text(0, 0, [labelStr]) - .addClass('repeat-label'); + let label = this.container.text(0, 0, [labelStr]) + .addClass('repeat-label'), + labelBox = label.getBBox(), + box = this.getBBox(); if (tooltipStr) { - tooltip = this.container.el('title') + let tooltip = this.container.el('title') .append(this.container.text(0, 0, tooltipStr)); label.append(tooltip); } - box = this.getBBox(); - labelBox = label.getBBox(); label.transform(Snap.matrix().translate( box.x2 - labelBox.width - (this.repeat.hasSkip ? 5 : 0), box.y2 + labelBox.height)); diff --git a/src/js/parser/javascript/node.js b/src/js/parser/javascript/node.js index 89b4868..48d3b06 100644 --- a/src/js/parser/javascript/node.js +++ b/src/js/parser/javascript/node.js @@ -116,17 +116,17 @@ export default class Node { // // - __text__ - String or array of strings to render as a label. renderLabel(text) { - var group = this.container.group() + let group = this.container.group() .addClass('label'), rect = group.rect(), - text = group.text(0, 0, _.flatten([text])); + label = group.text(0, 0, _.flatten([text])); return this.deferredStep() .then(() => { - let box = text.getBBox(), + let box = label.getBBox(), margin = 5; - text.transform(Snap.matrix() + label.transform(Snap.matrix() .translate(margin, box.height / 2 + 2 * margin)); rect.attr({ @@ -140,12 +140,12 @@ export default class Node { // Renders a labeled box around another SVG element. Returns a Promise. // - // - __label__ - String or array of strings to label the box with. + // - __text__ - String or array of strings to label the box with. // - __content__ - SVG element to wrap in the box. // - __options.padding__ - Pixels of padding to place between the content and // the box. - renderLabeledBox(label, content, options) { - var label = this.container.text(0, 0, _.flatten([label])) + renderLabeledBox(text, content, options) { + let label = this.container.text(0, 0, _.flatten([text])) .addClass(`${this.type}-label`), box = this.container.rect() .addClass(`${this.type}-box`) diff --git a/src/js/parser/javascript/regexp.js b/src/js/parser/javascript/regexp.js index 89fad23..61b8d28 100644 --- a/src/js/parser/javascript/regexp.js +++ b/src/js/parser/javascript/regexp.js @@ -9,7 +9,7 @@ export default { // Renders the regexp into the currently set container. _render() { - var matchContainer = this.container.group() + let matchContainer = this.container.group() .addClass('regexp-matches') .transform(Snap.matrix() .translate(20, 0)); @@ -56,7 +56,7 @@ export default { // - __containerBox__ - Bounding box of the container. // - __match__ - Match node that the line will be drawn to. makeSide(containerBox, match) { - var box = match.getBBox(), + let box = match.getBBox(), distance = Math.abs(box.ay - containerBox.cy); // Only need to draw side lines if the match is more than 15 pixels from @@ -79,7 +79,7 @@ export default { // - __containerBox__ - Bounding box of the container. // - __match__ - Match node that the line will be drawn to. makeCurve(containerBox, match) { - var box = match.getBBox(), + let box = match.getBBox(), distance = Math.abs(box.ay - containerBox.cy); if (distance >= 15) { @@ -109,7 +109,7 @@ export default { // - __containerBox__ - Bounding box of the container. // - __match__ - Match node that the line will be drawn to. makeConnector(containerBox, match) { - var box = match.getBBox(); + let box = match.getBBox(); return `M0,${box.ay}h${box.ax}M${box.ax2},${box.ay}H${containerBox.width}`; }, diff --git a/src/js/parser/javascript/repeat.js b/src/js/parser/javascript/repeat.js index 73edcc6..1953439 100644 --- a/src/js/parser/javascript/repeat.js +++ b/src/js/parser/javascript/repeat.js @@ -76,7 +76,7 @@ export default { // Returns the path spec to render the line that skips over the content for // fragments that are optionally matched. skipPath(box) { - var paths = []; + let paths = []; if (this.hasSkip) { let vert = Math.max(0, box.ay - box.y - 10), @@ -96,7 +96,7 @@ export default { // Returns the path spec to render the line that repeats the content for // fragments that are matched more than once. loopPath(box) { - var paths = []; + let paths = []; if (this.hasLoop) { let vert = box.y2 - box.ay - 10; diff --git a/src/js/parser/javascript/root.js b/src/js/parser/javascript/root.js index b9e8004..cc6c89c 100644 --- a/src/js/parser/javascript/root.js +++ b/src/js/parser/javascript/root.js @@ -14,7 +14,7 @@ export default { // Renders the root into the currently set container. _render() { - var flagText; + let flagText; // Render a label for any flags that have been set of the expression. if (this.flags.length > 0) { @@ -24,8 +24,6 @@ export default { // Render the content of the regular expression. return this.regexp.render(this.container.group()) .then(() => { - let box; - // Move rendered regexp to account for flag label and to allow for // decorative elements. if (flagText) { @@ -36,7 +34,7 @@ export default { .translate(10, 0)); } - box = this.regexp.getBBox(); + let box = this.regexp.getBBox(); // Render decorative elements. this.container.path(`M${box.ax},${box.ay}H0M${box.ax2},${box.ay}H${box.x2 + 10}`); diff --git a/src/js/parser/javascript/subexp.js b/src/js/parser/javascript/subexp.js index 4c63439..9f97811 100644 --- a/src/js/parser/javascript/subexp.js +++ b/src/js/parser/javascript/subexp.js @@ -34,7 +34,7 @@ export default { // **NOTE:** `this.label()` **MUST** be called here, in _render, and before // any child nodes are rendered. This is to keep the group numbers in the // correct order. - var label = this.label(); + let label = this.label(); // Render the contained regexp. return this.regexp.render(this.container.group()) diff --git a/src/js/regexper.js b/src/js/regexper.js index 6a6900d..74e22a9 100644 --- a/src/js/regexper.js +++ b/src/js/regexper.js @@ -63,7 +63,7 @@ export default class Regexper { // Event handler for URL hash changes. Starts rendering of the expression. hashchangeListener() { - var expr = this._getHash(); + let expr = this._getHash(); if (expr instanceof Error) { this.state = 'has-error'; @@ -85,11 +85,9 @@ export default class Regexper { // Detect if https://bugzilla.mozilla.org/show_bug.cgi?id=483304 is in effect detectBuggyHash() { - var url; - if (typeof window.URL === 'function') { try { - url = new URL('http://regexper.com/#%25'); + let url = new URL('http://regexper.com/#%25'); this.buggyHash = (url.hash === '#%'); } catch(e) { @@ -108,9 +106,8 @@ export default class Regexper { // automated testing, but also does some basic error handling for malformed // URLs. _getHash() { - var hash; try { - hash = location.hash.slice(1) + let hash = location.hash.slice(1) return this.buggyHash ? hash : decodeURIComponent(hash); } catch(e) { @@ -155,7 +152,7 @@ export default class Regexper { // Update the URLs of the 'download' and 'permalink' links. updateLinks() { - var classes = _.without(this.links.className.split(' '), ['hide-download', 'hide-permalink']); + let classes = _.without(this.links.className.split(' '), ['hide-download', 'hide-permalink']); // Create the 'download' image URL. try { @@ -192,7 +189,7 @@ export default class Regexper { // // - __expression__ - Regular expression to render renderRegexp(expression) { - var parseError = false, + let parseError = false, startTime, endTime; // When a render is already in progress, cancel it and try rendering again