From 5fd7c6f08c0650ed67297fc83c8a0590c9a92cc8 Mon Sep 17 00:00:00 2001 From: Estelle Date: Mon, 23 Mar 2015 18:48:19 -0700 Subject: [PATCH 1/2] added naming convention of UPPERCASE names --- README.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/README.md b/README.md index 2c6c5c6c7d..1116dcb4ba 100644 --- a/README.md +++ b/README.md @@ -3139,6 +3139,33 @@ Other Style Guides ]; ``` + + - [23.10](#naming--uppercase) Use UPPERCASE for nested object namespacing, global variables, and constants. + + + ```javascript + // bad + const namespace = namespace || {}; + + namespace.util.Widget = { + // ...stuff... + } + + // bad + const apiKey = '44b345234534t455245njkl523452-vbb9'; + + // good + const NAMESPACE = NAMESPACE || {}; + + NAMESPACE.util.Widget = { + // ...stuff... + } + + // good + const API_KEY = '44b345234534t455245njkl523452-vbb9'; + ``` + + **[⬆ back to top](#table-of-contents)** ## Accessors From a9f5d519fe7356a60843c2c24aae974f716e6d17 Mon Sep 17 00:00:00 2001 From: Shane Mileham Date: Mon, 12 Mar 2018 11:20:34 -0700 Subject: [PATCH 2/2] Added naming--uppercase section from comment --- README.md | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 1116dcb4ba..49f554e2cf 100644 --- a/README.md +++ b/README.md @@ -3140,32 +3140,43 @@ Other Style Guides ``` - - [23.10](#naming--uppercase) Use UPPERCASE for nested object namespacing, global variables, and constants. + - [23.10](#naming--uppercase) You may optionally uppercase a constant only if it (1) is exported, (2) is a `const` (it can not be reassigned), and (3) the programmer can trust it (and its nested properties) to never change. + > Why? This is an additional tool to assist in situations where the programmer would be unsure if a variable might ever change. UPPERCASE_VARIABLES are letting the programmer know that they can trust the variable (and its properties) not to change. + - What about all `const` variables? - This is unnecessary, so uppercasing should not be used for constants within a file. It should be used for exported constants however. + - What about exported objects? - Uppercase at the top level of export (e.g. `EXPORTED_OBJECT.key`) and maintain that all nested properties do not change. ```javascript // bad - const namespace = namespace || {}; + const PRIVATE_VARIABLE = 'should not be unnecessarily uppercased within a file'; - namespace.util.Widget = { - // ...stuff... - } + // bad + export const THING_TO_BE_CHANGED = 'should obviously not be uppercased'; // bad - const apiKey = '44b345234534t455245njkl523452-vbb9'; + export let REASSIGNABLE_VARIABLE = 'do not use let with uppercase variables'; - // good - const NAMESPACE = NAMESPACE || {}; + // --- - NAMESPACE.util.Widget = { - // ...stuff... - } + // allowed but does not supply semantic value + export const apiKey = 'SOMEKEY'; + + // better in most cases + export const API_KEY = 'SOMEKEY'; + + // --- + + // bad - unnecessarily uppercases key while adding no semantic value + export const MAPPING = { + KEY: 'value' + }; // good - const API_KEY = '44b345234534t455245njkl523452-vbb9'; + export const MAPPING = { + key: 'value' + }; ``` - **[⬆ back to top](#table-of-contents)** ## Accessors