@dartess/eslint-plugin 0.4.0 → 0.5.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 +12 -8
- package/dist/configs/mobx.js +3 -2
- package/dist/index.js +2 -0
- package/dist/rules/mobx-sync-action.d.ts +3 -0
- package/dist/rules/mobx-sync-action.js +28 -0
- package/docs/rules/mobx-sync-action.md +27 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
[//]: # (https://keepachangelog.com/en/1.1.0/)
|
|
4
4
|
|
|
5
|
+
## [0.5.0] - 2026-01-16
|
|
6
|
+
- add rule `@dartess/mobx-sync-action`
|
|
7
|
+
- add `@dartess/mobx-sync-action` to `mobx` config
|
|
8
|
+
|
|
5
9
|
## [0.4.0] - 2026-01-15
|
|
6
10
|
- add rule `@dartess/mobx-sync-autorun`
|
|
7
11
|
- add `@dartess/mobx-sync-autorun` to `mobx` config
|
package/README.md
CHANGED
|
@@ -60,8 +60,6 @@ npm i -D eslint-plugin-storybook
|
|
|
60
60
|
|
|
61
61
|
## Usage configs
|
|
62
62
|
|
|
63
|
-
Shared config based on `eslint-config-airbnb`, `eslint-config-airbnb-typescript`, `eslint-plugin-react/recommended`, `eslint-plugin-react/jsx-runtime`.
|
|
64
|
-
|
|
65
63
|
Edit or create `eslint.config.ts` (or `eslint.config.mts`). You probably have to install `jiti` for it.
|
|
66
64
|
|
|
67
65
|
```ts
|
|
@@ -159,15 +157,21 @@ Each rule has emojis denoting:
|
|
|
159
157
|
|
|
160
158
|
| Name | Description | ✅ | 🔧 | 💡 |
|
|
161
159
|
|:-----------------------------------------------------------------------------------------------------------|:------------------------------------------------------------------------------|:--|:---|:---|
|
|
162
|
-
|
|
|
163
|
-
| [
|
|
164
|
-
|
|
|
160
|
+
| **imports** | _config: recommended_ | | | |
|
|
161
|
+
| [max-parent-import-depth](docs/rules/max-parent-import-depth.md) | Limit relative imports to a maximum parent depth. | ✅ | | |
|
|
162
|
+
| **TypeScript** | _config: recommended_ | | | |
|
|
163
|
+
| [ts-named-tuple-elements](docs/rules/ts-named-tuple-elements.md) | Enforce (or forbid) named tuple elements | ✅ | | |
|
|
164
|
+
| **React** | _config: react_ | | | |
|
|
165
165
|
| [jsx-no-text-as-child](docs/rules/jsx-text-as-child.md) | JSX elements should not have text without translation | | | |
|
|
166
|
+
| [prevent-mixing-external-and-internal-classes](docs/rules/prevent-mixing-external-and-internal-classes.md) | Prevent mixing of outer and inner classes to avoid dependency on style order. | | | |
|
|
167
|
+
| **Storybook** | _config: storybook_ | | | |
|
|
166
168
|
| [stories-export-meta](docs/rules/stories-export-meta.md) | Storybook's Meta should be typed | ✅ | | |
|
|
167
169
|
| [stories-export-typed](docs/rules/stories-export-typed.md) | Storybook's Stories should be typed | ✅ | | |
|
|
168
|
-
|
|
|
169
|
-
| [
|
|
170
|
-
| [
|
|
170
|
+
| **MobX** | _config: mobx_ | | | |
|
|
171
|
+
| [strict-observable-components-declaration](docs/rules/strict-observable-components-declaration.md) | Wrapping components in `observer` must comply with the regulations. | ✅ | | |
|
|
172
|
+
| [require-observer](docs/rules/require-observer.md) | Components using the stores must be wrapped in an `observer` | ✅ | 🔧 | |
|
|
173
|
+
| [mobx-sync-autorun](docs/rules/mobx-sync-autorun.md) | Enforce synchronous autorun callback | ✅ | | |
|
|
174
|
+
| [mobx-sync-action](docs/rules/mobx-sync-action.md) | Enforce synchronous actions | | | |
|
|
171
175
|
|
|
172
176
|
## Code Reuse Policy
|
|
173
177
|
|
package/dist/configs/mobx.js
CHANGED
|
@@ -5,10 +5,11 @@ const config = [
|
|
|
5
5
|
name: '@dartess/mobx',
|
|
6
6
|
rules: {
|
|
7
7
|
'mobx/missing-observer': 'off', // replaced by the neater "@dartess/require-observer"
|
|
8
|
-
'mobx/missing-make-observable': 'off', // useless with modern decorators syntax
|
|
8
|
+
'mobx/missing-make-observable': 'off', // useless with modern decorators syntax. TODO check original plugin?
|
|
9
9
|
'@dartess/strict-observable-components-declaration': 'error',
|
|
10
10
|
'@dartess/require-observer': 'error',
|
|
11
|
-
'@dartess/mobx-sync-autorun': 'error',
|
|
11
|
+
'@dartess/mobx-sync-autorun': 'error', // TODO implement it by types?
|
|
12
|
+
'@dartess/mobx-sync-action': 'error', // TODO implement it by types?
|
|
12
13
|
},
|
|
13
14
|
},
|
|
14
15
|
];
|
package/dist/index.js
CHANGED
|
@@ -8,6 +8,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
10
|
import ruleMobxSyncAutorun from "./rules/mobx-sync-autorun.js";
|
|
11
|
+
import ruleMobxSyncAction from "./rules/mobx-sync-action.js";
|
|
11
12
|
const plugin = {
|
|
12
13
|
meta: {
|
|
13
14
|
name: packageJson.name,
|
|
@@ -24,6 +25,7 @@ const plugin = {
|
|
|
24
25
|
'max-parent-import-depth': ruleMaxParentImportDepth,
|
|
25
26
|
'ts-named-tuple-elements': ruleTsNamedTupleElements,
|
|
26
27
|
'mobx-sync-autorun': ruleMobxSyncAutorun,
|
|
28
|
+
'mobx-sync-action': ruleMobxSyncAction,
|
|
27
29
|
},
|
|
28
30
|
};
|
|
29
31
|
export default plugin;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ESLintUtils } from '@typescript-eslint/utils';
|
|
2
|
+
export default ESLintUtils.RuleCreator(() => '')({
|
|
3
|
+
name: 'mobx-sync-action',
|
|
4
|
+
defaultOptions: [],
|
|
5
|
+
meta: {
|
|
6
|
+
type: 'problem',
|
|
7
|
+
docs: {
|
|
8
|
+
description: 'Mobx methods marked as `@action` must must be synchronous.',
|
|
9
|
+
},
|
|
10
|
+
messages: {
|
|
11
|
+
requireSyncAction: '`action` must be synchronous function',
|
|
12
|
+
},
|
|
13
|
+
schema: [],
|
|
14
|
+
},
|
|
15
|
+
create(context) {
|
|
16
|
+
const selector = [
|
|
17
|
+
'MethodDefinition[value.async="true"] Decorator[expression.object.name="action"]',
|
|
18
|
+
'MethodDefinition[value.async="true"] Decorator[expression.name="action"]',
|
|
19
|
+
'PropertyDefinition[value.type="ArrowFunctionExpression"][value.async="true"] Decorator[expression.object.name="action"]',
|
|
20
|
+
'PropertyDefinition[value.type="ArrowFunctionExpression"][value.async="true"] Decorator[expression.name="action"]',
|
|
21
|
+
].join(', ');
|
|
22
|
+
return {
|
|
23
|
+
[selector]: node => {
|
|
24
|
+
context.report({ node, messageId: 'requireSyncAction' });
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
},
|
|
28
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Enforce synchronous actions
|
|
2
|
+
|
|
3
|
+
Mobx methods marked as `@action` must be synchronous: https://mobx.js.org/actions.html#asynchronous-actions
|
|
4
|
+
|
|
5
|
+
## Rule Details
|
|
6
|
+
|
|
7
|
+
Examples of **incorrect** code for this rule:
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
class Store {
|
|
11
|
+
@action async method1() {};
|
|
12
|
+
@action.bound async method2() {};
|
|
13
|
+
@action method3 = async () => {};
|
|
14
|
+
@action.bound method4 = async () => {};
|
|
15
|
+
}
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Examples of **correct** code for this rule:
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
class Store {
|
|
22
|
+
@action method1() {};
|
|
23
|
+
@action.bound method2() {};
|
|
24
|
+
@action method3 = () => {};
|
|
25
|
+
@action.bound method4 = () => {};
|
|
26
|
+
}
|
|
27
|
+
```
|