Open reubenlillie opened 4 years ago
@zachleat, since the request for more vanilla JS doc examples came up in 11ty/eleventy issue 921 do you think it'd be a good idea to add this to the Eleventy 1.0 project board?
Um, JSDoc comments are most likely written by me if they document the signature :-) Willing to chime in, once https://github.com/11ty/eleventy/pull/720 gets merged.
@Ryuno-Ki, Ha! I was referring both to JSdoc, the automation app, and the notion of JS examples in the docs. Sorry for any confusion. I use JSDoc.app extensively on my own sites too. In any case, I want to help make sure the JS examples are as consistent and useful as possible.
Same here :-) However, I'd rather not have big PRs but a set of small ones. I defer to @zachleat to decide when to move forward on this topic. I'm aware, that documentation is something, many developers don't like to deal with. But in my opinion, it is too important to neglect.
@Ryuno-Ki, of course. I was imaging making separate PRs for each snippet on the site, individual pages of them at the most. @zachleat?
Here’s my best attempt at @zachleat -style JavaScript a la the docs, at least for code snippets:
return
when returning a string or an object, but not a function (e.g., setTimeout()
)function
and ()
when declaring an anonymous functionconst
and let
, not var
this
binding for shortcodes, filters, transforms, etc.exports.data = {}; exports.render = function() {};
pattern available since 0.9.0
, thanks again @jakearchibald! (Okay, I added this one, but there are no examples in the docs of this option, and I strongly believe it should be the default format in the docs for reasons too numerous and heartfelt for the purposes of this list.)if
statements when it may aid readability (This is a guess, the ternary operator makes more sense than wrapping conditional logic in an IIFE inside template strings.)How’d I do?
Do not include a space between function and () when declaring an anonymous function
I'm not sure, where I found that trick, but it's a neat hack: By adding the space, you can easily find the declaration of a function instead of all its invocations. I'd suggest to keep it.
@Ryuno-Ki,
I'm not sure, where I found that trick, but it's a neat hack: By adding the space, you can easily find the declaration of a function instead of all its invocations. I'd suggest to keep it.
Yes. I use the space in my own code. But, like I said, I’m foregoing my own style for consistency within the docs.
Hm, I'm wondering, whether we could put together an ESLint config to ease with an agreed upon style convention …
@Ryuno-Ki, do you know how to/want to make that kind of config?
Sure, why not? Would you be willing to review it then?
Absolutely.
@Ryuno-Ki, are you still interested in the idea of an ESLint config of some kind? I'm still happy to review.
Shoot, totally forgot about this! Yes, I'm still interested. Thanks for the reminder!
Looking into that right now (but @matt-auckland was faster with https://github.com/11ty/11ty-website/commit/3a0ce3b1535d7d220091df86bb20a9faff40c916 ):
If you agree, I'd fill a PR with those rules added.
@zachleat,
Can we drum up a quick style guide for vanilla JS code examples? I'm willing to forego my (otherwise highly opinionated) personal style for a standard.
I can mimic what's already there, but it'd be good to establish something formally—for consistency within the docs (if not also the codebase). Here are the major categories I'm thinking we could use some clear ground rules:
return
statements?var
v.const
andlet
?exports.render
import
v.require()
this
I'm convinced more folks would reach for the vanilla 🍦 if they had more examples in the docs—and I wanna help.