Skip to content

Commit b394ede

Browse files
gauravclaude
andcommitted
Fix Biome lint errors in JS source files.
Applied safe fixes (arrow functions, node: protocol prefixes) via `biome lint --write --unsafe`, then manually converted forEach calls to for...of loops to satisfy the noForEach rule. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 7de1ac6 commit b394ede

File tree

4 files changed

+49
-49
lines changed

4 files changed

+49
-49
lines changed

phyx2ontology/phyx2ontology.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ const MAX_INTERNAL_SPECIFIERS = process.env.MAX_INTERNAL_SPECIFIERS || 7;
1616
const MAX_EXTERNAL_SPECIFIERS = process.env.MAX_EXTERNAL_SPECIFIERS || 10;
1717

1818
// Load necessary modules.
19-
const fs = require('fs');
20-
const path = require('path');
19+
const fs = require('node:fs');
20+
const path = require('node:path');
2121
const yargs = require('yargs');
2222

2323
// Load phyx.js, our PHYX library.
@@ -111,8 +111,8 @@ const jsons = phyxFiles
111111
/* Convert every phyloreference (from every Phyx file) into a JSON-LD object. */
112112
const phylorefsByLabel = {};
113113
const phylorefs = [];
114-
jsons.forEach((phyxFile) => {
115-
phyxFile.phylorefs.forEach((phyloref) => {
114+
for (const phyxFile of jsons) {
115+
for (const phyloref of phyxFile.phylorefs) {
116116
// Convert phyloreference to JSON-LD.
117117
entityIndex += 1;
118118
const phylorefWrapper = new phyx.PhylorefWrapper(phyloref);
@@ -122,13 +122,13 @@ jsons.forEach((phyxFile) => {
122122
console.warn(`Phyloreference ${phylorefWrapper.label} has `
123123
+ `${phylorefWrapper.internalSpecifiers.length} internal specifiers but `
124124
+ `the limit is ${MAX_INTERNAL_SPECIFIERS}`);
125-
return;
125+
continue;
126126
}
127127
if (phylorefWrapper.externalSpecifiers.length > MAX_EXTERNAL_SPECIFIERS) {
128128
console.warn(`Phyloreference ${phylorefWrapper.label} has `
129129
+ `${phylorefWrapper.externalSpecifiers.length} external specifiers but `
130130
+ `the limit is ${MAX_EXTERNAL_SPECIFIERS}`);
131-
return;
131+
continue;
132132
}
133133

134134
// Convert to OWL/JSON-LD.
@@ -143,13 +143,13 @@ jsons.forEach((phyxFile) => {
143143
// Set a JSON-LD context so this block can be interpreted in isolation.
144144
jsonld['@context'] = PHYX_CONTEXT_JSON;
145145
phylorefs.push(jsonld);
146-
});
147-
});
146+
}
147+
}
148148

149149
/* Convert every phylogeny (from every Phyx file) into a JSON-LD object. */
150150
const phylogenies = [];
151-
jsons.forEach((phyxFile) => {
152-
phyxFile.phylogenies.forEach((phylogeny) => {
151+
for (const phyxFile of jsons) {
152+
for (const phylogeny of phyxFile.phylogenies) {
153153
// Convert phylogenies into JSON-LD.
154154
entityIndex += 1;
155155
const phylogenyAsJSONLD = new phyx.PhylogenyWrapper(phylogeny)
@@ -158,8 +158,8 @@ jsons.forEach((phyxFile) => {
158158
// Set a '@context' so it can be interpreted from other objects in the output file.
159159
phylogenyAsJSONLD['@context'] = PHYX_CONTEXT_JSON;
160160
phylogenies.push(phylogenyAsJSONLD);
161-
});
162-
});
161+
}
162+
}
163163

164164
/* Construct an object to represent the Clade Ontology itself. */
165165
let cladeOntologyObjects = [

regnum2phyx/regnum2phyx.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ const ICN_NAME = 'http://purl.obolibrary.org/obo/NOMEN_0000109';
2323
// const ICTV_NAME = 'http://purl.obolibrary.org/obo/NOMEN_0000111';
2424

2525
// Load necessary modules.
26-
const fs = require('fs');
27-
const path = require('path');
26+
const fs = require('node:fs');
27+
const path = require('node:path');
2828
const yargs = require('yargs');
2929
const {
3030
has, keys, pickBy, isEmpty,
@@ -161,7 +161,7 @@ function convertCitationsToBibJSON(citation) {
161161
});
162162

163163
// Since we've moved pages and ISBN into journal, we don't also need it in the main entry.
164-
if (has(entry, 'pages')) delete entry.pages;
164+
if (has(entry, 'pages')) entry.pages = undefined;
165165
} else {
166166
process.stderr.write(`Unknown citation type: '${type}', using anyway.`);
167167
}
@@ -264,7 +264,7 @@ dump.forEach((entry, index) => {
264264
);
265265

266266
// Convert each specifier into one
267-
(entry.specifiers || []).forEach((specifier) => {
267+
for (const specifier of (entry.specifiers || [])) {
268268
const kind = specifier.specifier_kind || '';
269269
let addTo = [];
270270
if (kind.startsWith('internal')) addTo = phylorefTemplate.internalSpecifiers;
@@ -320,7 +320,7 @@ dump.forEach((entry, index) => {
320320
};
321321

322322
addTo.push(specifierTemplate);
323-
});
323+
}
324324

325325
// Prepare a simple Phyx file template.
326326
const phyxTemplate = pickBy({

test/regnum2phyx/exec.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
*/
44

55
// Javascript libraries.
6-
const ChildProcess = require('child_process');
7-
const fs = require('fs');
6+
const ChildProcess = require('node:child_process');
7+
const fs = require('node:fs');
88

99
const tmp = require('tmp');
1010
const chai = require('chai');
@@ -19,9 +19,9 @@ function loadJSON(filename) {
1919
return JSON.parse(content);
2020
}
2121

22-
describe('Test regnum2phyx.js', function () {
23-
fs.readdirSync(`${__dirname}/examples`).forEach(function (filename) {
24-
describe(`Processing example Regnum dump: ${filename}`, function () {
22+
describe('Test regnum2phyx.js', () => {
23+
for (const filename of fs.readdirSync(`${__dirname}/examples`)) {
24+
describe(`Processing example Regnum dump: ${filename}`, () => {
2525
const filepath = `${__dirname}/examples/${filename}`;
2626

2727
// We only test '.json' files.
@@ -47,7 +47,7 @@ describe('Test regnum2phyx.js', function () {
4747
}
4848
);
4949

50-
it('could be executed by regnum2phyx.js', function () {
50+
it('could be executed by regnum2phyx.js', () => {
5151
expect(child.stderr).to.be.empty;
5252
expect(child.stdout).to.match(/^(\d+) Phyx files produced successfully.\n$/);
5353
expect(child.status).to.equal(0);
@@ -59,17 +59,17 @@ describe('Test regnum2phyx.js', function () {
5959
const producedFiles = fs.readdirSync(`${tmpdirname}`);
6060
const expectedFiles = fs.readdirSync(`${__dirname}/expected/${basename}`);
6161

62-
it('should produce the expected files', function () {
62+
it('should produce the expected files', () => {
6363
expect(producedFiles).to.deep.equal(expectedFiles);
6464
expect(producedFiles).to.not.be.empty;
6565
});
6666

67-
producedFiles.forEach(function (producedFile) {
68-
describe(`Testing produced file ${producedFile}`, function () {
67+
for (const producedFile of producedFiles) {
68+
describe(`Testing produced file ${producedFile}`, () => {
6969
const producedPhyx = loadJSON(`${tmpdirname}/${producedFile}`);
7070
const expectedPhyx = loadJSON(`${__dirname}/expected/${basename}/${producedFile}`);
7171

72-
it('should be identical to expected', function () {
72+
it('should be identical to expected', () => {
7373
expect(producedPhyx).to.deep.equal(expectedPhyx);
7474
});
7575

@@ -80,14 +80,14 @@ describe('Test regnum2phyx.js', function () {
8080
const phyxSchema = ajvInstance.compile(phyxSchemaJSON);
8181
const result = phyxSchema(producedPhyx);
8282

83-
it('should validate against the Phyx JSON Schema', function () {
84-
(phyxSchema.errors || []).forEach(function (error) {
83+
it('should validate against the Phyx JSON Schema', () => {
84+
for (const error of (phyxSchema.errors || [])) {
8585
assert.fail(ajvInstance.errorsText([error]));
86-
});
86+
}
8787
expect(result).is.true;
8888
});
8989
});
90-
});
90+
}
9191
});
92-
});
92+
}
9393
});

test/test_phyx.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ const BASE_DIR = 'phyx/';
1717
const phyx = require('@phyloref/phyx');
1818

1919
// Javascript libraries.
20-
const ChildProcess = require('child_process');
21-
const fs = require('fs');
22-
const path = require('path');
20+
const ChildProcess = require('node:child_process');
21+
const fs = require('node:fs');
22+
const path = require('node:path');
2323

2424
const Ajv = require('ajv');
2525
const chai = require('chai');
@@ -57,7 +57,7 @@ const phyxSchema = ajvInstance.compile(phyxSchemaJSON);
5757
* to get that list before we start testing.
5858
*/
5959
function findPhyxFiles(dirPath) {
60-
return fs.readdirSync(dirPath).map(function (filename) {
60+
return fs.readdirSync(dirPath).map((filename) => {
6161
const filePath = path.join(dirPath, filename);
6262

6363
if (fs.lstatSync(filePath).isDirectory()) {
@@ -72,12 +72,12 @@ function findPhyxFiles(dirPath) {
7272
}).reduce((x, y) => x.concat(y), []); // This flattens the list of results.
7373
}
7474

75-
describe('Test Phyx files in repository', function () {
75+
describe('Test Phyx files in repository', () => {
7676
// Test each input file.
77-
findPhyxFiles(BASE_DIR).forEach(function (filename) {
78-
describe(`Phyx file: ${filename}`, function () {
77+
for (const filename of findPhyxFiles(BASE_DIR)) {
78+
describe(`Phyx file: ${filename}`, () => {
7979
// Make sure the file to test isn't empty.
80-
it('is not empty', function () {
80+
it('is not empty', () => {
8181
const stats = fs.lstatSync(filename);
8282
assert.notEqual(stats.size, 0);
8383
});
@@ -95,7 +95,7 @@ describe('Test Phyx files in repository', function () {
9595
const phyxContent = data.toString('utf-8');
9696
const json = JSON.parse(phyxContent);
9797
// Remove the .skip once the Phyx files pass validation.
98-
it.skip('should validate against the Phyx JSON Schema', function () {
98+
it.skip('should validate against the Phyx JSON Schema', () => {
9999
const result = phyxSchema(json);
100100
const errorStrings = (phyxSchema.errors || []).map(err => ajvInstance.errorsText([err]));
101101
assert.deepEqual(errorStrings, []);
@@ -108,13 +108,13 @@ describe('Test Phyx files in repository', function () {
108108
try {
109109
wrappedPhyx = new phyx.PhyxWrapper(json);
110110
} catch (ex) {
111-
it('Exception thrown while loading Phyx to JSON-LD', function () {
111+
it('Exception thrown while loading Phyx to JSON-LD', () => {
112112
throw ex;
113113
});
114114
return;
115115
}
116116

117-
it('has at least one Newick phylogeny', function () {
117+
it('has at least one Newick phylogeny', () => {
118118
const phylogenies = json.phylogenies || [];
119119
// assert.isAbove(phylogenies.length, 0, 'No phylogenies found in file');
120120

@@ -166,7 +166,7 @@ describe('Test Phyx files in repository', function () {
166166
const jsonld = JSON.stringify(wrappedPhyx.asJSONLD());
167167

168168
// Make sure the produced JSON-LD is not empty.
169-
it('produced a non-empty JSON-LD ontology without throwing an exception', function () {
169+
it('produced a non-empty JSON-LD ontology without throwing an exception', () => {
170170
assert.isNotEmpty(jsonld);
171171
});
172172

@@ -198,12 +198,12 @@ describe('Test Phyx files in repository', function () {
198198
// console.log(`For ${filename}: ${matches}`);
199199

200200
// Test whether we have any failures.
201-
it('did not report any failures', function () {
201+
it('did not report any failures', () => {
202202
const failures = matches[2];
203203
assert.equal(failures, 0, `${failures} failures occurred during testing`);
204204
});
205205

206-
describe('test the results of resolution', function () {
206+
describe('test the results of resolution', () => {
207207
// Look for TODOs or skipped tests.
208208
const successes = matches[1];
209209
const todos = matches[3];
@@ -226,18 +226,18 @@ describe('Test Phyx files in repository', function () {
226226
// We could have zero failures but also zero successes. A Phyx file
227227
// without any failures, TODOs or any successes in the Clade Ontology
228228
// should be reported as a failure.
229-
it('had at least one success', function () {
229+
it('had at least one success', () => {
230230
assert.isAbove(successes, 0, 'No successes occurred during testing');
231231
});
232232

233233
// On the off chance that all of the above made sense but the exit code didn't,
234234
// we'll check that here.
235-
it('passed testing in JPhyloRef', function () {
235+
it('passed testing in JPhyloRef', () => {
236236
assert.equal(child.status, 0, 'Exit code from JPhyloRef was not zero');
237237
});
238238
});
239239
}
240240
}
241241
});
242-
});
242+
}
243243
});

0 commit comments

Comments
 (0)