@dartess/eslint-plugin 0.3.0 → 0.4.0
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 +4 -0
- package/README.md +1 -0
- package/dist/configs/mobx.js +1 -0
- package/dist/index.js +2 -0
- package/dist/rules/mobx-sync-autorun.d.ts +3 -0
- package/dist/rules/mobx-sync-autorun.js +26 -0
- package/docs/rules/mobx-sync-autorun.md +29 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
[//]: # (https://keepachangelog.com/en/1.1.0/)
|
|
4
4
|
|
|
5
|
+
## [0.4.0] - 2026-01-15
|
|
6
|
+
- add rule `@dartess/mobx-sync-autorun`
|
|
7
|
+
- add `@dartess/mobx-sync-autorun` to `mobx` config
|
|
8
|
+
|
|
5
9
|
## [0.3.0] - 2026-01-12
|
|
6
10
|
|
|
7
11
|
- add `eslint-plugin-react-hooks:recommended` config to `react` config
|
package/README.md
CHANGED
|
@@ -167,6 +167,7 @@ Each rule has emojis denoting:
|
|
|
167
167
|
| [stories-export-typed](docs/rules/stories-export-typed.md) | Storybook's Stories should be typed | ✅ | | |
|
|
168
168
|
| [max-parent-import-depth](docs/rules/max-parent-import-depth.md) | Limit relative imports to a maximum parent depth. | ✅ | | |
|
|
169
169
|
| [ts-named-tuple-elements](docs/rules/ts-named-tuple-elements.md) | Enforce (or forbid) named tuple elements | ✅ | | |
|
|
170
|
+
| [mobx-sync-autorun](docs/rules/mobx-sync-autorun.md) | Enforce synchronous autorun callback | ✅ | | |
|
|
170
171
|
|
|
171
172
|
## Code Reuse Policy
|
|
172
173
|
|
package/dist/configs/mobx.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -7,6 +7,7 @@ import ruleStrictObservableComponentsDeclaration from "./rules/strict-observable
|
|
|
7
7
|
import ruleRequireObserver from "./rules/require-observer.js";
|
|
8
8
|
import ruleMaxParentImportDepth from "./rules/max-parent-import-depth.js";
|
|
9
9
|
import ruleTsNamedTupleElements from "./rules/ts-named-tuple-elements.js";
|
|
10
|
+
import ruleMobxSyncAutorun from "./rules/mobx-sync-autorun.js";
|
|
10
11
|
const plugin = {
|
|
11
12
|
meta: {
|
|
12
13
|
name: packageJson.name,
|
|
@@ -22,6 +23,7 @@ const plugin = {
|
|
|
22
23
|
'require-observer': ruleRequireObserver,
|
|
23
24
|
'max-parent-import-depth': ruleMaxParentImportDepth,
|
|
24
25
|
'ts-named-tuple-elements': ruleTsNamedTupleElements,
|
|
26
|
+
'mobx-sync-autorun': ruleMobxSyncAutorun,
|
|
25
27
|
},
|
|
26
28
|
};
|
|
27
29
|
export default plugin;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ESLintUtils } from '@typescript-eslint/utils';
|
|
2
|
+
export default ESLintUtils.RuleCreator(() => '')({
|
|
3
|
+
name: 'mobx-sync-autorun',
|
|
4
|
+
defaultOptions: [],
|
|
5
|
+
meta: {
|
|
6
|
+
type: 'problem',
|
|
7
|
+
docs: {
|
|
8
|
+
description: "Autorun tracks only the observables that are read during the synchronous execution of the provided function, but it won't track anything that happens asynchronously.",
|
|
9
|
+
},
|
|
10
|
+
messages: {
|
|
11
|
+
requireSyncAutorun: '`effect` must be synchronous function',
|
|
12
|
+
},
|
|
13
|
+
schema: [],
|
|
14
|
+
},
|
|
15
|
+
create(context) {
|
|
16
|
+
const selector = [
|
|
17
|
+
'CallExpression[callee.name="autorun"] > ArrowFunctionExpression[async="true"]',
|
|
18
|
+
'CallExpression[callee.name="autorun"] > FunctionExpression[async="true"]',
|
|
19
|
+
].join(', ');
|
|
20
|
+
return {
|
|
21
|
+
[selector]: node => {
|
|
22
|
+
context.report({ node, messageId: 'requireSyncAutorun' });
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
},
|
|
26
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Enforce synchronous autorun callback
|
|
2
|
+
|
|
3
|
+
Mobx `autorun` function must accept only synchronous `effect` callback.
|
|
4
|
+
This follows from the rules from official documentation, https://mobx.js.org/reactions.html#rules #2:
|
|
5
|
+
|
|
6
|
+
```
|
|
7
|
+
Autorun tracks only the observables that are read during the synchronous execution of the provided function, but it won't track anything that happens asynchronously.
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
It would be nice to track this at the type level, but that doesn't happen at the moment.
|
|
11
|
+
|
|
12
|
+
## Rule Details
|
|
13
|
+
|
|
14
|
+
Examples of **incorrect** code for this rule:
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
autorun(async () => {
|
|
18
|
+
await sleep(1);
|
|
19
|
+
console.log(store.value)
|
|
20
|
+
})
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Examples of **correct** code for this rule:
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
autorun(() => {
|
|
27
|
+
console.log(store.value)
|
|
28
|
+
})
|
|
29
|
+
```
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dartess/eslint-plugin",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.4.0",
|
|
5
5
|
"description": "A set of rules and configs for various TypeScript projects",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"eslint",
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
}
|
|
84
84
|
},
|
|
85
85
|
"devDependencies": {
|
|
86
|
-
"@eslint-community/eslint-plugin-eslint-comments": "^4.
|
|
86
|
+
"@eslint-community/eslint-plugin-eslint-comments": "^4.6.0",
|
|
87
87
|
"@eslint/js": "^9.39.2",
|
|
88
88
|
"@types/confusing-browser-globals": "^1.0.3",
|
|
89
89
|
"@types/eslint-plugin-jsx-a11y": "^6.10.1",
|