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

Update/jsdoc package #295

Merged
merged 3 commits into from
Jan 13, 2021
Merged

Conversation

lmores
Copy link
Contributor

@lmores lmores commented Jan 10, 2021

This PR contains two distinct commits, each aiming to improve the jsdoc package.
(I also have a couple more ideas I would like to implement, but I will open an issue to discuss them before)

First commit
feat(jsdoc,nunjucks): update espree and nunjucks packages

Relates to issue #293

Second commit
feat(jsdoc): add support for more jsdoc tags

  • Add support for the following jsdoc tags: async, constant, enum, since
  • Improve support for the following jsdoc tags: deprecated, module
  • Add the booleanTagTransform() service for jsdoc tags like '@async' and '@deprecated'
  • Add the moduleTagTransform() service for the jsdoc tag '@module' to cope with jsdoc behaviour when no value is provided (see https://jsdoc.app/tags-module.html)

@google-cla
Copy link

google-cla bot commented Jan 10, 2021

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

1 similar comment
@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@google-cla google-cla bot added the cla: no label Jan 10, 2021
@lmores
Copy link
Contributor Author

lmores commented Jan 10, 2021

@googlebot I signed it!

@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

1 similar comment
@google-cla
Copy link

google-cla bot commented Jan 10, 2021

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

1 similar comment
@google-cla
Copy link

google-cla bot commented Jan 10, 2021

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@lmores
Copy link
Contributor Author

lmores commented Jan 10, 2021

@googlebot I fixed it.

Copy link
Member

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

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

Thanks for this PR @sir-ion. Generally looks good. I would like to avoid the breaking change to the API.

});
var _config = { ...OPTIONAL_ESPREE_CONFIG, ... MANDATORY_ESPREEE_CONFIG };

