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
+53-20Lines changed: 53 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,10 +5,44 @@ 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
+
JSX accessibility linting is available with the `mobify-es6-react-a11y.yml` configuration. It requires the additional modules:
13
+
14
+
-`eslint-plugin-react`
15
+
-`eslint-plugin-jsx-a11y`
16
+
17
+
## Global Names and Environments
18
+
19
+
By default, the lint configuration only assumes the standard set of
20
+
global names in the browser environment are defined. If writing a
21
+
script that runs in a different environment, such as a worker or Node,
22
+
add an `eslint-env` directive at the top of the file, e.g.:
23
+
```javascript
24
+
/* eslint-env node */
25
+
```
26
+
27
+
If you have defined or are using a global that is not associated with
28
+
any environment, you can define it for the linter in one of two
29
+
ways. If the global is only used in a single file or single place,
30
+
define it in that file by inserting a `global` directive at the top of
31
+
the file:
32
+
```javascript
33
+
/* global myGlobal anotherGlobal Mobify */
34
+
```
35
+
36
+
If, instead, it is used throughout your project, add it to the
37
+
`.eslintrc.yml` file for that project, with
38
+
```yaml
39
+
globals:
40
+
myGlobal: true
41
+
anotherGlobal: false
42
+
```
43
+
The boolean value indicates whether the global is to be treated as
44
+
read-only (`false`) or read-write (`true`).
45
+
12
46
## Overriding Lint Rules
13
47
14
48
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 +69,21 @@ if (x > y)
35
69
return x - y
36
70
else
37
71
return y - x
38
-
39
-
for (let item of cartItems)
72
+
73
+
for (let item of cartItems)
40
74
console.log(item)
41
-
75
+
42
76
//good!
43
77
if (x > y) {
44
78
return x - y
45
79
} else {
46
80
return y - x
47
81
}
48
-
82
+
49
83
for (let item of cartItems) {
50
84
console.log(item)
51
85
}
52
-
86
+
53
87
```
54
88
55
89
## Avoid 'Yoda' conditions
@@ -91,12 +125,12 @@ return {
91
125
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.
175
+
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
176
143
177
## Prefer template strings to string concatenation
144
178
@@ -159,9 +193,9 @@ Ternary expressions can be helpful, but can also lead to unclear code. If multip
0 commit comments