Commit 69d6e911 authored by Lin Jen-Shin's avatar Lin Jen-Shin
parent bcc059c4
......@@ -100,26 +100,44 @@ followed by any global declarations, then a blank newline prior to any imports o
export default Foo;
```
1. Relative paths: Unless you are writing a test, always reference other scripts using
relative paths instead of `~`
* In **app/assets/javascripts**:
1. Relative paths: when importing a module in the same directory, a child
directory, or an immediate parent directory prefer relative paths. When
importing a module which is two or more levels up, prefer either `~/` or `ee/`
.
```javascript
// bad
import Foo from '~/foo'
In **app/assets/javascripts/my-feature/subdir**:
// good
import Foo from '../foo';
```
* In **spec/javascripts**:
``` javascript
// bad
import Foo from '~/my-feature/foo';
import Bar from '~/my-feature/subdir/bar';
import Bin from '~/my-feature/subdir/lib/bin';
```javascript
// bad
import Foo from '../../app/assets/javascripts/foo'
// good
import Foo from '../foo';
import Bar from './bar';
import Bin from './lib/bin';
```
// good
import Foo from '~/foo';
```
In **spec/javascripts**:
``` javascript
// bad
import Foo from '../../app/assets/javascripts/my-feature/foo';
// good
import Foo from '~/my-feature/foo';
```
When referencing an **EE component**:
``` javascript
// bad
import Foo from '../../../../../ee/app/assets/javascripts/my-feature/ee-foo';
// good
import Foo from 'ee/my-feature/foo';
```
1. Avoid using IIFE. Although we have a lot of examples of files which wrap their
contents in IIFEs (immediately-invoked function expressions),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment