You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Copy file name to clipboardExpand all lines: es6/README.md
+48-20Lines changed: 48 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,10 +5,39 @@ Included is a default ESLint configuration, `mobify-es6.yml` written for ESLint
5
5
-`eslint-plugin-import`
6
6
-`eslint-import-resolver-webpack`
7
7
8
-
The lint configuration is the definitive source for rules; this document explains the most notable ones. `eslint <source-files> --fix` will fix most formatting issues, such as spacing.
8
+
The lint configuration is the definitive source for rules; this document explains the most notable ones. `eslint <source-files> --fix` will fix most formatting issues, such as spacing.
9
9
10
10
If React/JSX is in use, use the React default configuration `mobify-es6-react.yml`, which also requires the `eslint-plugin-react` module.
11
11
12
+
## Global Names and Environments
13
+
14
+
By default, the lint configuration only assumes the standard set of
15
+
global names in the browser environment are defined. If writing a
16
+
script that runs in a different environment, such as a worker or Node,
17
+
add an `eslint-env` directive at the top of the file, e.g.:
18
+
```javascript
19
+
/* eslint-env node */
20
+
```
21
+
22
+
If you have defined or are using a global that is not associated with
23
+
any environment, you can define it for the linter in one of two
24
+
ways. If the global is only used in a single file or single place,
25
+
define it in that file by inserting a `global` directive at the top of
26
+
the file:
27
+
```javascript
28
+
/* global myGlobal anotherGlobal Mobify */
29
+
```
30
+
31
+
If, instead, it is used throughout your project, add it to the
32
+
`.eslintrc.yml` file for that project, with
33
+
```yaml
34
+
globals:
35
+
myGlobal: true
36
+
anotherGlobal: false
37
+
```
38
+
The boolean value indicates whether the global is to be treated as
39
+
read-only (`false`) or read-write (`true`).
40
+
12
41
## Overriding Lint Rules
13
42
14
43
Some of the lint rules disallow uncommon but valid behaviour that is easily confused with/typoed from much more common behaviour. If you need to use the disallowed behaviour on purpose, use an explicit lint override in the source.
@@ -35,21 +64,21 @@ if (x > y)
35
64
return x - y
36
65
else
37
66
return y - x
38
-
39
-
for (let item of cartItems)
67
+
68
+
for (let item of cartItems)
40
69
console.log(item)
41
-
70
+
42
71
//good!
43
72
if (x > y) {
44
73
return x - y
45
74
} else {
46
75
return y - x
47
76
}
48
-
77
+
49
78
for (let item of cartItems) {
50
79
console.log(item)
51
80
}
52
-
81
+
53
82
```
54
83
55
84
## Avoid 'Yoda' conditions
@@ -91,12 +120,12 @@ return {
91
120
It is clearer to use dot notation instead of bracket notation when it is available (i.e. when the property name is a constant, identifier-legal string).
With ES6 (and the current lint rules!) we have finally arrived at an environment where automatic semicolon insertion won't cause problems. So don't use them.
170
+
With ES6 (and the current lint rules!) we have finally arrived at an environment where automatic semicolon insertion won't cause problems. So don't use them.
142
171
143
172
## Prefer template strings to string concatenation
144
173
@@ -159,9 +188,9 @@ Ternary expressions can be helpful, but can also lead to unclear code. If multip
0 commit comments