Skip to content

Commit

Permalink
[eslint] Correct syntax errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita_Ryzhov authored and Nikita_Ryzhov committed Feb 22, 2018
1 parent 6b95f95 commit ed59308
Show file tree
Hide file tree
Showing 29 changed files with 131 additions and 68 deletions.
10 changes: 3 additions & 7 deletions .eslintrc
Expand Up @@ -32,6 +32,7 @@
"no-fallthrough": "off",
"no-mixed-operators": "warn",
"no-multiple-empty-lines": ["error", { "max": 2, "maxEOF": 1 }],
"no-param-reassign": "off",
"no-plusplus": "off",
"no-restricted-syntax": ["error", "LabeledStatement", "WithStatement"],
"no-tabs": "off",
Expand All @@ -47,7 +48,7 @@

"object-curly-newline": "off",
"operator-assignment": ["error", "always"],
"prefer-promise-reject-errors": "off",
"prefer-destructuring": "off",
"prefer-template": "off",
"radix": "off",
"spaced-comment": ["error", "always", { "exceptions": ["*"] }],
Expand All @@ -72,11 +73,6 @@
"jsx-a11y/label-has-for": "off",
"jsx-a11y/iframe-has-title": "off",
"jsx-a11y/click-events-have-key-events": "off",
"jsx-a11y/no-noninteractive-element-interactions": "off",

