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-04-14 13:03:47 +0200
commit51d5d162b7614e09ae548726eb2197225559f395 (patch)
treee791182f32c626b0d770d17574bc8c8e25a67f15 /docs
parent94494805dae5641fcb7be821e144a6828178f435 (diff)
downloadUXP-51d5d162b7614e09ae548726eb2197225559f395.tar
UXP-51d5d162b7614e09ae548726eb2197225559f395.tar.gz
UXP-51d5d162b7614e09ae548726eb2197225559f395.tar.lz
UXP-51d5d162b7614e09ae548726eb2197225559f395.tar.xz
UXP-51d5d162b7614e09ae548726eb2197225559f395.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();