-
Notifications
You must be signed in to change notification settings - Fork 101
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
Update/jsdoc package #295
Conversation
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 What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
1 similar comment
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 What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
@googlebot I signed it! |
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. ℹ️ Googlers: Go here for more info. |
1 similar comment
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. ℹ️ Googlers: Go here for more info. |
2d8eaa2
to
01cba85
Compare
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
1 similar comment
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
@googlebot I fixed it. |
There was a problem hiding this 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.
jsdoc/services/jsParser.js
Outdated
}); | ||
var _config = { ...OPTIONAL_ESPREE_CONFIG, ... MANDATORY_ESPREEE_CONFIG }; | ||
|
||
return { |
There was a problem hiding this comment.
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;
There was a problem hiding this comment.
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);
};
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
jsdoc/tag-defs/deprecated.js
Outdated
return { | ||
name: 'deprecated', | ||
transforms: [ booleanTagTransform ] |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, my bad. Reverted!
jsdoc/services/jsParser.spec.js
Outdated
return new Dgeni.Package('testJsParserPackage', [mockPackage()]) | ||
.config(function(jsParser) { | ||
jsParser.config = { | ||
comment: false, // this value should NOT override the default (true) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this 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 🙏
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...). |
There was a problem hiding this 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
andlet
rather thanvar
; and also use of fat-arrow functions rather than anonymousfunction() {...}
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.
var newValue = transform(doc, tag, value); | ||
|
||
expect(newValue).toEqual(''); | ||
expect(tag).toEqual({ tagName: 'module', name: 'module:customName' }); |
There was a problem hiding this comment.
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') { |
There was a problem hiding this comment.
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.
doc.codeNode = null; | ||
doc.codeAncestors = null; |
There was a problem hiding this comment.
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.
if (remainder) { | ||
log.warn(createDocMessage(`Some text remained after parsing module name: ${remainder}`, doc)); | ||
} |
There was a problem hiding this comment.
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.
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. ℹ️ Googlers: Go here for more info. |
1 similar comment
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. ℹ️ Googlers: Go here for more info. |
6d4538d
to
853f005
Compare
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
1 similar comment
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
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.
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`.
853f005
to
c0b077b
Compare
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 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 ℹ️ Googlers: Go here for more info. |
1 similar comment
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 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 ℹ️ Googlers: Go here for more info. |
I just rebased and force-pushed this PR. I will now merge it into master. |
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
jsParser.config
objectRelates to issue #293
Second commit
feat(jsdoc): add support for more jsdoc tags