Skip to content

Document code style guidelines #1243

Closed
Closed
@brendanashworth

Description

@brendanashworth

After #1220, the need for meta-documentation seems prevalent, and the lack of it leads to unproductive discussions, as in #1241. If only we had a good, solid answer. This should also reduce the amount of unproductive discussion related to style nits in PRs - I'd say a large majority of edits a new contributor has to do, primarily deals with style.

Here's my proposal for the guidelines with what I could scrounge up from code as is. We can also discuss sharing a style guide with another project, like airbnb, but I think the core style is different from any others, as is.

When in doubt, make lint. This style guide doesn't cover stuff that fails lint (I think).

JavaScript

Variables

  • const should always be used over var for variables that never change, such as require'd modules
  • let should not be used [until v8 speed against var increases]
  • variable names should be camelCase, unless they are a FunctionConstructor

Conditionals

  • when using a conditional such as if {} else if {} else {}, it must all have braces or it must all not have braces, no mixing of braces
  • for simple if conditionals, do not use braces (ref)

Equality

  • whenever possible, use strict equality (===) rather than loose equality (==), unless you are dependent on type coercion

Lines

  • as the closure linter insists on 80 character lines, splitting up conditionals and strings must be done with the operand at the end of the previous line (ref)
  • indentations are two spaces

Comments

  • // Comments should start with a capital, include correct punctuation, and have a period.
  • todo format: TODO(username): More text here. Can also use FIXME(username).
  • // XXX(username) for hacks - however very few should exist if possible

Modules

  • modules should be split into separate, smaller modules (such as _stream_x and _http_x) when they are too large to fit into one concisely
  • module import statements should be done permanently, at the top of each module

util

  • we love you util, but in core, your util.isXXX functions are not to be used and should be replaced with their respective inline equivalents

et cetera

  • do not introduce style-only changes in a commit that deals with another feature or fix; each commit should relate to only one change

C++

I don't know C++, anyone want to jump in?

Other notes:

  • I think that the new errors document would be a subset of this, unless we decided to put them into separate markdown files
  • I have no idea where this file would go

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussIssues opened for discussions and feedbacks.docIssues and PRs related to the documentations.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions