Skip to content

Commit 08aa2a7

Browse files
committed
Added naming--uppercase section from comment
airbnb#255 (comment)
1 parent 9471975 commit 08aa2a7

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

README.md

+38
Original file line numberDiff line numberDiff line change
@@ -3139,6 +3139,44 @@ Other Style Guides
31393139
];
31403140
```
31413141
3142+
<a name="naming--uppercase"></a>
3143+
- [23.10](#naming--uppercase) You may optionally uppercase a constant only if it (1) is exported, (2) is a const, and (3) the programmer can trust it (and its nested properties) to never change.
3144+
3145+
> 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.
3146+
- 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.
3147+
- 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.
3148+
3149+
```javascript
3150+
// bad
3151+
const PRIVATE_VARIABLE = 'should not be unnecessarily uppercased within a file';
3152+
3153+
// bad
3154+
export const THING_TO_BE_CHANGED = 'should obviously not be uppercased';
3155+
3156+
// bad
3157+
export let REASSIGNABLE_VARIABLE = 'do not use let with uppercase variables';
3158+
3159+
// ---
3160+
3161+
// allowed but does not supply semantic value
3162+
export const apiKey = 'SOMEKEY';
3163+
3164+
// better in most cases
3165+
export const API_KEY = 'SOMEKEY';
3166+
3167+
// ---
3168+
3169+
// bad - unnecessarily uppercases key while adding no semantic value
3170+
export const MAPPING = {
3171+
KEY: 'value'
3172+
};
3173+
3174+
// good
3175+
export const MAPPING = {
3176+
key: 'value'
3177+
};
3178+
```
3179+
31423180
**[⬆ back to top](#table-of-contents)**
31433181

31443182
## Accessors

0 commit comments

Comments
 (0)