Commit 69d6e911 authored by Lin Jen-Shin's avatar Lin Jen-Shin
parent bcc059c4
...@@ -11,7 +11,7 @@ See [our current .eslintrc][eslintrc] for specific rules and patterns. ...@@ -11,7 +11,7 @@ See [our current .eslintrc][eslintrc] for specific rules and patterns.
#### ESlint #### ESlint
1. **Never** disable eslint rules unless you have a good reason. 1. **Never** disable eslint rules unless you have a good reason.
You may see a lot of legacy files with `/* eslint-disable some-rule, some-other-rule */` You may see a lot of legacy files with `/* eslint-disable some-rule, some-other-rule */`
at the top, but legacy files are a special case. Any time you develop a new feature or at the top, but legacy files are a special case. Any time you develop a new feature or
refactor an existing one, you should abide by the eslint rules. refactor an existing one, you should abide by the eslint rules.
...@@ -100,26 +100,44 @@ followed by any global declarations, then a blank newline prior to any imports o ...@@ -100,26 +100,44 @@ followed by any global declarations, then a blank newline prior to any imports o
export default Foo; export default Foo;
``` ```
1. Relative paths: Unless you are writing a test, always reference other scripts using 1. Relative paths: when importing a module in the same directory, a child
relative paths instead of `~` directory, or an immediate parent directory prefer relative paths. When
* In **app/assets/javascripts**: importing a module which is two or more levels up, prefer either `~/` or `ee/`
.
```javascript In **app/assets/javascripts/my-feature/subdir**:
// bad
import Foo from '~/foo'
// good ``` javascript
import Foo from '../foo'; // bad
``` import Foo from '~/my-feature/foo';
* In **spec/javascripts**: import Bar from '~/my-feature/subdir/bar';
import Bin from '~/my-feature/subdir/lib/bin';
```javascript // good
// bad import Foo from '../foo';
import Foo from '../../app/assets/javascripts/foo' import Bar from './bar';
import Bin from './lib/bin';
```
// good In **spec/javascripts**:
import Foo from '~/foo';
``` ``` 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 1. Avoid using IIFE. Although we have a lot of examples of files which wrap their
contents in IIFEs (immediately-invoked function expressions), 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