eslint-plugin-mobx 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/README.md +16 -14
- package/dist/index.js +11 -11
- package/package.json +1 -1
- package/src/index.js +25 -25
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# eslint-plugin-mobx
|
|
2
2
|
|
|
3
|
+
## 0.0.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`4b1337ec`](https://github.com/mobxjs/mobx/commit/4b1337ecd64c7bfc904a04063bd1b07e62e392f1) [#3228](https://github.com/mobxjs/mobx/pull/3228) Thanks [@ahoisl](https://github.com/ahoisl)! - fix name for missing-observer rule in recommended
|
|
8
|
+
|
|
3
9
|
## 0.0.5
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ Mobx specific linting rules for `eslint`.
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```
|
|
8
|
-
npm install --save-dev eslint @typescript-eslint/parser eslint-plugin-mobx
|
|
8
|
+
npm install --save-dev eslint @typescript-eslint/parser eslint-plugin-mobx
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
## Configuration
|
|
@@ -15,19 +15,19 @@ npm install --save-dev eslint @typescript-eslint/parser eslint-plugin-mobx
|
|
|
15
15
|
module.exports = {
|
|
16
16
|
parser: "@typescript-eslint/parser",
|
|
17
17
|
// Include "mobx" in plugins array:
|
|
18
|
-
plugins: ["mobx"],
|
|
18
|
+
plugins: ["mobx"],
|
|
19
19
|
// Either extend our recommended configuration:
|
|
20
20
|
extends: "plugin:mobx/recommended",
|
|
21
21
|
// ...or specify and customize individual rules:
|
|
22
22
|
rules: {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
}
|
|
23
|
+
// these values are the same as recommended
|
|
24
|
+
"mobx/exhaustive-make-observable": "warn",
|
|
25
|
+
"mobx/unconditional-make-observable": "error",
|
|
26
|
+
"mobx/missing-make-observable": "error",
|
|
27
|
+
"mobx/missing-observer": "warn",
|
|
28
|
+
"mobx/no-anonymous-observer": "warn"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
31
|
```
|
|
32
32
|
|
|
33
33
|
## Rules
|
|
@@ -42,7 +42,7 @@ Does not warn about annotated non-existing fields (there is a runtime check, but
|
|
|
42
42
|
|
|
43
43
|
### mobx/missing-make-observable
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
_When using decorators (eg `@observable foo = 5`)_, makes sure that `makeObservable(this)` is called in a constructor.<br>
|
|
46
46
|
**Autofix** creates a constructor if necessary and adds `makeObservable(this)` at it's end.
|
|
47
47
|
|
|
48
48
|
### mobx/unconditional-make-observable
|
|
@@ -51,7 +51,8 @@ Makes sure the `make(Auto)Observable(this)` is called unconditionally inside a c
|
|
|
51
51
|
|
|
52
52
|
### mobx/missing-observer
|
|
53
53
|
|
|
54
|
-
Makes sure every React component is wrapped with `observer`. A React component is considered to be any
|
|
54
|
+
Makes sure every React component is wrapped with `observer`. A React component is considered to be any _class_ extending from `Component` or `React.Component` and any _function_ which name has the first letter capitalized (for anonymous functions the name is inferred from variable). These are all considered components:
|
|
55
|
+
|
|
55
56
|
```javascript
|
|
56
57
|
class Cmp extends React.Component { }
|
|
57
58
|
class Cmp extends Component { }
|
|
@@ -65,8 +66,10 @@ const foo = function Named() { }
|
|
|
65
66
|
const Anonym = function () { };
|
|
66
67
|
const Arrow = () => { };
|
|
67
68
|
```
|
|
69
|
+
|
|
68
70
|
**Autofix** wraps the component with `observer` and if necessary declares a constant of the same name: `const Name = observer(function Name() {})`.
|
|
69
71
|
It's a bit opinionated and can lead to a lot of false positives depending on your conventions. You will probably want to combine this rule with `overrides` option, eg:
|
|
72
|
+
|
|
70
73
|
```javascript
|
|
71
74
|
// .eslintrc.js
|
|
72
75
|
"overrides": [
|
|
@@ -81,8 +84,7 @@ It's a bit opinionated and can lead to a lot of false positives depending on you
|
|
|
81
84
|
|
|
82
85
|
### mobx/no-anonymous-observer
|
|
83
86
|
|
|
84
|
-
Forbids anonymous functions or classes as `observer` components.
|
|
87
|
+
Forbids anonymous functions or classes as `observer` components.
|
|
85
88
|
Improves debugging experience and [avoids problem with inability to customize `displayName`](https://github.com/mobxjs/mobx/issues/2721).
|
|
86
89
|
Plays nice with `eslint-plugin-react-hooks` and `mobx/missing-observer` as both of these don't not recognize anonymous function as component.
|
|
87
90
|
**Autofix** infers the name from variable if possible.
|
|
88
|
-
|
package/dist/index.js
CHANGED
|
@@ -483,22 +483,22 @@ var noAnonymousObserver = noAnonymousObserver$1;
|
|
|
483
483
|
var src = {
|
|
484
484
|
configs: {
|
|
485
485
|
recommended: {
|
|
486
|
-
plugins: [
|
|
486
|
+
plugins: ["mobx"],
|
|
487
487
|
rules: {
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
488
|
+
"mobx/exhaustive-make-observable": "warn",
|
|
489
|
+
"mobx/unconditional-make-observable": "error",
|
|
490
|
+
"mobx/missing-make-observable": "error",
|
|
491
|
+
"mobx/missing-observer": "warn",
|
|
492
|
+
"mobx/no-anonymous-observer": "warn"
|
|
493
493
|
}
|
|
494
494
|
}
|
|
495
495
|
},
|
|
496
496
|
rules: {
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
497
|
+
"exhaustive-make-observable": exhaustiveMakeObservable,
|
|
498
|
+
"unconditional-make-observable": unconditionalMakeObservable,
|
|
499
|
+
"missing-make-observable": missingMakeObservable,
|
|
500
|
+
"missing-observer": missingObserver,
|
|
501
|
+
"no-anonymous-observer": noAnonymousObserver
|
|
502
502
|
}
|
|
503
503
|
};
|
|
504
504
|
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict"
|
|
2
2
|
|
|
3
|
-
const exhaustiveMakeObservable = require(
|
|
4
|
-
const unconditionalMakeObservable = require(
|
|
5
|
-
const missingMakeObservable = require(
|
|
6
|
-
const missingObserver = require(
|
|
7
|
-
const noAnonymousObserver = require(
|
|
3
|
+
const exhaustiveMakeObservable = require("./exhaustive-make-observable.js")
|
|
4
|
+
const unconditionalMakeObservable = require("./unconditional-make-observable.js")
|
|
5
|
+
const missingMakeObservable = require("./missing-make-observable.js")
|
|
6
|
+
const missingObserver = require("./missing-observer")
|
|
7
|
+
const noAnonymousObserver = require("./no-anonymous-observer.js")
|
|
8
8
|
|
|
9
9
|
module.exports = {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
10
|
+
configs: {
|
|
11
|
+
recommended: {
|
|
12
|
+
plugins: ["mobx"],
|
|
13
|
+
rules: {
|
|
14
|
+
"mobx/exhaustive-make-observable": "warn",
|
|
15
|
+
"mobx/unconditional-make-observable": "error",
|
|
16
|
+
"mobx/missing-make-observable": "error",
|
|
17
|
+
"mobx/missing-observer": "warn",
|
|
18
|
+
"mobx/no-anonymous-observer": "warn"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
20
21
|
},
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
22
|
+
rules: {
|
|
23
|
+
"exhaustive-make-observable": exhaustiveMakeObservable,
|
|
24
|
+
"unconditional-make-observable": unconditionalMakeObservable,
|
|
25
|
+
"missing-make-observable": missingMakeObservable,
|
|
26
|
+
"missing-observer": missingObserver,
|
|
27
|
+
"no-anonymous-observer": noAnonymousObserver
|
|
28
|
+
}
|
|
29
|
+
}
|