diff --git a/.eslintignore b/.eslintignore index 35534fa3..388ef910 100644 --- a/.eslintignore +++ b/.eslintignore @@ -11,5 +11,5 @@ CHECKS docker-compose.yml Dockerfile LICENSE -nightwatch.config.js +nightwatch.conf.js README.md diff --git a/.eslintrc.js b/.eslintrc.js index 346e1cbe..94e6f083 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -25,5 +25,6 @@ module.exports = { }, rules: { "no-prototype-builtins": "off", + "no-undef": "warn", }, }; diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 20e415ce..19e3d026 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -41,3 +41,17 @@ jobs: - name: Run Prettier check run: npx prettier --check . + + + lint: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Install dependencies + run: npm install + + - name: Run ESLint + run: npx eslint . diff --git a/client-data/js/board.js b/client-data/js/board.js index 2d8c900d..85493f56 100644 --- a/client-data/js/board.js +++ b/client-data/js/board.js @@ -23,7 +23,7 @@ * * @licend */ - +const Minitpl = require('./minitpl') var Tools = {}; Tools.i18n = (function i18n() { @@ -75,6 +75,7 @@ Tools.connect = function () { socket_params.query = "token=" + params.get("token"); } + // eslint-disable-next-line no-undef this.socket = io.connect("", socket_params); //Receive draw instructions from the server @@ -588,6 +589,7 @@ Tools.toolHooks = [ }; } + // eslint-disable-next-line no-unused-vars function wrapUnsetHover(f, toolName) { return function unsetHover(evt) { document.activeElement && @@ -643,6 +645,7 @@ Tools.generateUID = function (prefix, suffix) { Tools.createSVGElement = function createSVGElement(name, attrs) { var elem = document.createElementNS(Tools.svg.namespaceURI, name); if (typeof attrs !== "object") return elem; + // eslint-disable-next-line no-unused-vars Object.keys(attrs).forEach(function (key, i) { elem.setAttributeNS(null, key, attrs[key]); }); @@ -764,6 +767,7 @@ Tools.svg.height.baseVal.value = document.body.clientHeight; var dy = evt.clientY - pos.scroll; menu.scrollTop = pos.top - dy; } + // eslint-disable-next-line no-unused-vars function menu_mouseup(evt) { menu.removeEventListener("mousemove", menu_mousemove); document.removeEventListener("mouseup", menu_mouseup); diff --git a/client-data/js/canvascolor.js b/client-data/js/canvascolor.js index a3ccbd85..272047ce 100644 --- a/client-data/js/canvascolor.js +++ b/client-data/js/canvascolor.js @@ -34,6 +34,7 @@ // @use_types_for_optimization true // ==/ClosureCompiler== +// eslint-disable-next-line no-unused-vars var canvascolor = (function () { //Code Isolation "use strict"; diff --git a/client-data/js/minitpl.js b/client-data/js/minitpl.js index 0a32af9c..ca54182a 100644 --- a/client-data/js/minitpl.js +++ b/client-data/js/minitpl.js @@ -23,8 +23,9 @@ * * @licend */ - -Minitpl = (function () { +// eslint-disable-next-line no-unused-vars +const Minitpl = (function () { + // eslint-disable-next-line no-unused-vars function Minitpl(elem, data) { this.elem = typeof elem === "string" ? document.querySelector(elem) : elem; if (!elem) { diff --git a/client-data/js/path-data-polyfill.js b/client-data/js/path-data-polyfill.js index fd38dff7..cebd09b9 100644 --- a/client-data/js/path-data-polyfill.js +++ b/client-data/js/path-data-polyfill.js @@ -539,8 +539,8 @@ if ( var curves = []; for (var i = 0; i < params.length; i += 3) { - var r1 = rotate(params[i][0], params[i][1], angleRad); - var r2 = rotate(params[i + 1][0], params[i + 1][1], angleRad); + r1 = rotate(params[i][0], params[i][1], angleRad); + r2 = rotate(params[i + 1][0], params[i + 1][1], angleRad); var r3 = rotate(params[i + 2][0], params[i + 2][1], angleRad); curves.push([r1.x, r1.y, r2.x, r2.y, r3.x, r3.y]); } @@ -584,8 +584,8 @@ if ( currentX = x; currentY = y; } else if (type === "m") { - var x = currentX + seg.values[0]; - var y = currentY + seg.values[1]; + x = currentX + seg.values[0]; + y = currentY + seg.values[1]; absolutizedPathData.push({ type: "M", values: [x, y] }); @@ -595,16 +595,16 @@ if ( currentX = x; currentY = y; } else if (type === "L") { - var x = seg.values[0]; - var y = seg.values[1]; + x = seg.values[0]; + y = seg.values[1]; absolutizedPathData.push({ type: "L", values: [x, y] }); currentX = x; currentY = y; } else if (type === "l") { - var x = currentX + seg.values[0]; - var y = currentY + seg.values[1]; + x = currentX + seg.values[0]; + y = currentY + seg.values[1]; absolutizedPathData.push({ type: "L", values: [x, y] }); @@ -615,8 +615,8 @@ if ( var y1 = seg.values[1]; var x2 = seg.values[2]; var y2 = seg.values[3]; - var x = seg.values[4]; - var y = seg.values[5]; + x = seg.values[4]; + y = seg.values[5]; absolutizedPathData.push({ type: "C", @@ -626,12 +626,12 @@ if ( currentX = x; currentY = y; } else if (type === "c") { - var x1 = currentX + seg.values[0]; - var y1 = currentY + seg.values[1]; - var x2 = currentX + seg.values[2]; - var y2 = currentY + seg.values[3]; - var x = currentX + seg.values[4]; - var y = currentY + seg.values[5]; + x1 = currentX + seg.values[0]; + y1 = currentY + seg.values[1]; + x2 = currentX + seg.values[2]; + y2 = currentY + seg.values[3]; + x = currentX + seg.values[4]; + y = currentY + seg.values[5]; absolutizedPathData.push({ type: "C", @@ -641,28 +641,28 @@ if ( currentX = x; currentY = y; } else if (type === "Q") { - var x1 = seg.values[0]; - var y1 = seg.values[1]; - var x = seg.values[2]; - var y = seg.values[3]; + x1 = seg.values[0]; + y1 = seg.values[1]; + x = seg.values[2]; + y = seg.values[3]; absolutizedPathData.push({ type: "Q", values: [x1, y1, x, y] }); currentX = x; currentY = y; } else if (type === "q") { - var x1 = currentX + seg.values[0]; - var y1 = currentY + seg.values[1]; - var x = currentX + seg.values[2]; - var y = currentY + seg.values[3]; + x1 = currentX + seg.values[0]; + y1 = currentY + seg.values[1]; + x = currentX + seg.values[2]; + y = currentY + seg.values[3]; absolutizedPathData.push({ type: "Q", values: [x1, y1, x, y] }); currentX = x; currentY = y; } else if (type === "A") { - var x = seg.values[5]; - var y = seg.values[6]; + x = seg.values[5]; + y = seg.values[6]; absolutizedPathData.push({ type: "A", @@ -680,8 +680,8 @@ if ( currentX = x; currentY = y; } else if (type === "a") { - var x = currentX + seg.values[5]; - var y = currentY + seg.values[6]; + x = currentX + seg.values[5]; + y = currentY + seg.values[6]; absolutizedPathData.push({ type: "A", @@ -699,52 +699,52 @@ if ( currentX = x; currentY = y; } else if (type === "H") { - var x = seg.values[0]; + x = seg.values[0]; absolutizedPathData.push({ type: "H", values: [x] }); currentX = x; } else if (type === "h") { - var x = currentX + seg.values[0]; + x = currentX + seg.values[0]; absolutizedPathData.push({ type: "H", values: [x] }); currentX = x; } else if (type === "V") { - var y = seg.values[0]; + y = seg.values[0]; absolutizedPathData.push({ type: "V", values: [y] }); currentY = y; } else if (type === "v") { - var y = currentY + seg.values[0]; + y = currentY + seg.values[0]; absolutizedPathData.push({ type: "V", values: [y] }); currentY = y; } else if (type === "S") { - var x2 = seg.values[0]; - var y2 = seg.values[1]; - var x = seg.values[2]; - var y = seg.values[3]; + x2 = seg.values[0]; + y2 = seg.values[1]; + x = seg.values[2]; + y = seg.values[3]; absolutizedPathData.push({ type: "S", values: [x2, y2, x, y] }); currentX = x; currentY = y; } else if (type === "s") { - var x2 = currentX + seg.values[0]; - var y2 = currentY + seg.values[1]; - var x = currentX + seg.values[2]; - var y = currentY + seg.values[3]; + x2 = currentX + seg.values[0]; + y2 = currentY + seg.values[1]; + x = currentX + seg.values[2]; + y = currentY + seg.values[3]; absolutizedPathData.push({ type: "S", values: [x2, y2, x, y] }); currentX = x; currentY = y; } else if (type === "T") { - var x = seg.values[0]; - var y = seg.values[1]; + x = seg.values[0]; + y = seg.values[1]; absolutizedPathData.push({ type: "T", values: [x, y] }); currentX = x; currentY = y; } else if (type === "t") { - var x = currentX + seg.values[0]; - var y = currentY + seg.values[1]; + x = currentX + seg.values[0]; + y = currentY + seg.values[1]; absolutizedPathData.push({ type: "T", values: [x, y] }); @@ -794,8 +794,8 @@ if ( var y1 = seg.values[1]; var x2 = seg.values[2]; var y2 = seg.values[3]; - var x = seg.values[4]; - var y = seg.values[5]; + x = seg.values[4]; + y = seg.values[5]; reducedPathData.push({ type: "C", values: [x1, y1, x2, y2, x, y] }); @@ -805,30 +805,30 @@ if ( currentX = x; currentY = y; } else if (seg.type === "L") { - var x = seg.values[0]; - var y = seg.values[1]; + x = seg.values[0]; + y = seg.values[1]; reducedPathData.push({ type: "L", values: [x, y] }); currentX = x; currentY = y; } else if (seg.type === "H") { - var x = seg.values[0]; + x = seg.values[0]; reducedPathData.push({ type: "L", values: [x, currentY] }); currentX = x; } else if (seg.type === "V") { - var y = seg.values[0]; + y = seg.values[0]; reducedPathData.push({ type: "L", values: [currentX, y] }); currentY = y; } else if (seg.type === "S") { - var x2 = seg.values[0]; - var y2 = seg.values[1]; - var x = seg.values[2]; - var y = seg.values[3]; + x2 = seg.values[0]; + y2 = seg.values[1]; + x = seg.values[2]; + y = seg.values[3]; var cx1, cy1; @@ -848,10 +848,10 @@ if ( currentX = x; currentY = y; } else if (seg.type === "T") { - var x = seg.values[0]; - var y = seg.values[1]; + x = seg.values[0]; + y = seg.values[1]; - var x1, y1; + // var x1, y1; if (lastType === "Q" || lastType === "T") { x1 = currentX + (currentX - lastControlX); @@ -861,8 +861,8 @@ if ( y1 = currentY; } - var cx1 = currentX + (2 * (x1 - currentX)) / 3; - var cy1 = currentY + (2 * (y1 - currentY)) / 3; + cx1 = currentX + (2 * (x1 - currentX)) / 3; + cy1 = currentY + (2 * (y1 - currentY)) / 3; var cx2 = x + (2 * (x1 - x)) / 3; var cy2 = y + (2 * (y1 - y)) / 3; @@ -877,15 +877,15 @@ if ( currentX = x; currentY = y; } else if (seg.type === "Q") { - var x1 = seg.values[0]; - var y1 = seg.values[1]; - var x = seg.values[2]; - var y = seg.values[3]; + x1 = seg.values[0]; + y1 = seg.values[1]; + x = seg.values[2]; + y = seg.values[3]; - var cx1 = currentX + (2 * (x1 - currentX)) / 3; - var cy1 = currentY + (2 * (y1 - currentY)) / 3; - var cx2 = x + (2 * (x1 - x)) / 3; - var cy2 = y + (2 * (y1 - y)) / 3; + cx1 = currentX + (2 * (x1 - currentX)) / 3; + cy1 = currentY + (2 * (y1 - currentY)) / 3; + cx2 = x + (2 * (x1 - x)) / 3; + cy2 = y + (2 * (y1 - y)) / 3; reducedPathData.push({ type: "C", @@ -903,8 +903,8 @@ if ( var angle = seg.values[2]; var largeArcFlag = seg.values[3]; var sweepFlag = seg.values[4]; - var x = seg.values[5]; - var y = seg.values[6]; + x = seg.values[5]; + y = seg.values[6]; if (r1 === 0 || r2 === 0) { reducedPathData.push({ @@ -958,6 +958,7 @@ if ( setAttribute.call(this, name, value); }; + // eslint-disable-next-line no-unused-vars SVGPathElement.prototype.removeAttribute = function (name, value) { if (name === "d") { this[$cachedPathData] = null; @@ -989,7 +990,7 @@ if ( if (this[$cachedPathData]) { return clonePathData(this[$cachedPathData]); } else { - var pathData = parsePathDataString(this.getAttribute("d") || ""); + pathData = parsePathDataString(this.getAttribute("d") || ""); this[$cachedPathData] = clonePathData(pathData); return pathData; } diff --git a/client-data/tools/clear/clear.js b/client-data/tools/clear/clear.js index 29c01118..dd7b2c22 100644 --- a/client-data/tools/clear/clear.js +++ b/client-data/tools/clear/clear.js @@ -36,6 +36,7 @@ Tools.drawAndSend(msg, Tools.list["Clear"]); } + // eslint-disable-next-line no-unused-vars function draw(data) { Tools.drawingArea.innerHTML = ""; } diff --git a/client-data/tools/ellipse/ellipse.js b/client-data/tools/ellipse/ellipse.js index 1450fac1..33f64280 100644 --- a/client-data/tools/ellipse/ellipse.js +++ b/client-data/tools/ellipse/ellipse.js @@ -56,6 +56,7 @@ y2: y, }); + // eslint-disable-next-line no-self-assign curUpdate.id = curUpdate.id; curUpdate.x = x; curUpdate.y = y; diff --git a/client-data/tools/grid/grid.js b/client-data/tools/grid/grid.js index be6885d3..f688ddfe 100644 --- a/client-data/tools/grid/grid.js +++ b/client-data/tools/grid/grid.js @@ -30,6 +30,7 @@ var index = 0; //grid off by default var states = ["none", "url(#grid)", "url(#dots)"]; + // eslint-disable-next-line no-unused-vars function toggleGrid(evt) { index = (index + 1) % states.length; gridContainer.setAttributeNS(null, "fill", states[index]); diff --git a/client-data/tools/hand/hand.js b/client-data/tools/hand/hand.js index 51133350..7e164c09 100644 --- a/client-data/tools/hand/hand.js +++ b/client-data/tools/hand/hand.js @@ -87,7 +87,7 @@ ), ]; - for (i in blockedSelectionButtons) { + for (var i in blockedSelectionButtons) { delete selectionButtons[blockedSelectionButtons[i]]; } @@ -273,7 +273,7 @@ selectionRect.width.baseVal.value = 0; selectionRect.height.baseVal.value = 0; selectionRect.style.display = ""; - tmatrix = get_transform_matrix(selectionRect); + var tmatrix = get_transform_matrix(selectionRect); tmatrix.e = 0; tmatrix.f = 0; } @@ -284,6 +284,7 @@ var selected = []; for (var i = 0; i < elements.length; i++) { if ( + // eslint-disable-next-line no-undef transformedBBoxIntersects(selectionTBBox, elements[i].transformedBBox()) ) selected.push(Tools.drawingArea.children[i]); @@ -421,6 +422,7 @@ function draw(data) { if (data._children) { + // eslint-disable-next-line no-undef batchCall(draw, data._children); } else { switch (data.type) { @@ -442,6 +444,7 @@ break; case "delete": data.tool = "Eraser"; + // eslint-disable-next-line no-undef messageForTool(data); break; default: @@ -463,6 +466,7 @@ if (button) { button.clickCallback(x, y, evt); } else if ( + // eslint-disable-next-line no-undef pointInTransformedBBox([x, y], selectionRect.transformedBBox()) ) { hideSelectionButtons(); @@ -477,6 +481,7 @@ } } + // eslint-disable-next-line no-unused-vars function releaseSelector(x, y, evt) { if (selectorState == selectorStates.selecting) { selected_els = calculateSelection(); @@ -489,6 +494,7 @@ selectorState = selectorStates.pointing; } + // eslint-disable-next-line no-unused-vars function moveSelector(x, y, evt) { if (selectorState == selectorStates.selecting) { updateRect(x, y, selectionRect); diff --git a/client-data/tools/pencil/pencil.js b/client-data/tools/pencil/pencil.js index 36b37d34..9cacfae2 100644 --- a/client-data/tools/pencil/pencil.js +++ b/client-data/tools/pencil/pencil.js @@ -156,6 +156,7 @@ function addPoint(line, x, y) { var pts = getPathData(line); + // eslint-disable-next-line no-undef pts = wboPencilPoint(pts, x, y); line.setPathData(pts); } @@ -212,6 +213,7 @@ release: stopLineAt, }, draw: draw, + // eslint-disable-next-line no-unused-vars onstart: function (oldTool) { //Reset stylus hasUsedStylus = false; @@ -225,6 +227,7 @@ toggleSize(); }, }, + // eslint-disable-next-line no-dupe-keys onstart: function () { //When switching from another tool to white-out, restore white-out size if (pencilTool.secondary.active) { diff --git a/client-data/tools/text/text.js b/client-data/tools/text/text.js index 27689740..f1b2b549 100644 --- a/client-data/tools/text/text.js +++ b/client-data/tools/text/text.js @@ -58,6 +58,7 @@ Tools.setSize(curText.oldSize); } + // eslint-disable-next-line no-unused-vars function clickHandler(x, y, evt, isTouchEvent) { //if(document.querySelector("#menu").offsetWidth>Tools.menu_width+3) return; if (evt.target === input) return; @@ -99,6 +100,7 @@ active = true; if (!input.parentNode) board.appendChild(input); input.value = ""; + // eslint-disable-next-line no-unused-vars var left = curText.x - document.documentElement.scrollLeft + "px"; var clientW = Math.max( document.documentElement.clientWidth, @@ -176,6 +178,7 @@ } } + // eslint-disable-next-line no-unused-vars function draw(data, isLocal) { Tools.drawingEvent = true; switch (data.type) { diff --git a/client-data/tools/zoom/zoom.js b/client-data/tools/zoom/zoom.js index 85c79b63..9a2dd89d 100644 --- a/client-data/tools/zoom/zoom.js +++ b/client-data/tools/zoom/zoom.js @@ -153,6 +153,7 @@ Tools.board.addEventListener("touchend", touchend); Tools.board.addEventListener("touchcancel", touchend); + // eslint-disable-next-line no-unused-vars function release(x, y, evt, isTouchEvent) { if (pressed && !moved) { var delta = evt.shiftKey === true ? -1 : 1; diff --git a/package.json b/package.json index 319af6e8..6832a8bc 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,8 @@ "start": "node ./server/server.js", "test": "nightwatch tests && nightwatch tests --env jwt", "prettier": "prettier . --write", - "prettier-check": "prettier . --check" + "prettier-check": "prettier . --check", + "lint": "eslint ." }, "main": "./server/server.js", "repository": {