Skip to content

Commit

Permalink
eslint: add and update eslint configs (#1568)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesgeorgewilliams authored Nov 9, 2021
1 parent 7dee5dc commit d75de7d
Show file tree
Hide file tree
Showing 29 changed files with 231 additions and 130 deletions.
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
**/node_modules
/scripts
/dist
/build
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ install: npm install

before_script:
- grunt install

script:
- npm run test
- npm run lint
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,6 @@ To run only the client-side tests:
grunt test:client
```

To run code style checks:
```
grunt test:code-style
```

### Lint

Expand Down
49 changes: 49 additions & 0 deletions demo/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -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']
}
}]
};

4 changes: 2 additions & 2 deletions demo/chess/src/garbochess.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
14 changes: 7 additions & 7 deletions demo/elk/src/app.js
Original file line number Diff line number Diff line change
@@ -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 = () => {
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -167,7 +167,7 @@ const addZoomListeners = paper => {
zoomLevel = Math.max(0.2, zoomLevel - 0.2);
zoom(zoomLevel);
});
}
};

const placementsOptions = {
H_RIGHT: 'H_RIGHT',
Expand All @@ -176,7 +176,7 @@ const placementsOptions = {
V_TOP: 'V_TOP',
V_BOTTOM: 'V_BOTTOM',
V_CENTER: 'V_CENTER',
}
};

const getLabelPlacement = label => {
const placement = {};
Expand All @@ -203,4 +203,4 @@ const getLabelPlacement = label => {
}

return placement;
}
};
2 changes: 1 addition & 1 deletion demo/expand/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ var isCollapsed = function(cell, portId) {

var runTests = function() {

/////////////
/////////////
a.hide();
console.assert(aa.portProp('in1', 'collapsed'), 'aa in1 is collapsed');

Expand Down
2 changes: 1 addition & 1 deletion demo/interpreter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions demo/links/src/custom-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -24,19 +24,19 @@ 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);
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();
Expand All @@ -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
Expand Down
20 changes: 10 additions & 10 deletions demo/org/src/org.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
});
Expand Down Expand Up @@ -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 }]);
14 changes: 7 additions & 7 deletions demo/ports/port-layouts-defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
$('<h2/>').text('Default settings').appendTo('body');
var graph1 = createPaper().model;
$('<button/>').text('add port').appendTo('body').on('click', function() {
g1.addPort({ attrs: { circle: { magnet: true, stroke: '#31d0c6', 'stroke-width': 2, fill: '#ffffff' } } });
g1.addPort({ attrs: { circle: { magnet: true, stroke: '#31d0c6', 'stroke-width': 2, fill: '#ffffff' }}});
});
$('<button/>').text('remove port').appendTo('body').on('click', function() {
g1.removePort(g1.getPorts()[0]);
Expand All @@ -15,9 +15,9 @@ var g1 = new joint.shapes.basic.Rect({
}
});
graph1.addCell(g1);
g1.addPort({ attrs: { circle: { magnet: true, stroke: '#31d0c6', 'stroke-width': 2, fill: '#ffffff' } } });
g1.addPort({ attrs: { circle: { magnet: true, stroke: '#31d0c6', 'stroke-width': 2, fill: '#ffffff' } } });
g1.addPort({ attrs: { circle: { magnet: true, stroke: '#31d0c6', 'stroke-width': 2, fill: '#ffffff' } } });
g1.addPort({ attrs: { circle: { magnet: true, stroke: '#31d0c6', 'stroke-width': 2, fill: '#ffffff' }}});
g1.addPort({ attrs: { circle: { magnet: true, stroke: '#31d0c6', 'stroke-width': 2, fill: '#ffffff' }}});
g1.addPort({ attrs: { circle: { magnet: true, stroke: '#31d0c6', 'stroke-width': 2, fill: '#ffffff' }}});
new joint.shapes.basic.Circle({
position: { x: 20, y: 150 },
id: 'target',
Expand All @@ -27,6 +27,6 @@ new joint.shapes.basic.Circle({
}
}).addTo(graph1);

new joint.dia.Link({ source: { id: 'target' }, target: { id: g1.id, port: g1.getPorts()[0].id } }).addTo(graph1);
new joint.dia.Link({ source: { id: 'target' }, target: { id: g1.id, port: g1.getPorts()[1].id } }).addTo(graph1);
new joint.dia.Link({ source: { id: 'target' }, target: { id: g1.id, port: g1.getPorts()[2].id } }).addTo(graph1);
new joint.dia.Link({ source: { id: 'target' }, target: { id: g1.id, port: g1.getPorts()[0].id }}).addTo(graph1);
new joint.dia.Link({ source: { id: 'target' }, target: { id: g1.id, port: g1.getPorts()[1].id }}).addTo(graph1);
new joint.dia.Link({ source: { id: 'target' }, target: { id: g1.id, port: g1.getPorts()[2].id }}).addTo(graph1);
6 changes: 3 additions & 3 deletions demo/vectorizer/vectorizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ svg.append(curvePath);
var text = V('text', { x: 250, y: 30, fill: 'black' });

text.text('This is a rich text.\nThis text goes to multiple lines.', { lineHeight: 'auto', annotations: [
{ start: 5, end: 10, attrs: { fill: 'red', 'font-size': 30, rotate: '20' } },
{ start: 7, end: 15, attrs: { fill: 'blue' } },
{ start: 20, end: 30, attrs: { fill: 'blue', 'class': 'text-link', style: 'text-decoration: underline' } }
{ start: 5, end: 10, attrs: { fill: 'red', 'font-size': 30, rotate: '20' }},
{ start: 7, end: 15, attrs: { fill: 'blue' }},
{ start: 20, end: 30, attrs: { fill: 'blue', 'class': 'text-link', style: 'text-decoration: underline' }}
], includeAnnotationIndices: true });

svg.append(text);
26 changes: 13 additions & 13 deletions demo/vuejs/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ var TaskComponent = {

var taskElement = Vue.ref(null);
var taskElementPosition = Vue.shallowRef({ x: 0, y: 0 });
var taskElementStyle = Vue.computed(function () {
var taskElementStyle = Vue.computed(function() {
return {
top: (taskElementPosition.value.y || 0) + 'px',
left: (taskElementPosition.value.x || 0) + 'px',
transform: 'scale(' + props.scale + ')',
transformOrigin: '0 0',
}
};
});

// Update task element position to match the graph Element View
Expand All @@ -80,7 +80,7 @@ var TaskComponent = {
}
}

Vue.onMounted(function () {
Vue.onMounted(function() {
// Resize the graph Element to match the task element ...
graph.getCell(props.id).resize(taskElement.value.offsetWidth, taskElement.value.offsetHeight);
// ... and update task element position afterwards
Expand All @@ -89,13 +89,13 @@ var TaskComponent = {

// React to changes of position/scale
Vue.watch(
function () {
function() {
return {
position: props.position,
scale: props.scale,
};
},
updateTaskElementPosition,
updateTaskElementPosition
);

return {
Expand Down Expand Up @@ -133,7 +133,7 @@ var JointPaperComponent = {
Vue.provide('paperContext', paperContext);

// Create JointJS Paper (after the paper element is available)
Vue.onMounted(function () {
Vue.onMounted(function() {
paperContext.paper = new joint.dia.Paper({
el: paperElement.value,
model: graph,
Expand All @@ -151,13 +151,13 @@ var JointPaperComponent = {
* too many updates and cause performance issues.
*/
var htmlElements = Vue.shallowRef(
graph.getElements().map(function (cell) {
return { id: cell.get('id'), position: cell.get('position')};
graph.getElements().map(function(cell) {
return { id: cell.get('id'), position: cell.get('position') };
})
);

// Track positions of graph elements
graph.on('change:position', function (cell) {
graph.on('change:position', function(cell) {
for (var i = 0; i < htmlElements.value.length; i += 1) {
if (htmlElements.value[i].id === cell.get('id')) {
htmlElements.value[i].position = cell.get('position');
Expand All @@ -169,8 +169,8 @@ var JointPaperComponent = {

// React to changes of scale
Vue.watch(
function () { return scale.value; },
function (value) {
function() { return scale.value; },
function(value) {
var size = paperContext.paper.getComputedSize();
paperContext.paper.translate(0, 0);
paperContext.paper.scale(value, value, size.width / 2, size.height / 2);
Expand Down Expand Up @@ -224,8 +224,8 @@ var app = Vue.createApp({
graph.getCell('taskB').position(297, 100);
graph.getCell('taskC').position(576, 100);

Object.entries(DATA.tasks).forEach(function ([taskId, task]) {
Object.entries(task).forEach(function ([key, value]) {
Object.entries(DATA.tasks).forEach(function([taskId, task]) {
Object.entries(task).forEach(function([key, value]) {
handleTaskChange(taskId, key, value);
});
});
Expand Down
Loading

0 comments on commit d75de7d

Please sign in to comment.