mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-01-05 14:14:12 +01:00
59 lines
2.0 KiB
Plaintext
59 lines
2.0 KiB
Plaintext
== Coding Style ==
|
|
|
|
In general: Just look at the existing source code!
|
|
We try to be quite consistent, but of course, that's not always possible.
|
|
|
|
=== The most important style issues are: ===
|
|
|
|
* Use 4 spaces to indent things, no tabs, not 2, nor 8 spaces. If you use Vim,
|
|
this should be taken care of automatically by the modeline.
|
|
|
|
* No trailing whitespace.
|
|
|
|
* Use " for enclosing strings instead of ', unless using ' avoids escaping of lots of "
|
|
Example: alert("foo") instead of alert('foo');
|
|
|
|
* Exactly one space after if/for/while/catch etc. and after a comma, but none
|
|
after a parenthesis or after a function call:
|
|
for (pre, condition, post)
|
|
but:
|
|
alert("foo");
|
|
|
|
* Opening curly brackets { must be on a new line, unless it is used in a closure:
|
|
myFunction ()
|
|
{
|
|
return;
|
|
}
|
|
but:
|
|
setTimeout(function () {
|
|
...
|
|
});
|
|
|
|
* Anonymous function definitions should be formatted with a space after the
|
|
keyword "function". Example: function () {}, not function() {}.
|
|
|
|
* Prefer the use of let over var i.e. only use var when required.
|
|
For more details, see
|
|
https://developer.mozilla.org/en/New_in_JavaScript_1.7#Block_scope_with_let
|
|
|
|
* Reuse common local variable names E.g. "elem" is generally used for element,
|
|
"win" for windows etc.
|
|
|
|
* Prefer // over /* */ comments (exceptions for big comments are usually OK)
|
|
Right: if (HACK) // TODO: remove hack
|
|
Wrong: if (HACK) /* TODO: remove hack */
|
|
Documentation comment blocks use /** ... */
|
|
|
|
* Only wrap lines if it makes the code obviously clearer. Lines longer than 132
|
|
characters should probably be broken up rather than wrapped anyway.
|
|
|
|
* Use UNIX new lines (\n), not windows (\r\n) or old Mac ones (\r)
|
|
|
|
== Testing/Optimization ==
|
|
|
|
TODO: Add some information here about testing/validation/etc.
|
|
Information about how/when to use :regressions might be nice.
|
|
Additionally, maybe there should be some benchmark information here --
|
|
something to let a developer know what's "too" slow...? Or general
|
|
guidelines about optimization?
|