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

build(docs-infra): support hiding constructors of injectable classes #24529

Conversation

petebacondarwin
Copy link
Member

@petebacondarwin petebacondarwin commented Jun 14, 2018

Class that are injectable often have constructors that should not be
called by the application developer. It is the responsibility of the
injector to instantiate the class and the constructor often contains
private implementation details that may need to change.

@petebacondarwin petebacondarwin added action: review The PR is still awaiting reviews from at least one requested reviewer effort1: hours severity1: confusing target: patch This PR is targeted for the next patch release labels Jun 14, 2018
@petebacondarwin petebacondarwin added this to the Backlog milestone Jun 14, 2018
@ngbot ngbot bot modified the milestones: Backlog, needsTriage Jun 14, 2018
@mary-poppins
Copy link

You can preview aca3297 at https://pr24529-aca3297.ngbuilds.io/.

Copy link
Member

@gkalpak gkalpak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to also update overview-dump.template.html.

@gkalpak gkalpak added action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Jun 15, 2018
@gkalpak
Copy link
Member

gkalpak commented Jun 15, 2018

On second thought, I find the tag name a little confusing. docsNotRequired might also mean "you don't need to add docs" (for whatever reason 😛). It is not clear that it will be hidden in docs.

Maybe something more assertive, like hideInDocs or excludeFromDocs?

@petebacondarwin
Copy link
Member Author

How about even more descriptive and specific: @injectableConstructor?
Or... we could automatically hide the constructor if the following is true:

  1. the class has @Injectable decorator
  2. the constructor has no description

What do you think?

@gkalpak
Copy link
Member

gkalpak commented Jun 15, 2018

If it is true that all @Injectable constructors should not appear in docs, then option (2) sounds perfect 😃

Classes that are injectable often have constructors that should not be
called by the application developer. It is the responsibility of the
injector to instantiate the class and the constructor often contains
private implementation details that may need to change.

This commit removes constructors from the docs for API items that are
both:

a) Marked with an injectable decorator (e.g. Injectable, Directive,
Component, Pipe), and
b) Have no constructor description

This second rule allows the developer to override the removal if there
is something useful to say about the constructor.

Note that "normal" classes such as `angimations/HttpHeaders` do not have
their constructor removed, despite (at this time) having no description.
@petebacondarwin petebacondarwin force-pushed the aio-hide-injectable-constructors branch from aca3297 to 2a76143 Compare June 15, 2018 12:08
@petebacondarwin
Copy link
Member Author

I rewrote this PR so you don't need to annotate the class constructor to make it hidden. I also noticed that Component and other decorators also indicate that the class is injectable so I am removing their decorators too. See the commit message for details of the approach.

@petebacondarwin
Copy link
Member Author

@gkalpak PTAL due to the complete rewrite

@petebacondarwin petebacondarwin added action: review The PR is still awaiting reviews from at least one requested reviewer and removed action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews labels Jun 15, 2018
@petebacondarwin petebacondarwin modified the milestones: needsTriage, Backlog Jun 15, 2018
@ngbot ngbot bot modified the milestones: Backlog, needsTriage Jun 15, 2018
expect(processor.$runBefore).toEqual(['docs-processed']);
});

it('should remove undocumented constructors from docs that have an "Injectable" decorator on it', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it --> them 😇

const injector = dgeni.configureInjector();
const processor = injector.get('removeInjectableConstructors');
expect(processor.$process).toBeDefined();
expect(processor.$runAfter).toEqual(['processing-docs']);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be ['processing-docs', 'splitDescription']?

return {
$runAfter: ['processing-docs', 'splitDescription'],
$runBefore: ['docs-processed'],
injectableDecorators: ['Injectable', 'Directive', 'Component', 'Pipe'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about NgModule?

docs.forEach(doc => {
if (
doc.constructorDoc &&
!doc.constructorDoc.shortDescription &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can a constructorDoc have a description but no shortDescription?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not if it runs after the splitDescription processor.

@gkalpak gkalpak added the action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews label Jun 15, 2018
@gkalpak gkalpak removed the action: review The PR is still awaiting reviews from at least one requested reviewer label Jun 15, 2018
@jbogarthyde
Copy link
Contributor

This solution makes the doc writer responsible for NOT including a doc comment (or including an empty one) on the constructor for a service. Is that what you want? If so, I will add it to the guidelines.

An explicit tag would have the advantage of showing that the choice not to document is explicit, and not a side-effect of incomplete documentation.

@petebacondarwin
Copy link
Member Author

Actually they could still add an explicit tag, e.g. @docsNotRequired, which would have no effect but at least it would be a marker to the reviewer? This tag could even have a boilerplate comment. For example:

@docsNotRequired this class is `Injectable` so the constructor is a private implementation.

As it stands we would not fail if this were missing but perhaps it could become enforceable later.

@petebacondarwin petebacondarwin removed the action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews label Jun 22, 2018
@petebacondarwin petebacondarwin moved this from REVIEW to MERGE in docs-infra Jun 22, 2018
@mary-poppins
Copy link

You can preview a4fed6c at https://pr24529-a4fed6c.ngbuilds.io/.

@jbogarthyde
Copy link
Contributor

I like that with the boilerplate -- it would make people think about what they are doing, and provide an explanation for users who are looking at the code.

@mary-poppins
Copy link

You can preview 4feac28 at https://pr24529-4feac28.ngbuilds.io/.

@petebacondarwin petebacondarwin added the action: merge The PR is ready for merge by the caretaker label Jun 26, 2018
@jasonaden jasonaden closed this in cf0968f Jun 26, 2018
jasonaden pushed a commit that referenced this pull request Jun 26, 2018
…24529)

Classes that are injectable often have constructors that should not be
called by the application developer. It is the responsibility of the
injector to instantiate the class and the constructor often contains
private implementation details that may need to change.

This commit removes constructors from the docs for API items that are
both:

a) Marked with an injectable decorator (e.g. Injectable, Directive,
Component, Pipe), and
b) Have no constructor description

This second rule allows the developer to override the removal if there
is something useful to say about the constructor.

Note that "normal" classes such as `angimations/HttpHeaders` do not have
their constructor removed, despite (at this time) having no description.

PR Close #24529
@gkalpak gkalpak removed this from MERGE in docs-infra Jul 17, 2018
@petebacondarwin petebacondarwin deleted the aio-hide-injectable-constructors branch July 18, 2018 07:20
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes effort1: hours target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants