From 8fcbb0e5a22274360279ee66c531c18d72ea5507 Mon Sep 17 00:00:00 2001 From: Daniel Caldas <11733994+danielcaldas@users.noreply.github.com> Date: Mon, 4 Mar 2019 16:38:43 +0100 Subject: [PATCH] Refactor/run lint on sandbox (#179) * Minor typos in docs * Configure lint to run against sandbox --- .eslintignore | 3 +- package.json | 3 +- sandbox/Sandbox.jsx | 66 ++-- sandbox/data/custom-node/CustomNode.jsx | 20 +- .../data/custom-node/custom-node.config.js | 34 +- sandbox/data/marvel/marvel.config.js | 34 +- sandbox/data/marvel/marvel.data.js | 312 +++++++++--------- sandbox/data/small/small.config.js | 28 +- sandbox/index.jsx | 10 +- src/components/graph/graph.config.js | 2 +- src/components/graph/graph.renderer.jsx | 8 +- 11 files changed, 262 insertions(+), 258 deletions(-) diff --git a/.eslintignore b/.eslintignore index 55bef869b..7fa67c699 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1 +1,2 @@ -/cypress/** \ No newline at end of file +/cypress/** +/sandbox/rd3g* \ No newline at end of file diff --git a/package.json b/package.json index b0d45fccb..735e2a669 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,8 @@ "functional:local": "export CYPRESS_SANDBOX_URL=http://localhost:3002 && cypress open", "functional:remote": "export CYPRESS_SANDBOX_URL=https://danielcaldas.github.io/react-d3-graph/sandbox/index.html && cypress open", "functional": "export CYPRESS_SANDBOX_URL=http://127.0.0.1:8888 && cypress run", - "lint:src": "node_modules/eslint/bin/eslint.js --config=.eslintrc.js \"src/**/*.js*\"", + "lint:fix": "node_modules/eslint/bin/eslint.js --config=.eslintrc.js --fix \"src/**/*.js*\" \"sandbox/**/*.js*\"", + "lint:src": "node_modules/eslint/bin/eslint.js --config=.eslintrc.js \"src/**/*.js*\" \"sandbox/**/*.js*\"", "lint:test": "node_modules/eslint/bin/eslint.js --config=.eslintrc.test.config.js \"test/**/*.spec.js\"", "lint": "npm run lint:src && npm run lint:test && npm run docs:lint", "precommit": "lint-staged", diff --git a/sandbox/Sandbox.jsx b/sandbox/Sandbox.jsx index 15438255c..3dda5f1bd 100644 --- a/sandbox/Sandbox.jsx +++ b/sandbox/Sandbox.jsx @@ -1,16 +1,16 @@ /*global console*/ /*eslint require-jsdoc: 0, valid-jsdoc: 0, no-console: 0*/ -import React from 'react'; +import React from "react"; -import Form from 'react-jsonschema-form'; +import Form from "react-jsonschema-form"; -import './styles.css'; +import "./styles.css"; -import defaultConfig from '../src/components/graph/graph.config'; -import { Graph } from '../src'; -import utils from './utils'; -import reactD3GraphUtils from '../src/utils'; -import { JsonTree } from 'react-editable-json-tree'; +import defaultConfig from "../src/components/graph/graph.config"; +import { Graph } from "../src"; +import utils from "./utils"; +import reactD3GraphUtils from "../src/utils"; +import { JsonTree } from "react-editable-json-tree"; const sandboxData = utils.loadDataset(); @@ -28,16 +28,16 @@ export default class Sandbox extends React.Component { const { config: configOverride, data, fullscreen } = sandboxData; const config = Object.assign(defaultConfig, configOverride); - const schemaProps = utils.generateFormSchema(config, '', {}); + const schemaProps = utils.generateFormSchema(config, "", {}); const schema = { - type: 'object', - properties: schemaProps + type: "object", + properties: schemaProps, }; const uiSchema = { - height: { 'ui:readonly': 'true' }, - width: { 'ui:readonly': 'true' } + height: { "ui:readonly": "true" }, + width: { "ui:readonly": "true" }, }; this.uiSchema = uiSchema; @@ -47,11 +47,11 @@ export default class Sandbox extends React.Component { generatedConfig: {}, schema, data, - fullscreen + fullscreen, }; } - onClickGraph = () => console.info(`Clicked the graph`); + onClickGraph = () => console.info("Clicked the graph"); onClickNode = id => { !this.state.config.collapsible && window.alert(`Clicked node ${id}`); @@ -127,7 +127,7 @@ export default class Sandbox extends React.Component { while (this.state.data.nodes[i] && this.state.data.nodes[i].id && nLinks) { this.state.data.links.push({ source: newNode, - target: this.state.data.nodes[i].id + target: this.state.data.nodes[i].id, }); i++; @@ -135,13 +135,13 @@ export default class Sandbox extends React.Component { } this.setState({ - data: this.state.data + data: this.state.data, }); } else { // 1st node const data = { - nodes: [{ id: 'Node 1' }], - links: [] + nodes: [{ id: "Node 1" }], + links: [], }; this.setState({ data }); @@ -161,7 +161,7 @@ export default class Sandbox extends React.Component { this.setState({ data }); } else { - window.alert('No more nodes to remove!'); + window.alert("No more nodes to remove!"); } }; @@ -174,7 +174,7 @@ export default class Sandbox extends React.Component { utils.setValue(config, k, data.formData[k]); // Set new values for schema of jsonform schemaPropsValues[k] = {}; - schemaPropsValues[k]['default'] = data.formData[k]; + schemaPropsValues[k]["default"] = data.formData[k]; } return { config, schemaPropsValues }; @@ -186,7 +186,7 @@ export default class Sandbox extends React.Component { this.state.schema.properties = reactD3GraphUtils.merge(this.state.schema.properties, schemaPropsValues); this.setState({ - config + config, }); }; @@ -201,23 +201,23 @@ export default class Sandbox extends React.Component { onClickSubmit = () => { // Hack for allow submit button to live outside jsonform - document.body.querySelector('.invisible-button').click(); + document.body.querySelector(".invisible-button").click(); }; resetGraphConfig = () => { const generatedConfig = {}; - const schemaProps = utils.generateFormSchema(defaultConfig, '', {}); + const schemaProps = utils.generateFormSchema(defaultConfig, "", {}); const schema = { - type: 'object', - properties: schemaProps + type: "object", + properties: schemaProps, }; this.setState({ config: defaultConfig, generatedConfig, - schema + schema, }); }; @@ -232,7 +232,7 @@ export default class Sandbox extends React.Component { return nodes.map(n => Object.assign({}, n, { x: n.x || Math.floor(Math.random() * 500), - y: n.y || Math.floor(Math.random() * 500) + y: n.y || Math.floor(Math.random() * 500), }) ); }; @@ -250,7 +250,7 @@ export default class Sandbox extends React.Component { */ buildCommonInteractionsPanel = () => { const btnStyle = { - cursor: this.state.config.staticGraph ? 'not-allowed' : 'pointer' + cursor: this.state.config.staticGraph ? "not-allowed" : "pointer", }; const fullscreen = this.state.fullscreen ? ( @@ -309,11 +309,11 @@ export default class Sandbox extends React.Component { const data = { nodes: this.decorateGraphNodesWithInitialPositioning(this.state.data.nodes), links: this.state.data.links, - focusedNodeId: this.state.data.focusedNodeId + focusedNodeId: this.state.data.focusedNodeId, }; const graphProps = { - id: 'graph', + id: "graph", data, config: this.state.config, onClickNode: this.onClickNode, @@ -324,13 +324,13 @@ export default class Sandbox extends React.Component { onMouseOverNode: this.onMouseOverNode, onMouseOutNode: this.onMouseOutNode, onMouseOverLink: this.onMouseOverLink, - onMouseOutLink: this.onMouseOutLink + onMouseOutLink: this.onMouseOutLink, }; if (this.state.fullscreen) { graphProps.config = Object.assign({}, graphProps.config, { height: window.innerHeight, - width: window.innerWidth + width: window.innerWidth, }); return ( diff --git a/sandbox/data/custom-node/CustomNode.jsx b/sandbox/data/custom-node/CustomNode.jsx index 1297c6ec4..047b6bd22 100644 --- a/sandbox/data/custom-node/CustomNode.jsx +++ b/sandbox/data/custom-node/CustomNode.jsx @@ -1,25 +1,27 @@ -import React from 'react'; +/* eslint-disable valid-jsdoc */ +import React from "react"; -import './res/styles/custom-node.css'; +import "./res/styles/custom-node.css"; -const ICON_PATH = './data/custom-node/res/images/'; +const ICON_PATH = "./data/custom-node/res/images/"; const ICON_TYPES = { - MAN: ICON_PATH + 'man.svg', - WOMAN: ICON_PATH + 'girl.svg', - CAR: ICON_PATH + 'car.svg', - BIKE: ICON_PATH + 'bike.svg' + MAN: ICON_PATH + "man.svg", + WOMAN: ICON_PATH + "girl.svg", + CAR: ICON_PATH + "car.svg", + BIKE: ICON_PATH + "bike.svg", }; /** * Component that renders a person's name and gender, along with icons * representing if they have a driver license for bike and / or car. + * @param {Object} props component props to render. */ function CustomNode({ person }) { - const isMale = person.gender === 'male'; + const isMale = person.gender === "male"; return ( -