Skip to content

Commit

Permalink
Added more strict js linting
Browse files Browse the repository at this point in the history
  • Loading branch information
dwitvliet committed Jun 3, 2020
1 parent b8ad221 commit 3ff6965
Show file tree
Hide file tree
Showing 30 changed files with 339 additions and 273 deletions.
79 changes: 75 additions & 4 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,83 @@ module.exports = {
},
extends: 'eslint:recommended',
parserOptions: {
ecmaVersion: 8
ecmaVersion: 8,
ecmaFeatures: {
impliedScrict: true
}
},
rules: {
semi: ['error', 'always'], // Always have semi-colons.
'no-console': 'error', // Don't allow console.log().
'no-var': 'error', // Use let or const.
// Potential errors.
'semi': 'error',
'curly': 'error',
'no-else-return': 'error',
'no-eq-null': 'error',
'no-eval': 'error',
'no-implied-eval': 'error',
'no-labels': 'error',
'no-console': 'error',
'no-var': 'error',
'no-warning-comments': 'warn',
'max-depth': [
'error',
5
],
'no-mixed-operators': [
'error',
{'groups': [['&&', '||']]}
],
'no-unneeded-ternary': 'error',
'no-prototype-builtins': 'off', // Allow using hasOwnProperty.
'max-len': [
'warn',
100
],
// Styling.
'yoda': 'error',
'no-multi-spaces': 'error',
'camelcase': 'warn',
'quotes': [
'error',
'single'
],
'brace-style': [
'error',
'1tbs',
{'allowSingleLine': true}
],
'func-names': [
'error',
'never'
],
'indent': [
'error',
2,
{'SwitchCase': 1}
],
'operator-assignment': 'error',
'no-tabs': 'error',
'comma-spacing': 'error',
'block-spacing': 'error',
'space-before-blocks': 'error',
'func-call-spacing': 'error',
'key-spacing': 'error',
'keyword-spacing': 'error',
'no-whitespace-before-property': 'error',
'space-infix-ops': 'error',
'semi-spacing': 'error',
'space-unary-ops': 'error',
'space-before-function-paren': ['error', {
'anonymous': 'never',
'named': 'never',
'asyncArrow': 'always',
}],
'computed-property-spacing': 'error',
'space-in-parens': 'error',
/*'array-bracket-spacing': [
'error',
'never'
],
'object-curly-spacing': 'error',*/

}
};
14 changes: 8 additions & 6 deletions src/client/js/cell-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,21 +143,22 @@ class CellInfo {
this.isClass[cell] = cell == cls;

// Set cell classes.
cellClass[cls] = null;
cellClass[cell] = cls;
classMembers[cell] = [];

if (classMembers[cls] == null) {
if (classMembers[cls] === undefined) {
classMembers[cls] = [];
}

classMembers[cls].push(cell);
}

// when this function is called:
//- all body wall muscle class members annotated at zhen lab will have their class become the generic 'body wall muscles'
// class instead of BWM01, BWM02, etc. to make it compatible for comparison with the John White dataset
// all other legacy classes will have no class members to make it compatible for comparison
//- all body wall muscle class members annotated at zhen lab will have their
// class become the generic 'body wall muscles' class instead of BWM01, BWM02,
// etc. to make it compatible for comparison with the John White dataset
// all other legacy classes will have no class members to make it compatible
// for comparison
setToLegacy() {
Object.entries(this.cellClassLegacy).forEach(entry => {
let [cls, legacyCellClass] = entry;
Expand All @@ -173,7 +174,8 @@ class CellInfo {
}

// the inverse function of setToLegacy
// - zhen lab specific body wall muscle cells will revert to their correct class
// - zhen lab specific body wall muscle cells will revert to their correct
// class
// - legacy classes will have their class members registered again
setToNonLegacy() {
Object.entries(this.cellClassNonLegacy).forEach(entry => {
Expand Down
6 changes: 3 additions & 3 deletions src/client/js/controller/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ class Controller extends EventEmitter {
bindLegendEvents({ model, view });
}

setState(state, fromUrl=false) {
setState(state, fromUrl = false) {
let { model, view } = this;

model.clear();
Expand All @@ -429,8 +429,8 @@ class Controller extends EventEmitter {
let database = state['database'] || 'head';
let allDatasets = DataService.getDatasetList(database);
let datasets = intersection(allDatasets, state['datasets'] || []);
if (datasets.length == 0) {
datasets = database == 'head' ? ['witvliet_2020_7', 'witvliet_2020_8'] : allDatasets;
if (datasets.length === 0) {
datasets = (database == 'head') ? ['witvliet_2020_7', 'witvliet_2020_8'] : allDatasets;
}
let nodeColor = state['nodeColor'] || 'type';
let layout = state['layout'] || 'concentric';
Expand Down
4 changes: 2 additions & 2 deletions src/client/js/controller/tour.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ class Tour {
this.view.help.hideTour();
this.view.graph.one('layoutstop', () => d.resolve());

if (step.state != null) {
if (step.state !== undefined) {
for (let key in step.state) {
this.state[key] = step.state[key];
}

if (step.state.coordinates != null) {
if (step.state.coordinates !== undefined) {
this.state.coordinates = this.view.graph.scaleCoordinatesToViewport(
deepCopy(this.state.coordinates)
);
Expand Down
6 changes: 3 additions & 3 deletions src/client/js/data-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ class DataService {
)[0];
}

getDatasetById(datasetId){
getDatasetById(datasetId) {
this.checkLoaded();
return this.datasets.find( d => d.id === datasetId );
return this.datasets.find(d => d.id === datasetId);
}

setDatasetType(databaseType) {
Expand Down Expand Up @@ -194,7 +194,7 @@ class DataService {
ANALDEP: 'anal dep'
};

if (namesWithSpaces[name] != null) {
if (namesWithSpaces[name] !== undefined) {
return namesWithSpaces[name];
}

Expand Down
6 changes: 3 additions & 3 deletions src/client/js/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ $(document).ready(() => {
view.searchbar.focus();
})
.catch(e => {
let errorMsg =
'Cannot load data!\nPlease contact us if the problem persists!';
alert(errorMsg);
if (!DEBUG) {
alert('Cannot load data!\nPlease contact us if the problem persists!');
}
throw e;
});
});
4 changes: 2 additions & 2 deletions src/client/js/model/cytoscape-adaptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ ModelPrototype.makeCytoscapeEdge = function(

// only add the first annotation type w.r.t annnotation order
//that is found in this connections annotations
if (showAnnotations && this.database == 'head'){
if (showAnnotations && this.database == 'head') {
let edgeIsAnnotated = false;
for ( let annotation of ANNOTATION_ORDER ){
for (let annotation of ANNOTATION_ORDER) {
if (annotations.includes(annotation)) {
classes.push(ANNOTATION_DISPLAY_LABEL_MAP[annotation]);
edgeIsAnnotated = true;
Expand Down
20 changes: 10 additions & 10 deletions src/client/js/model/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ModelPrototype.createGroup = function({
return i + '';
};

let groupId = id == null ? findValidGroupId() : id;
let groupId = (id === null || id === undefined) ? findValidGroupId() : id;

this.groups[groupId] = {
id: groupId,
Expand Down Expand Up @@ -91,15 +91,15 @@ ModelPrototype.getGroups = function() {
};

ModelPrototype.getGroupById = function(groupId) {
if (this.groups[groupId] == null) {
if (!this.groups.hasOwnProperty(groupId)) {
throw new Error(`${groupId} is not a group`);
}

return this.groups[groupId];
};

ModelPrototype.getGroupByMemberId = function(groupMemberId) {
if (this.parent[groupMemberId] == null) {
if (!this.parent.hasOwnProperty(groupMemberId)) {
throw new Error(`${groupMemberId} does not belong to a group`);
}

Expand Down Expand Up @@ -141,11 +141,11 @@ ModelPrototype.positionGroupMembers = function(groupId) {
let groupMemberXPositions = [];
let groupMemberYPositions = [];

let groupMembersWithoutPositions = groupMembers.filter( m => {
let groupMembersWithoutPositions = groupMembers.filter(m => {
let hasPosition = true;
try {
this.getPosition(m);
} catch (e){
} catch (e) {
hasPosition = false;
}
return !hasPosition;
Expand All @@ -164,7 +164,7 @@ ModelPrototype.positionGroupMembers = function(groupId) {

this.setPositions(gridPositions);

groupMembers.forEach( m => {
groupMembers.forEach(m => {
let { x, y } = this.getPosition(m);
groupMemberXPositions.push(x);
groupMemberYPositions.push(y);
Expand All @@ -184,7 +184,7 @@ ModelPrototype.positionGroupMembers = function(groupId) {
};

ModelPrototype.group = function(nodes) {
let groupId = null;
let groupId;
let toGroup = [];

nodes.forEach(node => {
Expand All @@ -202,7 +202,7 @@ ModelPrototype.group = function(nodes) {
}

// Create group if no group is selected.
if (groupId == null) {
if (groupId === undefined) {
groupId = this.createGroup();
let meanPositionOfToGroup = meanPosition(
toGroup.map(id => this.getPosition(id))
Expand All @@ -223,12 +223,12 @@ ModelPrototype.group = function(nodes) {
};

ModelPrototype.groupSelected = function() {
let groupId = null;
let groupId;
if (this.canBeGrouped(this.getRawSelected())) {
groupId = this.group(this.getRawSelected());
}

if (groupId != null) {
if (groupId !== undefined) {
this.setSelected([groupId]);
}

Expand Down
20 changes: 4 additions & 16 deletions src/client/js/model/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
const modelToCytoscape = require('./cytoscape-adaptor');

const EventEmitter = require('../EventEmitter');

const services = require('../services');
const DataService = require('../data-service');

const { positionModule } = require('./position');
const modelToCytoscape = require('./cytoscape-adaptor');
const summary = require('./summary');
const setters = require('./setters');
const { positionModule } = require('./position');
const splitJoin = require('./split-join');
const input = require('./input');
const hide = require('./hidden');
Expand All @@ -19,17 +17,6 @@ class Model extends EventEmitter {
constructor(cy) {
super();
this.cy = cy;
//this.database; //eventually this and all following will be local variables.
//this.datasets;
//this.nodeColor;
//this.layout;
//this.showLinked;
//this.showIndividual;
//this.showEdgeLabel;
//this.showPostemb;
//this.thresholdChemical;
//this.thresholdElectrical;
//this.showAnnotations;

this.legendItems = [];

Expand All @@ -41,7 +28,7 @@ class Model extends EventEmitter {
this.joined = [];

this.groups = {};
this.parent = {}; // should only be used by the groups module, every other module should not access this directly
this.parent = {}; // should only be used by the groups module, no other module should not access this directly

this.positions = {};
this.lockedPositions = [];
Expand All @@ -66,6 +53,7 @@ class Model extends EventEmitter {
});
}


updateNetwork(updateType = '', runLayout = true) {
this.emit('networkUpdate');

Expand Down
14 changes: 7 additions & 7 deletions src/client/js/model/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ ModelPrototype.replaceClassMembersWithClassInInput = function(
});
};

ModelPrototype.getValidInput = function(rawInput){
ModelPrototype.getValidInput = function(rawInput) {
return unique(rawInput).filter((nodeId, i, arr) => {
let cellClass = DataService.cellClass(nodeId);
let containsCellClass = arr.includes(cellClass);
Expand All @@ -76,14 +76,14 @@ ModelPrototype.getValidInput = function(rawInput){

};

ModelPrototype.setInputFromUrlState = function(rawInput){
ModelPrototype.setInputFromUrlState = function(rawInput) {

let validInput = this.getValidInput(rawInput);
let previousValidInput = this.getValidInput(this.input);
let newValidInput = difference(validInput, previousValidInput);

// Emit notification if input contains hidden post-embryonic nodes or nodes only present in
// other datasets.
// Emit notification if input contains hidden post-embryonic nodes or nodes
// only present in other datasets.
if (!this.showPostemb) {
let newPostEmbInput = newValidInput
.filter(nodeId => !DataService.isEmb(nodeId))
Expand Down Expand Up @@ -181,9 +181,9 @@ ModelPrototype.setInput = function(rawInput) {
let validInput = this.getValidInput(rawInput);

let groupIds = validInput
.filter(nodeId => this.isGroupMember(nodeId))
.map(nodeId => this.getGroupByMemberId(nodeId))
.map(group => group.id);
.filter(nodeId => this.isGroupMember(nodeId))
.map(nodeId => this.getGroupByMemberId(nodeId))
.map(group => group.id);

this.unhide(validInput.concat(groupIds));

Expand Down
2 changes: 1 addition & 1 deletion src/client/js/model/setters.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ ModelPrototype.setShowEdgeLabel = function(checked) {
this.emit('showEdgeLabelChanged', checked);
};

ModelPrototype.setShowAnnotations = function(checked){
ModelPrototype.setShowAnnotations = function(checked) {
this.showAnnotations = checked;
this.emit('showAnnotationsChanged', checked);
};
Expand Down
Loading

0 comments on commit 3ff6965

Please sign in to comment.