Fixing lint warning that came with the new version of JSCS

Also some other minor code cleanup
This commit is contained in:
Jeff Avallone 2016-07-27 11:00:17 -04:00
parent 1bd3df524a
commit 6efa287c4e
11 changed files with 35 additions and 45 deletions

View File

@ -78,7 +78,7 @@ export default class Parser {
// Render the parsed expression to an SVG. // Render the parsed expression to an SVG.
render() { render() {
var svg = Snap(this.container.querySelector('svg')); let svg = Snap(this.container.querySelector('svg'));
return this.parsed.render(svg.group()) return this.parsed.render(svg.group())
// Once rendering is complete, the rendered expression is positioned and // Once rendering is complete, the rendered expression is positioned and

View File

@ -9,7 +9,7 @@ export default {
// Renders the charset range into the currently set container // Renders the charset range into the currently set container
_render() { _render() {
var contents = [ let contents = [
this.first, this.first,
this.container.text(0, 0, '-'), this.container.text(0, 0, '-'),
this.last this.last

View File

@ -30,7 +30,7 @@ export default {
}, },
setup() { setup() {
var addHex; let addHex;
// The escape code. For an escape such as `\b` it would be "b". // The escape code. For an escape such as `\b` it would be "b".
this.code = this.properties.esc.properties.code.textValue; this.code = this.properties.esc.properties.code.textValue;
@ -69,7 +69,7 @@ export default {
7: ['Back reference (group = 7)', -1, false], 7: ['Back reference (group = 7)', -1, false],
8: ['Back reference (group = 8)', -1, false], 8: ['Back reference (group = 8)', -1, false],
9: ['Back reference (group = 9)', -1, false], 9: ['Back reference (group = 9)', -1, false],
0() { 0: function() {
if (this.arg) { if (this.arg) {
return [`octal: ${this.arg}`, parseInt(this.arg, 8), true]; return [`octal: ${this.arg}`, parseInt(this.arg, 8), true];
} else { } else {

View File

@ -29,13 +29,9 @@ export default {
// Renders the match into the currently set container. // Renders the match into the currently set container.
_render() { _render() {
var partPromises,
items;
// Render each of the match fragments. // Render each of the match fragments.
partPromises = _.map(this.parts, part => part.render(this.container.group())); let partPromises = _.map(this.parts, part => part.render(this.container.group())),
items = _(partPromises).compact().value();
items = _(partPromises).compact().value();
// Handle the situation where a regular expression of `()` is rendered. // Handle the situation where a regular expression of `()` is rendered.
// This leads to a Match node with no fragments. Something must be 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. // Returns an array of SVG path strings between each item.
// - __items__ - Array of SVG elements or nodes. // - __items__ - Array of SVG elements or nodes.
connectorPaths(items) { connectorPaths(items) {
var prev, next; let prev, next;
prev = util.normalizeBBox(_.first(items).getBBox()); prev = util.normalizeBBox(_.first(items).getBBox());
return _.map(items.slice(1), item => { return _.map(items.slice(1), item => {

View File

@ -52,22 +52,21 @@ export default {
// Renders label for the loop path indicating how many times the content may // Renders label for the loop path indicating how many times the content may
// be matched. // be matched.
loopLabel() { loopLabel() {
var labelStr = this.repeat.label, let labelStr = this.repeat.label,
tooltipStr = this.repeat.tooltip, tooltipStr = this.repeat.tooltip;
label, tooltip, labelBox, box;
if (labelStr) { if (labelStr) {
label = this.container.text(0, 0, [labelStr]) let label = this.container.text(0, 0, [labelStr])
.addClass('repeat-label'); .addClass('repeat-label'),
labelBox = label.getBBox(),
box = this.getBBox();
if (tooltipStr) { if (tooltipStr) {
tooltip = this.container.el('title') let tooltip = this.container.el('title')
.append(this.container.text(0, 0, tooltipStr)); .append(this.container.text(0, 0, tooltipStr));
label.append(tooltip); label.append(tooltip);
} }
box = this.getBBox();
labelBox = label.getBBox();
label.transform(Snap.matrix().translate( label.transform(Snap.matrix().translate(
box.x2 - labelBox.width - (this.repeat.hasSkip ? 5 : 0), box.x2 - labelBox.width - (this.repeat.hasSkip ? 5 : 0),
box.y2 + labelBox.height)); box.y2 + labelBox.height));

View File

@ -116,17 +116,17 @@ export default class Node {
// //
// - __text__ - String or array of strings to render as a label. // - __text__ - String or array of strings to render as a label.
renderLabel(text) { renderLabel(text) {
var group = this.container.group() let group = this.container.group()
.addClass('label'), .addClass('label'),
rect = group.rect(), rect = group.rect(),
text = group.text(0, 0, _.flatten([text])); label = group.text(0, 0, _.flatten([text]));
return this.deferredStep() return this.deferredStep()
.then(() => { .then(() => {
let box = text.getBBox(), let box = label.getBBox(),
margin = 5; margin = 5;
text.transform(Snap.matrix() label.transform(Snap.matrix()
.translate(margin, box.height / 2 + 2 * margin)); .translate(margin, box.height / 2 + 2 * margin));
rect.attr({ rect.attr({
@ -140,12 +140,12 @@ export default class Node {
// Renders a labeled box around another SVG element. Returns a Promise. // 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. // - __content__ - SVG element to wrap in the box.
// - __options.padding__ - Pixels of padding to place between the content and // - __options.padding__ - Pixels of padding to place between the content and
// the box. // the box.
renderLabeledBox(label, content, options) { renderLabeledBox(text, content, options) {
var label = this.container.text(0, 0, _.flatten([label])) let label = this.container.text(0, 0, _.flatten([text]))
.addClass(`${this.type}-label`), .addClass(`${this.type}-label`),
box = this.container.rect() box = this.container.rect()
.addClass(`${this.type}-box`) .addClass(`${this.type}-box`)

View File

@ -9,7 +9,7 @@ export default {
// Renders the regexp into the currently set container. // Renders the regexp into the currently set container.
_render() { _render() {
var matchContainer = this.container.group() let matchContainer = this.container.group()
.addClass('regexp-matches') .addClass('regexp-matches')
.transform(Snap.matrix() .transform(Snap.matrix()
.translate(20, 0)); .translate(20, 0));
@ -56,7 +56,7 @@ export default {
// - __containerBox__ - Bounding box of the container. // - __containerBox__ - Bounding box of the container.
// - __match__ - Match node that the line will be drawn to. // - __match__ - Match node that the line will be drawn to.
makeSide(containerBox, match) { makeSide(containerBox, match) {
var box = match.getBBox(), let box = match.getBBox(),
distance = Math.abs(box.ay - containerBox.cy); distance = Math.abs(box.ay - containerBox.cy);
// Only need to draw side lines if the match is more than 15 pixels from // 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. // - __containerBox__ - Bounding box of the container.
// - __match__ - Match node that the line will be drawn to. // - __match__ - Match node that the line will be drawn to.
makeCurve(containerBox, match) { makeCurve(containerBox, match) {
var box = match.getBBox(), let box = match.getBBox(),
distance = Math.abs(box.ay - containerBox.cy); distance = Math.abs(box.ay - containerBox.cy);
if (distance >= 15) { if (distance >= 15) {
@ -109,7 +109,7 @@ export default {
// - __containerBox__ - Bounding box of the container. // - __containerBox__ - Bounding box of the container.
// - __match__ - Match node that the line will be drawn to. // - __match__ - Match node that the line will be drawn to.
makeConnector(containerBox, match) { 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}`; return `M0,${box.ay}h${box.ax}M${box.ax2},${box.ay}H${containerBox.width}`;
}, },

View File

@ -76,7 +76,7 @@ export default {
// Returns the path spec to render the line that skips over the content for // Returns the path spec to render the line that skips over the content for
// fragments that are optionally matched. // fragments that are optionally matched.
skipPath(box) { skipPath(box) {
var paths = []; let paths = [];
if (this.hasSkip) { if (this.hasSkip) {
let vert = Math.max(0, box.ay - box.y - 10), 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 // Returns the path spec to render the line that repeats the content for
// fragments that are matched more than once. // fragments that are matched more than once.
loopPath(box) { loopPath(box) {
var paths = []; let paths = [];
if (this.hasLoop) { if (this.hasLoop) {
let vert = box.y2 - box.ay - 10; let vert = box.y2 - box.ay - 10;

View File

@ -14,7 +14,7 @@ export default {
// Renders the root into the currently set container. // Renders the root into the currently set container.
_render() { _render() {
var flagText; let flagText;
// Render a label for any flags that have been set of the expression. // Render a label for any flags that have been set of the expression.
if (this.flags.length > 0) { if (this.flags.length > 0) {
@ -24,8 +24,6 @@ export default {
// Render the content of the regular expression. // Render the content of the regular expression.
return this.regexp.render(this.container.group()) return this.regexp.render(this.container.group())
.then(() => { .then(() => {
let box;
// Move rendered regexp to account for flag label and to allow for // Move rendered regexp to account for flag label and to allow for
// decorative elements. // decorative elements.
if (flagText) { if (flagText) {
@ -36,7 +34,7 @@ export default {
.translate(10, 0)); .translate(10, 0));
} }
box = this.regexp.getBBox(); let box = this.regexp.getBBox();
// Render decorative elements. // Render decorative elements.
this.container.path(`M${box.ax},${box.ay}H0M${box.ax2},${box.ay}H${box.x2 + 10}`); this.container.path(`M${box.ax},${box.ay}H0M${box.ax2},${box.ay}H${box.x2 + 10}`);

View File

@ -34,7 +34,7 @@ export default {
// **NOTE:** `this.label()` **MUST** be called here, in _render, and before // **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 // any child nodes are rendered. This is to keep the group numbers in the
// correct order. // correct order.
var label = this.label(); let label = this.label();
// Render the contained regexp. // Render the contained regexp.
return this.regexp.render(this.container.group()) return this.regexp.render(this.container.group())

View File

@ -63,7 +63,7 @@ export default class Regexper {
// Event handler for URL hash changes. Starts rendering of the expression. // Event handler for URL hash changes. Starts rendering of the expression.
hashchangeListener() { hashchangeListener() {
var expr = this._getHash(); let expr = this._getHash();
if (expr instanceof Error) { if (expr instanceof Error) {
this.state = 'has-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 // Detect if https://bugzilla.mozilla.org/show_bug.cgi?id=483304 is in effect
detectBuggyHash() { detectBuggyHash() {
var url;
if (typeof window.URL === 'function') { if (typeof window.URL === 'function') {
try { try {
url = new URL('http://regexper.com/#%25'); let url = new URL('http://regexper.com/#%25');
this.buggyHash = (url.hash === '#%'); this.buggyHash = (url.hash === '#%');
} }
catch(e) { catch(e) {
@ -108,9 +106,8 @@ export default class Regexper {
// automated testing, but also does some basic error handling for malformed // automated testing, but also does some basic error handling for malformed
// URLs. // URLs.
_getHash() { _getHash() {
var hash;
try { try {
hash = location.hash.slice(1) let hash = location.hash.slice(1)
return this.buggyHash ? hash : decodeURIComponent(hash); return this.buggyHash ? hash : decodeURIComponent(hash);
} }
catch(e) { catch(e) {
@ -155,7 +152,7 @@ export default class Regexper {
// Update the URLs of the 'download' and 'permalink' links. // Update the URLs of the 'download' and 'permalink' links.
updateLinks() { 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. // Create the 'download' image URL.
try { try {
@ -192,7 +189,7 @@ export default class Regexper {
// //
// - __expression__ - Regular expression to render // - __expression__ - Regular expression to render
renderRegexp(expression) { renderRegexp(expression) {
var parseError = false, let parseError = false,
startTime, endTime; startTime, endTime;
// When a render is already in progress, cancel it and try rendering again // When a render is already in progress, cancel it and try rendering again