From d75de7dc848e63d26fa40ae1a7cd80414eebaf50 Mon Sep 17 00:00:00 2001 From: James Williams <42288565+jamesgeorgewilliams@users.noreply.github.com> Date: Tue, 9 Nov 2021 11:06:55 +0100 Subject: [PATCH] eslint: add and update eslint configs (#1568) --- .eslintignore | 4 ++ .travis.yml | 4 ++ README.md | 4 -- demo/.eslintrc.js | 49 +++++++++++++ demo/chess/src/garbochess.js | 4 +- demo/elk/src/app.js | 14 ++-- demo/expand/index.js | 2 +- demo/interpreter.js | 2 +- demo/links/src/custom-router.js | 10 +-- demo/org/src/org.js | 20 +++--- demo/ports/port-layouts-defaults.js | 14 ++-- demo/vectorizer/vectorizer.js | 6 +- demo/vuejs/demo.js | 26 +++---- docs/.eslintrc.js | 33 +++++++++ docs/demo/layout/DirectedGraph/js/clusters.js | 2 +- docs/demo/layout/Port/js/port.js | 4 +- docs/demo/layout/Port/js/portRotationComp.js | 2 +- docs/demo/layout/PortLabel/js/portLabel.js | 6 +- grunt/config/aliases.js | 2 - grunt/config/compileDocs.js | 2 +- grunt/config/concat.js | 2 +- grunt/config/copy.js | 2 +- grunt/config/eslint.js | 22 ------ grunt/config/karma.js | 2 +- test/.eslintrc.js | 22 +++++- tutorials/.eslintrc.js | 21 ++++++ tutorials/js/circle-constraint.js | 4 +- tutorials/js/hierarchy-reparenting.js | 70 +++++++++---------- tutorials/js/pipes.js | 6 +- 29 files changed, 231 insertions(+), 130 deletions(-) create mode 100644 .eslintignore create mode 100644 demo/.eslintrc.js create mode 100644 docs/.eslintrc.js delete mode 100644 grunt/config/eslint.js create mode 100644 tutorials/.eslintrc.js diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 000000000..57a9206cf --- /dev/null +++ b/.eslintignore @@ -0,0 +1,4 @@ +**/node_modules +/scripts +/dist +/build diff --git a/.travis.yml b/.travis.yml index 11021b803..5939ac8e1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,3 +9,7 @@ install: npm install before_script: - grunt install + +script: + - npm run test + - npm run lint diff --git a/README.md b/README.md index b7d4daff3..146b9e291 100644 --- a/README.md +++ b/README.md @@ -98,10 +98,6 @@ To run only the client-side tests: grunt test:client ``` -To run code style checks: -``` -grunt test:code-style -``` ### Lint diff --git a/demo/.eslintrc.js b/demo/.eslintrc.js new file mode 100644 index 000000000..e5f55e224 --- /dev/null +++ b/demo/.eslintrc.js @@ -0,0 +1,49 @@ +module.exports = { + 'extends': [ + '../.eslintrc.js', + ], + 'parserOptions': { + // 2018 allows use of async and spread syntax + 'ecmaVersion': '2018' + }, + 'globals': { + 'joint': true, + 'g': true, + 'V': true, + '$': true, + 'Backbone': true, + 'Vue': true + }, + 'ignorePatterns': ['/ts-demo/vendor/**'], + 'overrides': [{ + 'files': [ + 'rough/src/rough.js', + 'ports/port-z-index.js', + 'ports/port-layouts-defaults.js', + 'expand/expand.paper.js', + 'chess/src/garbochess.js', + 'vuejs/demo.js', + 'petri nets/src/pn.js', + 'org/src/org.js', + 'custom-router.js', + 'archive/links.js', + 'embedding/nested-clone.js', + 'expand/index.js', + 'expand/shapes.js', + 'vectorizer/vectorizer.js' + ], + // Globals contained in HTML script, etc + 'globals': { + 'rough': true, + 'createPaper': true, + 'paper': true + }, + 'rules': { + // Exceptions currently used in demo directory + 'no-redeclare': ['off'], + 'no-unused-vars': ['off'], + 'no-console': ['off'] + } + }] +}; + diff --git a/demo/chess/src/garbochess.js b/demo/chess/src/garbochess.js index cf5f8b9eb..3efc2f704 100644 --- a/demo/chess/src/garbochess.js +++ b/demo/chess/src/garbochess.js @@ -1657,7 +1657,7 @@ function MakeMove(move){ if (flags) { if (flags & moveflagCastleKing) { if (IsSquareAttackable(from + 1, otherColor) || - IsSquareAttackable(from + 2, otherColor)) { + IsSquareAttackable(from + 2, otherColor)) { g_moveCount--; return false; } @@ -1680,7 +1680,7 @@ function MakeMove(move){ g_pieceList[((rook & 0xF) << 4) | rookIndex] = to - 1; } else if (flags & moveflagCastleQueen) { if (IsSquareAttackable(from - 1, otherColor) || - IsSquareAttackable(from - 2, otherColor)) { + IsSquareAttackable(from - 2, otherColor)) { g_moveCount--; return false; } diff --git a/demo/elk/src/app.js b/demo/elk/src/app.js index 7cb25d1f5..2148ec79f 100644 --- a/demo/elk/src/app.js +++ b/demo/elk/src/app.js @@ -1,7 +1,7 @@ import * as joint from '../../../build/joint'; import ELK from 'elkjs/lib/elk-api.js'; import elkWorker from 'elkjs/lib/elk-worker.js'; -import { Child, Label, Edge } from "./shapes"; +import { Child, Label, Edge } from './shapes'; import elkGraph from '../elkGraph.json'; export const init = () => { @@ -142,7 +142,7 @@ export const init = () => { addEdges(edges); paper.unfreeze(); - paper.fitToContent({ useModelGeometry: true, padding: 100, allowNewOrigin: 'any' }) + paper.fitToContent({ useModelGeometry: true, padding: 100, allowNewOrigin: 'any' }); }); canvas.appendChild(paper.el); @@ -155,8 +155,8 @@ const addZoomListeners = paper => { const zoom = zoomLevel => { paper.scale(zoomLevel); - paper.fitToContent({ useModelGeometry: true, padding: 100 * zoomLevel, allowNewOrigin: 'any' }) - } + paper.fitToContent({ useModelGeometry: true, padding: 100 * zoomLevel, allowNewOrigin: 'any' }); + }; document.getElementById('zoom-in').addEventListener('click', () => { zoomLevel = Math.min(3, zoomLevel + 0.2); @@ -167,7 +167,7 @@ const addZoomListeners = paper => { zoomLevel = Math.max(0.2, zoomLevel - 0.2); zoom(zoomLevel); }); -} +}; const placementsOptions = { H_RIGHT: 'H_RIGHT', @@ -176,7 +176,7 @@ const placementsOptions = { V_TOP: 'V_TOP', V_BOTTOM: 'V_BOTTOM', V_CENTER: 'V_CENTER', -} +}; const getLabelPlacement = label => { const placement = {}; @@ -203,4 +203,4 @@ const getLabelPlacement = label => { } return placement; -} +}; diff --git a/demo/expand/index.js b/demo/expand/index.js index 72943f2a5..bd75a9703 100644 --- a/demo/expand/index.js +++ b/demo/expand/index.js @@ -207,7 +207,7 @@ var isCollapsed = function(cell, portId) { var runTests = function() { -///////////// + ///////////// a.hide(); console.assert(aa.portProp('in1', 'collapsed'), 'aa in1 is collapsed'); diff --git a/demo/interpreter.js b/demo/interpreter.js index 5843720d6..c8771741e 100644 --- a/demo/interpreter.js +++ b/demo/interpreter.js @@ -52,7 +52,7 @@ graph.on('signal', function(cell) { var token = V('circle', { r: 7, fill: 'green' }); cell.findView(paper).sendToken(token, 1000, function() { - targetCell.trigger('signal', targetCell); + targetCell.trigger('signal', targetCell); }); } else { diff --git a/demo/links/src/custom-router.js b/demo/links/src/custom-router.js index 8264e4419..f17cbc7a2 100644 --- a/demo/links/src/custom-router.js +++ b/demo/links/src/custom-router.js @@ -12,7 +12,7 @@ var paper = new joint.dia.Paper({ // define the router inside joint.routers // allows passing custom arguments // can be serialized with `toJSON()` -joint.routers.randomWalk = function (vertices, args, linkView) { +joint.routers.randomWalk = function(vertices, args, linkView) { var NUM_BOUNCES = args.numBounces || 20; @@ -24,11 +24,11 @@ joint.routers.randomWalk = function (vertices, args, linkView) { var targetCorner = linkView.targetBBox.center(); var randomPoint = g.Point.random(sourceCorner.x, targetCorner.x, sourceCorner.y, targetCorner.y); - vertices.push(randomPoint) + vertices.push(randomPoint); } return vertices; -} +}; var source = new joint.shapes.standard.Rectangle(); source.position(50, 50); @@ -36,7 +36,7 @@ source.resize(140, 70); source.attr('label/text', 'Source'); var target = source.clone(); -target.translate(700, 400) +target.translate(700, 400); target.attr('label/text', 'Target'); var link = new joint.shapes.standard.Link(); @@ -47,7 +47,7 @@ link.target(target); // pass by name under which it was saved in joint.routers namespace link.router('randomWalk', { numBounces: 10, -}) +}); // APPROACH 2: // pass a function diff --git a/demo/org/src/org.js b/demo/org/src/org.js index 84b633956..67b686ac7 100644 --- a/demo/org/src/org.js +++ b/demo/org/src/org.js @@ -12,14 +12,14 @@ var paper = new joint.dia.Paper({ var member = function(x, y, rank, name, image, background, textColor) { - textColor = textColor || "#000"; + textColor = textColor || '#000'; var cell = new joint.shapes.org.Member({ position: { x: x, y: y }, attrs: { - '.card': { fill: background, stroke: 'none'}, - image: { 'xlink:href': 'images/'+ image, opacity: 0.7 }, - '.rank': { text: rank, fill: textColor, 'word-spacing': '-5px', 'letter-spacing': 0}, + '.card': { fill: background, stroke: 'none' }, + image: { 'xlink:href': 'images/'+ image, opacity: 0.7 }, + '.rank': { text: rank, fill: textColor, 'word-spacing': '-5px', 'letter-spacing': 0 }, '.name': { text: name, fill: textColor, 'font-size': 13, 'font-family': 'Arial', 'letter-spacing': 0 } } }); @@ -57,9 +57,9 @@ var carl = member(190, 500, 'Manager', 'Carl Carlson', 'male.png', '#feb563'); -link(bart, marge, [{x: 385, y: 180}]); -link(bart, homer, [{x: 385, y: 180}, {x: 175, y: 180}]); -link(bart, lisa, [{x: 385, y: 180}, {x: 585, y: 180}]); -link(homer, lenny, [{x:175 , y: 380}]); -link(homer, carl, [{x:175 , y: 530}]); -link(marge, maggie, [{x:385 , y: 380}]); +link(bart, marge, [{ x: 385, y: 180 }]); +link(bart, homer, [{ x: 385, y: 180 }, { x: 175, y: 180 }]); +link(bart, lisa, [{ x: 385, y: 180 }, { x: 585, y: 180 }]); +link(homer, lenny, [{ x:175 , y: 380 }]); +link(homer, carl, [{ x:175 , y: 530 }]); +link(marge, maggie, [{ x:385 , y: 380 }]); diff --git a/demo/ports/port-layouts-defaults.js b/demo/ports/port-layouts-defaults.js index 9d078265a..5bf99dd33 100644 --- a/demo/ports/port-layouts-defaults.js +++ b/demo/ports/port-layouts-defaults.js @@ -2,7 +2,7 @@ $('

').text('Default settings').appendTo('body'); var graph1 = createPaper().model; $('