From 51d5d162b7614e09ae548726eb2197225559f395 Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Sat, 7 Mar 2020 12:30:31 +0100 Subject: Update UXP coding style guide JS guide. --- docs/UXP Coding Style.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'docs') 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(); -- cgit v1.2.3