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
Copy file name to clipboardExpand all lines: docs/rules/func-style.md
+24-34Lines changed: 24 additions & 34 deletions
Original file line number
Diff line number
Diff line change
@@ -1,22 +1,22 @@
1
-
# Enforce Function Style (func-style)
1
+
# enforce the consistent use of either `function` declarations or expressions (func-style)
2
2
3
-
There are two ways of defining functions in JavaScript: function declarations and function expressions. Declarations have the `function` keyword first, followed by a name, followed by its arguments and the function body, such as:
3
+
There are two ways of defining functions in JavaScript: `function` declarations and `function` expressions. Declarations contain the `function` keyword first, followed by a name and then its arguments and the function body, for example:
4
4
5
5
```js
6
6
functiondoSomething() {
7
7
// ...
8
8
}
9
9
```
10
10
11
-
Equivalent function expressions begin with the `var` keyword, followed by a name, and then the function itself, such as:
11
+
Equivalent function expressions begin with the `var` keyword, followed by a name and then the function itself, such as:
12
12
13
13
```js
14
14
vardoSomething=function() {
15
15
// ...
16
16
};
17
17
```
18
18
19
-
The primary difference between function declarations and function expressions is that declarations are *hoisted* to the top of the scope in which they are defined, which allows you to write code that uses the function before the declaration. For example:
19
+
The primary difference between `function` declarations and `function expressions` is that declarations are *hoisted* to the top of the scope in which they are defined, which allows you to write code that uses the function before its declaration. For example:
20
20
21
21
```js
22
22
doSomething();
@@ -26,9 +26,9 @@ function doSomething() {
26
26
}
27
27
```
28
28
29
-
Although this code might seem like an error, it actually works fine because JavaScript engines hoist the function declarations to the top of the scope. That means this code is treated as if the declaration came before the invocation.
29
+
Although this code might seem like an error, it actually works fine because JavaScript engines hoist the `function` declarations to the top of the scope. That means this code is treated as if the declaration came before the invocation.
30
30
31
-
For function expressions, you must define the function before it is used, otherwise it causes an error. Example:
31
+
For `function` expressions, you must define the function before it is used, otherwise it causes an error. Example:
32
32
33
33
```js
34
34
doSomething(); // error!
@@ -44,19 +44,22 @@ Due to these different behaviors, it is common to have guidelines as to which st
44
44
45
45
## Rule Details
46
46
47
-
This rule is aimed at enforcing a particular type of function style throughout a JavaScript file, either declarations or expressions. You can specify which you prefer in the configuration.
47
+
This rule enforces a particular type of `function` style throughout a JavaScript file, either declarations or expressions. You can specify which you prefer in the configuration.
48
48
49
49
## Options
50
50
51
-
### "expression"
51
+
This rule has a string option:
52
52
53
-
This is the default configuration. It reports an error when function declarations are used instead of function expressions.
53
+
*`"expression"` (default) requires the use of function expressions instead of function declarations
54
+
*`"declaration"` requires the use of function declarations instead of function expressions
54
55
55
-
```json
56
-
"func-style": ["error", "expression"]
57
-
```
56
+
This rule has an object option for an exception:
57
+
58
+
*`"allowArrowFunctions": true` (default `false`) allows the use of arrow functions
58
59
59
-
The following patterns are considered problems:
60
+
### expression
61
+
62
+
Examples of **incorrect** code for this rule with the default `"expression"` option:
60
63
61
64
```js
62
65
/*eslint func-style: ["error", "expression"]*/
@@ -66,7 +69,7 @@ function foo() {
66
69
}
67
70
```
68
71
69
-
The following patterns are not considered problems:
72
+
Examples of **correct** code for this rule with the default `"expression"` option:
70
73
71
74
```js
72
75
/*eslint func-style: ["error", "expression"]*/
@@ -76,37 +79,21 @@ var foo = function() {
76
79
};
77
80
```
78
81
79
-
### "declaration"
80
-
81
-
This reports an error if any function expressions are used where function declarations are expected. You can specify to use expressions instead:
82
-
83
-
```json
84
-
"func-style": ["error", "declaration"]
85
-
```
86
-
87
-
An additional option object can be added with a property `"allowArrowFunctions"`. Setting this to `true` will allow arrow functions.
Copy file name to clipboardExpand all lines: docs/rules/id-blacklist.md
+15-16Lines changed: 15 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -1,41 +1,40 @@
1
-
# Blacklist certain identifiers to prevent them being used (id-blacklist)
1
+
# disallow specified identifiers (id-blacklist)
2
2
3
3
> "There are only two hard things in Computer Science: cache invalidation and naming things." — Phil Karlton
4
4
5
-
Bad names can lead to hard to decipher code. Using generic names, such as `data` don't infer much about the code and the values it receives. This rule allows you to configure a blacklist of bad identifier names, that you don't want to see in your code.
5
+
Bad names can lead to hard-to-decipher code. Generic names, such as `data`, don't infer much about the code and the values it receives. This rule allows you to configure a blacklist of bad identifier names, that you don't want to see in your code.
6
6
7
7
## Rule Details
8
8
9
-
This rule compares assignments and function definitions to a provided list of identifier names. If the identifier is present in the list, it will return an error.
9
+
This rule disallows specified identifiers in assignments and `function` definitions.
10
10
11
11
This rule will catch blacklisted identifiers that are:
12
12
13
13
- variable declarations
14
14
- function declarations
15
-
- object properties
15
+
- object properties assigned to during object creation
16
16
17
17
It will not catch blacklisted identifiers that are:
18
18
19
19
- function calls (so you can still use functions you do not have control over)
20
20
- object properties (so you can still use objects you do not have control over)
21
21
22
-
23
22
## Options
24
23
25
-
This rule needs a a set of identifier names to blacklist, like so:
24
+
The rule takes one or more strings as options: the names of restricted identifiers.
25
+
26
+
For example, to restrict the use of common generic identifiers:
0 commit comments