summaryrefslogtreecommitdiffstats
path: root/docs
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@wolfbeast.com>2020-03-07 12:30:31 +0100
committerwolfbeast <mcwerewolf@wolfbeast.com>2020-03-07 12:30:31 +0100
commit9815e4bdf0b71078f5811d5f403e0cbfd21fdda5 (patch)
tree924a26c8f8e2a24e533dd2d7bf31165f598fd357 /docs
parentd0b2595322f663bf857debe2a2eecedf9dca9f13 (diff)
downloadUXP-9815e4bdf0b71078f5811d5f403e0cbfd21fdda5.tar
UXP-9815e4bdf0b71078f5811d5f403e0cbfd21fdda5.tar.gz
UXP-9815e4bdf0b71078f5811d5f403e0cbfd21fdda5.tar.lz
UXP-9815e4bdf0b71078f5811d5f403e0cbfd21fdda5.tar.xz
UXP-9815e4bdf0b71078f5811d5f403e0cbfd21fdda5.zip
Update UXP coding style guide JS guide.
Diffstat (limited to 'docs')
-rw-r--r--docs/UXP Coding Style.md35
1 files changed, 35 insertions, 0 deletions
diff --git a/docs/UXP Coding Style.md b/docs/UXP Coding Style.md
index c18e5a277..77a50e0f1 100644
--- a/docs/UXP Coding Style.md
+++ b/docs/UXP Coding Style.md
@@ -356,6 +356,32 @@ switch (variable) {
code_for_default;
}
```
+Alternatively (braced):
+```JavaScript
+switch (variable) {
+ case value1: {
+ // Comment describing 1
+ code_for_1;
+ code_for_1;
+ break;
+ }
+ case value2: {
+ code_for_2;
+ code_for_2;
+ // fallthrough
+ }
+ case value3:
+ case value4: {
+ code_for_3_and_4;
+ break;
+ }
+ default: {
+ code_for_default;
+ code_for_default;
+ }
+}
+```
+
#### try..catch
- When using `try..catch` blocks, the use of optional catch binding is discouraged. Please always include the error variable.
@@ -400,6 +426,7 @@ If statements on a single line become overly long, they should be split into mul
- Binary operators (including ternary) must be left on their original lines if the line break happens around the operator. The second line should start in the same column as the start of the expression in the first line.
- Lists of variables (e.g. when calling or declaring a function) should be split at the wrapping column.
- Long OOP calls should be split at the period with the period on the start of the new line, indented to the column of the first object, filling to the wrapping column where possible.
+- When breaking assignments/operations/logic, break right after the operator (`=`, `+`, `&&`, `||`, etc.)
WRONG:
```JavaScript
@@ -412,6 +439,10 @@ if (somelongvariable == somelongothervariable
somelongvariable = somelongexpression ? somevalue1
: somevalue2;
+var iShouldntBeUsingThisLongOfAVarName
+ = someValueToAdd + someValueToAdd + someValueToAdd
+ + someValueToAdd;
+
Cu.import("resource:///modules/DownloadsCommon.jsm", {}).
DownloadsCommon.initializeAllDataLinks();
```
@@ -427,6 +458,10 @@ somelongvariable = somelongexpression ?
somevalue1 :
somevalue2;
+var iShouldntBeUsingThisLongOfAVarName =
+ someValueToAdd + someValueToAdd + someValueToAdd +
+ someValueToAdd;
+
Cu.import("resource:///modules/DownloadsCommon.jsm", {})
.DownloadsCommon.initializeAllDataLinks();