Skip to content

Commit

Permalink
fix(module): Remove empty comment blocks of merge target modules
Browse files Browse the repository at this point in the history
Closes #142
  • Loading branch information
christopherthielen committed Jan 14, 2020
1 parent 89b4141 commit c800a22
Show file tree
Hide file tree
Showing 13 changed files with 254 additions and 4 deletions.
16 changes: 12 additions & 4 deletions plugin.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Reflection, ReflectionKind } from 'typedoc/dist/lib/models/reflections/abstract';
import { DeclarationReflection } from 'typedoc/dist/lib/models/reflections/declaration';
import { Component, ConverterComponent } from 'typedoc/dist/lib/converter/components';
import { Converter } from 'typedoc/dist/lib/converter/converter';
import { Context } from 'typedoc/dist/lib/converter/context';
import { Converter } from 'typedoc/dist/lib/converter/converter';
import { CommentPlugin } from 'typedoc/dist/lib/converter/plugins/CommentPlugin';
import { Comment } from 'typedoc/dist/lib/models';
import { Reflection, ReflectionKind } from 'typedoc/dist/lib/models/reflections/abstract';
import { ContainerReflection } from 'typedoc/dist/lib/models/reflections/container';
import { DeclarationReflection } from 'typedoc/dist/lib/models/reflections/declaration';
import { getRawComment } from './getRawComment';

