Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-03-16 21:18:33 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-03-16 21:18:33 +0300
commitf64a639bcfa1fc2bc89ca7db268f594306edfd7c (patch)
treea2c3c2ebcc3b45e596949db485d6ed18ffaacfa1 /doc/development/fe_guide/style/javascript.md
parentbfbc3e0d6583ea1a91f627528bedc3d65ba4b10f (diff)
Add latest changes from gitlab-org/gitlab@13-10-stable-eev13.10.0-rc40
Diffstat (limited to 'doc/development/fe_guide/style/javascript.md')
-rw-r--r--doc/development/fe_guide/style/javascript.md23
1 files changed, 22 insertions, 1 deletions
diff --git a/doc/development/fe_guide/style/javascript.md b/doc/development/fe_guide/style/javascript.md
index 5c35b880eab..334372af1f4 100644
--- a/doc/development/fe_guide/style/javascript.md
+++ b/doc/development/fe_guide/style/javascript.md
@@ -14,7 +14,7 @@ In addition to the style guidelines set by Airbnb, we also have a few specific r
listed below.
NOTE:
-You can run ESLint locally by running `yarn eslint`
+You can run ESLint locally by running `yarn run lint:eslint:all` or `yarn run lint:eslint $PATH_TO_FILE`.
## Avoid forEach
@@ -294,3 +294,24 @@ Strive to write many small pure functions and minimize where mutations occur
var c = pureFunction(values.foo);
```
+
+## Export constants as primitives
+
+Prefer exporting constant primitives with a common namespace over exporting objects. This allows for better compile-time reference checks and helps to avoid accidential `undefined`s at runtime. In addition, it helps in reducing bundle sizes.
+
+Only export the constants as a collection (array, or object) when there is a need to iterate over them, for instance, for a prop validator.
+
+ ```javascript
+ // bad
+ export const VARIANT = {
+ WARNING: 'warning',
+ ERROR: 'error',
+ };
+
+ // good
+ export const VARIANT_WARNING = 'warning';
+ export const VARIANT_ERROR = 'error';
+
+ // good, if the constants need to be iterated over
+ export const VARIANTS = [VARIANT_WARNING, VARIANT_ERROR];
+ ```