/* remove below */ // TODO !!!
"prefer-destructuring": "off", // TODO 200 errs ! DO IT
"no-param-reassign": "off", // TODO 281 !!!
"max-len": "off" // TODO many!!!
"jsx-a11y/no-noninteractive-element-interactions": "off"
}
}
3 changes: 2 additions & 1 deletion src/script/chem/.eslintrc
Expand Up @@ -8,6 +8,7 @@
"vars-on-top": 0,
"one-var-declaration-per-line": 0,
"block-scoped-var": 0,
"no-shadow": 0
"no-shadow": 0,
"max-len": 0
}
}
3 changes: 2 additions & 1 deletion src/script/editor/actions/aromatic-fusing.js
Expand Up @@ -62,7 +62,8 @@ export function fromAromaticTemplateOnBond(restruct, template, bid, events, simp

afterMerge = getFragmentWithBondMap(restruct.molecule, frid);

return events.dearomatizeStruct.dispatch(afterMerge.frag).then(res => molfile.parse(res.struct));
return events.dearomatizeStruct.dispatch(afterMerge.frag)
.then(res => molfile.parse(res.struct));
}).then((destruct) => {
destruct.bonds.forEach((bond) => {
if (bond.type === Struct.Bond.PATTERN.TYPE.AROMATIC)
Expand Down
4 changes: 2 additions & 2 deletions src/script/editor/actions/bond.js
Expand Up @@ -25,7 +25,7 @@ import { fromAtomMerge, mergeFragments } from './atom';
import { removeSgroupIfNeeded, removeAtomFromSgroupIfNeeded } from './sgroup';
import { fromFragmentSplit } from './fragment';

export function fromBondAddition(restruct, bond, begin, end, pos, pos2) { // eslint-disable-line max-params, max-statements
export function fromBondAddition(restruct, bond, begin, end, pos, pos2) { // eslint-disable-line
if (end === undefined) {
var atom = atomForNewBond(restruct, begin);
end = atom.atom;
Expand Down Expand Up @@ -61,7 +61,7 @@ export function fromBondAddition(restruct, bond, begin, end, pos, pos2) { // esl

if (!(typeof end === 'number')) {
end.fragment = frid;
// TODO: <op>.data.aid here is a hack, need a better way to access the id of a newly created atom
// TODO: <op>.data.aid here is a hack, need a better way to access the id of a created atom
end = action.addOp(new op.AtomAdd(end, pos).perform(restruct)).data.aid;
if (typeof begin === 'number') {
atomGetSGroups(restruct, begin).forEach((sid) => {
Expand Down
3 changes: 2 additions & 1 deletion src/script/editor/actions/fragment.js
Expand Up @@ -139,7 +139,8 @@ function processAtom(restruct, aid, frid, newfrid) {
* @param frid { number }
* @return { Action }
*/
export function fromFragmentSplit(restruct, frid) { // TODO [RB] the thing is too tricky :) need something else in future
// TODO [RB] the thing is too tricky :) need something else in future
export function fromFragmentSplit(restruct, frid) {
var action = new Action();
var rgid = Struct.RGroup.findRGroupByFragment(restruct.molecule.rgroups, frid);

Expand Down
10 changes: 7 additions & 3 deletions src/script/editor/actions/paste.js
Expand Up @@ -42,15 +42,17 @@ export function fromPaste(restruct, pstruct, point, angle = 0) {
fridMap.set(atom.fragment, action.addOp(new op.FragmentAdd().perform(restruct)).frid);

const tmpAtom = Object.assign(atom.clone(), { fragment: fridMap.get(atom.fragment) });
const operation = new op.AtomAdd(tmpAtom, Vec2.diff(atom.pp, xy0).rotate(angle).add(point)).perform(restruct);
const operation = new op.AtomAdd(tmpAtom, Vec2.diff(atom.pp, xy0).rotate(angle).add(point))
.perform(restruct);
action.addOp(operation);
aidMap.set(aid, operation.data.aid);

pasteItems.atoms.push(operation.data.aid);
});

pstruct.bonds.forEach((bond) => {
const operation = new op.BondAdd(aidMap.get(bond.begin), aidMap.get(bond.end), bond).perform(restruct);
const operation = new op.BondAdd(aidMap.get(bond.begin), aidMap.get(bond.end), bond)
.perform(restruct);
action.addOp(operation);

pasteItems.bonds.push(operation.data.bid);
Expand All @@ -59,7 +61,9 @@ export function fromPaste(restruct, pstruct, point, angle = 0) {
pstruct.sgroups.forEach((sg) => {
const newsgid = restruct.molecule.sgroups.newId();
const sgAtoms = sg.atoms.map(aid => aidMap.get(aid));
const sgAction = fromSgroupAddition(restruct, sg.type, sgAtoms, sg.data, newsgid, sg.pp ? sg.pp.add(offset) : null);
const sgAction = fromSgroupAddition(
restruct, sg.type, sgAtoms, sg.data, newsgid, sg.pp ? sg.pp.add(offset) : null
);
sgAction.operations.reverse().forEach((oper) => {
action.addOp(oper);
});
Expand Down
2 changes: 1 addition & 1 deletion src/script/editor/actions/rotate.js
Expand Up @@ -109,7 +109,7 @@ export function fromFlip(restruct, selection, dir) { // eslint-disable-line max-
return action.perform(restruct);
}

export function fromRotate(restruct, selection, center, angle) { // eslint-disable-line max-statements
export function fromRotate(restruct, selection, center, angle) { // eslint-disable-line
const struct = restruct.molecule;

const action = new Action();
Expand Down
7 changes: 4 additions & 3 deletions src/script/editor/actions/sgroup.js
Expand Up @@ -35,8 +35,9 @@ export function fromSeveralSgroupAddition(restruct, type, atoms, attrs) {
const localAttrs = Object.assign({}, attrs);
localAttrs.fieldValue = fValue;

return acc
.mergeWith(fromSgroupAddition(restruct, type, atoms, localAttrs, restruct.molecule.sgroups.newId()));
return acc.mergeWith(
fromSgroupAddition(restruct, type, atoms, localAttrs, restruct.molecule.sgroups.newId())
);
}, new Action());
}

Expand Down Expand Up @@ -94,7 +95,7 @@ export function fromSgroupDeletion(restruct, id) {
return action;
}

export function fromSgroupAddition(restruct, type, atoms, attrs, sgid, pp) { // eslint-disable-line max-params, max-statements
export function fromSgroupAddition(restruct, type, atoms, attrs, sgid, pp) { // eslint-disable-line
let action = new Action();

// TODO: shoud the id be generated when OpSGroupCreate is executed?
Expand Down
10 changes: 7 additions & 3 deletions src/script/editor/actions/template.js
Expand Up @@ -38,7 +38,9 @@ function extraBondAction(restruct, aid, angle, sgroups) {

if (angle === null) {
const middleAtom = atomForNewBond(restruct, aid);
const actionRes = fromBondAddition(restruct, { type: 1 }, aid, middleAtom.atom, middleAtom.pos.get_xy0());
const actionRes = fromBondAddition(
restruct, { type: 1 }, aid, middleAtom.atom, middleAtom.pos.get_xy0()
);
action = actionRes[0];
action.operations.reverse();
additionalAtom = actionRes[2];
Expand Down Expand Up @@ -120,7 +122,8 @@ export function fromTemplateOnAtom(restruct, template, aid, angle, extraBond) {
});

tmpl.bonds.forEach((bond) => {
const operation = new op.BondAdd(map.get(bond.begin), map.get(bond.end), bond).perform(restruct);
const operation = new op.BondAdd(map.get(bond.begin), map.get(bond.end), bond)
.perform(restruct);
action.addOp(operation);

pasteItems.bonds.push(operation.data.bid);
Expand Down Expand Up @@ -208,7 +211,8 @@ function fromTemplateOnBond(restruct, template, bid, flip) { // TODO: refactor f
tmpl.bonds.forEach((tBond) => {
const existId = struct.findBondId(atomsMap.get(tBond.begin), atomsMap.get(tBond.end));
if (existId === null) {
const operation = new op.BondAdd(atomsMap.get(tBond.begin), atomsMap.get(tBond.end), tBond).perform(restruct);
const operation = new op.BondAdd(atomsMap.get(tBond.begin), atomsMap.get(tBond.end), tBond)
.perform(restruct);
action.addOp(operation);

pasteItems.bonds.push(operation.data.bid);
Expand Down
6 changes: 4 additions & 2 deletions src/script/editor/actions/utils.js
Expand Up @@ -123,7 +123,8 @@ export function atomForNewBond(restruct, id) { // eslint-disable-line max-statem
});
neiNeighbours.sort((nei1, nei2) => nei1 - nei2);

if (neiNeighbours[0] <= Math.PI * 1.01 && neiNeighbours[neiNeighbours.length - 1] <= 1.01 * Math.PI)
if (neiNeighbours[0] <= Math.PI * 1.01 &&
neiNeighbours[neiNeighbours.length - 1] <= 1.01 * Math.PI)
maxAngle *= -1;
}
}
Expand All @@ -143,5 +144,6 @@ export function atomForNewBond(restruct, id) { // eslint-disable-line max-statem

export function getRelSgroupsBySelection(restruct, selectedAtoms) {
return restruct.molecule.sgroups
.filter((sgid, sg) => !sg.data.attached && !sg.data.absolute && difference(sg.atoms, selectedAtoms).length === 0);
.filter((sgid, sg) =>
!sg.data.attached && !sg.data.absolute && difference(sg.atoms, selectedAtoms).length === 0);
}
3 changes: 2 additions & 1 deletion src/script/editor/shared/action.js
Expand Up @@ -47,7 +47,8 @@ Action.prototype.perform = function (restruct) {

Action.prototype.isDummy = function (restruct) {
return this.operations.find(
operation => (restruct ? !operation.isDummy(restruct) : true) // TODO [RB] the condition is always true for op.* operations
// TODO [RB] the condition is always true for op.* operations
operation => (restruct ? !operation.isDummy(restruct) : true)
) === undefined;
};

Expand Down
7 changes: 5 additions & 2 deletions src/script/editor/shared/closest.js
Expand Up @@ -117,7 +117,7 @@ function findClosestBond(restruct, pos, skip, minDist, scale) { // eslint-disabl
};
}

if (closestBond !== null && minDist > SELECTION_DISTANCE_COEFFICIENT * scale) { // hack (ported from old code)
if (closestBond !== null && minDist > SELECTION_DISTANCE_COEFFICIENT * scale) {
return {
id: closestBond,
dist: minDist
Expand Down Expand Up @@ -331,7 +331,10 @@ function findCloseMerge(restruct, selected, maps = ['atoms', 'bonds'], scale) {

selected.bonds.forEach((bid) => {
const bond = struct.bonds.get(bid);
pos.bonds.set(bid, Vec2.lc2(struct.atoms.get(bond.begin).pp, 0.5, struct.atoms.get(bond.end).pp, 0.5));
pos.bonds.set(
bid,
Vec2.lc2(struct.atoms.get(bond.begin).pp, 0.5, struct.atoms.get(bond.end).pp, 0.5)
);
});

const result = {};
Expand Down
57 changes: 41 additions & 16 deletions src/script/editor/shared/op.js
Expand Up @@ -82,7 +82,7 @@ function AtomAdd(atom, pos) {
const arrow = struct.rxnArrows.get(0);
if (arrow) {
const atom = struct.atoms.get(this.data.aid);
atom.rxnFragmentType = struct.defineRxnFragmentTypeForAtomset(new Pile([this.data.aid]), arrow.pp.x);
atom.rxnFragmentType = struct.defineRxnFragmentTypeForAtomset(new Pile([this.data.aid]), arrow.pp.x); // eslint-disable-line
}
};

Expand Down Expand Up @@ -131,8 +131,13 @@ function AtomAttr(aid, attribute, value) {

this.execute = function (restruct) {
const atom = restruct.molecule.atoms.get(this.data.aid);
if (!this.data2)
this.data2 = { aid: this.data.aid, attribute: this.data.attribute, value: atom[this.data.attribute] };
if (!this.data2) {
this.data2 = {
aid: this.data.aid,
attribute: this.data.attribute,
value: atom[this.data.attribute]
};
}

atom[this.data.attribute] = this.data.value;
invalidateAtom(restruct, this.data.aid);
Expand Down Expand Up @@ -183,7 +188,8 @@ function BondMove(bid, d) {
this.data = { bid, d };

this.execute = function (restruct) {
restruct.bonds.get(this.data.bid).visel.translate(scale.obj2scaled(this.data.d, restruct.render.options));
restruct.bonds.get(this.data.bid).visel
.translate(scale.obj2scaled(this.data.d, restruct.render.options));
this.data.d = this.data.d.negated();
};

Expand All @@ -200,9 +206,12 @@ function LoopMove(id, d) {

this.execute = function (restruct) {
// not sure if there should be an action to move a loop in the first place
// but we have to somehow move the aromatic ring, which is associated with the loop, rather than with any of the bonds
if (restruct.reloops.get(this.data.id) && restruct.reloops.get(this.data.id).visel)
restruct.reloops.get(this.data.id).visel.translate(scale.obj2scaled(this.data.d, restruct.render.options));
// but we have to somehow move the aromatic ring,
// which is associated with the loop, rather than with any of the bonds
if (restruct.reloops.get(this.data.id) && restruct.reloops.get(this.data.id).visel) {
restruct.reloops.get(this.data.id).visel
.translate(scale.obj2scaled(this.data.d, restruct.render.options));
}
this.data.d = this.data.d.negated();
};

Expand Down Expand Up @@ -431,7 +440,7 @@ function BondAdd(begin, end, bond) {
struct.atomAddNeighbor(struct.bonds.get(this.data.bid).hb2);

// notifyBondAdded
restruct.bonds.set(this.data.bid, new ReStruct.Bond(restruct.molecule.bonds.get(this.data.bid)));
restruct.bonds.set(this.data.bid, new ReStruct.Bond(struct.bonds.get(this.data.bid)));
restruct.markBond(this.data.bid, 1);
};

Expand Down Expand Up @@ -498,8 +507,13 @@ function BondAttr(bid, attribute, value) {
this.execute = function (restruct) {
const bond = restruct.molecule.bonds.get(this.data.bid);

if (!this.data2)
this.data2 = { bid: this.data.bid, attribute: this.data.attribute, value: bond[this.data.attribute] };
if (!this.data2) {
this.data2 = {
bid: this.data.bid,
attribute: this.data.attribute,
value: bond[this.data.attribute]
};
}

bond[this.data.attribute] = this.data.value;

Expand Down Expand Up @@ -564,8 +578,13 @@ function RGroupAttr(rgid, attribute, value) {

this.execute = function (restruct) {
const rgp = restruct.molecule.rgroups.get(this.data.rgid);
if (!this.data2)
this.data2 = { rgid: this.data.rgid, attribute: this.data.attribute, value: rgp[this.data.attribute] };
if (!this.data2) {
this.data2 = {
rgid: this.data.rgid,
attribute: this.data.attribute,
value: rgp[this.data.attribute]
};
}

rgp[this.data.attribute] = this.data.value;

Expand Down Expand Up @@ -688,7 +707,10 @@ function RxnArrowAdd(pos) {
struct.rxnArrows.set(this.data.arid, new Struct.RxnArrow());

// notifyRxnArrowAdded
restruct.rxnArrows.set(this.data.arid, new ReStruct.RxnArrow(restruct.molecule.rxnArrows.get(this.data.arid)));
restruct.rxnArrows.set(
this.data.arid,
new ReStruct.RxnArrow(struct.rxnArrows.get(this.data.arid))
);

struct.rxnArrowSetPos(this.data.arid, new Vec2(this.data.pos));

Expand Down Expand Up @@ -780,7 +802,10 @@ function RxnPlusAdd(pos) {
struct.rxnPluses.set(this.data.plid, new Struct.RxnPlus());

// notifyRxnPlusAdded
restruct.rxnPluses.set(this.data.plid, new ReStruct.RxnPlus(restruct.molecule.rxnPluses.get(this.data.plid)));
restruct.rxnPluses.set(
this.data.plid,
new ReStruct.RxnPlus(struct.rxnPluses.get(this.data.plid))
);

struct.rxnPlusSetPos(this.data.plid, new Vec2(this.data.pos));

Expand Down Expand Up @@ -845,8 +870,8 @@ function SGroupDataMove(id, d) {
this.data = { id, d };

this.execute = function (restruct) {
const struct = restruct.molecule;
struct.sgroups.get(this.data.id).pp.add_(this.data.d); // eslint-disable-line no-underscore-dangle
const { sgroups } = restruct.molecule;
sgroups.get(this.data.id).pp.add_(this.data.d); // eslint-disable-line no-underscore-dangle
this.data.d = this.data.d.negated();
invalidateItem(restruct, 'sgroupData', this.data.id, 1); // [MK] this currently does nothing since the DataSGroupData Visel only contains the highlighting/selection and SGroups are redrawn every time anyway
};
Expand Down
3 changes: 2 additions & 1 deletion src/script/editor/tool/helper/locate.js
Expand Up @@ -58,7 +58,8 @@ function getElementsInRectangle(restruct, p0, p1) {

const sgroupDataList = [];
restruct.sgroupData.forEach((item, id) => {
if (item.sgroup.pp.x > x0 && item.sgroup.pp.x < x1 && item.sgroup.pp.y > y0 && item.sgroup.pp.y < y1)
if (item.sgroup.pp.x > x0 && item.sgroup.pp.x < x1 &&
item.sgroup.pp.y > y0 && item.sgroup.pp.y < y1)
sgroupDataList.push(id);
});

Expand Down
3 changes: 2 additions & 1 deletion src/script/editor/tool/paste.js
Expand Up @@ -71,7 +71,7 @@ PasteTool.prototype.mouseup = function () {
}
};

PasteTool.prototype.cancel = PasteTool.prototype.mouseleave = function () { // eslint-disable-line no-multi-assign
PasteTool.prototype.cancel = function () {
const rnd = this.editor.render;
this.editor.hover(null);
if (this.action) {
Expand All @@ -80,5 +80,6 @@ PasteTool.prototype.cancel = PasteTool.prototype.mouseleave = function () { // e
rnd.update();
}
};
PasteTool.prototype.mouseleave = PasteTool.prototype.cancel;

export default PasteTool;
5 changes: 4 additions & 1 deletion src/script/editor/tool/reactionmap.js
Expand Up @@ -86,7 +86,10 @@ ReactionMapTool.prototype.mouseup = function (event) { // eslint-disable-line ma
if (!aam1 || aam1 !== aam2) {
if (aam1 && aam1 !== aam2 || !aam1 && aam2) { // eslint-disable-line no-mixed-operators
atoms.forEach((atom, aid) => {
if (aid !== this.dragCtx.item.id && (aam1 && atom.aam === aam1 || aam2 && atom.aam === aam2)) // eslint-disable-line no-mixed-operators
if (
aid !== this.dragCtx.item.id &&
((aam1 && atom.aam === aam1) || (aam2 && atom.aam === aam2))
)
action.mergeWith(fromAtomsAttrs(rnd.ctab, aid, { aam: 0 }));
});
}
Expand Down
3 changes: 2 additions & 1 deletion src/script/editor/tool/rgroupatom.js
Expand Up @@ -60,7 +60,8 @@ function propsDialog(editor, id, pos) {
});

Promise.resolve(res).then((elem) => {
elem = Object.assign({}, Struct.Atom.attrlist, elem); // TODO review: using Atom.attrlist as a source of default property values
// TODO review: using Atom.attrlist as a source of default property values
elem = Object.assign({}, Struct.Atom.attrlist, elem);

if (!id && id !== 0 && elem.rglabel) {
editor.update(fromAtomAddition(editor.render.ctab, pos, elem));
Expand Down

0 comments on commit ed59308

Please sign in to comment.