Skip to content

Commit

Permalink
style: lint JS (#885)
Browse files Browse the repository at this point in the history
* style: reconfigure linting

* style: fix linting errors

* style: prefer const over let and let over var

* style: eslint --fix

* style: fix linting errors

Co-authored-by: Vis Bot <[email protected]>
  • Loading branch information
Thomaash and vis-bot authored Jul 22, 2020
1 parent b1f636c commit d7babcd
Show file tree
Hide file tree
Showing 76 changed files with 1,712 additions and 1,653 deletions.
25 changes: 5 additions & 20 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,23 +130,14 @@ jobs:
paths:
- "repo/examples"

lint_js:
lint:
executor: node

steps:
- attach_workspace:
at: ..

- run: npm run lint:js

lint_ts:
executor: node

steps:
- attach_workspace:
at: ..

- run: npm run lint:ts
- run: npm run lint

test_unit:
executor: node
Expand Down Expand Up @@ -234,11 +225,7 @@ workflows:
- prepare
- build

# - lint_js:
# requires:
# - prepare

- lint_ts:
- lint:
requires:
- prepare

Expand All @@ -259,10 +246,9 @@ workflows:

- gh_pages:
requires:
# - lint_js
- build
- examples
- lint_ts
- lint
- prepare
- test_e2e_functional
- test_e2e_visual
Expand All @@ -274,11 +260,10 @@ workflows:

- release:
requires:
# - lint_js
- build
- examples
- gh_pages
- lint_ts
- lint
- prepare
- test_e2e_functional
- test_e2e_visual
Expand Down
18 changes: 15 additions & 3 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
*.min.js
*.min.ts
dist/**/*
/cypress/fixtures/**/*.js
/cypress/fixtures/**/*.js.map
/cypress/integration/**/*.js
/cypress/integration/**/*.js.map
/cypress/pages/**/*.js
/cypress/pages/**/*.js.map
/cypress/screenshots/
/cypress/snapshots/
/cypress/support/**/*.js
/cypress/support/**/*.js.map
/cypress/videos/
/examples/examples.css
/examples/index.html
/examples/static/
/examples/thumbnails/
22 changes: 13 additions & 9 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
sourceType: "module",
ecmaVersion: 2019,
project: 'tsconfig.json',
ecmaVersion: 2020,
project: 'tsconfig.lint.json',
extraFileExtensions: [".json"],
},

