Skip to content

Commit

Permalink
chore: update ESLint config and lint all js code
Browse files Browse the repository at this point in the history
  • Loading branch information
targos committed Jul 19, 2024
1 parent 054c457 commit 487fb01
Show file tree
Hide file tree
Showing 30 changed files with 1,586 additions and 1,974 deletions.
1 change: 0 additions & 1 deletion .eslintignore

This file was deleted.

9 changes: 0 additions & 9 deletions .eslintrc.yml

This file was deleted.

6 changes: 6 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CHANGELOG.md
dist
distold
gwt
openchemlib
war
2 changes: 1 addition & 1 deletion __tests__/SmilesParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ it('should should optionally not invent coordinates', () => {

it('should should optionally not parse stereo features', () => {
const parser = new SmilesParser();
const vitaminA = 'C/C(=C\\CO)/C=C/C=C(/C)\\C=C\\C1=C(C)CCCC1(C)C';
const vitaminA = String.raw`C/C(=C\CO)/C=C/C=C(/C)\C=C\C1=C(C)CCCC1(C)C`;
const molecule = new Molecule(0, 0);
parser.parseMolecule(vitaminA, { molecule, noStereo: true });
const idCodeWithoutStereo = molecule.getIDCode();
Expand Down
12 changes: 6 additions & 6 deletions __tests__/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ test('core', () => {
});

test('full', () => {
[full, pretty].forEach((lib) => {
for (const lib of [full, pretty]) {
checkHas(lib, allAPI);
});
}
});

allAPI.forEach((key) => {
for (const key of allAPI) {
const api = full[key];
if (typeof api === 'function') {
test(`static properties of ${key}`, () => {
Expand All @@ -64,16 +64,16 @@ allAPI.forEach((key) => {
});
}
}
});
}

function checkHas(obj, properties) {
expect(Object.keys(obj).sort()).toStrictEqual(properties.sort());
}

function checkHasNot(obj, properties) {
properties.forEach((prop) => {
for (const prop of properties) {
expect(obj).not.toHaveProperty(prop);
});
}
}

function getFilteredKeys(obj) {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/molecule.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const fs = require('fs');
const fs = require('node:fs');

const { Molecule } = require('../minimal');

Expand Down
6 changes: 3 additions & 3 deletions __tests__/molfileAndAtomMapNo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ test('molfile with atomMapNo', () => {
const newMolfile = molecule.toMolfile();
const atomMapNo = newMolfile
.split(/\r?\n/)
.filter((line) => line.match(/ [OCH] /))
// eslint-disable-next-line prefer-named-capture-group
.filter((line) => line.match(/ [CHO] /))
.map((line) =>
line.replace(/.* (?<och>[OCH]) .*(?<n>.) {2}0 {2}0$/, '$<och> $<n>'),
line.replace(/.* (?<och>[CHO]) .*(?<n>.) {2}0 {2}0$/, '$<och> $<n>'),
);

expect(atomMapNo).toStrictEqual(['O 5', 'C 1', 'C 3', 'C 4', 'H 2']);

const svg = molecule.toSVG(300, 200);
Expand Down
3 changes: 1 addition & 2 deletions __tests__/sssearcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ describe('SSSearcher', () => {
let benzeneFragment = Molecule.fromSmiles('c1ccccc1');
benzeneFragment.setFragment(true);
let ethylBenzene = Molecule.fromSmiles('CCc1ccccc1');
let allicin = Molecule.fromSmiles('O=S(SC\\C=C)C\\C=C');

let allicin = Molecule.fromSmiles(String.raw`O=S(SC\C=C)C\C=C`);
it('should find in itself', () => {
let searcher = new SSSearcher();
searcher.setMolecule(benzene);
Expand Down
2 changes: 1 addition & 1 deletion __tests__/sssearcher_with_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ function getTestData() {
const ethylBenzene = Molecule.fromSmiles('CCc1ccccc1');
const ethylBenzeneIndex = searcher.createIndex(ethylBenzene);

const allicin = Molecule.fromSmiles('O=S(SC\\C=C)C\\C=C');
const allicin = Molecule.fromSmiles(String.raw`O=S(SC\C=C)C\C=C`);
const allicinIndex = searcher.createIndex(allicin);
return {
benzene,
Expand Down
3 changes: 0 additions & 3 deletions benchmark/.eslintrc.yml

This file was deleted.

24 changes: 0 additions & 24 deletions benchmark/diastereoID.js

This file was deleted.

16 changes: 16 additions & 0 deletions benchmark/diastereoID.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { getDiastereotopicAtomIDs } from 'openchemlib-utils';

import { Molecule, version } from '../full.js';

console.log('OCL version', version);
console.time('diastereoID');
const response = await fetch('https://wikipedia.cheminfo.org/data.json');
const { data } = await response.json();
let totalLength = 0;
for (const entry of data.molecules.slice(0, 700)) {
const molecule = Molecule.fromIDCode(entry.idCode);
const ids = getDiastereotopicAtomIDs(molecule);
totalLength += ids.length;
}
console.timeEnd('diastereoID');
console.log(totalLength);
8 changes: 3 additions & 5 deletions benchmark/molfile.js → benchmark/molfile.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
'use strict';
import Benchmark from 'benchmark';

const Benchmark = require('benchmark');

const OCLOld = require('../distold/openchemlib-full.pretty');
const OCLNew = require('../full.pretty');
import OCLOld from '../distold/openchemlib-full.pretty.js';
import OCLNew from '../full.pretty.js';

const idcode = 'enYXNH@MHDAELem`OCIILdhhdiheCDlieKDdefndZRVVjjfjjfjihJBbb@@@';
const mol = OCLNew.Molecule.fromIDCode(idcode);
Expand Down
8 changes: 3 additions & 5 deletions benchmark/sssearcher.js → benchmark/sssearcher.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
'use strict';
import Benchmark from 'benchmark';

const Benchmark = require('benchmark');

const OCLOld = require('../distold/openchemlib-full.pretty');
const OCLNew = require('../full.pretty');
import OCLOld from '../distold/openchemlib-full.pretty.js';
import OCLNew from '../full.pretty.js';

let benzeneFragmentNew = OCLNew.Molecule.fromSmiles('c1ccccc1');
benzeneFragmentNew.setFragment(true);
Expand Down
22 changes: 0 additions & 22 deletions benchmark/wikipedia.js

This file was deleted.

14 changes: 14 additions & 0 deletions benchmark/wikipedia.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Molecule, version } from '../full.js';

console.log('OCL version', version);
console.time('wikipedia');
const response = await fetch('https://wikipedia.cheminfo.org/data.json');
const { data } = await response.json();
const idCodes = [];
for (const entry of data.molecules.slice(0, 10000)) {
const molecule = Molecule.fromIDCode(entry.idCode);
const idCode = molecule.getIDCode();
idCodes.push(idCode);
}
console.timeEnd('wikipedia');
console.log(idCodes.join(',').length);
63 changes: 63 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import cheminfo from 'eslint-config-cheminfo/base';
import unicorn from 'eslint-config-cheminfo/unicorn';
import globals from 'globals';

export default [
{
ignores: [
'dist/**',
'distold/**',
'examples/**',
'gwt/**',
'scripts/stringWidthDataGenerator.js',
'war/**',
],
},
...cheminfo,
...unicorn,
{
files: ['*.js'],
languageOptions: {
sourceType: 'commonjs',
},
},
{
files: ['__tests__/**'],
languageOptions: {
globals: {
...globals.node,
...globals.jest,
},
sourceType: 'commonjs',
},
},
{
files: ['benchmark/**'],
languageOptions: {
globals: {
...globals.node,
},
},
rules: {
'no-console': 'off',
},
},
{
files: ['scripts/**'],
languageOptions: {
globals: {
...globals.node,
},
sourceType: 'commonjs',
},
rules: {
'unicorn/no-process-exit': 'off',
},
},
{
files: ['tests/**'],
rules: {
'no-console': 'off',
},
},
];
4 changes: 0 additions & 4 deletions examples/.eslintrc.yml

This file was deleted.

2 changes: 1 addition & 1 deletion full.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ export {
SVGRenderer,
AtomHighlightCallback,
BondHighlightCallback,
ChangeListenerCallback
ChangeListenerCallback,
} from './types';
Loading

0 comments on commit 487fb01

Please sign in to comment.