return {
Copy link
Member

Choose a reason for hiding this comment

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

Can we avoid the breaking change (where the user must now call jsParser.parse() rather than just jsParser()) by attaching config to the function itself?

Also I would avoid the setter/getter since it doesn't make it clear that you cannot mutate the config object directly and expect it to affect the parse() function.

E.g.:

function parse(code) { return jsParserImpl.parse(code, _config); }
parse.setConfig(config) { ... };
parse.getConfig() { ... };
return parse;

Copy link
Member

Choose a reason for hiding this comment

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

Actually, even better. Let's make the jsParser config an injectable service of its own, which the jsParser depends upon.

module.exports = function jsParser(jsParserConfig) {
  return function(code) {
    return jsParserImpl.parse(code, jsParserConfig);
  };
};

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

return {
name: 'deprecated',
transforms: [ booleanTagTransform ]
Copy link
Member

Choose a reason for hiding this comment

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

Deprecated is not actually a boolean jsdoc tag - https://jsdoc.app/tags-deprecated.html - it can contain a description of the deprecation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whoops, my bad. Reverted!

return new Dgeni.Package('testJsParserPackage', [mockPackage()])
.config(function(jsParser) {
jsParser.config = {
comment: false, // this value should NOT override the default (true)
Copy link
Member

Choose a reason for hiding this comment

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

I don't quite understand the comment on this line. Should this override the default or not?

Copy link
Member

Choose a reason for hiding this comment

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

Are you saying that even if you set the config for comment it will not affect the value passed to the parser?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that was my goal. Since the current implementation of the jsdoc package requires javascript comments to be attached to the espree AST in order to work properly, I forbade the user to override such options. (However now I realize that this choice goes against the general goal to provide a fully customizable tool to the users)

Anyway, in my last commit I moved the config to the new jsParserConfig service.

jsdoc/file-readers/jsdoc.js Outdated Show resolved Hide resolved
jsdoc/services/code-name.js Show resolved Hide resolved
Copy link
Member

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

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

Great! The only thing I wish for now is a spec file for the new moduleTagTransform service 🙏

@lmores
Copy link
Contributor Author

lmores commented Jan 12, 2021

Great! The only thing I wish for now is a spec file for the new moduleTagTransform service

You are totally right.

Actually, looking at jsdoc module page I realized that the implementation of transformers for the module tagDef could be improved. Have a look and tell me if you agree with the changes I made (unfortunately they are not fully backward compatitle...).

Copy link
Member

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

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

Thanks for the work here @sir-ion.

I have two requests:

  • the first is that I am about to land a bit refactoring that updates the code to more "modern" standards. In particular use of const and let rather than var; and also use of fat-arrow functions rather than anonymous function() {...} style functions. Could you rebase on top of that work when it lands and ensure that you update the code here to match?
  • the second is that I have some concerns over this new @module tag definition (or more specifically the transform). Could we pull that change out of this PR into its own so that we can land the other changes here without delay? Then we can discuss the update to @module separately.

jsdoc/services/transforms/extract-module-name.js Outdated Show resolved Hide resolved
jsdoc/services/transforms/extract-module-name.js Outdated Show resolved Hide resolved
var newValue = transform(doc, tag, value);

expect(newValue).toEqual('');
expect(tag).toEqual({ tagName: 'module', name: 'module:customName' });
Copy link
Member

Choose a reason for hiding this comment

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

From my reading of the JSDOC docs the name in this case should just be customName. I.e. the module: prefix is not part of the name.

*/
module.exports = function extractModuleNameTransform(log, createDocMessage) {
return function(doc, tag, value) {
if (tag.tagName == 'module') {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think it is necessary to guard this transform, since we only apply it to the module tagDef.

Comment on lines 18 to 19
doc.codeNode = null;
doc.codeAncestors = null;
Copy link
Member

Choose a reason for hiding this comment

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

I am worried that this will break other jsdoc tags...

For example, consider the following code:

/**
 * @module
 */

/**
 * Description of foo().
 */
  function foo() {}

Then I think that both comment blocks will be processed with respect to a single doc that has the foo() function as its codeNode.

Now the @module tag will cause this doc to lose connection to the foo() function.

The fact that we don't have a good way to distinguish JSDOC comments that should apply to the file only, is one reason why I have not properly implemented this before.

Comment on lines 33 to 35
if (remainder) {
log.warn(createDocMessage(`Some text remained after parsing module name: ${remainder}`, doc));
}
Copy link
Member

Choose a reason for hiding this comment

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

I would also not warn about this either, since it makes the transform less usable elsewhere.
If we want to ensure that that there is nothing else on the line for the @module tagDef then we could add another transform that did this check.

@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

1 similar comment
@google-cla
Copy link

google-cla bot commented Jan 13, 2021

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

@google-cla
Copy link

google-cla bot commented Jan 13, 2021

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

1 similar comment
@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@lmores
Copy link
Contributor Author

lmores commented Jan 13, 2021

  • the first is that I am about to land a bit refactoring that updates the code to more "modern" standards. In particular use of const and let rather than var; and also use of fat-arrow functions rather than anonymous function() {...} style functions. Could you rebase on top of that work when it lands and ensure that you update the code here to match?

Sure! Actually, I was tempted to already adopt those more "modern" standards, but in the end I chose to apply the "never been here" approach.

  • the second is that I have some concerns over this new @module tag definition (or more specifically the transform). Could we pull that change out of this PR into its own so that we can land the other changes here without delay? Then we can discuss the update to @module separately.

Done, last commit reverts all changes to the module tagDef so that it matches the one in the current master.

 - Update nunjucks package to ^3.2.2
 - Move nunjucks 'throwOnUndefined' option to nunjucks Environment config (as
   per nunjucks docs https://mozilla.github.io/nunjucks/api.html#environment).
 - Update espree package to ^7.3.1 (this enable parsing of new js keywords
   like `async/await`).
 - Update the espree config object as per https://github.com/eslint/espree#options

Note: since espree 7.3.1 no longer throws exceptions with the 'description'
property, the error messages generated in jsdoc/file-readers/jsdoc.js:19 are
a bit less descriptive
(see https://github.com/eslint/espree/blob/3b4ca9e3141514ffac93bb7fef6c1329370df310/lib/espree.js#L188).

Relates to issue angular#293
 - Add support for the following jsdoc tags: `async`, `constant`, `enum`, `since`.
 - Improve support for the following jsdoc tags: deprecated, module.
 - Add the booleanTagTransform() service for jsdoc tags like '@async'.
 - Add jsParserConfig service for `jsParser`.
@googlebot
Copy link

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

1 similar comment
@google-cla
Copy link

google-cla bot commented Jan 13, 2021

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@petebacondarwin
Copy link
Member

I just rebased and force-pushed this PR. I will now merge it into master.

@petebacondarwin petebacondarwin merged commit 8b673a8 into angular:master Jan 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants