11ty / 11ty-website

Documentation site for the Eleventy static site generator.
https://www.11ty.dev/
MIT License
470 stars 680 forks source link

JavaScript style guide for documentation PRs #397

Open reubenlillie opened 4 years ago

reubenlillie commented 4 years ago

@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:

I'm convinced more folks would reach for the vanilla 🍦 if they had more examples in the docs—and I wanna help.

reubenlillie commented 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?

Ryuno-Ki commented 4 years ago

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.

reubenlillie commented 4 years ago

@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.

Ryuno-Ki commented 4 years ago

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.

reubenlillie commented 4 years ago

@Ryuno-Ki, of course. I was imaging making separate PRs for each snippet on the site, individual pages of them at the most. @zachleat?

reubenlillie commented 4 years ago

Here’s my best attempt at @zachleat -style JavaScript a la the docs, at least for code snippets:

How’d I do?

Ryuno-Ki commented 4 years ago

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.

reubenlillie commented 4 years ago

@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.

Ryuno-Ki commented 4 years ago

Hm, I'm wondering, whether we could put together an ESLint config to ease with an agreed upon style convention …

reubenlillie commented 4 years ago

@Ryuno-Ki, do you know how to/want to make that kind of config?

Ryuno-Ki commented 4 years ago

Sure, why not? Would you be willing to review it then?

reubenlillie commented 4 years ago

Absolutely.

reubenlillie commented 3 years ago

@Ryuno-Ki, are you still interested in the idea of an ESLint config of some kind? I'm still happy to review.

Ryuno-Ki commented 3 years ago

Shoot, totally forgot about this! Yes, I'm still interested. Thanks for the reminder!

Ryuno-Ki commented 3 years ago

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.