diff --git a/.babelrc b/.babelrc deleted file mode 100644 index 1320b9a3..00000000 --- a/.babelrc +++ /dev/null @@ -1,3 +0,0 @@ -{ - "presets": ["@babel/preset-env"] -} diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 1ab1e710..d6267d73 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -26,4 +26,4 @@ jobs: - name: Install dependencies run: npm ci - name: Run babel on all files - run: npm run babel + run: npm run babel-test diff --git a/ChemEquilibrium/AcidModel.js b/ChemEquilibrium/AcidModel.js index ad7d48c9..43fdb8a3 100644 --- a/ChemEquilibrium/AcidModel.js +++ b/ChemEquilibrium/AcidModel.js @@ -147,7 +147,7 @@ let pkas = [ { ha: 'HCl', a: 'Cl-', pka: 1, specie: { label: 'Cl-', number: 1, pka: 1 } }, ]; -define(['lodash'], function (_) { +define(['lodash'], (_) => { class AcidBase { constructor(customPkas) { this.pkas = customPkas || pkas; @@ -165,14 +165,14 @@ define(['lodash'], function (_) { addAcidBase(label, total) { let titrProtonCount; - let titrSpecie = pkas.find(function (pka) { + let titrSpecie = pkas.find(function equalsLabel(pka) { return pka.ha === label; }); if (titrSpecie) { titrProtonCount = titrSpecie.specie.number; titrSpecie = titrSpecie.specie.label; } else { - titrSpecie = pkas.find(function (pka) { + titrSpecie = pkas.find(function equalsLabel(pka) { return pka.a === label; }); if (titrSpecie) { @@ -222,13 +222,13 @@ define(['lodash'], function (_) { getModel() { // Get all involved pkas let pkas = this.pkas.filter((pka) => { - return this.components.find(function (c) { + return this.components.find(function equalsLabel(c) { return String(c.label) === String(pka.specie.label); }); }); // group pkas by component - let grouped = _.groupBy(pkas, function (pka) { + let grouped = _.groupBy(pkas, function equalsLabel(pka) { return String(pka.specie.label); }); @@ -241,7 +241,7 @@ define(['lodash'], function (_) { // Model components model.components = new Array(nbComponents); - for (i = 0; i < this.components.length; i++) { + for (let i = 0; i < this.components.length; i++) { model.components[i] = { ...this.components[i] }; } @@ -256,7 +256,7 @@ define(['lodash'], function (_) { model.formedSpecies[0].components[protonIndex] = -1; - for (var i = 0; i < this.components.length; i++) { + for (let i = 0; i < this.components.length; i++) { if (i === protonIndex) continue; let group = grouped[this.components[i].label]; if (!group) throw new Error('Should be unreachable'); diff --git a/ChemEquilibrium/chart.js b/ChemEquilibrium/chart.js index 816251c3..1d400209 100644 --- a/ChemEquilibrium/chart.js +++ b/ChemEquilibrium/chart.js @@ -1,4 +1,4 @@ -define(['src/util/color'], function (Color) { +define(['src/util/color'], (Color) => { return { getChart(x, y, options) { options = options || {}; @@ -20,10 +20,9 @@ define(['src/util/color'], function (Color) { let species = Object.keys(y[0]); let colors = Color.getDistinctColors(species.length); - for (var i = 0; i < species.length; i++) { + for (let i = 0; i < species.length; i++) { let data = {}; chart.data.push(data); - // eslint-disable-next-line no-loop-func data.y = y.map((y) => { return y[species[i]]; }); diff --git a/biology/needleman/index.js b/biology/needleman/index.js index 3d414eb4..ab98d91b 100644 --- a/biology/needleman/index.js +++ b/biology/needleman/index.js @@ -49,7 +49,7 @@ function run(v, w, options = {}) { let matrixScore; try { matrixScore = S[v[i - 1]][w[j - 1]]; - } catch (e) { + } catch { // e.g. a letter is not found in the matrix matrixScore = indel; } diff --git a/chemistry/PubChem.js b/chemistry/PubChem.js index 203bfc00..12af9427 100644 --- a/chemistry/PubChem.js +++ b/chemistry/PubChem.js @@ -10,7 +10,6 @@ async function getMolecules(mf) { let response = await fetch(`${pubchemURL}${searchParams.toString()}`); let results = await response.json(); - console.log(results.data); return results.data; } @@ -66,7 +65,7 @@ module.exports = { rowHeight: 140, }, }) - .catch(function (e) { + .catch((e) => { console.error(e); // eslint-disable-line no-console ui.showNotification('search failed', 'error'); }); diff --git a/chemistry/chemcalcSequenceSVG.js b/chemistry/chemcalcSequenceSVG.js index 16d33692..55abcfaf 100644 --- a/chemistry/chemcalcSequenceSVG.js +++ b/chemistry/chemcalcSequenceSVG.js @@ -1,7 +1,7 @@ define([ 'https://www.lactame.com/github/adobe-webplatform/Snap.svg/84fbff7d512c8145c522b71fc9c872cb0bcae49a/dist/snap.svg-min.js', './sequenceSplitter', -], function (Snap, sequenceSplitter) { +], (snap, sequenceSplitter) => { function getSVG(sequence, analysisResult, options) { const { width = 600, @@ -24,7 +24,7 @@ define([ let line = 0; // we create a temporary paper in order to get the width of the text blocs - let tempPaper = Snap(1000, 40); + let tempPaper = snap(1000, 40); for (let i = 0; i < mfParts.length; i++) { let part = mfParts[i]; let text = tempPaper.text(xPos, 20, part); @@ -130,11 +130,11 @@ define([ rowHeight * (line + 1) + 50 + verticalShiftForTerminalAnnotations; // We start to create the SVG and create the paper - let paper = Snap(width, height); + let paper = snap(width, height); addScript(paper); - residues.forEach(function (residue) { + residues.forEach((residue) => { residue.y = (residue.line + 1) * rowHeight; let text = paper.text(residue.xFrom, residue.y, residue.label); text.attr({ id: `residue-${residue.nTer}` }); @@ -163,7 +163,7 @@ define([ let used = {}; for (let i = from; i < to; i++) { let residue = residues[i]; - residue.usedSlots.forEach(function (usedSlot, index) { + residue.usedSlots.forEach((usedSlot, index) => { used[index] = true; }); } @@ -182,7 +182,7 @@ define([ function drawTerminals() { for (let result of results) { - var residue; + let residue; let nTerminal = false; if (result.fromNTerm) { residue = residues[result.to]; @@ -267,7 +267,7 @@ define([ // var charge = result.charge > 0 ? '+' + result.charge : result.charge; // var label = result.type + ' (' + charge + ', ' + Math.round(result.similarity) + '%)'; // we need to check on how many lines we are - var fromX, toX, y; + let fromX, toX, y; for (let line = fromResidue.line; line <= toResidue.line; line++) { y = -10 - diff --git a/chemistry/orbitals.js b/chemistry/orbitals.js index 375def68..fec4c1ac 100644 --- a/chemistry/orbitals.js +++ b/chemistry/orbitals.js @@ -1,6 +1,6 @@ define([ 'https://www.lactame.com/github/adobe-webplatform/Snap.svg/84fbff7d512c8145c522b71fc9c872cb0bcae49a/dist/snap.svg-min.js', -], function (Snap) { +], (snap) => { let exports = {}; let defaultOptions = { @@ -133,7 +133,7 @@ define([ } svgModifier = []; - paper = Snap(width, height); + paper = snap(width, height); paper .path('M 0 0 L 10 4 L 0 8 z') @@ -216,7 +216,7 @@ define([ function parseelConfig(elConfig) { elConfig = elConfig.split(' '); - elConfig = elConfig.map(function (o) { + elConfig = elConfig.map((o) => { let m = o.match(/^(\d\w)(\d+)/); return { layer: m[1], @@ -282,11 +282,11 @@ define([ return Math.floor(electron / num) === 0 ? 1 : -1; } - exports.getSvg = function (...args) { + exports.getSvg = function getSvg(...args) { createSvg(args); return svg; }; - exports.getSvgAndModifier = function (...args) { + exports.getSvgAndModifier = function getSvgAndModifier(...args) { createSvg(args); return { svg, svgModifier }; }; diff --git a/chemistry/structuralAnalysisExercises.js b/chemistry/structuralAnalysisExercises.js index c9b04bbf..798563bd 100644 --- a/chemistry/structuralAnalysisExercises.js +++ b/chemistry/structuralAnalysisExercises.js @@ -43,7 +43,7 @@ async function fetchData( } let datum = data[file.rn]; switch (file.kind) { - case 'mol': + case 'mol': { datum.mol = { type: 'mol2d', url: file.url }; const molfile = await (await fetch(file.url)).text(); const molecule = Molecule.fromMolfile(molfile); @@ -61,6 +61,7 @@ async function fetchData( datum.nbH = Number(datum.mf.replace(/.*H([0-9]+).*/, '$1')); datum.nbC = Number(datum.mf.replace(/.*C([0-9]+).*/, '$1')); break; + } case 'mass': datum.mass = { type: 'jcamp', url: file.url }; datum.isMass = true; diff --git a/defaultOptions/mass.js b/defaultOptions/mass.js index 6e440873..e83a9800 100644 --- a/defaultOptions/mass.js +++ b/defaultOptions/mass.js @@ -1,4 +1,4 @@ -define(function () { +define(() => { return { monoisotopicMass: 300.123, resolution: 100000, diff --git a/edx/channel.js b/edx/channel.js index d7fc7f6f..e28051da 100644 --- a/edx/channel.js +++ b/edx/channel.js @@ -1,6 +1,6 @@ define([ 'https://cdnjs.cloudflare.com/ajax/libs/jschannel/1.0.0-git-commit1-8c4f7eb/jschannel.js', -], function () { +], () => { let initialized = false; function init(options) { if (initialized) return; diff --git a/eln/.eslintrc.yml b/eln/.eslintrc.yml deleted file mode 100644 index add5a785..00000000 --- a/eln/.eslintrc.yml +++ /dev/null @@ -1,2 +0,0 @@ -parserOptions: - sourceType: module diff --git a/eln/BioReaction.js b/eln/BioReaction.js index ee4eea36..80f6daab 100644 --- a/eln/BioReaction.js +++ b/eln/BioReaction.js @@ -177,10 +177,11 @@ class BioReaction { case 'save': await this.roc.update(this.sample); break; - case 'deleteAttachment': - var attachment = action.value.name; + case 'deleteAttachment': { + const attachment = action.value.name; await this.roc.deleteAttachment(this.sample, attachment); break; + } case 'unattach': await this.roc.unattach(this.sample, action.value); break; diff --git a/eln/ExpandableMolecule.js b/eln/ExpandableMolecule.js index 6994a125..fa1a7498 100644 --- a/eln/ExpandableMolecule.js +++ b/eln/ExpandableMolecule.js @@ -208,10 +208,11 @@ class ExpandableMolecule { case 'toggleJSMEEdition': this.toggleJSMEEdition(!this.jsmeEditionMode); break; - case 'clearMolfile': - var molfile = API.getData('editableMolfile'); + case 'clearMolfile': { + const molfile = API.getData('editableMolfile'); molfile.setValue(''); break; + } case 'swapHydrogens': this.setExpandedHydrogens(); break; diff --git a/eln/ExtSample.js b/eln/ExtSample.js index 7430f2a8..636daf1e 100644 --- a/eln/ExtSample.js +++ b/eln/ExtSample.js @@ -100,7 +100,7 @@ class Sample { case '$content.general.mf': try { this.mf.fromMF(); - } catch (e) { + } catch { // ignore } break; @@ -119,7 +119,7 @@ class Sample { } async _init() { - this._initialized = new Promise(async (resolve) => { + this._initialized = (async () => { let sample; if (this.options.trackId) { try { @@ -143,8 +143,7 @@ class Sample { sample.$content.general.molfile = ''; // can not be edited otherwise } this._loadSample(sample); - resolve(); - }); + })(); } bindChange() { @@ -157,7 +156,7 @@ class Sample { } async handleDrop(name, askType, options = {}) { - let { converters = {}, autoJcamp, autoKind } = options; + let { converters = {}, autoKind } = options; if (!name) { throw new Error('handleDrop expects a variable name'); } @@ -201,8 +200,6 @@ class Sample { } if (converters[kind]) { - autoJcamp = false; - let converted = await converters[kind](droppedData.content); if (!Array.isArray(converted)) { converted = [converted]; diff --git a/eln/MF.js b/eln/MF.js index a69d96ca..b8e27ca0 100644 --- a/eln/MF.js +++ b/eln/MF.js @@ -20,9 +20,9 @@ class MF { let mfInfo = new MolecularFormula.MF(mf).getInfo(); this.setCanonizedMF(mfInfo.mf); this.previousEMMF = mfInfo.monoisotopicMass; - } catch (e) { + } catch (err) { this.setCanonizedMF(''); - console.log('Could not parse MF: ', mf); + reportError(err); } } } @@ -97,10 +97,6 @@ class MF { this.sample.setChildSync(['$content', 'general', 'mf'], mf); } - setMF(mf) { - this.sample.setChildSync(['$content', 'general', 'mf'], mf); - } - setMW(mw) { this.sample.setChildSync(['$content', 'general', 'mw'], mw); } diff --git a/eln/Nmr1dManager.js b/eln/Nmr1dManager.js index 5e7f54aa..dd134d42 100644 --- a/eln/Nmr1dManager.js +++ b/eln/Nmr1dManager.js @@ -177,13 +177,14 @@ class Nmr1dManager { this._autoRanges(currentNmr); break; } - case 'deleteAllRanges': - var ranges = API.getData('currentNmrRanges'); + case 'deleteAllRanges': { + const ranges = API.getData('currentNmrRanges'); while (ranges.length) { ranges.pop(); } ranges.triggerChange(); break; + } case 'clearAssignments': { let ranges = this.getCurrentRanges(); if (ranges) { @@ -298,8 +299,9 @@ class Nmr1dManager { _getNMR(currentNMRLine) { let filename = String(currentNMRLine.getChildSync(['jcamp', 'filename'])); return currentNMRLine.getChild(['jcamp', 'data']).then((jcamp) => { + let spectrum; if (filename && this.spectra[filename]) { - var spectrum = this.spectra[filename]; + spectrum = this.spectra[filename]; } else if (jcamp) { jcamp = String(jcamp.get()); spectrum = NMR.fromJcamp(jcamp); @@ -381,7 +383,7 @@ class Nmr1dManager { if (mfInfo && mfInfo.atoms && mfInfo.atoms.H) { return mfInfo.atoms.H || 100; } - } catch (e) { + } catch { return 100; } } diff --git a/eln/Sample.js b/eln/Sample.js index 25f3d871..4ffb765f 100644 --- a/eln/Sample.js +++ b/eln/Sample.js @@ -616,11 +616,15 @@ Your local changes will be lost.

`; content = atob(droppedData.content); droppedData.encoding = 'text'; break; - case 'buffer': + case 'buffer': { const decoder = new TextDecoder(); content = decoder.decode(droppedData.content); droppedData.encoding = 'text'; break; + } + default: { + // No special handling + } } droppedData.content = convertToJcamp(content, { meta, @@ -675,8 +679,8 @@ Your local changes will be lost.

`; case 'translateNucleic': Sequence.translateNucleic(this.sample); break; - case 'createOptions': - var advancedOptions1H = API.cache('nmr1hAdvancedOptions'); + case 'createOptions': { + const advancedOptions1H = API.cache('nmr1hAdvancedOptions'); if (advancedOptions1H) { API.createData( 'nmr1hOndeTemplate', @@ -689,9 +693,11 @@ Your local changes will be lost.

`; ); } break; + } case 'recreateVariables': this.createVariables(); - case 'deleteAttachment': + break; + case 'deleteAttachment': { const ok = await UI.confirm( 'Are you sure you want to delete the attachment?', ); @@ -700,6 +706,7 @@ Your local changes will be lost.

`; await this.roc.deleteAttachment(this.sample, attachment); this.updateOtherAttachments(); break; + } case 'deleteNmr': // Deprecated. Use unattach. Leave this for backward compatibility case 'unattach': if ( @@ -845,7 +852,6 @@ async function pasteAnalysis(sample) { API.doAction('refresh', { noConfirmation: true }); function getName(existingAttachments, filename) { - console.log({ existingAttachments, filename }); if (!existingAttachments[filename]) { return filename; } diff --git a/eln/StockSample.js b/eln/StockSample.js index 86568a17..007fd52f 100644 --- a/eln/StockSample.js +++ b/eln/StockSample.js @@ -56,7 +56,7 @@ class Sample { case '$content.general.mf': try { this.mf.fromMF(); - } catch (e) { + } catch { // ignore } break; @@ -69,11 +69,10 @@ class Sample { } async _init() { - this._initialized = new Promise(async (resolve) => { + this._initialized = (async () => { this.sample = await API.createData(this.options.varName, this.sample); this._loadSample(); - resolve(); - }); + })(); } bindChange() { diff --git a/eln/nucleic/genbank.js b/eln/nucleic/genbank.js index 0f0a79ee..4080f010 100644 --- a/eln/nucleic/genbank.js +++ b/eln/nucleic/genbank.js @@ -1,7 +1,8 @@ -import Twig from 'lib/twigjs/twig'; +// eslint-disable-next-line import/no-unassigned-import import 'angularplasmid'; -import typerenderer from 'src/util/typerenderer'; import $ from 'jquery'; +import Twig from 'lib/twigjs/twig'; +import typerenderer from 'src/util/typerenderer'; const templateOptions = { style: ` @@ -86,9 +87,9 @@ export async function getSvg(parsedGb, options) { } async function compile(val) { - return new Promise(function (resolve) { + return new Promise(function compile(resolve) { let $injector = self.angular.injector(['ng', 'angularplasmid']); - $injector.invoke(function ($rootScope, $compile) { + $injector.invoke(function invoke($rootScope, $compile) { const svg = $compile(String(val))($rootScope); // TODO: why is this setTimeout needed setTimeout(() => resolve(svg), 0); diff --git a/eln/pubchem/ghs.js b/eln/pubchem/ghs.js index 92196858..75a44487 100644 --- a/eln/pubchem/ghs.js +++ b/eln/pubchem/ghs.js @@ -2,7 +2,7 @@ import OCL from 'openchemlib'; // returns GHS information based on pubchem and a smiles -define(['src/util/ui', 'src/util/api'], function (UI, API) { +define(['src/util/ui', 'src/util/api'], (UI, API) => { async function fromIDCode(oclCode, options) { const molecule = OCL.Molecule.fromIDCode(oclCode); const smiles = molecule.toSmiles(); diff --git a/eln/pubchem/info.js b/eln/pubchem/info.js index c317d077..46d5ffef 100644 --- a/eln/pubchem/info.js +++ b/eln/pubchem/info.js @@ -2,14 +2,14 @@ import OCL from 'openchemlib'; // returns GHS information based on pubchem and a smiles -define(['src/util/ui', 'src/util/api'], function (UI, API) { +define(['src/util/ui'], (UI) => { async function fromIDCode(oclCode, options) { const molecule = OCL.Molecule.fromIDCode(oclCode); const smiles = molecule.toSmiles(); return fromSMILES(smiles, options); } - async function fromSMILES(smiles, options = {}) { + async function fromSMILES(smiles) { const html = ``; @@ -24,185 +24,3 @@ define(['src/util/ui', 'src/util/api'], function (UI, API) { return { fromIDCode, fromSMILES }; }); - -const ghsTemplate = ` - -
- {% if ghs.pictograms %} -

Pictograms

- - {% for pictogram in ghs.pictograms %} - - - - - - {% endfor %} -
- {{pictogram.code}} - -
- {{rendertypeBlock(pictogram.code,'ghs')}} -
-
- {{pictogram.description}} -
- {% endif %} - {% if ghs.hStatements %} -

Hazard statements

- - {% for h in ghs.hStatements %} - - - - - {% endfor %} -
- {{h.code}} - - {{h.description}} -
- {% endif %} - {% if ghs.pStatements %} -

Precautionary statements

- - {% for p in ghs.pStatements %} - - - - - {% endfor %} -
- {{p.code}} - - {{p.description}} -
- {% endif %} -
-`; - -const ghsFullTemplate = ` - -
-

Detailed safety information

- {% if ghsFull.pictograms %} -

Pictograms

- {% for entry in ghsFull.pictograms %} -

{{entry.reference.sourceName}}

-

- Name: {{entry.reference.name}} -

-

{{entry.reference.description}}

- - {% for pictogram in entry.data %} - - - - - - {% endfor %} -
- {{pictogram.code}} - -
- {{rendertypeBlock(pictogram.code,'ghs')}} -
-
- {{pictogram.description}} -
- {% endfor %} - {% endif %} - {% if ghsFull.hStatements %} -

Hazard statements

- {% for entry in ghsFull.hStatements %} -

{{entry.reference.sourceName}}

-

- Name: {{entry.reference.name}} -

-

{{entry.reference.description}}

- - {% for hStatement in entry.data %} - - - - - {% endfor %} -
- {{hStatement.code}} - - {{hStatement.description}} -
- {% endfor %} - {% endif %} - {% if ghsFull.pStatements %} -

Precautionary statements

- {% for entry in ghsFull.pStatements %} -

{{entry.reference.sourceName}}

-

- Name: {{entry.reference.name}} -

-

{{entry.reference.description}}

- - {% for pStatement in entry.data %} - - - - - {% endfor %} -
- {{pStatement.code}} - - {{pStatement.description}} -
- {% endfor %} - {% endif %} -
-`; diff --git a/eln/reaction/Reaction.js b/eln/reaction/Reaction.js index cc2fa8cc..a2645d06 100644 --- a/eln/reaction/Reaction.js +++ b/eln/reaction/Reaction.js @@ -196,10 +196,9 @@ export async function selectProduct(reactionRXN, options = {}) { row.kind = 'crude'; rows.push(row); } - if (rows.length === 0) { - } else if (rows.length === 1) { + if (rows.length === 1) { return rows[0]; - } else { + } else if (rows.length !== 0) { const chooseList = []; for (let i = 0; i < rows.length; i++) { chooseList.push({ diff --git a/eln/request/processAction.js b/eln/request/processAction.js index 8afd1507..5f6ad02e 100644 --- a/eln/request/processAction.js +++ b/eln/request/processAction.js @@ -33,8 +33,6 @@ async function processAction(actionName, actionValue) { API.doAction('refreshRequests'); } break; - case 'deleteActivity': - break; case 'createForm': createForm(); break; diff --git a/eln/sample/SequencesDataSet.js b/eln/sample/SequencesDataSet.js index e8c2537f..b58c3b75 100644 --- a/eln/sample/SequencesDataSet.js +++ b/eln/sample/SequencesDataSet.js @@ -120,7 +120,6 @@ class SequencesDataSet { } async processAction(action) { - console.log({ action }); switch (action.name) { case 'clickedSample': this.clickedSample(action.value); @@ -164,6 +163,7 @@ class SequencesDataSet { sequence.category = getJpath(sequence); } selectedSequences.triggerChange(); + break; } case 'showSpectra': this.showSpectra(); @@ -190,7 +190,10 @@ class SequencesDataSet { action.value.resurrect(), ); break; - default: + default: { + // eslint-disable-next-line no-console + console.log(`Unhandled action: ${action.name}`); + } } } diff --git a/eln/sample/compare/processActions.js b/eln/sample/compare/processActions.js index ea4e5287..ca224428 100644 --- a/eln/sample/compare/processActions.js +++ b/eln/sample/compare/processActions.js @@ -22,10 +22,11 @@ async function processActions(action) { case 'recalculateCharts': recalculateCharts(); break; - case 'spectrumInfo': + case 'spectrumInfo': { const jcampInfo = await API.require('vh/eln/util/jcampInfo'); jcampInfo(action.value); break; + } case 'removeSpectrum': { removeSpectrum(action); break; @@ -39,9 +40,6 @@ async function processActions(action) { .filter((entry) => DataObject.resurrect(entry.display)) .map((entry) => String(entry.id)); let analysis = analysesManager.getAnalyses({ ids })[0]; - if (!analysis) { - console.error('No analysis found'); - } const text = ExtendedCommonSpectrum.toText(analysis, { selector: preferences.selector, @@ -63,9 +61,6 @@ async function processActions(action) { .filter((entry) => DataObject.resurrect(entry.display)) .map((entry) => String(entry.id)); let analyses = analysesManager.getAnalyses({ ids }); - if (!analyses) { - console.error('No analysis found'); - } const text = ExtendedCommonSpectrum.toMatrix(analyses, { selector: preferences.selector, @@ -96,11 +91,12 @@ async function processActions(action) { API.getData('selectedSpectra').triggerChange(); updateDistinctLabelUnits(); break; - case 'addSpectrum': - let result = await addSpectrum(action, {}); + case 'addSpectrum': { + const result = await addSpectrum(action, {}); API.getData('selectedSpectra').triggerChange(); updateDistinctLabelUnits(); return result; + } case 'hideSpectra': hideSpectra(); break; @@ -120,7 +116,8 @@ async function processActions(action) { showAllSpectra(); break; default: - console.error(`Action ${action.name} is not recognized`); + // eslint-disable-next-line no-console + console.log(`Unhandled action ${action.name}`); } } catch (e) { UI.showNotification(e.message, 'error'); @@ -167,7 +164,6 @@ async function addSpectrum(action, options = {}) { let spectrumUUID = options.spectrumUUID || getSpectrumUUID(action.value); let spectrumID = `${sampleID} ${action.value.__name}`; - console.log({ spectrumID, spectrumUUID }); let jcamp = ''; if (action.value.jcamp && action.value.jcamp.filename) { diff --git a/eln/sample/compare/recalculateCharts.js b/eln/sample/compare/recalculateCharts.js index 81685a24..156c5888 100644 --- a/eln/sample/compare/recalculateCharts.js +++ b/eln/sample/compare/recalculateCharts.js @@ -16,7 +16,6 @@ export default function recalculateCharts() { let analyses = analysesManager.getAnalyses({ ids }); - console.log('Calculate chart'); try { if (preferences.normalization.processing) { let chartProcessed = ExtendedCommonSpectrum.JSGraph.getJSGraph(analyses, { diff --git a/eln/sample/compare/trackMove.js b/eln/sample/compare/trackMove.js index 635a559f..b5154e12 100644 --- a/eln/sample/compare/trackMove.js +++ b/eln/sample/compare/trackMove.js @@ -31,6 +31,8 @@ function generateTrackAnnotations(action) { const analysesManager = API.cache('analysesManager'); let data; + // TODO: What should we do with this? + // eslint-disable-next-line no-constant-condition if (false) { if (analysesManager.getAnalysisBySpectrumId) { function getColor(spectrumId) { diff --git a/eln/sample/compareMeasurements/processActions.js b/eln/sample/compareMeasurements/processActions.js index 2fbb226d..24588f2c 100644 --- a/eln/sample/compareMeasurements/processActions.js +++ b/eln/sample/compareMeasurements/processActions.js @@ -21,11 +21,11 @@ async function processActions(action) { case 'recalculateCharts': recalculateCharts(); break; - case 'measurementInfo': + case 'measurementInfo': { const jcampInfo = await API.require('vh/eln/util/jcampInfo'); - console.log(action.value); jcampInfo(action.value); break; + } case 'removeMeasurement': { removeMeasurement(action); break; @@ -47,11 +47,12 @@ async function processActions(action) { API.getData('selectedMeasurements').triggerChange(); updateDistinctLabelUnits(); break; - case 'addMeasurement': - let result = await addMeasurement(action, {}); + case 'addMeasurement': { + const result = await addMeasurement(action, {}); API.getData('selectedMeasurements').triggerChange(); updateDistinctLabelUnits(); return result; + } case 'hideMeasurements': hideMeasurements(); break; @@ -70,6 +71,10 @@ async function processActions(action) { case 'showAllMeasurements': showAllMeasurements(); break; + default: { + // eslint-disable-next-line no-console + console.log(`Unhandled action: ${action.name}`); + } } } @@ -115,7 +120,6 @@ async function addMeasurement(action, options = {}) { let measurementID = sampleID + (action.value.__name !== 0 ? ` ${action.value.__name}` : ''); - console.log({ measurementID, measurementUUID }); let jcamp = ''; if (action.value.jcamp && action.value.jcamp.filename) { diff --git a/eln/sample/compareMeasurements/recalculateCharts.js b/eln/sample/compareMeasurements/recalculateCharts.js index 5a91f68c..51f30706 100644 --- a/eln/sample/compareMeasurements/recalculateCharts.js +++ b/eln/sample/compareMeasurements/recalculateCharts.js @@ -1,5 +1,4 @@ import API from 'src/util/api'; -import UI from 'src/util/ui'; export default function recalculateCharts() { const ExtendedCommonMeasurement = API.cache('ExtendedCommonMeasurement'); diff --git a/eln/sample/compareMeasurements/trackMove.js b/eln/sample/compareMeasurements/trackMove.js index 3853c7f8..72b24483 100644 --- a/eln/sample/compareMeasurements/trackMove.js +++ b/eln/sample/compareMeasurements/trackMove.js @@ -31,6 +31,8 @@ function generateTrackAnnotations(action) { const analysesManager = API.cache('analysesManager'); let data; + // TODO: What should we do with this? + // eslint-disable-next-line no-constant-condition if (false) { if (analysesManager.getAnalysisByMeasurementId) { function getColor(measurementId) { diff --git a/eln/sample/ml/SpectraDataSet.js b/eln/sample/ml/SpectraDataSet.js index c700d818..fde8879c 100644 --- a/eln/sample/ml/SpectraDataSet.js +++ b/eln/sample/ml/SpectraDataSet.js @@ -444,7 +444,6 @@ class SpectraDataSet { } async processAction(action) { - console.log({ action }); switch (action.name) { case 'resetMinMax': this.resetMinMax(); @@ -491,10 +490,12 @@ class SpectraDataSet { spectrum.category = getJpath(spectrum); } spectraInDataset.triggerChange(); + break; } - case 'addSpectraToSelection': + case 'addSpectraToSelection': { this.addSpectraToSelection(); break; + } case 'selectAllSpectra': this.selectAllSpectra(); break; @@ -542,7 +543,10 @@ class SpectraDataSet { case 'addDirectSpectra': // data are in memory in data property this.addDirectSpectra(); break; - default: + default: { + // eslint-disable-next-line no-console + console.log(`SpectraDataSet: unhandled action ${action.name}`); + } } } @@ -630,7 +634,6 @@ class SpectraDataSet { addDirectSpectrum(spectrum) { let spectraInDataset = API.getData('spectraInDataset'); - console.log({ spectraInDataset }); this.addDirectSpectrumToSelected(spectrum, spectraInDataset); recolor(spectraInDataset); spectraInDataset.triggerChange(); @@ -679,7 +682,6 @@ class SpectraDataSet { } addDirectSpectrumToSelected(spectrum, spectraInDataset) { - console.log(spectrum); if (spectrum.data) { let spectrumID = String(spectrum.id); let sampleID = String(spectrum.name); diff --git a/eln/sample/ml/recreateCharts.js b/eln/sample/ml/recreateCharts.js index 9b856229..509e178a 100644 --- a/eln/sample/ml/recreateCharts.js +++ b/eln/sample/ml/recreateCharts.js @@ -1,4 +1,4 @@ -define(['src/util/api', 'src/util/ui'], function (API, UI) { +define(['src/util/api', 'src/util/ui'], (API, UI) => { async function recreateCharts(variable, action) { if (!API.getData('preferences')) return; const preferences = JSON.parse(JSON.stringify(API.getData('preferences'))); @@ -33,7 +33,6 @@ define(['src/util/api', 'src/util/ui'], function (API, UI) { } } API.cache('previousIdsInDataSet', currentSpectraIds); - console.log('Update chart'); const selectedIDs = spectraProcessor.spectra .filter((spectrum) => spectrum.meta.selected) @@ -69,7 +68,6 @@ define(['src/util/api', 'src/util/ui'], function (API, UI) { )[0]; } postProcessingOptions.ids = ids; - console.log({ postProcessingOptions }); API.createData( 'chart', spectraProcessor.getPostProcessedChart(postProcessingOptions), @@ -118,6 +116,7 @@ define(['src/util/api', 'src/util/ui'], function (API, UI) { } else { preferences.display.correlationIndex = Number.parseInt( preferences.display.correlationIndex, + 10, ); if (!Number.isInteger(preferences.display.correlationIndex)) { preferences.display.correlationIndex = Math.floor( diff --git a/eln/sample/preselectSpectrum.js b/eln/sample/preselectSpectrum.js index 45abc957..09a899b2 100644 --- a/eln/sample/preselectSpectrum.js +++ b/eln/sample/preselectSpectrum.js @@ -3,9 +3,9 @@ import API from 'src/util/api'; /* Need to be able to select a spectrum when loading the page. We receive an event that contains spectrumID - + In General preference we add: - + if (data.message.spectrumID) { preselectSpectrum('ir', data.message.spectrumID); } @@ -15,16 +15,15 @@ We need to find out when the module containing the spectra is loaded before send We create a global action in the General preferences called `SpectraListLoaded` API.cache('SpectraListLoaded', true); - + We add in the module that contains the list of spectra an action out with 'onLoaded': 'SpectraListLoaded' - - + + */ module.exports = function preselectSpectrum(kind, spectrumID) { setTimeout(() => { const spectra = API.getData(kind); - console.log({ kind, spectrumID }); if (spectra && API.cache('SpectraListLoaded')) { const toSelect = findSpectrum(spectra, spectrumID); API.doAction('SelectSpectrum', toSelect); diff --git a/eln/sample/renderer/ghs.js b/eln/sample/renderer/ghs.js index 418dc266..3301db5a 100644 --- a/eln/sample/renderer/ghs.js +++ b/eln/sample/renderer/ghs.js @@ -2,15 +2,14 @@ import TypeRenderer from 'src/util/typerenderer'; export function add(GHS) { TypeRenderer.addType('ghsPictogram', { - toscreen($element, val, root, options = {}) { + toscreen($element, val) { const code = val.code || val; const svg = String(GHS.getGHSObject()[code].svg); const dom = $(svg); - console.log(dom); const width = dom.attr('width'); const height = dom.attr('height'); if (width && height) { - let viewbox = [0, 0, parseInt(width), parseInt(height)]; + let viewbox = [0, 0, parseInt(width, 10), parseInt(height, 10)]; dom[0].setAttribute('viewBox', viewbox.join(' ')); } dom.removeAttr('id'); @@ -22,14 +21,14 @@ export function add(GHS) { }); TypeRenderer.addType('ghsHStatement', { - toscreen($element, val, root, options = {}) { + toscreen($element, val) { const code = val.code || val; const label = String(GHS.getHStatementsObject()[code].statement); $element.html(label); }, }); TypeRenderer.addType('ghsPStatement', { - toscreen($element, val, root, options = {}) { + toscreen($element, val) { const code = val.code || val; const label = String(GHS.getPStatementsObject()[code].statement); $element.html(label); diff --git a/eln/sample/splitJcamp.js b/eln/sample/splitJcamp.js index 783b48e6..708388b6 100644 --- a/eln/sample/splitJcamp.js +++ b/eln/sample/splitJcamp.js @@ -44,7 +44,6 @@ export function splitJcamp(file) { } const baseFilename = file.filename.replace(/(\.fid|\.j?dx)/gi, ''); - console.log(file); for (const group of groups) { if (group.fid) { newFiles.push({ diff --git a/eln/sample/tocLookup.js b/eln/sample/tocLookup.js index 82f1b6ce..1eddc550 100644 --- a/eln/sample/tocLookup.js +++ b/eln/sample/tocLookup.js @@ -1,4 +1,3 @@ -import _ from 'lodash'; import ui from 'src/util/ui'; module.exports = { @@ -54,21 +53,9 @@ module.exports = { rowHeight: 150, }, }) - .catch(function (e) { - console.error(e); // eslint-disable-line no-console + .catch((err) => { + reportError(err); ui.showNotification('search failed', 'error'); }); }, }; - -function listTemplate(val, prop) { - return ` -
- - {% for n in ${val} %} - - {% endfor %} -
{{ n${prop} }}
-
- `; -} diff --git a/eln/setSpecdtrumClasses.js b/eln/setSpecdtrumClasses.js index 933056ee..d98a3117 100644 --- a/eln/setSpecdtrumClasses.js +++ b/eln/setSpecdtrumClasses.js @@ -17,7 +17,7 @@ const spectrumCategories = [ }, ]; -define(['src/util/ui', 'lodash'], function (UI, _) { +define(['src/util/ui', 'lodash'], (UI, _) => { function setspectrumCategories(record, allCategories) { let selectedCategories = categories; @@ -48,7 +48,7 @@ define(['src/util/ui', 'lodash'], function (UI, _) { `, entrysample, { twig: data }, - ).then(function (result) { + ).then((result) => { if (!result) return null; const selected = Object.keys(result.group).filter( (key) => result.group[key], diff --git a/eln/showSimilarityAlgorithm.js b/eln/showSimilarityAlgorithm.js index 2322eb93..b3e18161 100644 --- a/eln/showSimilarityAlgorithm.js +++ b/eln/showSimilarityAlgorithm.js @@ -163,7 +163,7 @@ let html = ` ✔ ✘ - + diff --git a/eln/stock/ACI/samples.js b/eln/stock/ACI/samples.js index 625db91d..f978b2fc 100644 --- a/eln/stock/ACI/samples.js +++ b/eln/stock/ACI/samples.js @@ -1,4 +1,4 @@ -module.exports = function (roc) { +module.exports = function aciSamples(roc) { return { async getNextCommercialBatch(structureId) { structureId = String(structureId); diff --git a/eln/stock/ACI/structures.js b/eln/stock/ACI/structures.js index 1dbc8a7d..76df4827 100644 --- a/eln/stock/ACI/structures.js +++ b/eln/stock/ACI/structures.js @@ -9,7 +9,7 @@ function Structure(roc) { }; if (type) { - options.filter = function (entry) { + options.filter = (entry) => { return entry.$id[1] === type; }; } @@ -55,8 +55,8 @@ function Structure(roc) { disableNotification: true, }); return entry; - } catch (e) { - if (e.message === 'Conflict') { + } catch (err) { + if (err.message === 'Conflict') { // try to get id const result = await roc.view('entryById', { key: [ocl.idCode, type], @@ -64,7 +64,9 @@ function Structure(roc) { if (result.length) { return result[0]; } else { - throw new Error('Unexpected error creating structure'); + throw new Error('Unexpected error creating structure', { + cause: err, + }); } } } diff --git a/eln/stock/ACI/util.js b/eln/stock/ACI/util.js index 3efa4406..0cfd55d9 100644 --- a/eln/stock/ACI/util.js +++ b/eln/stock/ACI/util.js @@ -2,7 +2,7 @@ import _ from 'lodash'; import OCL from 'openchemlib'; import UI from 'src/util/ui'; -module.exports = function (roc, prefix) { +module.exports = function aciUtil(roc, prefix) { function getMoleculeWithSalts(options) { const { saltCode, idCode, nbSalts, value } = options; const oclid = idCode || value; @@ -212,7 +212,7 @@ module.exports = function (roc, prefix) { }; }; -var salts = { +const salts = { NX: { name: 'Free base', mf: '', diff --git a/eln/stock/printer/LabelRanges.js b/eln/stock/printer/LabelRanges.js index c592ddbc..4aea20bb 100644 --- a/eln/stock/printer/LabelRanges.js +++ b/eln/stock/printer/LabelRanges.js @@ -56,7 +56,6 @@ function expandRanges(data) { const extensions = ['from', 'to', 'format']; for (let key in data) { let field; - let value; for (let extension of extensions) { if (key.endsWith(`_${extension}`)) { field = key.replace(/_.*?$/, ''); diff --git a/eln/stock/printer/PrintServer.js b/eln/stock/printer/PrintServer.js index 6fc80f92..a01c3a33 100644 --- a/eln/stock/printer/PrintServer.js +++ b/eln/stock/printer/PrintServer.js @@ -1,4 +1,4 @@ -define(['superagent', 'uri/URI'], function (superagent, URI) { +define(['superagent', 'uri/URI'], (superagent, URI) => { class PrintServer { constructor(server, opts) { opts = opts || {}; diff --git a/eln/stock/printer/PrinterInstance.js b/eln/stock/printer/PrinterInstance.js index 411f590b..8b262dcb 100644 --- a/eln/stock/printer/PrinterInstance.js +++ b/eln/stock/printer/PrinterInstance.js @@ -3,7 +3,7 @@ define([ './printServerFactory', './printProcessors', '../../libs/MolecularFormula', -], function (Util, printServerFactory, processors, MolecularFormula) { +], (Util, printServerFactory, processors, MolecularFormula) => { class Printer { constructor(printer, printServer, opts) { this.url = String(printServer.url); @@ -50,7 +50,6 @@ define([ `${result.$content.general.mf}`, ); result.mfCanonic = mf.toMF(); - console.log(result.mfCanonic); } if (result.$content.general.description) { result.line1 = result.$content.general.description.substring( diff --git a/eln/stock/printer/ZebraPrintServer.js b/eln/stock/printer/ZebraPrintServer.js index 34276cd6..28ba6815 100644 --- a/eln/stock/printer/ZebraPrintServer.js +++ b/eln/stock/printer/ZebraPrintServer.js @@ -1,4 +1,4 @@ -define(['superagent', 'uri/URI'], function (superagent, URI) { +define(['superagent', 'uri/URI'], (superagent, URI) => { class ZebraPrintServer { constructor(server, opts) { this.server = server; diff --git a/eln/stock/printer/factory.js b/eln/stock/printer/factory.js index 69909894..b2c9a58f 100644 --- a/eln/stock/printer/factory.js +++ b/eln/stock/printer/factory.js @@ -1,12 +1,12 @@ import printer from './printer'; -module.exports = function (opts, cb) { +module.exports = function printerFactor(opts, cb) { if (typeof opts === 'function') { cb = opts; opts = {}; } if (typeof IframeBridge !== 'undefined') { - self.IframeBridge.onMessage(async function (data) { + self.IframeBridge.onMessage(async (data) => { if (data.type === 'tab.data') { let optsCopy = { ...opts }; if (data.message.printer && data.message.printer.couchDB) { diff --git a/eln/stock/printer/helper.js b/eln/stock/printer/helper.js index 040f59a0..d4b1f2f4 100644 --- a/eln/stock/printer/helper.js +++ b/eln/stock/printer/helper.js @@ -10,7 +10,6 @@ module.exports = { ...JSON.parse(JSON.stringify(printer)), formats: [], })); - console.log(varPrinterFormats); for (let i = 0; i < printers.length; i++) { for (let j = 0; j < types.length; j++) { const sFormats = (await printer.getFormats(printers[i], types[j])).map( @@ -33,7 +32,6 @@ module.exports = { await API.createData(`${types[j]}Formats`, varFormats[j]); } API.createData('varPrinterFormats', varPrinterFormats); - console.log(varPrinterFormats); }, async askPrintEntry(entry, type) { diff --git a/eln/stock/printer/printProcessors.js b/eln/stock/printer/printProcessors.js index 99f4400d..2c432e23 100644 --- a/eln/stock/printer/printProcessors.js +++ b/eln/stock/printer/printProcessors.js @@ -5,7 +5,7 @@ define([ 'canvg', '../../libs/Image', 'openchemlib', -], function (Datas, UI, twig, canvg, IJS, OCL) { +], (Datas, UI, twig, canvg, IJS, OCL) => { IJS = IJS.default; const DataObject = Datas.DataObject; let chars = @@ -175,12 +175,12 @@ define([ return decode(bmp); } - function concatenate(resultConstructor, ...arrays) { + function concatenate(ResultConstructor, ...arrays) { let totalLength = 0; for (let arr of arrays) { totalLength += arr.length; } - let result = new resultConstructor(totalLength); + let result = new ResultConstructor(totalLength); let offset = 0; for (let arr of arrays) { result.set(arr, offset); @@ -221,7 +221,7 @@ define([ function dataToHexa(arr) { return Array.prototype.map - .call(arr, function (n) { + .call(arr, (n) => { let hex = n.toString(16); if (hex.length === 1) hex = `0${hex}`; return hex; diff --git a/eln/stock/printer/printer.js b/eln/stock/printer/printer.js index a659ce1f..b4735642 100644 --- a/eln/stock/printer/printer.js +++ b/eln/stock/printer/printer.js @@ -4,11 +4,11 @@ define([ './printProcessors', './printServerFactory', '../../../rest-on-couch/Roc', -], function (API, Printer, processors, printServerFactory, Roc) { +], (API, Printer, processors, printServerFactory, Roc) => { const SECOND = 1000; const MINUTE = 60 * SECOND; const LIMIT = 11 * MINUTE; - return async function (opts) { + return async function stockPrinter(opts) { let printerRoc, formatsRoc, printServerRoc, @@ -88,7 +88,7 @@ define([ // printerFormat: uuid of the printer format or printer format document async print(printer, printFormat, data) { - printer = await printerRoc.get(printer); + const dbPrinter = await printerRoc.get(printer); if (printFormat.resurrect) { printFormat = printFormat.resurrect(); } @@ -99,9 +99,9 @@ define([ const printServer = printServers.find( (ps) => String(ps.$content.macAddress) === - String(printer.$content.macAddress), + String(dbPrinter.$content.macAddress), ); - const p = new Printer(printer.$content, printServer.$content, opts); + const p = new Printer(dbPrinter.$content, printServer.$content, opts); await p.print(printFormat.$content, data); }, @@ -139,7 +139,7 @@ define([ // get online printers that can print a given format async getPrinters(format) { if (!format) return onlinePrinters; - format = await formatsRoc.get(format); + const dbFormat = await formatsRoc.get(format); const onlineMacAdresses = onlinePrinters.map( (ps) => ps.$content.macAddress, ); @@ -147,7 +147,7 @@ define([ .filter((p) => onlineMacAdresses.includes(p.$content.macAddress)) .filter((p) => { return ( - format.$content.models.filter( + dbFormat.$content.models.filter( (m) => String(m.name) === String(p.$content.model), ).length > 0 ); @@ -155,8 +155,9 @@ define([ }, async getFormats(printer, type) { + let formats; if (!printer) { - var formats = printFormats.filter((f) => { + formats = printFormats.filter((f) => { return onlinePrinters.some((printer) => f.$content.models.some( (m) => String(m.name) === String(printer.$content.model), @@ -164,10 +165,10 @@ define([ ); }); } else { - printer = await printerRoc.get(printer); + const dbPrinter = await printerRoc.get(printer); formats = printFormats.filter((f) => f.$content.models.some( - (m) => String(m.name) === String(printer.$content.model), + (m) => String(m.name) === String(dbPrinter.$content.model), ), ); } diff --git a/eln/stock/search/chemexper.js b/eln/stock/search/chemexper.js index faf8e89d..3433bc68 100644 --- a/eln/stock/search/chemexper.js +++ b/eln/stock/search/chemexper.js @@ -1,4 +1,3 @@ -import _ from 'lodash'; import ui from 'src/util/ui'; import util from 'src/util/util'; import superagent from 'superagent'; diff --git a/eln/stock/search/chemspider.js b/eln/stock/search/chemspider.js index aa238599..49d68815 100644 --- a/eln/stock/search/chemspider.js +++ b/eln/stock/search/chemspider.js @@ -32,10 +32,10 @@ function fromChemspider(chemspider) { source: 'chemspider', }; - const name = (entry.$content.general.name = []); - const identifier = (entry.$content.identifier = {}); - const cas = (identifier.cas = []); - const CSID = (identifier.chemSpiderID = []); + const name = entry.$content.general.name ?? []; + const identifier = entry.$content.identifier ?? {}; + const cas = identifier.cas ?? []; + const CSID = identifier.chemSpiderID ?? []; const synonyms = chemspider.Synonyms; for (let i = 0; i < synonyms.length; i++) { const synonym = synonyms[i]; diff --git a/eln/stock/search/epfl.js b/eln/stock/search/epfl.js index 092276e2..c8a071ef 100644 --- a/eln/stock/search/epfl.js +++ b/eln/stock/search/epfl.js @@ -13,7 +13,7 @@ module.exports = { term, )}`, ) - .then(function (result) { + .then((result) => { result = result.body && result.body.entry; if (!result) { ui.showNotification('No results in reference DB', 'warn'); diff --git a/eln/stock/search/search.js b/eln/stock/search/search.js index 639167fa..8228ca74 100644 --- a/eln/stock/search/search.js +++ b/eln/stock/search/search.js @@ -33,7 +33,6 @@ module.exports = { endkey: ['sample', [`${term}\ufff0`, {}]], }) .then((data) => { - console.log(data); data.forEach((d) => { const status = d.$content && @@ -129,8 +128,8 @@ module.exports = { rowHeight: 150, }, }) - .catch(function (e) { - console.error(e); // eslint-disable-line no-console + .catch((err) => { + reportError(err); ui.showNotification('search failed', 'error'); }); }, diff --git a/eln/structureSearch/fromFile.js b/eln/structureSearch/fromFile.js index e5f8811a..a16759b1 100644 --- a/eln/structureSearch/fromFile.js +++ b/eln/structureSearch/fromFile.js @@ -4,7 +4,7 @@ import { OCL, OCLUtils } from '../libs/OCLUtils'; function waitImmediate() { return new Promise((resolve) => { - setImmediate(resolve); + window.setImmediate(resolve); }); } diff --git a/eln/taxonomy/renderer.js b/eln/taxonomy/renderer.js index 8e88f244..7a159d85 100644 --- a/eln/taxonomy/renderer.js +++ b/eln/taxonomy/renderer.js @@ -4,7 +4,6 @@ import { createTaxonomyTree } from '../../../../../../../../lib/mass-tools/7.8.2 import * as TreeSVG from '../../../../../../../../lib/react-tree-svg/0.1.1/react-tree-svg'; export function add() { - console.log(TreeSVG); TypeRenderer.addType('taxonomyTree', { toscreen($element, val, root, options = {}) { let taxonomies = val.code || val; diff --git a/eln/templates/TemplatesManager.js b/eln/templates/TemplatesManager.js index 5f1769a0..4a6d16dc 100644 --- a/eln/templates/TemplatesManager.js +++ b/eln/templates/TemplatesManager.js @@ -4,7 +4,7 @@ define([ 'src/util/api', 'vh/rest-on-couch/showRecordInfo', 'src/util/ui', -], function (Roc, getChangedGroups, API, showRecordInfo, UI) { +], (Roc, getChangedGroups, API, showRecordInfo, UI) => { class TemplatesManager { /** * @@ -29,7 +29,6 @@ define([ } async updateTemplate() { - console.log('UPDATE TEMPLATE'); const template = API.getData('currentTemplate'); await this.roc.update(template.value); this.refreshTemplates(); @@ -47,7 +46,7 @@ define([ this.refreshTemplates(); } - async createTemplate(options = {}) { + async createTemplate() { const form = await UI.form( `
@@ -102,7 +101,6 @@ define([ const template = await this.roc.create(templateEntry); await this.refreshTemplates(); - console.log(template); return template; } @@ -140,8 +138,6 @@ define([ let actionName = action.name; let actionValue = action.value; - console.log('ACTION:', actionName, actionValue); - switch (actionName) { case 'createTemplate': return this.createTemplate(options); @@ -157,6 +153,10 @@ define([ return this.editTemplateAccess(actionValue); case 'refreshTemplates': return this.refreshTemplates(); + default: { + // eslint-disable-next-line no-console + console.log(`TemplatesManager: unhandled action ${actionName}`); + } } } @@ -178,8 +178,6 @@ define([ async showTemplateInfo(entry) { const record = await this.roc.get(entry.id); - console.log('got record'); - console.log({ record }); return showRecordInfo(record); } } diff --git a/eln/templates/load.js b/eln/templates/load.js index b677078e..66dc2213 100644 --- a/eln/templates/load.js +++ b/eln/templates/load.js @@ -18,20 +18,22 @@ module.exports = async function load(categories, options = {}) { let templates; if (roc) { - await fetch(`${roc.url}/db/templates/_query/template?key=abcdef`) - .then(async (result) => { - if (result.status === 200) { - templates = await fetchAndLink(`${roc.url}`, categories); - if (!templates || templates.length === 0) { - templates = await fetchPublicAndLink(categories); - } - } else { + const result = await fetch( + `${roc.url}/db/templates/_query/template?key=abcdef`, + ); + + if (result.status === 200) { + try { + templates = await fetchAndLink(`${roc.url}`, categories); + if (!templates || templates.length === 0) { templates = await fetchPublicAndLink(categories); } - }) - .catch(async () => { + } catch { templates = await fetchPublicAndLink(categories); - }); + } + } else { + templates = await fetchPublicAndLink(categories); + } } else { templates = await fetchPublicAndLink(categories); } @@ -78,7 +80,10 @@ async function fetchPublicAndLink(categories) { return templates; } -async function fetchAndLink(url = 'https://mydb.cheminfo.org', categories) { +async function fetchAndLink( + url = 'https://mydb.cheminfo.org', + categories = undefined, +) { let templates = []; for (let category of categories) { let startkey = category; diff --git a/eln/templates/loadTwig.js b/eln/templates/loadTwig.js index 0f4e7819..0913c22c 100644 --- a/eln/templates/loadTwig.js +++ b/eln/templates/loadTwig.js @@ -6,7 +6,7 @@ module.exports = async function loadTwig(category, options = {}) { const { variableName = 'twigTemplate' } = options; try { - let templates = DataObject(await load(category)); + let templates = new DataObject(await load(category)); let twigTemplate = await templates.getChild([ '0', 'document', @@ -15,9 +15,8 @@ module.exports = async function loadTwig(category, options = {}) { ]); if (variableName) API.createData(variableName, twigTemplate); return twigTemplate; - } catch (e) { - // eslint-disable-next-line no-console - console.log(`No twig format found for ${category}`); + } catch (err) { + reportError(err); return ''; } }; diff --git a/eln/util/appendedDragAndDrop.js b/eln/util/appendedDragAndDrop.js index 30c96830..c813d748 100644 --- a/eln/util/appendedDragAndDrop.js +++ b/eln/util/appendedDragAndDrop.js @@ -32,7 +32,7 @@ export function appendedDragAndDrop(experimentalFiles, targetName) { target.push({ file }); } } else { - var type; + let type; if (String(file.encoding) === 'text') { type = getTargetType(String(file.content)); } else { diff --git a/eln/util/jcampInfo.js b/eln/util/jcampInfo.js index 0cbbb4b2..df0ae223 100644 --- a/eln/util/jcampInfo.js +++ b/eln/util/jcampInfo.js @@ -9,8 +9,6 @@ async function jcampInfo(value) { keepRecordsRegExp: /.*/, }).flatten[0]; - console.log(parsed); - let data = []; for (let key of Object.keys(parsed.meta)) { diff --git a/eln/util/newSampleDialog.js b/eln/util/newSampleDialog.js index 473d0c9a..fee5ecef 100644 --- a/eln/util/newSampleDialog.js +++ b/eln/util/newSampleDialog.js @@ -1,4 +1,4 @@ -define(['src/util/ui', 'lodash'], function (ui, _) { +define(['src/util/ui', 'lodash'], (ui, _) => { return async function createSample(roc, allGroups) { const storageKey = 'eln-new-sample-default-groups'; let entrysample = { $content: {} }; diff --git a/eln/zenodo/ZenodoUtils.js b/eln/zenodo/ZenodoUtils.js index 65d760ea..4d87cff0 100644 --- a/eln/zenodo/ZenodoUtils.js +++ b/eln/zenodo/ZenodoUtils.js @@ -229,7 +229,7 @@ export function getReadmeForDeposition(ZenodoDeposition) { '', ); if (Array.isArray(meta.creators) && meta.creators.length > 0) { - for (const [i, c] of meta.creators.entries()) { + for (const [, c] of meta.creators.entries()) { const identifiers = c.person_or_org.identifiers || []; if (identifiers.length === 0) { identifiers.push({ scheme: 'orcid', identifier: '' }); @@ -255,7 +255,7 @@ export function getReadmeForDeposition(ZenodoDeposition) { } if (Array.isArray(meta.contributors) && meta.contributors.length > 0) { md.push('', `## Contributors`, ''); - for (const [i, c] of meta.contributors.entries()) { + for (const [, c] of meta.contributors.entries()) { md.push( `- [**${c.person_or_org.name}**${ c.affiliations[0].name @@ -440,6 +440,7 @@ function getAdditionalDescription(description) { break; } } + return outputHTML; } export function getKeywordsForDeposition(samples) { diff --git a/eslint.config.mjs b/eslint.config.mjs index 2e98d653..53f345ea 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -6,8 +6,9 @@ export default defineConfig( globalIgnores([ 'node_modules', 'build', - 'tiles/font-awesome', + // Ignore third-party libraries + 'tiles/font-awesome', 'util/aesjs.js', 'util/cloneDeepLimitArray.js', 'util/md5.js', @@ -33,6 +34,8 @@ export default defineConfig( 'import/no-extraneous-dependencies': 'off', 'import/no-named-as-default': 'off', 'import/no-named-as-default-member': 'off', + 'no-await-in-loop': 'warn', + 'prefer-named-capture-group': 'off', }, }, ); diff --git a/moocs/answer.js b/moocs/answer.js index b2c3d5bd..e20a9293 100644 --- a/moocs/answer.js +++ b/moocs/answer.js @@ -1,7 +1,8 @@ -define(['mathjs'], function (mathjs) { +define(['mathjs'], (mathjs) => { let exports = {}; - exports.isCorrect = function (sol, ans, options) { + exports.isCorrect = function isCorrect(sol, ans, options) { + let errorUnit, solUnit, ansUnit, solU; sol = String(sol); ans = String(ans); options = { ...options }; @@ -11,7 +12,7 @@ define(['mathjs'], function (mathjs) { if (options.absoluteError !== undefined) { options.absoluteError = String(options.absoluteError); try { - var errorUnit = mathjs.unit(options.absoluteError); + errorUnit = mathjs.unit(options.absoluteError); } catch (e) { if (e.message.match(/no units/)) { options.absoluteError = +options.absoluteError; @@ -22,7 +23,7 @@ define(['mathjs'], function (mathjs) { } try { - var solUnit = mathjs.unit(String(sol)); + solUnit = mathjs.unit(String(sol)); } catch (e) { if (e.message.match(/no units/)) { sol = +sol; @@ -33,7 +34,7 @@ define(['mathjs'], function (mathjs) { reason: 'did not expect units in answer', }; } else { - return isCorrect(sol, ans, options); + return checkCorrectness(sol, ans, options); } } else { return { @@ -44,8 +45,8 @@ define(['mathjs'], function (mathjs) { } try { - var ansUnit = mathjs.unit(String(ans)); - var solU = solUnit.formatUnits(); + ansUnit = mathjs.unit(String(ans)); + solU = solUnit.formatUnits(); } catch (e) { return { correct: false, @@ -64,14 +65,14 @@ define(['mathjs'], function (mathjs) { if (errorUnit) { options.absoluteError = errorUnit.toNumber(solU); } - return isCorrect(sol, ans, options); + return checkCorrectness(sol, ans, options); } }; return exports; }); -function isCorrect(sol, ans, options) { +function checkCorrectness(sol, ans, options) { let absoluteError = options.absoluteError !== undefined && !isNaN(options.absoluteError) ? options.absoluteError diff --git a/moocs/exercisesManager.js b/moocs/exercisesManager.js index e3e53657..aec5f4d4 100644 --- a/moocs/exercisesManager.js +++ b/moocs/exercisesManager.js @@ -1,4 +1,4 @@ -define(['src/util/api'], function (API) { +define(['src/util/api'], (API) => { async function exercisesManager(action, allExercises, options) { switch (action) { case 'init': { @@ -60,8 +60,8 @@ define(['src/util/api'], function (API) { saveState(options.cookieName, state); return API.createData('exercises', selectedExercises).then( - function (exercises) { - exercises.onChange(function (evt) { + (exercises) => { + exercises.onChange((evt) => { if (evt.target.__name === 'myResult') { let target = evt.target.__parent; if (target) { diff --git a/moocs/stoechiometry.js b/moocs/stoechiometry.js index 78e0cbf3..bb050546 100644 --- a/moocs/stoechiometry.js +++ b/moocs/stoechiometry.js @@ -1,41 +1,41 @@ define([ 'https://www.lactame.com/lib/chemcalc/3.0.6/chemcalc.js', 'https://www.lactame.com/lib/ml/1.0.0/ml.js', -], function (CC, ml) { +], (CC, ml) => { let exports = {}; - exports.findCoefficients = function (reagents, products) { + exports.findCoefficients = function findCoefficient(reagents, products) { let atoms = {}; let nbCoeff = reagents.length + products.length; let matrix = new Array(nbCoeff); - for (var i = 0; i < nbCoeff; i++) { + for (let i = 0; i < nbCoeff; i++) { matrix[i] = []; } - for (i = 0; i < reagents.length; i++) { - var c = CC.analyseMF(reagents[i]); - var part = c.parts[0]; - for (var k = 0; k < part.ea.length; k++) { - var ea = part.ea[k]; + for (let i = 0; i < reagents.length; i++) { + const c = CC.analyseMF(reagents[i]); + const part = c.parts[0]; + for (let k = 0; k < part.ea.length; k++) { + const ea = part.ea[k]; atoms[ea.element] = true; - var idx = Object.keys(atoms).indexOf(ea.element); + const idx = Object.keys(atoms).indexOf(ea.element); matrix[i][idx] = part.ea[k].number; } } - for (i = reagents.length; i < nbCoeff; i++) { - c = CC.analyseMF(products[i - reagents.length]); - part = c.parts[0]; - for (k = 0; k < part.ea.length; k++) { - ea = part.ea[k]; + for (let i = reagents.length; i < nbCoeff; i++) { + const c = CC.analyseMF(products[i - reagents.length]); + const part = c.parts[0]; + for (let k = 0; k < part.ea.length; k++) { + const ea = part.ea[k]; atoms[ea.element] = true; - idx = Object.keys(atoms).indexOf(ea.element); + const idx = Object.keys(atoms).indexOf(ea.element); matrix[i][idx] = part.ea[k].number; } } let nbAtoms = Object.keys(atoms).length; - for (i = 0; i < nbCoeff; i++) { + for (let i = 0; i < nbCoeff; i++) { for (let j = 0; j < nbAtoms; j++) { if (matrix[i][j] === undefined) { matrix[i][j] = 0; @@ -51,9 +51,9 @@ define([ let result; if (!matrix.isSquare()) { if (matrix.rows - matrix.columns === -1) { - var trivialRow = new Array(matrix.columns).fill(0); + const trivialRow = new Array(matrix.columns).fill(0); trivialRow[0] = 1; - var e = new Array(matrix.columns).fill([0]); + const e = new Array(matrix.columns).fill([0]); e[matrix.columns - 1] = [1]; matrix.addRow(matrix.rows, trivialRow); @@ -62,13 +62,14 @@ define([ console.warn('cannot solve'); // eslint-disable-line no-console } } else { - let LU = ml.Matrix.Decompositions.LU(matrix); + // eslint-disable-next-line new-cap + const LU = ml.Matrix.Decompositions.LU(matrix); if (LU.isSingular()) { let diag0Pos = findDiag0Pos(LU.LU); - idx = LU.pivotVector.indexOf(diag0Pos); - trivialRow = new Array(matrix.columns).fill(0); + const idx = LU.pivotVector.indexOf(diag0Pos); + const trivialRow = new Array(matrix.columns).fill(0); trivialRow[idx] = 1; - e = new Array(matrix.columns).fill([0]); + const e = new Array(matrix.columns).fill([0]); e[idx] = [1]; matrix.setRow(idx, trivialRow); result = matrix.solve(e); @@ -81,15 +82,15 @@ define([ return result; }; - exports.formatResult = function (reagents, products, result) { + exports.formatResult = function formatResult(reagents, products, result) { let rstr = reagents - .map(function (value, index) { + .map((value, index) => { return `${result[index]}${value}`; }) .join(' + '); let pstr = products - .map(function (value, index) { + .map((value, index) => { return `${ result[reagents.length + index] }${value}`; diff --git a/on-tabs/.eslintrc.yml b/on-tabs/.eslintrc.yml deleted file mode 100644 index add5a785..00000000 --- a/on-tabs/.eslintrc.yml +++ /dev/null @@ -1,2 +0,0 @@ -parserOptions: - sourceType: module diff --git a/on-tabs/util.js b/on-tabs/util.js index 05b1c33d..8fd50d52 100644 --- a/on-tabs/util.js +++ b/on-tabs/util.js @@ -26,8 +26,8 @@ function onRocInit(data) { return false; } -function onDataFocus(dataId, tabId, type) { - return function (data) { +function createOnDataFocus(dataId, tabId, type) { + return function onDataFocus(data) { if (data.type === 'tab.focus') { let data; if (type === 'data') data = API.getData(dataId); @@ -51,10 +51,10 @@ module.exports = { }); }, sendCacheOnFocus(dataId, tabId) { - IB.onMessage(onDataFocus(dataId, tabId, 'cache')); + IB.onMessage(createOnDataFocus(dataId, tabId, 'cache')); }, sendDataOnFocus(dataId, tabId) { - IB.onMessage(onDataFocus(dataId, tabId, 'data')); + IB.onMessage(createOnDataFocus(dataId, tabId, 'data')); }, sendVariableOnChange(data, tabId) { data.onChange((event) => { @@ -75,7 +75,7 @@ module.exports = { }, // register callback to handle message of type 'message', without info about the sender onMessage(cb) { - IB.onMessage(function (data) { + IB.onMessage((data) => { if (data.type === 'tab.message') { cb(data.message); } diff --git a/package.json b/package.json index 0dddb4d3..8d3e0b19 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "version": "0.0.0", "description": "", "scripts": { - "babel": "babel . --out-dir ./build", + "babel-test": "babel . --config-file=./test-build.babel.mjs --out-dir ./build", "eslint": "eslint . --cache", "eslint-fix": "npm run eslint -- --fix", "prettier": "prettier --check .", diff --git a/rest-on-couch/Roc.js b/rest-on-couch/Roc.js index 68c2edb8..68329be4 100644 --- a/rest-on-couch/Roc.js +++ b/rest-on-couch/Roc.js @@ -13,7 +13,7 @@ define([ 'eventEmitter', './UserViewPrefs', './UserAnalysisResults', -], function ( +], ( Datas, API, ui, @@ -28,14 +28,14 @@ define([ EventEmitter, UserViewPrefs, UserAnalysisResults, -) { +) => { const DataObject = Datas.DataObject; const eventEmitters = {}; const objectHasOwnProperty = Object.prototype.hasOwnProperty; - const hasOwnProperty = function (obj, prop) { + function hasOwnProperty(obj, prop) { return objectHasOwnProperty.call(obj, prop); - }; + } function setTabSavedStatus(saved) { if (self.IframeBridge) { @@ -220,7 +220,7 @@ define([ credentials: 'include', }) ).json(); - } catch (e) { + } catch { this.setUserPrefs(defaultPrefs); return defaultPrefs; } @@ -288,8 +288,8 @@ define([ } return res.body; }) - .then(handleSuccess(this, options)) - .catch(handleError(this, options)); + .then(createHandleSuccess(this, options)) + .catch(createHandleError(this, options)); } async queryBySampleId(options) { @@ -314,8 +314,8 @@ define([ } return res.body; }) - .then(handleSuccess(this, options)) - .catch(handleError(this, options)); + .then(createHandleSuccess(this, options)) + .catch(createHandleError(this, options)); } async query(viewName, options) { @@ -372,8 +372,8 @@ define([ } return res.body; }) - .then(handleSuccess(this, options)) - .catch(handleError(this, options)); + .then(createHandleSuccess(this, options)) + .catch(createHandleError(this, options)); } getDocumentEventEmitter(uuid) { @@ -499,8 +499,8 @@ define([ return res.body; } return null; - } catch (e) { - handleError(this, options); + } catch { + createHandleError(this, options); return null; } } @@ -519,7 +519,7 @@ define([ } return null; }) - .catch(handleError(this, options)) + .catch(createHandleError(this, options)) ); } @@ -546,7 +546,7 @@ define([ } return null; }) - .catch(handleError(this, options)); + .catch(createHandleError(this, options)); } async getById(id, options) { @@ -556,7 +556,7 @@ define([ if (!entry || options.fromCache) { return entry; } - return this.get(entry).catch(handleError(this, options)); + return this.get(entry).catch(createHandleError(this, options)); } // Get the groups the user is owner of @@ -571,7 +571,7 @@ define([ .get(groupUrl) .withCredentials() .then((res) => res.body) - .catch(handleError(this, options)); + .catch(createHandleError(this, options)); } // Get basic info about every group (only name and description) @@ -586,7 +586,7 @@ define([ .get(groupsInfoUrl) .withCredentials() .then((res) => res.body) - .catch(handleError(this, options)); + .catch(createHandleError(this, options)); } // Get the groups the user is member of @@ -599,7 +599,7 @@ define([ .get(url) .withCredentials() .then((res) => res.body) - .catch(handleError(this, options)); + .catch(createHandleError(this, options)); } async create(entry, options) { @@ -613,7 +613,7 @@ define([ .post(this.entryUrl) .withCredentials() .send(entry) - .then(handleSuccess(this, options)) + .then(createHandleSuccess(this, options)) .then((res) => { if (res.body && (res.status === 200 || res.status === 201)) { return this.get(res.body.id); @@ -639,7 +639,7 @@ define([ } return entry; }) - .catch(handleError(this, options)); + .catch(createHandleError(this, options)); } async getLastRevision(entry) { @@ -657,7 +657,7 @@ define([ .put(`${this.entryUrl}/${String(entry._id)}`) .withCredentials() .send(reqEntry) - .then(handleSuccess(this, options)) + .then(createHandleSuccess(this, options)) .then((res) => { if (res.body && res.status === 200) { entry._rev = res.body.rev; @@ -672,14 +672,14 @@ define([ } return entry; }) - .catch(handleError(this, options)); + .catch(createHandleError(this, options)); } async deleteAttachment(entry, attachments, options) { await this.__ready; options = createOptions(options, 'deleteAttachment'); if (DataObject.getType(entry) !== 'object') { - handleError(this, options)(new Error('invalid argument')); + createHandleError(this, options)(new Error('invalid argument')); return null; } if (Array.isArray(attachments) && attachments.length === 0) return entry; @@ -706,10 +706,10 @@ define([ await this.update(entry, options); } else if (entry.triggerChange && !options.noTrigger) { entry.triggerChange(); - handleSuccess(this, options)(entry); + createHandleSuccess(this, options)(entry); } } catch (e) { - return handleError(this, options)(e); + return createHandleError(this, options)(e); } return entry; } @@ -803,9 +803,9 @@ define([ this.typeUrl(entry.$content, entry); await this.update(entry); } catch (e) { - return handleError(this, attachOptions)(e); + return createHandleError(this, attachOptions)(e); } - handleSuccess(this, attachOptions)(entry); + createHandleSuccess(this, attachOptions)(entry); return entry; } @@ -837,9 +837,9 @@ define([ this.typeUrl(entry.$content, entry); await this.update(entry); } catch (e) { - return handleError(this, attachOptions)(e); + return createHandleError(this, attachOptions)(e); } - handleSuccess(this, attachOptions)(entry); + createHandleSuccess(this, attachOptions)(entry); return entry; } @@ -855,7 +855,7 @@ define([ }); try { await idb.delete(uuid); - } catch (e) { + } catch { // ignored error } // Track data again @@ -868,7 +868,7 @@ define([ await this.__ready; options = createOptions(options, 'getAttachment'); const cdb = this._getCdb(entry); - return cdb.get(name, options).catch(handleError(this, options)); + return cdb.get(name, options).catch(createHandleError(this, options)); } async getAttachmentList(entry) { @@ -933,9 +933,9 @@ define([ entry.triggerChange(); } } catch (e) { - return handleError(this, options)(e); + return createHandleError(this, options)(e); } - handleSuccess(this, options)(entry); + createHandleSuccess(this, options)(entry); return entry; } @@ -957,9 +957,9 @@ define([ return superagent .get(tokenUrl) .withCredentials() - .then(handleSuccess(this, options)) + .then(createHandleSuccess(this, options)) .then((res) => res.body) - .catch(handleError(this, options)); + .catch(createHandleError(this, options)); } async getToken(token, options) { @@ -973,9 +973,9 @@ define([ return superagent .get(tokenUrl) .withCredentials() - .then(handleSuccess(this, options)) + .then(createHandleSuccess(this, options)) .then((res) => res.body) - .catch(handleError(this, options)); + .catch(createHandleError(this, options)); } async createToken(entry, options) { @@ -993,9 +993,9 @@ define([ request.query({ rights }); } return request - .then(handleSuccess(this, options)) + .then(createHandleSuccess(this, options)) .then((res) => res.body) - .catch(handleError(this, options)); + .catch(createHandleError(this, options)); } async createUserToken(options) { @@ -1012,9 +1012,9 @@ define([ request.query({ rights }); } return request - .then(handleSuccess(this, options)) + .then(createHandleSuccess(this, options)) .then((res) => res.body) - .catch(handleError(this, options)); + .catch(createHandleError(this, options)); } async deleteToken(token, options) { @@ -1028,9 +1028,9 @@ define([ return superagent .del(tokenUrl) .withCredentials() - .then(handleSuccess(this, options)) + .then(createHandleSuccess(this, options)) .then((res) => res.body) - .catch(handleError(this, options)); + .catch(createHandleError(this, options)); } async addGroup(entry, group, options, remove) { @@ -1046,7 +1046,7 @@ define([ `${this.entryUrl}/${uuid}/_owner/${String(group)}`, ) .withCredentials() - .then(handleSuccess(this, options)) + .then(createHandleSuccess(this, options)) .then((res) => { if (!options.noUpdate) { return this.get(uuid).then(() => res.body); @@ -1054,7 +1054,7 @@ define([ return res.body; } }) - .catch(handleError(this, options)); + .catch(createHandleError(this, options)); } deleteGroup(entry, group, options) { @@ -1068,7 +1068,7 @@ define([ return superagent .del(`${this.entryUrl}/${uuid}`) .withCredentials() - .then(handleSuccess(this, options)) + .then(createHandleSuccess(this, options)) .then((res) => { if (res.body && res.status === 200) { for (let key in this.variables) { @@ -1083,7 +1083,7 @@ define([ } return res.body; }) - .catch(handleError(this, options)); + .catch(createHandleError(this, options)); } remove(entry, options) { @@ -1256,7 +1256,7 @@ define([ if (!Array.isArray(filename) && typeof filename !== 'undefined') { filename = [filename]; } - this._traverseFilename(v, function (v) { + this._traverseFilename(v, (v) => { if (typeof filename === 'undefined') { r.push(v); } else if (filename.indexOf(String(v.filename)) !== -1) { @@ -1333,8 +1333,8 @@ define([ return options; } - function handleError(ctx, options) { - return function (err) { + function createHandleError(ctx, options) { + return function handleError(err) { if (!options.mute || !options.muteError) { if (err.status || err.timeout) { // error comes from superagent @@ -1348,8 +1348,8 @@ define([ }; } - function handleSuccess(ctx, options) { - return function (data) { + function createHandleSuccess(ctx, options) { + return function handleSuccess(data) { if (!options.mute && !options.muteSuccess) { if (data.status) { handleSuperagentSuccess(data, ctx, options); diff --git a/rest-on-couch/UserAnalysisResults.js b/rest-on-couch/UserAnalysisResults.js index 16bac685..f271f62c 100644 --- a/rest-on-couch/UserAnalysisResults.js +++ b/rest-on-couch/UserAnalysisResults.js @@ -1,8 +1,7 @@ -define([ - '../util/getViewInfo', - 'src/util/api', - 'src/util/couchdbAttachments', -], function (getViewInfo, API) { +define(['../util/getViewInfo', 'src/util/api', 'src/util/couchdbAttachments'], ( + getViewInfo, + API, +) => { class UserAnalysisResults { constructor(roc, sampleID) { this.roc = roc; @@ -38,7 +37,10 @@ define([ */ async loadResults(key, options = {}) { if (!this.roc) { - console.log('Can not retrieve results, not connected to roc'); + // eslint-disable-next-line no-console + console.log( + 'UserAnalysisResults: cannnot retrieve results, not connected to roc', + ); return; } const { sampleID = this.sampleID } = options; @@ -59,7 +61,6 @@ define([ /* if (sampleID) { return entries.filter((entry) => entry.$id[2].match(/^[0-9a-f]{32}$/i)); }*/ - console.log({ entries }); return entries; } @@ -78,7 +79,6 @@ define([ return loadTemplateFromLocalStorage(this.viewID, String(entry._id)); } this.lastEntry = entry; - console.log(this.lastEntry); return this.roc.getAttachment(entry, 'result.json'); } @@ -106,7 +106,6 @@ define([ if (!entry._id) entry._id = entry.id; entry = await this.roc.get(entry); entry.$content = meta; - console.log({ entry }); await this.roc.update(entry); } else { entry = await this.roc.create({ diff --git a/rest-on-couch/UserViewPrefs.js b/rest-on-couch/UserViewPrefs.js index c2595bc0..2d0839c7 100644 --- a/rest-on-couch/UserViewPrefs.js +++ b/rest-on-couch/UserViewPrefs.js @@ -1,4 +1,4 @@ -define(['../util/getViewInfo'], function (getViewInfo) { +define(['../util/getViewInfo'], (getViewInfo) => { class UserViewPrefs { constructor(roc) { this.roc = roc; diff --git a/rest-on-couch/factory.js b/rest-on-couch/factory.js index 97b42402..fa9d0b67 100644 --- a/rest-on-couch/factory.js +++ b/rest-on-couch/factory.js @@ -1,11 +1,11 @@ -define(['./Roc'], function (Roc) { - return function (opts, cb) { +define(['./Roc'], (Roc) => { + return function rocFactory(opts, cb) { if (typeof opts === 'function') { cb = opts; opts = {}; } if (typeof IframeBridge !== 'undefined') { - self.IframeBridge.onMessage(function (data) { + self.IframeBridge.onMessage((data) => { if (data.type === 'tab.data') { if (data.message.couchDB) { const options = { ...data.message.couchDB, ...opts }; diff --git a/rest-on-couch/getChangedGroups.js b/rest-on-couch/getChangedGroups.js index 1949d332..0ef33e0e 100644 --- a/rest-on-couch/getChangedGroups.js +++ b/rest-on-couch/getChangedGroups.js @@ -1,4 +1,4 @@ -define(['src/util/ui', 'lodash'], function (UI, _) { +define(['src/util/ui', 'lodash'], (UI, _) => { function editGroups(record, allGroups) { const groups = JSON.parse(JSON.stringify(allGroups)); const groupNames = groups.map((group) => group.name); @@ -43,7 +43,7 @@ define(['src/util/ui', 'lodash'], function (UI, _) { `, { groups }, { twig: { groups } }, - ).then(function (result) { + ).then((result) => { if (!result) return undefined; let groups = result.groups; let add = groups diff --git a/rest-on-couch/showRecordInfo.js b/rest-on-couch/showRecordInfo.js index d6e44d98..1e1ab89c 100644 --- a/rest-on-couch/showRecordInfo.js +++ b/rest-on-couch/showRecordInfo.js @@ -1,4 +1,4 @@ -define(['src/util/ui'], function (UI) { +define(['src/util/ui'], (UI) => { function showRecordInfo(record) { let html = ''; html += `