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
Style Guide updates #241
Style Guide updates #241
Conversation
- of course, we’ll have some updates to make following this!
- start a list of code review requirements
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.
Just a couple of typos
developer/code-reviews.md
Outdated
- jsDoc (API documentation) | ||
|
||
- every file should have a summary | ||
- every method should a summary |
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.
- should have
developer/code-reviews.md
Outdated
|
||
- sufficient inline commenting | ||
- explains functionality to someone NOT reading any other docs | ||
- enough detail to assistance full documentation to expand upon |
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.
this is a little confusing? I think I get what you were going for.
Maybe: Provide enough detail so that detailed docs can expand upon the topic?
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.
Maybe add: "Provide links to source documentation where appropriate (e.g. SO Answers, API docs, etc)"
developer/styleguide.md
Outdated
* local app files | ||
- Double quoted strings | ||
- Well spaced function | ||
- 160 character line length |
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.
Didn't we change the line length to 120? Do we want to add "spaces around brackets"?
developer/styleguide.md
Outdated
|
||
#### Folder Names | ||
As a convention of there are multiple files that make up a functionality, these files should be grouped within a folder. If the files are stand-alone and the name needs to represent functionality, you can use a hyphen for the seperator. |
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.
if there
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.
just a suggestion but maybe "if some functionality is broken down across multiple files" rather than "make up a functionality"?
developer/styleguide.md
Outdated
**Bad** | ||
|
||
- Underscores and camelCased are not to be used unless expressly required; | ||
|
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.
Ok but don't we have a ton of existing files like this?
Sorry, I missed that the WIP was on there. Feel free to ignore/dismiss. |
@zenweasel your comments are exactly why it's WIP -> so thanks for reviewing. We do have a ton of files that break these rules -> and because the previous rules were unclear, or unenforced -> it's been sort of a 50/50 on the styles... the question is, is this newly updated guideline -> better, easier, more x-platform, etc.. then I guess we have some clean up to do. |
developer/styleguide.md
Outdated
- Spaces around brackets | ||
- 120 character line length | ||
- `import` order | ||
- npm packages |
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 thought we had added that we import React first.
This is not comprehensive but some standards I would add about naming conventions that I think are pretty standard but that's certainly subjective. These are just my opinions for discussion.
|
developer/code-reviews.md
Outdated
|
||
Here are is a brief checklist of common items reviewed in every merge. | ||
|
||
- Code style guide adhered to and **linted** (`eslint`, 0 errors, no ignores) |
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.
There are some API's where using an eslint-disable-line is necessary because the api requires underscored rather than camelcase arguments
developer/styleguide.md
Outdated
|
||
- Package name should contain hyphens to make it easier to read. | ||
- Underscores are not to be used unless expressly required. | ||
- Folder names should not be camelCased. |
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.
Should we have a refactor party to get everything updated to hyphens instead of camelcase?
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.
developer/code-reviews.md
Outdated
- Code style guide adhered to and **linted** (`eslint`, 0 errors, no ignores) | ||
- i18n keys on all text | ||
- i18n values added to appropriate `en.json` | ||
- Translations are updated (LingoHub) |
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 do a quick training session to go over LIngohub? I've looked over the shoulder of aaron doing it, but I don't think I'd know what to do on my own. Maybe after the Dev meeting on Friday or Wednesday?
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.
Should probably involve @machikoyasuda and make sure that our deployment docs get updated with any changes to our Lingohub process as well.
To add to @zenweasel's methods list:
Something @aaronjudd has mentioned multiple times: Good |
I wonder if we should require/strongly advise that all methods return some sort of value. Even if it's a |
I think requiring a object arg for more than two argument is a little too much |
over
|
To add:
|
Some more thoughts: Always use parensAlways use parens around all function args, in all cases, even if not technically required.
more clear
No multi-line shorthand arrow functionsIf you have to break your arrow function into multiple lines, it's better for readability to use curly brackets and a return rather than trying to break the shorthand arrow function into multiple lines. less clear
more clear
|
YES @spencern. Absolutely agree. I can't stand the ambiguity from not having those parens around function args. It's a little too shorthand. One more related thing I might add is I like the return shorthand with arrow functions (where appropriate). Meaning that you can use parens instead of curlies with an explicit So... // instead of this
arr.find((foo) => {
return foo.bar === foobar;
})
// prefer either of these...
arr.find((foo) => foo.bar === foobar);
arr.find((foo) => (
foo.bar === foobar;
)); One of the places I find myself using this pattern the most is with stateless React components that only return markup. // instead of this
const MyComponent = ({ title, content }) => {
return (
<div>
<h1>{title}</h1>
<div>{content}/</div>
</div>
);
}
// prefer this
const MyComponent = ({ title, content }) => (
<div>
<h1>{title}</h1>
<div>{content}/</div>
</div>
); Or when you're iterating over arrays in a component... const MyThings = ({ things }) => (
<ul>
{things.map((thing) => <li>{thing}</li>)}
</ul>
);
// or
const MyThings = ({ things }) => (
<ul>
{things.map((thing) => (
<li>{thing}</li>
))}
</ul>
); |
@jshimko - I hadn't considered the react use case for permitting multi-line "shorthand" arrow functions. I think that could be an exception. I totally agree that the typical shorthand arrow functions are fine, what I'm trying to create a rule against is trying too hard to keep something a "returnless" arrow function when it would be more easily read as a arrow to curlies with a return. |
Another thing that might just bug me I don't like the shorthand Collection.findOne - e.g.
Much prefer the explicit
|
@jshimko Had noted these before in other conversations:
also, more use of |
I don't think we need to go overboard with eliminating lodash because they are already compact and efficient implementations and the babel plugin helps us not ship ones we don't use. But here is the beginnings of a list of ones which there are 1-to-1 ES6 replacements for so we should not be using them.
|
Another |
not (e), not (err), but (error) is preferred style. |
A few more, while we're replacing lodash with native js:
For |
Add details on what happens post-merge, how triage happens, and exact commands to run before you make a PR.
Hi team - I added recommendations for variable, method naming conventions and more on lodash replacements, using ()s in methods - viewable here https://docs.reactioncommerce.com/reaction-docs/style-guide-reviews/styleguide |
@machikoyasuda, |
developer/styleguide.md
Outdated
- `.eslintrc` - [http://eslint.org/](https://eslint.org/) | ||
- `.jsbeautifyrc` - [http://jsbeautifier.org/](https://jsbeautifier.org/) | ||
- `.editorconfig` - [http://editorconfig.org/](https://editorconfig.org/) | ||
### Avoid camel-casing files and folders |
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 think that using positive language here might be more clear.
E.g. instead of Avoid camel-casing files and folders
, something like Use hyphens to separate words in files and directories
or File and directory names should be hyphenated
developer/styleguide.md
Outdated
|
||
## Variables |
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.
Should these two headers both be H2?
developer/styleguide.md
Outdated
- File names must start with a lowercased letter and may be camel cased if joining more than one word. | ||
- File names may contain multiple (.) characters as needed | ||
### Method names should: | ||
- Methods names should use a verb/noun style when possible, e.g. `checkConfiguration` or `addToCart`. |
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.
Not sure if I've written this down anywhere yet, but I think in cases where we might have multiple methods acting on the same resource we should consider the following style: cart/items/add
, cart/items/remove
-
this is probably too much change for this PR. One of the reasons for moving to a style like this is that it will naturally organize our method jsdocs.
I've used this style in the Shopify connector which we also used to experiment with jsdocs.
developer/styleguide.md
Outdated
|
||
- Avoid ternary operators and one-line `if` statements |
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.
exceptions for this in React
code?
- Replace `_.filter`, with `Array.prototype.filter` | ||
- Replace `_.each`, `_.forEach`, with `Array.prototype.forEach` | ||
- Replace `_.isArray`, with `Array.isArray` | ||
- Replace `_.extend` with `Object.assign` |
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.
Missing:
_.find
=> Array.prototype.find
_.keys
=> Object.keys
_.values
=> Object.values
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.
also missing _.uniq
developer/styleguide.md
Outdated
|
||
Use native ES6 elements over lodash whenever there is a 1-for-1 replacement. Here are some examples of lodash methods that can be replaced with native elements: |
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.
Should probably decide if we're going to say ES6 or ES2015 and be consistent there.
Also many of these Array.prototype methods have been around since well before ES6
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 think we might just want to just say "native Javascript"?
developer/styleguide.md
Outdated
- Double quoted strings | ||
- Well spaced function | ||
- 160 character line length | ||
Our rules are similar to [Airbnb JavaScript Style Guide](https://github.com/airbnb/javascript) and [Meteor Code Style](https://guide.meteor.com/code-style.html), [standard template of ESLint rules](https://www.npmjs.com/package/eslint-config-airbnb), with a few custom Reaction-specific rules: |
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.
Not necessary for this PR, but we should potentially fork and change, or create our own style guide that goes through all of our ESLint rules. Pointing people to other style guides that are kinda similar doesn't feel ideal
Once a pull request goes through both the automated and Core team reviews, it's ready to be merged. Here are some things you may want to consider after that: | ||
|
||
- If your pull request referenced an issue, close that issue. | ||
- Does your new feature require new user documentation or developer documentation? Make an issue for that in [reaction-docs](https://github.com/reactioncommerce/reaction-docs/issues). |
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 feel like we should make a doc PR a requirement for some PR's to be merged?
Updates to coding style guide, and more details/examples. We've been not enforcing the current style guide, and are half way between this document and the previous version. This is an attempt to update and clarify.