Skip to content

Commit cbaa015

Browse files
committed
Merge branch 'rs-fix-style_guide_js-docs' into 'master'
Fix broken Frontend JS guide See merge request !13912
2 parents 0a5231e + 8e8644d commit cbaa015

File tree

1 file changed

+58
-63
lines changed

1 file changed

+58
-63
lines changed

doc/development/fe_guide/style_guide_js.md

+58-63
Original file line numberDiff line numberDiff line change
@@ -102,67 +102,65 @@ followed by any global declarations, then a blank newline prior to any imports o
102102

103103
1. Relative paths: when importing a module in the same directory, a child
104104
directory, or an immediate parent directory prefer relative paths. When
105-
importing a module which is two or more levels up, prefer either `~/` or `ee/`
106-
.
105+
importing a module which is two or more levels up, prefer either `~/` or `ee/`.
107106

108-
In **app/assets/javascripts/my-feature/subdir**:
107+
In **app/assets/javascripts/my-feature/subdir**:
109108

110-
``` javascript
111-
// bad
112-
import Foo from '~/my-feature/foo';
113-
import Bar from '~/my-feature/subdir/bar';
114-
import Bin from '~/my-feature/subdir/lib/bin';
109+
```javascript
110+
// bad
111+
import Foo from '~/my-feature/foo';
112+
import Bar from '~/my-feature/subdir/bar';
113+
import Bin from '~/my-feature/subdir/lib/bin';
115114

116-
// good
117-
import Foo from '../foo';
118-
import Bar from './bar';
119-
import Bin from './lib/bin';
120-
```
115+
// good
116+
import Foo from '../foo';
117+
import Bar from './bar';
118+
import Bin from './lib/bin';
119+
```
121120

122-
In **spec/javascripts**:
121+
In **spec/javascripts**:
123122

124-
``` javascript
125-
// bad
126-
import Foo from '../../app/assets/javascripts/my-feature/foo';
123+
```javascript
124+
// bad
125+
import Foo from '../../app/assets/javascripts/my-feature/foo';
127126

128-
// good
129-
import Foo from '~/my-feature/foo';
130-
```
127+
// good
128+
import Foo from '~/my-feature/foo';
129+
```
131130

132-
When referencing an **EE component**:
131+
When referencing an **EE component**:
133132

134-
``` javascript
135-
// bad
136-
import Foo from '../../../../../ee/app/assets/javascripts/my-feature/ee-foo';
133+
```javascript
134+
// bad
135+
import Foo from '../../../../../ee/app/assets/javascripts/my-feature/ee-foo';
137136

138-
// good
139-
import Foo from 'ee/my-feature/foo';
140-
```
137+
// good
138+
import Foo from 'ee/my-feature/foo';
139+
```
141140

142141
1. Avoid using IIFE. Although we have a lot of examples of files which wrap their
143142
contents in IIFEs (immediately-invoked function expressions),
144143
this is no longer necessary after the transition from Sprockets to webpack.
145144
Do not use them anymore and feel free to remove them when refactoring legacy code.
146145

147146
1. Avoid adding to the global namespace.
148-
```javascript
149-
// bad
150-
window.MyClass = class { /* ... */ };
147+
```javascript
148+
// bad
149+
window.MyClass = class { /* ... */ };
151150

152-
// good
153-
export default class MyClass { /* ... */ }
154-
```
151+
// good
152+
export default class MyClass { /* ... */ }
153+
```
155154

156155
1. Side effects are forbidden in any script which contains exports
157-
```javascript
158-
// bad
159-
export default class MyClass { /* ... */ }
160-
161-
document.addEventListener("DOMContentLoaded", function(event) {
162-
new MyClass();
163-
}
164-
```
156+
```javascript
157+
// bad
158+
export default class MyClass { /* ... */ }
165159
160+
document.addEventListener("DOMContentLoaded", function(event) {
161+
new MyClass();
162+
}
163+
```
166164

167165
#### Data Mutation and Pure functions
168166
1. Strive to write many small pure functions, and minimize where mutations occur.
@@ -414,19 +412,19 @@ A forEach will cause side effects, it will be mutating the array being iterated.
414412
#### Data
415413
1. `data` method should always be a function
416414

417-
```javascript
418-
// bad
419-
data: {
420-
foo: 'foo'
421-
}
422-
423-
// good
424-
data() {
425-
return {
415+
```javascript
416+
// bad
417+
data: {
426418
foo: 'foo'
427-
};
428-
}
429-
```
419+
}
420+
421+
// good
422+
data() {
423+
return {
424+
foo: 'foo'
425+
};
426+
}
427+
```
430428

431429
#### Directives
432430

@@ -481,7 +479,8 @@ A forEach will cause side effects, it will be mutating the array being iterated.
481479
1. `beforeDestroy`
482480
1. `destroyed`
483481

484-
#### Vue and Boostrap
482+
#### Vue and Bootstrap
483+
485484
1. Tooltips: Do not rely on `has-tooltip` class name for Vue components
486485
```javascript
487486
// bad
@@ -511,23 +510,19 @@ A forEach will cause side effects, it will be mutating the array being iterated.
511510
512511
$('span').tooltip('fixTitle');
513512
```
513+
514514
### The Javascript/Vue Accord
515515
The goal of this accord is to make sure we are all on the same page.
516516
517517
1. When writing Vue, you may not use jQuery in your application.
518-
1.1 If you need to grab data from the DOM, you may query the DOM 1 time while bootstrapping your application to grab data attributes using `dataset`. You can do this without jQuery.
519-
1.2 You may use a jQuery dependency in Vue.js following [this example from the docs](https://vuejs.org/v2/examples/select2.html).
520-
1.3 If an outside jQuery Event needs to be listen to inside the Vue application, you may use jQuery event listeners.
521-
1.4 We will avoid adding new jQuery events when they are not required. Instead of adding new jQuery events take a look at [different methods to do the same task](https://vuejs.org/v2/api/#vm-emit).
522-
518+
1. If you need to grab data from the DOM, you may query the DOM 1 time while bootstrapping your application to grab data attributes using `dataset`. You can do this without jQuery.
519+
1. You may use a jQuery dependency in Vue.js following [this example from the docs](https://vuejs.org/v2/examples/select2.html).
520+
1. If an outside jQuery Event needs to be listen to inside the Vue application, you may use jQuery event listeners.
521+
1. We will avoid adding new jQuery events when they are not required. Instead of adding new jQuery events take a look at [different methods to do the same task](https://vuejs.org/v2/api/#vm-emit).
523522
1. You may query the `window` object 1 time, while bootstrapping your application for application specific data (e.g. `scrollTo` is ok to access anytime). Do this access during the bootstrapping of your application.
524-
525523
1. You may have a temporary but immediate need to create technical debt by writing code that does not follow our standards, to be refactored later. Maintainers need to be ok with the tech debt in the first place. An issue should be created for that tech debt to evaluate it further and discuss. In the coming months you should fix that tech debt, with it's priority to be determined by maintainers.
526-
527524
1. When creating tech debt you must write the tests for that code before hand and those tests may not be rewritten. e.g. jQuery tests rewritten to Vue tests.
528-
529525
1. You may choose to use VueX as a centralized state management. If you choose not to use VueX, you must use the *store pattern* which can be found in the [Vue.js documentation](https://vuejs.org/v2/guide/state-management.html#Simple-State-Management-from-Scratch).
530-
531526
1. Once you have chosen a centralized state management solution you must use it for your entire application. i.e. Don't mix and match your state management solutions.
532527
533528
## SCSS

0 commit comments

Comments
 (0)