Skip to content

Commit

Permalink
Relinted source code.
Browse files Browse the repository at this point in the history
  • Loading branch information
gaurav committed May 8, 2024
1 parent fe40751 commit 063f6e1
Show file tree
Hide file tree
Showing 19 changed files with 95 additions and 59 deletions.
45 changes: 24 additions & 21 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
{
"extends": [
"airbnb-base",
"plugin:mocha/recommended"
],
"parserOptions": {
"parser": "babel-eslint",
"ecmaVersion": 6,
"sourceType": "module"
},
"env": {
"es6": true
},
"plugins": [
"mocha",
"json-format"
],
"rules": {
"prefer-destructuring": "off",
"comma-dangle": ["error", {
"extends": [
"airbnb-base",
"plugin:mocha/recommended"
],
"parserOptions": {
"parser": "babel-eslint",
"ecmaVersion": 6,
"sourceType": "module"
},
"env": {
"es6": true
},
"plugins": [
"mocha",
"json-format"
],
"rules": {
"prefer-destructuring": "off",
"comma-dangle": [
"error",
{
"arrays": "always-multiline",
"objects": "always-multiline",
"imports": "always-multiline",
"exports": "always-multiline",
"functions": "ignore"
}]
}
}
]
}
}
2 changes: 1 addition & 1 deletion src/matchers/TaxonomicUnitMatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class TaxonomicUnitMatcher {
const externalRefs2 = wrappedTUnit2.externalReferences;

return externalRefs1.some(
extref1 => externalRefs2.some(
(extref1) => externalRefs2.some(
(extref2) => {
if (
extref1
Expand Down
1 change: 0 additions & 1 deletion src/utils/owlterms.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

// Some OWL constants to be used.
module.exports = {
// Where is our context file located?
Expand Down
14 changes: 7 additions & 7 deletions src/wrappers/CitationWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ class CitationWrapper {

// Add DOIs and URLs.
additionalInfo += (this.citation.identifier || [])
.filter(id => id.type === 'doi')
.map(doi => ` doi: ${doi.id}`)
.filter((id) => id.type === 'doi')
.map((doi) => ` doi: ${doi.id}`)
.join('');
additionalInfo += (this.citation.link || []).map(link => ` URL: ${link.url}`).join('');
additionalInfo += (this.citation.link || []).map((link) => ` URL: ${link.url}`).join('');

additionalInfo += (this.citation.identifier || [])
.filter(id => id.type === 'isbn')
.map(isbn => ` ISBN: ${isbn.id}`)
.filter((id) => id.type === 'isbn')
.map((isbn) => ` ISBN: ${isbn.id}`)
.join('');

// A citation for a journal article should be different from others.
Expand All @@ -86,8 +86,8 @@ class CitationWrapper {
const journalIssue = (has(journal, 'number')) ? `(${journal.number})` : '';
const pages = (has(journal, 'pages')) ? `:${journal.pages}` : '';
additionalInfo += (journal.identifier || [])
.filter(id => id.type === 'issn')
.map(issn => `ISSN: ${issn.id} `)
.filter((id) => id.type === 'issn')
.map((issn) => `ISSN: ${issn.id} `)
.join('');
return `${authorsAndTitle} ${journal.name || 'Unknown journal'} ${journal.volume || 'Unknown volume'}${journalIssue}${pages}${additionalInfo}`;
}
Expand Down
20 changes: 10 additions & 10 deletions src/wrappers/PhylogenyWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ class PhylogenyWrapper {
const tunits = new Set();

nodeLabels.forEach(
nodeLabel => this.getTaxonomicUnitsForNodeLabel(nodeLabel)
.forEach(tunit => tunits.add(tunit))
(nodeLabel) => this.getTaxonomicUnitsForNodeLabel(nodeLabel)
.forEach((tunit) => tunits.add(tunit))
);

return tunits;
Expand All @@ -160,8 +160,8 @@ class PhylogenyWrapper {
return Array.from(
new Set(
Array.from(vertices)
.map(vertex => vertex.label)
.filter(label => label !== undefined)
.map((vertex) => vertex.label)
.filter((label) => label !== undefined)
)
);
}
Expand All @@ -170,8 +170,8 @@ class PhylogenyWrapper {
// Return the internal nodes (those with atleast one child).
return Array.from(new Set(
Array.from(arcs)
.map(arc => arc[0].label) // Retrieve the label of the parent vertex in this arc.
.filter(label => label !== undefined)
.map((arc) => arc[0].label) // Retrieve the label of the parent vertex in this arc.
.filter((label) => label !== undefined)
));
}

Expand All @@ -188,7 +188,7 @@ class PhylogenyWrapper {
const allLabels = this.getNodeLabels('both');
const internalLabels = new Set(this.getNodeLabels('internal'));

return allLabels.filter(label => !internalLabels.has(label));
return allLabels.filter((label) => !internalLabels.has(label));
}

throw new Error(`Unknown nodeType: '${nodeType}'`);
Expand Down Expand Up @@ -241,7 +241,7 @@ class PhylogenyWrapper {
// Attempt pairwise matches between taxonomic units in the specifier
// and associated with the node.
return nodeTUnits.some(
tunit => new TaxonomicUnitMatcher(specifier, tunit).matched
(tunit) => new TaxonomicUnitMatcher(specifier, tunit).matched
);
});
}
Expand Down Expand Up @@ -399,7 +399,7 @@ class PhylogenyWrapper {
Object.keys(nodeIdsByParentId).forEach((parentId) => {
// What are the children of this parentId?
const childrenIDs = Array.from(nodeIdsByParentId[parentId]);
const children = childrenIDs.map(childId => nodesById[childId]);
const children = childrenIDs.map((childId) => nodesById[childId]);

// Is this the root node?
if (has(nodesById, parentId)) {
Expand All @@ -410,7 +410,7 @@ class PhylogenyWrapper {
children.forEach((child) => {
const childToModify = child;
// Add all other sibling to node.siblings, but don't add this node itself!
childToModify.siblings = childrenIDs.filter(childId => childId !== child['@id']);
childToModify.siblings = childrenIDs.filter((childId) => childId !== child['@id']);
});
});

Expand Down
18 changes: 8 additions & 10 deletions src/wrappers/PhylorefWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ class PhylorefWrapper {
// owlterms.UNKNOWN_CODEs, then that is still usable as a default
// nomenclatural code for this phyloreference.
const uniqNomenCodesNoUnknowns = this.uniqNomenCodes
.filter(code => code !== owlterms.UNKNOWN_CODE);
.filter((code) => code !== owlterms.UNKNOWN_CODE);
if (uniqNomenCodesNoUnknowns.length === 1) return uniqNomenCodesNoUnknowns[0];

return owlterms.UNKNOWN_CODE;
Expand Down Expand Up @@ -576,15 +576,15 @@ class PhylorefWrapper {
// selected internals -- when there are fewer, we'll just end up with the inverses
// of the previous comparisons, which we'll already have covered.
if (remainingInternals.length > 1 && selected.length <= remainingInternals.length) {
remainingInternals.map(newlySelected => this.createClassExpressionsForInternals(
remainingInternals.map((newlySelected) => this.createClassExpressionsForInternals(
jsonld,
// The new remaining is the old remaining minus the selected TU.
remainingInternals.filter(i => i !== newlySelected),
remainingInternals.filter((i) => i !== newlySelected),
// The new selected is the old selected plus the selected TU.
selected.concat([newlySelected])
))
.reduce((acc, val) => acc.concat(val), [])
.forEach(expr => classExprs.push(expr));
.forEach((expr) => classExprs.push(expr));
}

return classExprs;
Expand Down Expand Up @@ -675,7 +675,7 @@ class PhylorefWrapper {
logicalExpressions = externalSpecifiers.map((selectedExternal) => {
// Add the internal specifiers.
const intersectionExprs = internalSpecifiers.map(
sp => this.getIncludesRestrictionForTU(sp)
(sp) => this.getIncludesRestrictionForTU(sp)
);

// Add the selected external specifier.
Expand All @@ -689,7 +689,7 @@ class PhylorefWrapper {
});

// Collect all of the externals that are not selected.
const remainingExternals = externalSpecifiers.filter(ex => ex !== selectedExternal);
const remainingExternals = externalSpecifiers.filter((ex) => ex !== selectedExternal);

// Add the remaining externals, which we assume will resolve outside of
// this clade.
Expand Down Expand Up @@ -718,9 +718,7 @@ class PhylorefWrapper {

// We only have internal specifiers. We therefore need to use the algorithm in
// this.createClassExpressionsForInternals() to create this expression.
logicalExpressions = this.createClassExpressionsForInternals(
phylorefAsJSONLD, internalSpecifiers, []
);
logicalExpressions = this.createClassExpressionsForInternals(phylorefAsJSONLD, internalSpecifiers, []);

Check failure on line 721 in src/wrappers/PhylorefWrapper.js

View workflow job for this annotation

GitHub Actions / build (18.x)

This line has a length of 109. Maximum allowed is 100

Check failure on line 721 in src/wrappers/PhylorefWrapper.js

View workflow job for this annotation

GitHub Actions / build (20.x)

This line has a length of 109. Maximum allowed is 100
}

// If we have a single logical expression, we set that as an equivalentClass
Expand Down Expand Up @@ -758,7 +756,7 @@ class PhylorefWrapper {
// 2. We need to set each of these component classes to be a subclass of
// this phyloreference so that it can include instances from each of the
// logical expressions.
phylorefAsJSONLD.subClasses = logicalExpressions.map(classExpr => this.createComponentClass(
phylorefAsJSONLD.subClasses = logicalExpressions.map((classExpr) => this.createComponentClass(
phylorefAsJSONLD,
internalSpecifiers,
externalSpecifiers,
Expand Down
2 changes: 1 addition & 1 deletion src/wrappers/PhyxWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class PhyxWrapper {
get defaultNomenCode() {
if (has(this.phyx, 'defaultNomenclaturalCodeIRI')) return this.phyx.defaultNomenclaturalCodeIRI;
const nomenCodes = (this.phyx.phylorefs || [])
.map(phyloref => new PhylorefWrapper(phyloref).defaultNomenCode);
.map((phyloref) => new PhylorefWrapper(phyloref).defaultNomenCode);
const uniqNomenCodes = uniq(nomenCodes);
if (uniqNomenCodes.length === 1) return uniqNomenCodes[0];
return owlterms.UNKNOWN_CODE;
Expand Down
2 changes: 1 addition & 1 deletion src/wrappers/SpecimenWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class SpecimenWrapper {
'file://',
'urn:',
];
if (URL_URN_PREFIXES.filter(prefix => occurID.toLowerCase().startsWith(prefix)).length > 0) {
if (URL_URN_PREFIXES.filter((prefix) => occurID.toLowerCase().startsWith(prefix)).length > 0) {
return specimen;
}

Expand Down
2 changes: 1 addition & 1 deletion src/wrappers/TaxonNameWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class TaxonNameWrapper {

// Look for the entry with the same IRI as the provided IRI.
const matchingCode = codes
.find(code => (code.iri || '').toLowerCase() === nomenCode.toLowerCase());
.find((code) => (code.iri || '').toLowerCase() === nomenCode.toLowerCase());
if (matchingCode) return matchingCode;
return undefined;
}
Expand Down
4 changes: 2 additions & 2 deletions src/wrappers/TaxonomicUnitWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class TaxonomicUnitWrapper {
const externalReferences = this.externalReferences;
if (externalReferences.length > 0) {
return externalReferences
.map(externalRef => `<${externalRef}>`)
.map((externalRef) => `<${externalRef}>`)
.join(' and ');
}

Expand Down Expand Up @@ -180,7 +180,7 @@ class TaxonomicUnitWrapper {
'urn:',
];

if (URL_URN_PREFIXES.filter(prefix => nodeLabel.startsWith(prefix)).length > 0) {
if (URL_URN_PREFIXES.filter((prefix) => nodeLabel.startsWith(prefix)).length > 0) {
// The node label starts with something that looks like a URL!
// Treat it as an external reference.
if (tunit === undefined) tunit = {};
Expand Down
2 changes: 1 addition & 1 deletion test/examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('PhyxWrapper', function () {

describe('Test all correct example Phyx files', function () {
const examples = fs.readdirSync(path.resolve(__dirname, './examples/correct'))
.filter(filename => filename.endsWith('.json'));
.filter((filename) => filename.endsWith('.json'));

examples.forEach((example) => {
const basename = path.resolve(__dirname, './examples/correct', path.parse(example).name);
Expand Down
2 changes: 1 addition & 1 deletion test/jphyloref.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('JPhyloRef', function () {

describe('test example JSON-LD files using JPhyloRef', function () {
fs.readdirSync(path.resolve(__dirname, 'examples', 'correct'))
.filter(filename => filename.endsWith('.nq'))
.filter((filename) => filename.endsWith('.nq'))
.forEach((filename) => {
it(`testing ${filename}`, function () {
this.timeout(60000);
Expand Down
2 changes: 2 additions & 0 deletions test/phylogenies.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,15 @@ describe('PhylogenyWrapper', function () {
expect(jsonld).to.have.property('@id');
expect(jsonld['@id']).to.equal('#providedId');
});

it('should generate a new @id on input phylorefs', function () {
const jsonld = new phyx.PhylogenyWrapper({
newick: '((Homo_sapiens, Panthera_tigris), Mus_musculus)',
}, owlterms.ICZN_CODE).asJSONLD('#phylogeny0');
expect(jsonld).to.have.property('@id');
expect(jsonld['@id']).to.equal('#phylogeny0');
});

it('should generate the phylogeny in JSON-LD as expected', function () {
const expectedResults = [
{
Expand Down
2 changes: 2 additions & 0 deletions test/phylorefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ describe('PhylorefWrapper', function () {
expect(jsonld).to.have.property('@id');
expect(jsonld['@id']).to.equal('#providedId');
});

it('should generate a new @id on input phylorefs', function () {
const jsonld = new phyx.PhylorefWrapper({
internalSpecifiers: [specifier1],
Expand All @@ -266,6 +267,7 @@ describe('PhylorefWrapper', function () {
expect(jsonld).to.have.property('@id');
expect(jsonld['@id']).to.equal('#phyloref0');
});

it('should generate the expected equivClass expression for 1 int, 1 ext phyloref', function () {
const jsonld = new phyx.PhylorefWrapper({
internalSpecifiers: [specifier1],
Expand Down
7 changes: 5 additions & 2 deletions test/scripts/phyx2owl.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describe(PHYX2OWL_JS, function () {
expect(result.stdout).to.be.empty;
expect(result.stderr).to.contain('No input files provided.');
});

it('should support `--help`', function () {
const result = child.spawnSync(PHYX2OWL_JS, ['--help'], {
encoding: 'utf-8',
Expand All @@ -35,6 +36,7 @@ describe(PHYX2OWL_JS, function () {
expect(result.stderr).to.be.empty;
expect(result.stdout).to.contain('phyx2owl.js [files or directories to convert into OWL ontologies]');
});

it('should be able to convert `brochu_2003.json`', function () {
const PHYX_FILE = path.resolve(__dirname, '../examples/correct/brochu_2003.json');
const NQ_FILE = path.resolve(__dirname, '../examples/correct/brochu_2003.nq');
Expand Down Expand Up @@ -62,10 +64,11 @@ describe(PHYX2OWL_JS, function () {
const nqExpected = fs.readFileSync(NQ_FILE, 'utf8');
expect(nqGenerated).to.equal(nqExpected);
});

it('should be able to convert the entire `test/examples/correct` directory', function () {
const EXAMPLE_DIR = path.resolve(__dirname, '../examples/correct');
const jsonFilesInExamples = fs.readdirSync(EXAMPLE_DIR, 'utf8')
.filter(fileName => fileName.toLowerCase().endsWith('.json'));
.filter((fileName) => fileName.toLowerCase().endsWith('.json'));

const result = child.spawnSync(PHYX2OWL_JS, [EXAMPLE_DIR, '--base-iri', 'http://example.org/phyx.js/example#'], {
encoding: 'utf-8',
Expand All @@ -82,7 +85,7 @@ describe(PHYX2OWL_JS, function () {

// Make sure that the generated files *look* like JSON-LD files.
fs.readdirSync(EXAMPLE_DIR, 'utf8')
.filter(fileName => fileName.toLowerCase().endsWith('.owl'))
.filter((fileName) => fileName.toLowerCase().endsWith('.owl'))
.forEach((owlFilename) => {
const nqGenerated = fs.readFileSync(path.resolve(EXAMPLE_DIR, owlFilename), 'utf8');

Expand Down
3 changes: 3 additions & 0 deletions test/scripts/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ describe('bin/resolve.js', function () {
expect(result.stdout).to.be.empty;
expect(result.stderr).to.contain('No input files provided.');
});

it('should support `--help`', function () {
const result = child.spawnSync(RESOLVE_JS, ['--help'], {
encoding: 'utf-8',
Expand All @@ -36,6 +37,7 @@ describe('bin/resolve.js', function () {
expect(result.stderr).to.be.empty;
expect(result.stdout).to.contain('resolve.js [files to resolve on the Open Tree of Life]');
});

it('should provide the expected results on the `brochu_2003.json` example file', function () {
var resultObj; // eslint-disable-line no-var

Expand Down Expand Up @@ -77,6 +79,7 @@ describe('bin/resolve.js', function () {
error: 'no_mrca_found:400',
});
});

it('should correctly report errors with certain phyloreferences', function () {
var resultObj; // eslint-disable-line no-var

Expand Down
Loading

0 comments on commit 063f6e1

Please sign in to comment.