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

tools/doc: improvements for types #11167

Closed
wants to merge 2 commits into from
Closed

Conversation

silverwind
Copy link
Contributor

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

The first commit capitalizes all primitive types so the parser can pick them up.
The second commit adds logic to the doctool to allow parsing of Type[] array syntax.

Before

After

@silverwind silverwind added doc Issues and PRs related to the documentations. tools Issues and PRs related to the tools directory. labels Feb 4, 2017
@TimothyGu
Copy link
Member

The first commit LGTM. For the second, I would prefer a more generic syntax like Array<String>. This way, we can not only have links to MDN for both Array and String, but also have better symmetry with other language types/protocols like Promise and Iterable (e.g. for URLSearchParams it'd be Iterable<String, String>).

@mscdex
Copy link
Contributor

mscdex commented Feb 4, 2017

I actually prefer primitives to stay lowercase. Can't we just fix the parser?

Also on an unrelated note, in the particular example you showed, the inline 'pem' property description should actually have Buffer instead of buffer too.

@silverwind
Copy link
Contributor Author

I actually prefer primitives to stay lowercase

I don't have stats, but I estimate that > 80% of our types are currently capitalized.

the inline 'pem' property description should actually have Buffer instead of buffer too.

That'd be quite hard to parse. It's not following the type convention of {Type} at all.

@mscdex
Copy link
Contributor

mscdex commented Feb 5, 2017

That'd be quite hard to parse. It's not following the type convention of {Type} at all.

I'm not suggesting it should parse it necessarily, I'm mostly just pointing out a typo that should be corrected.

@@ -62,6 +62,17 @@ module.exports = {
typeUrl = nodeDocUrl + typeMap[typeText];
}

if (/\[]$/.test(typeText)) {
const typeTextBare = typeText.slice(0, -2);
if (jsPrimitives[typeTextBare]) {
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 merge this if...else chain with the previous one on line 57?

@silverwind
Copy link
Contributor Author

silverwind commented Feb 5, 2017

So on current master we have 571 occurences in docs with capitalized primitive types and 160 without. I could change those all to lowercase as suggested by @mscdex. MDN currently lists them capitalized and the href would need to be capitalized as well.

@thefourtheye
Copy link
Contributor

... the href would need to be capitalized as well.

I would consider this as a problem.

@silverwind
Copy link
Contributor Author

silverwind commented Feb 14, 2017

Updated:

  • Primitive types are now all lowercased. This seems to be a common convention in JS documention.
  • Removed some duplicated code as per @lpinca's suggestion and made sure primitives of any case are picked up correctly by the parser.

Example:

@nodejs/documentation PTAL.

@sam-github
Copy link
Contributor

Consistency sounds great to me.

Is the example in #11167 (comment) what it looks like now?

How come string is lower case, and Buffer and Object are upper case? It seems a bit random. Its not even built-in vs node specific, because String and Object are both builtin.

@silverwind
Copy link
Contributor Author

Because stringis a primitive while the others are not.

@TimothyGu
Copy link
Member

@silverwind, have you seen my comment above?
#11167 (comment)

@silverwind
Copy link
Contributor Author

Yes, I think Array<String> make sense for non-Array types, and it's certainly something we can support in the parser. I'd just like to avoid packing too many changes in this PR. Maybe open an separate issue for it?

@silverwind
Copy link
Contributor Author

While I couldn't find definitive recommendations, the style of lowercasing primitives (and capitalizing everything else) is in use by both JSDoc and closure compile. See examples here and here.

@sam-github
Copy link
Contributor

Not so sure that's a useful distinction that we need to convey to our doc readers, given that strings do have methods in practical cases, but at least its something we can point to in our docs, and say we are following jsdoc.

Did you mean to write Array<String> , not Array<string>?

@joyeecheung
Copy link
Member

joyeecheung commented Feb 27, 2017

BTW flow and TypeScript are using lower-cased primitive types too(therefore used by definitely typed, where a lot of people get their types from in their tools nowadays even if they don't use TypeScript)

@TimothyGu
Copy link
Member

FWIW, Tern also uses lowercased primitive types.

@thefourtheye
Copy link
Contributor

My mind is trained to understand a name as a constructor function if it starts with a capital letter. So I am going to go with lowercase names.

@silverwind
Copy link
Contributor Author

I think we are in agreement that lowercase primitives is the way to go. Can I get a few LGTMs? I'll rebase and land shortly after it's approved.

Copy link
Member

@joyeecheung joyeecheung left a comment

Choose a reason for hiding this comment

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

LTGM with a rebase

@silverwind
Copy link
Contributor Author

silverwind commented Mar 2, 2017

Thanks! Rebased and landed in ff13619 and 9be03a2.

@silverwind silverwind closed this Mar 2, 2017
silverwind added a commit that referenced this pull request Mar 2, 2017
PR-URL: #11167
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
@MylesBorins
Copy link
Contributor

ping

@silverwind
Copy link
Contributor Author

Backport in #13054

gibfahn pushed a commit that referenced this pull request May 16, 2017
PR-URL: #11167
Backport-PR-URL: #13054
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
gibfahn pushed a commit that referenced this pull request May 16, 2017
PR-URL: #11167
Backport-PR-URL: #13054
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
MylesBorins pushed a commit that referenced this pull request May 18, 2017
PR-URL: #11167
Backport-PR-URL: #13054
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
MylesBorins pushed a commit that referenced this pull request May 18, 2017
PR-URL: #11167
Backport-PR-URL: #13054
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
silverwind added a commit to silverwind/node that referenced this pull request May 18, 2017
PR-URL: nodejs#11167
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
silverwind added a commit to silverwind/node that referenced this pull request May 18, 2017
PR-URL: nodejs#11167
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
gibfahn pushed a commit to gibfahn/node that referenced this pull request Jun 17, 2017
PR-URL: nodejs#11167
Backport-PR-URL: nodejs#13054
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
gibfahn pushed a commit to gibfahn/node that referenced this pull request Jun 17, 2017
PR-URL: nodejs#11167
Backport-PR-URL: nodejs#13054
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
gibfahn pushed a commit that referenced this pull request Jun 20, 2017
PR-URL: #11167
Backport-PR-URL: #13054
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
gibfahn pushed a commit that referenced this pull request Jun 20, 2017
PR-URL: #11167
Backport-PR-URL: #13054
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
MylesBorins pushed a commit that referenced this pull request Jul 11, 2017
PR-URL: #11167
Backport-PR-URL: #13054
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
MylesBorins pushed a commit that referenced this pull request Jul 11, 2017
PR-URL: #11167
Backport-PR-URL: #13054
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
@MylesBorins MylesBorins mentioned this pull request Jul 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Issues and PRs related to the documentations. tools Issues and PRs related to the tools directory.
Projects
None yet
Development

Successfully merging this pull request may close these issues.