plugins: ["prettier", "@typescript-eslint", "cypress"],
Expand All @@ -22,12 +23,12 @@ module.exports = {
rules: {
'prettier/prettier': ['off'],

complexity: [2, 55],
"max-statements": [2, 115],
"no-unreachable": 1,
"no-useless-escape": 0,
complexity: ['error', 55],
"max-statements": ['error', 115],
"no-unreachable": 'warn',
"no-useless-escape": 'off',

"no-console": 0,
"no-console": 'off',
// To flag presence of console.log without breaking linting:
//"no-console": ["warn", { allow: ["warn", "error"] }],

Expand All @@ -39,13 +40,16 @@ module.exports = {
ArrowFunctionExpression: false
}
}],
"valid-jsdoc": [2, {
"valid-jsdoc": ['error', {
requireReturnDescription: false,
requireReturn: false,
requireParamDescription: false,
requireReturnType: true
}],
"guard-for-in": 1,
"guard-for-in": 'warn',

"no-var": "error",
"prefer-const": "error",
},
overrides: [
{
Expand Down
5 changes: 5 additions & 0 deletions examples/network/datasources/WorldCup2014.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// These variables will be injected into a page that will use them.
/* eslint no-unused-vars: "off" */
// Const won't work here, only var.
/* eslint no-var: "off" */

var nodes = [
{id: 1, label: 'Abdelmoumene Djabou', title: 'Country: ' + 'Algeria' + '<br>' + 'Team: ' + 'Club Africain', value: 22, group: 24, x: -1392.5499, y: 1124.1614},
{id: 2, label: 'Abel Aguilar', title: 'Country: ' + 'Colombia' + '<br>' + 'Team: ' + 'Toulouse', value: 24, group: 11, x: -660.82574, y: 1009.18976},
Expand Down
7 changes: 5 additions & 2 deletions examples/network/datasources/largeHierarchicalDataset.js

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions examples/network/exampleApplications/disassemblerExample.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
var options = {
// These variables will be injected into a page that will use them.
/* eslint no-unused-vars: "off" */

const options = {
manipulation: false,
height: '90%',
layout: {
Expand All @@ -14,7 +17,7 @@ var options = {
}
};

var nodes = [
const nodes = [
{'id': 'cfg_0x00405a2e', 'size': 150, 'label': "0x00405a2e:\nmov DWORD PTR ss:[esp + 0x000000b0], 0x00000002\nmov DWORD PTR ss:[ebp + 0x00], esi\ntest bl, 0x02\nje 0x00405a49<<Insn>>\n", 'color': "#FFCFCF", 'shape': 'box', 'font': {'face': 'monospace', 'align': 'left'}},
{'id': 'cfg_0x00405a49', 'size': 150, 'label': "0x00405a49:\ntest bl, 0x01\nje 0x00405a62<<Insn>>\n", 'color': "#FFCFCF", 'shape': 'box', 'font': {'face': 'monospace', 'align': 'left'}},
{'id': 'cfg_0x00405a55', 'size': 150, 'label': "0x00405a55:\nmov ecx, DWORD PTR ss:[esp + 0x1c]\npush ecx\ncall 0x004095c6<<Func>>\n", 'color': "#FFCFCF", 'shape': 'box', 'font': {'face': 'monospace', 'align': 'left'}},
Expand All @@ -35,7 +38,7 @@ var nodes = [
//
// The edges with these id's will not load into the Network instance.
//
var edges = [
const edges = [
{'from': "cfg_0x00405a2e", 'to': "cfg_0x00405a39", 'arrows': 'to', 'physics': false, 'smooth': {'type': 'cubicBezier'}},
{'from': "cfg_0x00405a2e", 'to': "cfg_0x00405a49", 'arrows': 'to', 'physics': false, 'smooth': {'type': 'cubicBezier'}},
{'from': "cfg_0x00405a49", 'to': "cfg_0x00405a4e", 'arrows': 'to', 'physics': false, 'smooth': {'type': 'cubicBezier'}},
Expand Down
69 changes: 38 additions & 31 deletions examples/network/exampleUtil.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
// These globals will be injected into a page that will use them.
/* eslint no-unused-vars: "off" */

// This is quite old and I don't want to waste too much time here. We probably
// should stop using this altogether as the examples should be easy and
// straightforward to understand and this only obscures it.
/* eslint require-jsdoc: "off" */

/* global Alea:false seededRandom:true */

/**
* Created by Alex on 5/20/2015.
*
Expand All @@ -6,7 +16,7 @@
*/

function loadJSON(path, success, error) {
var xhr = new XMLHttpRequest();
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
Expand All @@ -23,12 +33,12 @@ function loadJSON(path, success, error) {


function getScaleFreeNetwork(nodeCount) {
var nodes = [];
var edges = [];
var connectionCount = [];
const nodes = [];
const edges = [];
const connectionCount = [];

// randomly create some nodes and edges
for (var i = 0; i < nodeCount; i++) {
for (let i = 0; i < nodeCount; i++) {
nodes.push({
id: i,
label: String(i)
Expand All @@ -38,8 +48,8 @@ function getScaleFreeNetwork(nodeCount) {

// create edges in a scale-free-network way
if (i == 1) {
var from = i;
var to = 0;
const from = i;
const to = 0;
edges.push({
from: from,
to: to
Expand All @@ -48,18 +58,18 @@ function getScaleFreeNetwork(nodeCount) {
connectionCount[to]++;
}
else if (i > 1) {
var conn = edges.length * 2;
var rand = Math.floor(seededRandom() * conn);
var cum = 0;
var j = 0;
const conn = edges.length * 2;
const rand = Math.floor(seededRandom() * conn);
let cum = 0;
let j = 0;
while (j < connectionCount.length && cum < rand) {
cum += connectionCount[j];
j++;
}


var from = i;
var to = j;
const from = i;
const to = j;
edges.push({
from: from,
to: to
Expand All @@ -72,20 +82,17 @@ function getScaleFreeNetwork(nodeCount) {
return {nodes:nodes, edges:edges};
}

var seededRandom = Alea('SEED')
seededRandom = Alea('SEED')

function getScaleFreeNetworkSeeded(nodeCount, seed) {
if (seed) {
randomSeed = Number(seed);
}
var nodes = [];
var edges = [];
var connectionCount = [];
var edgesId = 0;
function getScaleFreeNetworkSeeded(nodeCount) {
const nodes = [];
const edges = [];
const connectionCount = [];
let edgesId = 0;


// randomly create some nodes and edges
for (var i = 0; i < nodeCount; i++) {
for (let i = 0; i < nodeCount; i++) {
nodes.push({
id: i,
label: String(i)
Expand All @@ -95,8 +102,8 @@ function getScaleFreeNetworkSeeded(nodeCount, seed) {

// create edges in a scale-free-network way
if (i == 1) {
var from = i;
var to = 0;
const from = i;
const to = 0;
edges.push({
id: edgesId++,
from: from,
Expand All @@ -106,18 +113,18 @@ function getScaleFreeNetworkSeeded(nodeCount, seed) {
connectionCount[to]++;
}
else if (i > 1) {
var conn = edges.length * 2;
var rand = Math.floor(seededRandom() * conn);
var cum = 0;
var j = 0;
const conn = edges.length * 2;
const rand = Math.floor(seededRandom() * conn);
let cum = 0;
let j = 0;
while (j < connectionCount.length && cum < rand) {
cum += connectionCount[j];
j++;
}


var from = i;
var to = j;
const from = i;
const to = j;
edges.push({
id: edgesId++,
from: from,
Expand Down
20 changes: 10 additions & 10 deletions lib/DOMutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
*/
export function prepareElements (JSONcontainer) {
// cleanup the redundant svgElements;
for (var elementType in JSONcontainer) {
if (JSONcontainer.hasOwnProperty(elementType)) {
for (const elementType in JSONcontainer) {
if (Object.prototype.hasOwnProperty.call(JSONcontainer, elementType)) {
JSONcontainer[elementType].redundant = JSONcontainer[elementType].used;
JSONcontainer[elementType].used = [];
}
Expand All @@ -24,10 +24,10 @@ export function prepareElements (JSONcontainer) {
*/
export function cleanupElements (JSONcontainer) {
// cleanup the redundant svgElements;
for (var elementType in JSONcontainer) {
if (JSONcontainer.hasOwnProperty(elementType)) {
for (const elementType in JSONcontainer) {
if (Object.prototype.hasOwnProperty.call(JSONcontainer, elementType)) {
if (JSONcontainer[elementType].redundant) {
for (var i = 0; i < JSONcontainer[elementType].redundant.length; i++) {
for (let i = 0; i < JSONcontainer[elementType].redundant.length; i++) {
JSONcontainer[elementType].redundant[i].parentNode.removeChild(JSONcontainer[elementType].redundant[i]);
}
JSONcontainer[elementType].redundant = [];
Expand Down Expand Up @@ -57,9 +57,9 @@ export function resetElements (JSONcontainer) {
* @private
*/
export function getSVGElement (elementType, JSONcontainer, svgContainer) {
var element;
let element;
// allocate SVG element, if it doesnt yet exist, create one.
if (JSONcontainer.hasOwnProperty(elementType)) { // this element has been created before
if (Object.prototype.hasOwnProperty.call(JSONcontainer, elementType)) { // this element has been created before
// check if there is an redundant element
if (JSONcontainer[elementType].redundant.length > 0) {
element = JSONcontainer[elementType].redundant[0];
Expand Down Expand Up @@ -93,9 +93,9 @@ export function getSVGElement (elementType, JSONcontainer, svgContainer) {
* @returns {*}
*/
export function getDOMElement (elementType, JSONcontainer, DOMContainer, insertBefore) {
var element;
let element;
// allocate DOM element, if it doesnt yet exist, create one.
if (JSONcontainer.hasOwnProperty(elementType)) { // this element has been created before
if (Object.prototype.hasOwnProperty.call(JSONcontainer, elementType)) { // this element has been created before
// check if there is an redundant element
if (JSONcontainer[elementType].redundant.length > 0) {
element = JSONcontainer[elementType].redundant[0];
Expand Down Expand Up @@ -144,7 +144,7 @@ export function getDOMElement (elementType, JSONcontainer, DOMContainer, insertB
* @returns {vis.PointItem}
*/
export function drawPoint (x, y, groupTemplate, JSONcontainer, svgContainer, labelObj) {
var point;
let point;
if (groupTemplate.style == 'circle') {
point = getSVGElement('circle', JSONcontainer, svgContainer);
point.setAttributeNS(null, "cx", x);
Expand Down
2 changes: 1 addition & 1 deletion lib/hammerUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const offRelease = offTouch;
* @return {Hammer.Pinch} returns the pinchRecognizer
*/
export function disablePreventDefaultVertically (pinchRecognizer) {
var TOUCH_ACTION_PAN_Y = 'pan-y';
const TOUCH_ACTION_PAN_Y = 'pan-y';

pinchRecognizer.getTouchAction = function() {
// default method returns [TOUCH_ACTION_NONE]
Expand Down
2 changes: 1 addition & 1 deletion lib/module/hammer.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function hammerMock() {


if (typeof window !== 'undefined') {
var Hammer = window['Hammer'] || require('@egjs/hammerjs');
const Hammer = window['Hammer'] || require('@egjs/hammerjs');
module.exports = Hammer;
}
else {
Expand Down
Loading

0 comments on commit d7babcd

Please sign in to comment.