From 3dad5476ce817bcbed762e81b4649ab3a38eb0f6 Mon Sep 17 00:00:00 2001 From: Damien Cassou Date: Fri, 8 Dec 2023 14:30:10 +0100 Subject: [PATCH] Cleanup code following eslint recommendations --- .eslintrc.js | 4 +++- src/Widget2.js | 8 ++++---- src/currentWidget.js | 2 +- src/router.js | 6 +++--- src/router/abstractSegment.js | 2 +- src/router/hashLocation.js | 4 ++-- src/router/optionalParameterSegment.js | 6 ++---- src/router/parameterSegment.js | 4 ++-- src/router/route.js | 8 ++++---- src/router/routeFactory.js | 8 ++++---- src/router/routeMatchResult.js | 2 +- src/router/router.js | 8 ++++---- src/router/staticSegment.js | 6 ++---- src/router/url.js | 2 +- src/test/htmlCanvasTest.js | 2 +- src/test/router/hashLocationTest.js | 2 +- src/test/router/routeTest.js | 2 +- src/test/router/routerTest.js | 2 +- src/test/tests.js | 10 +++++----- src/test/widgetTest.js | 4 ++-- src/widget.js | 12 ++++++------ src/widgetjs.js | 10 +++++----- 22 files changed, 56 insertions(+), 58 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index aa2ef8b4..571093bc 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -17,7 +17,9 @@ module.exports = { "src/widgetjs.js", // List of files not exporting anything: "**/.eslintrc.js", - "webpack*" + "webpack*", + "src/router/optionalParameterSegment.js", + "src/router/staticSegment.js" ], }, ] diff --git a/src/Widget2.js b/src/Widget2.js index 4a444082..329b77a8 100644 --- a/src/Widget2.js +++ b/src/Widget2.js @@ -1,9 +1,9 @@ -import router from "./router"; +import router from "./router.js"; import {eventCategory} from "yaem"; -import htmlCanvas from "./htmlCanvas"; +import htmlCanvas from "./htmlCanvas.js"; import jQuery from "jquery"; -import {getCurrentWidget, withCurrentWidget} from "./currentWidget"; -import {newId} from "./idGenerator"; +import {getCurrentWidget, withCurrentWidget} from "./currentWidget.js"; +import {newId} from "./idGenerator.js"; /** * Base for all widgets. A widget can keep state in variables, contain logic and diff --git a/src/currentWidget.js b/src/currentWidget.js index 85b2255f..a9c0779f 100644 --- a/src/currentWidget.js +++ b/src/currentWidget.js @@ -4,7 +4,7 @@ export function getCurrentWidget() { return currentWidget; } -export function setCurrentWidget(widget) { +function setCurrentWidget(widget) { currentWidget = widget; } diff --git a/src/router.js b/src/router.js index 09ecf22a..98bd27ed 100644 --- a/src/router.js +++ b/src/router.js @@ -1,6 +1,6 @@ -import url from "./router/url"; -import route from "./router/route"; -import router from "./router/router"; +import url from "./router/url.js"; +import route from "./router/route.js"; +import router from "./router/router.js"; var routerSingleton = router(); diff --git a/src/router/abstractSegment.js b/src/router/abstractSegment.js index c834e403..72cb2c26 100644 --- a/src/router/abstractSegment.js +++ b/src/router/abstractSegment.js @@ -10,7 +10,7 @@ import { object } from "klassified"; * @param my * @returns {abstractSegment} */ -var abstractSegment = object.subclass(function(that, my) { +const abstractSegment = object.subclass(function(that, my) { my.initialize = function(spec) { my.super(spec); diff --git a/src/router/hashLocation.js b/src/router/hashLocation.js index c677741d..d10fb54a 100644 --- a/src/router/hashLocation.js +++ b/src/router/hashLocation.js @@ -1,6 +1,6 @@ import jQuery from "jquery"; import {eventCategory} from "yaem"; -import url from "./url"; +import url from "./url.js"; import { object } from "klassified"; /** @@ -30,7 +30,7 @@ var pollInterval = 25; * @param [my] * @returns {hashLocation} */ -var hashLocation = object.subclass(function(that, my) { +const hashLocation = object.subclass(function(that, my) { var pollTimerId = null; diff --git a/src/router/optionalParameterSegment.js b/src/router/optionalParameterSegment.js index 6d1fc61b..e0402aa0 100644 --- a/src/router/optionalParameterSegment.js +++ b/src/router/optionalParameterSegment.js @@ -1,4 +1,4 @@ -import parameterSegment from "./parameterSegment"; +import parameterSegment from "./parameterSegment.js"; /** * Optional parameters can have a default value. @@ -7,7 +7,7 @@ import parameterSegment from "./parameterSegment"; * @param my * @returns {parameter} */ -var optionalParameterSegment = parameterSegment.subclass(function(that, my) { +const optionalParameterSegment = parameterSegment.subclass(function(that, my) { my.initialize = function(spec) { my.super(spec); @@ -57,5 +57,3 @@ optionalParameterSegment.class(function(that) { return segmentString.substr(0, 1) === "?"; }; }); - -export default optionalParameterSegment; diff --git a/src/router/parameterSegment.js b/src/router/parameterSegment.js index 9c92f98a..10561045 100644 --- a/src/router/parameterSegment.js +++ b/src/router/parameterSegment.js @@ -1,4 +1,4 @@ -import abstractSegment from "./abstractSegment"; +import abstractSegment from "./abstractSegment.js"; /** * Constructs validator functions from constraints parameters. @@ -40,7 +40,7 @@ function parameterValidator(constraint) { * @param [my] * @returns {parameterSegment} */ -var parameterSegment = abstractSegment.subclass(function(that, my) { +const parameterSegment = abstractSegment.subclass(function(that, my) { my.initialize = function(spec) { my.super(spec); diff --git a/src/router/route.js b/src/router/route.js index 4eecdec6..d9a218e3 100644 --- a/src/router/route.js +++ b/src/router/route.js @@ -1,7 +1,7 @@ -import routeFactory from "./routeFactory"; +import routeFactory from "./routeFactory.js"; import {eventCategory} from "yaem"; -import routeMatchResult from "./routeMatchResult"; -import url from "./url"; +import routeMatchResult from "./routeMatchResult.js"; +import url from "./url.js"; import { object } from "klassified"; import "jquery"; @@ -56,7 +56,7 @@ import "jquery"; * @param {{}} my * @returns {route} */ -var route = object.subclass(function(that, my) { +const route = object.subclass(function(that, my) { var segments; var ignoreTrailingSegments; diff --git a/src/router/routeFactory.js b/src/router/routeFactory.js index 9fe1b9e8..8e2de30a 100644 --- a/src/router/routeFactory.js +++ b/src/router/routeFactory.js @@ -1,7 +1,7 @@ -import abstractSegment from "./abstractSegment"; -import "./parameterSegment"; -import "./optionalParameterSegment"; -import "./staticSegment"; +import abstractSegment from "./abstractSegment.js"; +import "./parameterSegment.js"; +import "./optionalParameterSegment.js"; +import "./staticSegment.js"; /** * Token/Char used to separate segments in route patterns. diff --git a/src/router/routeMatchResult.js b/src/router/routeMatchResult.js index 974c59d2..566e0000 100644 --- a/src/router/routeMatchResult.js +++ b/src/router/routeMatchResult.js @@ -10,7 +10,7 @@ import { object } from "klassified"; * * @returns {routeMatchResult} */ -var routeMatchResult = object.subclass(function(that, my) { +const routeMatchResult = object.subclass(function(that, my) { var url; var route; diff --git a/src/router/router.js b/src/router/router.js index 24517f21..9b296fef 100755 --- a/src/router/router.js +++ b/src/router/router.js @@ -1,7 +1,7 @@ import {eventCategory} from "yaem"; -import route from "./route"; -import url from "./url"; -import hashLocation from "./hashLocation"; +import route from "./route.js"; +import url from "./url.js"; +import hashLocation from "./hashLocation.js"; import { object } from "klassified"; import "jquery"; @@ -33,7 +33,7 @@ function hashSingleton() { * * @returns {{}} */ -var router = object.subclass(function(that, my) { +const router = object.subclass(function(that, my) { my.initialize = function(spec) { my.super(spec); diff --git a/src/router/staticSegment.js b/src/router/staticSegment.js index 2fa27e5d..ccc4881c 100644 --- a/src/router/staticSegment.js +++ b/src/router/staticSegment.js @@ -1,4 +1,4 @@ -import abstractSegment from "./abstractSegment"; +import abstractSegment from "./abstractSegment.js"; /** * A static segment match URL segments that are identical @@ -8,7 +8,7 @@ import abstractSegment from "./abstractSegment"; * @param [my] * @returns {segment} */ -var staticSegment = abstractSegment.subclass(function(that, my) { +const staticSegment = abstractSegment.subclass(function(that, my) { /** * Static segment match if URL and route segment @@ -35,5 +35,3 @@ staticSegment.class(function(that) { return ["#", "?"].indexOf(segmentString[0]) === -1; }; }); - -export default staticSegment; diff --git a/src/router/url.js b/src/router/url.js index 2a74afb0..2baf3046 100644 --- a/src/router/url.js +++ b/src/router/url.js @@ -18,7 +18,7 @@ var urlSeparator = "/"; * @param {string} rawUrl * @returns {url} */ -var url = object.subclass(function(that, my) { +const url = object.subclass(function(that, my) { var rawUrl; var path; diff --git a/src/test/htmlCanvasTest.js b/src/test/htmlCanvasTest.js index e3b479a5..8f23bd59 100644 --- a/src/test/htmlCanvasTest.js +++ b/src/test/htmlCanvasTest.js @@ -1,4 +1,4 @@ -import htmlCanvas from "../htmlCanvas"; +import htmlCanvas from "../htmlCanvas.js"; import jQuery from "jquery"; function withCanvas(callback) { diff --git a/src/test/router/hashLocationTest.js b/src/test/router/hashLocationTest.js index 7983b696..61af7866 100644 --- a/src/test/router/hashLocationTest.js +++ b/src/test/router/hashLocationTest.js @@ -1,5 +1,5 @@ import jQuery from "jquery"; -import hashLocationModel from "../../router/hashLocation"; +import hashLocationModel from "../../router/hashLocation.js"; // Helpers diff --git a/src/test/router/routeTest.js b/src/test/router/routeTest.js index 8d08c270..f23f57d2 100644 --- a/src/test/router/routeTest.js +++ b/src/test/router/routeTest.js @@ -1,4 +1,4 @@ -import router from "../../router"; +import router from "../../router.js"; function assertMatch(url, route, message) { expect(router.url({rawUrl: url}).matchRoute(router.route({ pattern: route })).isMatch()).toBeTruthy(); diff --git a/src/test/router/routerTest.js b/src/test/router/routerTest.js index 8adf9a07..2c56a211 100644 --- a/src/test/router/routerTest.js +++ b/src/test/router/routerTest.js @@ -1,4 +1,4 @@ -import router from "../../router/router"; +import router from "../../router/router.js"; function delayedSteps() { var steps = Array.prototype.slice.call(arguments); diff --git a/src/test/tests.js b/src/test/tests.js index 0257765e..41fe406f 100644 --- a/src/test/tests.js +++ b/src/test/tests.js @@ -1,5 +1,5 @@ -import "./htmlCanvasTest"; -import "./widgetTest"; -import "./router/hashLocationTest"; -import "./router/routerTest"; -import "./router/routeTest"; +import "./htmlCanvasTest.js"; +import "./widgetTest.js"; +import "./router/hashLocationTest.js"; +import "./router/routerTest.js"; +import "./router/routeTest.js"; diff --git a/src/test/widgetTest.js b/src/test/widgetTest.js index f7722987..7086ded9 100644 --- a/src/test/widgetTest.js +++ b/src/test/widgetTest.js @@ -1,5 +1,5 @@ -import widget from "../widget"; -import htmlCanvas from "../htmlCanvas"; +import widget from "../widget.js"; +import htmlCanvas from "../htmlCanvas.js"; import jQuery from "jquery"; var widgetSubclass = widget.subclass(function(that, my) { diff --git a/src/widget.js b/src/widget.js index 8fcab968..5a54e589 100644 --- a/src/widget.js +++ b/src/widget.js @@ -1,11 +1,11 @@ import { object } from "klassified"; -import widgetExtensions from "./widget-extensions"; -import router from "./router"; +import widgetExtensions from "./widget-extensions.js"; +import router from "./router.js"; import {eventCategory} from "yaem"; -import htmlCanvas from "./htmlCanvas"; +import htmlCanvas from "./htmlCanvas.js"; import jQuery from "jquery"; -import {getCurrentWidget, withCurrentWidget} from "./currentWidget"; -import {newId} from "./idGenerator"; +import {getCurrentWidget, withCurrentWidget} from "./currentWidget.js"; +import {newId} from "./idGenerator.js"; /** * Base for all widgets. A widget can keep state in variables, contain logic and @@ -46,7 +46,7 @@ import {newId} from "./idGenerator"; * * @returns {widget} */ -var widget = object.subclass(function(that, my) { +const widget = object.subclass(function(that, my) { /** * Keep track of the rendered subwidgets diff --git a/src/widgetjs.js b/src/widgetjs.js index b5592019..6d6504a1 100644 --- a/src/widgetjs.js +++ b/src/widgetjs.js @@ -1,5 +1,5 @@ -export {default as htmlCanvas} from "./htmlCanvas"; -export {default as widget} from "./widget"; -export {default as Widget} from "./Widget2"; -export {default as ext} from "./widget-extensions"; -export {default as router} from "./router"; +export {default as htmlCanvas} from "./htmlCanvas.js"; +export {default as widget} from "./widget.js"; +export {default as Widget} from "./Widget2.js"; +export {default as ext} from "./widget-extensions.js"; +export {default as router} from "./router.js";