/**
Expand Down Expand Up @@ -63,7 +64,7 @@ export class ExternalModuleNamePlugin extends ConverterComponent {
* @param node The node that is currently processed if available.
*/
private onDeclaration(context: Context, reflection: Reflection, node?) {
if (reflection.kindOf(ReflectionKind.ExternalModule)) {
if (reflection.kindOf(ReflectionKind.ExternalModule) || reflection.kindOf(ReflectionKind.Module)) {
let comment = getRawComment(node);
// Look for @module
let match = /@module\s+([\w\u4e00-\u9fa5\.\-_/@"]+)/.exec(comment);
Expand Down Expand Up @@ -160,10 +161,17 @@ export class ExternalModuleNamePlugin extends ConverterComponent {
// Remove @module and @preferred from the comment, if found.
CommentPlugin.removeTags(mergeTarget.comment, 'module');
CommentPlugin.removeTags(mergeTarget.comment, 'preferred');
if (isEmptyComment(mergeTarget.comment)) {
delete mergeTarget.comment;
}
});
}
}

function isEmptyComment(comment: Comment) {
return !comment || (!comment.text && !comment.shortText && (!comment.tags || comment.tags.length === 0));
}

interface ModuleRename {
renameTo: string;
preferred: boolean;
Expand Down
22 changes: 22 additions & 0 deletions test/typedoc-0.10.0/cypress/integration/example_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,28 @@ describe('docs', () => {
.contains('File2');
});

it('renders File1 doc comment', () => {
cy.visit('/');

cy.get('a')
.contains('root')
.click();
cy.get('a')
.contains('File1')
.click();

cy.contains('This is in the root module');
});

it('does not render empty comment blocks where @module used to be', () => {
cy.visit('/');

cy.get('a')
.contains('root')
.click();
cy.get('section.tsd-comment').should('not.exist');
});

it('renders Nest1 in dir1', () => {
cy.visit('/');

Expand Down
22 changes: 22 additions & 0 deletions test/typedoc-0.11.1/cypress/integration/example_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,28 @@ describe('docs', () => {
.contains('File2');
});

it('renders File1 doc comment', () => {
cy.visit('/');

cy.get('a')
.contains('root')
.click();
cy.get('a')
.contains('File1')
.click();

cy.contains('This is in the root module');
});

it('does not render empty comment blocks where @module used to be', () => {
cy.visit('/');

cy.get('a')
.contains('root')
.click();
cy.get('section.tsd-comment').should('not.exist');
});

it('renders Nest1 in dir1', () => {
cy.visit('/');

Expand Down
22 changes: 22 additions & 0 deletions test/typedoc-0.12.0/cypress/integration/example_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,28 @@ describe('docs', () => {
.contains('File2');
});

it('renders File1 doc comment', () => {
cy.visit('/');

cy.get('a')
.contains('root')
.click();
cy.get('a')
.contains('File1')
.click();

cy.contains('This is in the root module');
});

it('does not render empty comment blocks where @module used to be', () => {
cy.visit('/');

cy.get('a')
.contains('root')
.click();
cy.get('section.tsd-comment').should('not.exist');
});

it('renders Nest1 in dir1', () => {
cy.visit('/');

Expand Down
22 changes: 22 additions & 0 deletions test/typedoc-0.13.0/cypress/integration/example_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,28 @@ describe('docs', () => {
.contains('File2');
});

it('renders File1 doc comment', () => {
cy.visit('/');

cy.get('a')
.contains('root')
.click();
cy.get('a')
.contains('File1')
.click();

cy.contains('This is in the root module');
});

it('does not render empty comment blocks where @module used to be', () => {
cy.visit('/');

cy.get('a')
.contains('root')
.click();
cy.get('section.tsd-comment').should('not.exist');
});

it('renders Nest1 in dir1', () => {
cy.visit('/');

Expand Down
22 changes: 22 additions & 0 deletions test/typedoc-0.14.0/cypress/integration/example_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,28 @@ describe('docs', () => {
.contains('File2');
});

it('renders File1 doc comment', () => {
cy.visit('/');

cy.get('a')
.contains('root')
.click();
cy.get('a')
.contains('File1')
.click();

cy.contains('This is in the root module');
});

it('does not render empty comment blocks where @module used to be', () => {
cy.visit('/');

cy.get('a')
.contains('root')
.click();
cy.get('section.tsd-comment').should('not.exist');
});

it('renders Nest1 in dir1', () => {
cy.visit('/');

Expand Down
22 changes: 22 additions & 0 deletions test/typedoc-0.5.10/cypress/integration/example_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,28 @@ describe('docs', () => {
.contains('File2');
});

it('renders File1 doc comment', () => {
cy.visit('/');

cy.get('a')
.contains('root')
.click();
cy.get('a')
.contains('File1')
.click();

cy.contains('This is in the root module');
});

it('does not render empty comment blocks where @module used to be', () => {
cy.visit('/');

cy.get('a')
.contains('root')
.click();
cy.get('section.tsd-comment').should('not.exist');
});

it('renders Nest1 in dir1', () => {
cy.visit('/');

Expand Down
22 changes: 22 additions & 0 deletions test/typedoc-0.6.0/cypress/integration/example_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,28 @@ describe('docs', () => {
.contains('File2');
});

it('renders File1 doc comment', () => {
cy.visit('/');

cy.get('a')
.contains('root')
.click();
cy.get('a')
.contains('File1')
.click();

cy.contains('This is in the root module');
});

it('does not render empty comment blocks where @module used to be', () => {
cy.visit('/');

cy.get('a')
.contains('root')
.click();
cy.get('section.tsd-comment').should('not.exist');
});

it('renders Nest1 in dir1', () => {
cy.visit('/');

Expand Down
22 changes: 22 additions & 0 deletions test/typedoc-0.7.2/cypress/integration/example_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,28 @@ describe('docs', () => {
.contains('File2');
});

it('renders File1 doc comment', () => {
cy.visit('/');

cy.get('a')
.contains('root')
.click();
cy.get('a')
.contains('File1')
.click();

cy.contains('This is in the root module');
});

it('does not render empty comment blocks where @module used to be', () => {
cy.visit('/');

cy.get('a')
.contains('root')
.click();
cy.get('section.tsd-comment').should('not.exist');
});

it('renders Nest1 in dir1', () => {
cy.visit('/');

Expand Down
22 changes: 22 additions & 0 deletions test/typedoc-0.8.0/cypress/integration/example_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,28 @@ describe('docs', () => {
.contains('File2');
});

it('renders File1 doc comment', () => {
cy.visit('/');

cy.get('a')
.contains('root')
.click();
cy.get('a')
.contains('File1')
.click();

cy.contains('This is in the root module');
});

it('does not render empty comment blocks where @module used to be', () => {
cy.visit('/');

cy.get('a')
.contains('root')
.click();
cy.get('section.tsd-comment').should('not.exist');
});

it('renders Nest1 in dir1', () => {
cy.visit('/');

Expand Down
22 changes: 22 additions & 0 deletions test/typedoc-0.9.0/cypress/integration/example_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,28 @@ describe('docs', () => {
.contains('File2');
});

it('renders File1 doc comment', () => {
cy.visit('/');

cy.get('a')
.contains('root')
.click();
cy.get('a')
.contains('File1')
.click();

cy.contains('This is in the root module');
});

it('does not render empty comment blocks where @module used to be', () => {
cy.visit('/');

cy.get('a')
.contains('root')
.click();
cy.get('section.tsd-comment').should('not.exist');
});

it('renders Nest1 in dir1', () => {
cy.visit('/');

Expand Down
Binary file modified test/typedoc-latest.tgz
Binary file not shown.
22 changes: 22 additions & 0 deletions test/typedoc-latest/cypress/integration/example_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,28 @@ describe('docs', () => {
.contains('File2');
});

it('renders File1 doc comment', () => {
cy.visit('/');

cy.get('a')
.contains('root')
.click();
cy.get('a')
.contains('File1')
.click();

cy.contains('This is in the root module');
});

it('does not render empty comment blocks where @module used to be', () => {
cy.visit('/');

cy.get('a')
.contains('root')
.click();
cy.get('section.tsd-comment').should('not.exist');
});

it('renders Nest1 in dir1', () => {
cy.visit('/');

Expand Down

0 comments on commit c800a22

Please sign in to comment.