Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add disambiguateByNonOperator disambiguator #6540

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs_app/assets/images/marble-diagrams/concatAll.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 15 additions & 19 deletions docs_app/tools/transforms/links-package/index.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
var Package = require('dgeni').Package;
var jsdocPackage = require('dgeni-packages/jsdoc');

module.exports =
new Package('links', [jsdocPackage])
module.exports = new Package('links', [jsdocPackage])

.factory(require('./inline-tag-defs/link'))
.factory(require('./services/getAliases'))
.factory(require('./services/getDocFromAlias'))
.factory(require('./services/getLinkInfo'))
.factory(require('./services/disambiguators/disambiguateByDeprecated'))
.factory(require('./services/disambiguators/disambiguateByModule'))
.factory(require('./services/disambiguators/disambiguateByNonMember'))
.factory(require('./inline-tag-defs/link'))
.factory(require('./services/getAliases'))
.factory(require('./services/getDocFromAlias'))
.factory(require('./services/getLinkInfo'))
.factory(require('./services/disambiguators/disambiguateByDeprecated'))
.factory(require('./services/disambiguators/disambiguateByNonMember'))
.factory(require('./services/disambiguators/disambiguateByModule'))
.factory(require('./services/disambiguators/disambiguateByNonOperator'))

.config(function (inlineTagProcessor, linkInlineTagDef) {
inlineTagProcessor.inlineTagDefinitions.push(linkInlineTagDef);
})
.config(function (inlineTagProcessor, linkInlineTagDef) {
inlineTagProcessor.inlineTagDefinitions.push(linkInlineTagDef);
})

.config(function (getDocFromAlias, disambiguateByDeprecated, disambiguateByNonMember, disambiguateByModule) {
getDocFromAlias.disambiguators = [
disambiguateByDeprecated,
disambiguateByNonMember,
disambiguateByModule
];
});
.config(function (getDocFromAlias, disambiguateByDeprecated, disambiguateByNonMember, disambiguateByModule, disambiguateByNonOperator) {
getDocFromAlias.disambiguators = [disambiguateByDeprecated, disambiguateByNonMember, disambiguateByModule, disambiguateByNonOperator];
});
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
module.exports = function disambiguateByDeprecated() {
return (alias, originatingDoc, docs) => docs.filter(doc => doc.deprecated === undefined);
return (alias, originatingDoc, docs) => {
const filteredDocs = docs.filter((doc) => doc.deprecated === undefined);
return filteredDocs.length > 0 ? filteredDocs : docs;
};
};
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
const disambiguateByDeprecated = require('./disambiguateByDeprecated')();
const docs = [
{ id: 'doc1' },
{ id: 'doc2', deprecated: true },
{ id: 'doc3', deprecated: '' },
{ id: 'doc4' },
{ id: 'doc5', deprecated: 'Some text' },
];
const doc1 = { id: 'doc1' };
const doc2 = { id: 'doc2', deprecated: true };
const doc3 = { id: 'doc3', deprecated: '' };
const doc4 = { id: 'doc4' };
const doc5 = { id: 'doc5', deprecated: 'Some text' };

describe('disambiguateByDeprecated', () => {
it('should filter out docs whose `deprecated` property is defined', () => {
expect(disambiguateByDeprecated('alias', {}, docs)).toEqual([
{ id: 'doc1' },
{ id: 'doc4' },
]);
expect(disambiguateByDeprecated('alias', {}, [doc1, doc2, doc3, doc4, doc5])).toEqual([doc1, doc4]);
});
});

it('should not filter docs if all of them are `deprecated`', () => {
expect(disambiguateByDeprecated('alias', {}, [doc2, doc3, doc5])).toEqual([doc2, doc3, doc5]);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* This link disambiguator will remove all the members from the list of ambiguous links
* if there is at least one link to a doc that does not belong to 'operators' module.
* TODO Remove this disambiguator once 'rxjs/operators' export is removed
*/
module.exports = function disambiguateByNonOperator() {
return (alias, originatingDoc, docs) => {
const filteredDocs = docs.filter((doc) => doc.moduleDoc.id !== 'operators');
return filteredDocs.length > 0 ? filteredDocs : docs;
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const disambiguateByNonOperator = require('./disambiguateByNonOperator')();
const indexModule = { id: 'index' };
const operatorsModule = { id: 'operators' };
const doc1 = { id: 'doc1', moduleDoc: indexModule };
const doc2 = { id: 'doc2', moduleDoc: operatorsModule };
const doc3 = { id: 'doc3', moduleDoc: operatorsModule };
const doc4 = { id: 'doc4', moduleDoc: indexModule };

describe('disambiguateByNonOperator', () => {
it('should filter out docs that are not operators', () => {
const docs = [doc1, doc2];
expect(disambiguateByNonOperator('alias', {}, docs)).toEqual([doc1]);
});

it('should return all docs if there are no operators', () => {
const docs = [doc1, doc4];
expect(disambiguateByNonOperator('alias', {}, docs)).toEqual([doc1, doc4]);
});

it('should return all docs if there are only operators', () => {
const docs = [doc2, doc3];
expect(disambiguateByNonOperator('alias', {}, docs)).toEqual([doc2, doc3]);
});
});