@dxos/eslint-plugin-rules 0.8.4-main.66e292d → 0.8.4-main.69d29f4
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/index.js +3 -0
- package/package.json +5 -1
- package/rules/no-effect-run-promise.js +52 -0
package/index.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import comment from './rules/comment.js';
|
|
6
6
|
import effectSubpathImports from './rules/effect-subpath-imports.js';
|
|
7
7
|
import header from './rules/header.js';
|
|
8
|
+
import noEffectRunPromise from './rules/no-effect-run-promise.js';
|
|
8
9
|
import noEmptyPromiseCatch from './rules/no-empty-promise-catch.js';
|
|
9
10
|
import fs from 'node:fs';
|
|
10
11
|
|
|
@@ -20,6 +21,7 @@ const plugin = {
|
|
|
20
21
|
comment,
|
|
21
22
|
'effect-subpath-imports': effectSubpathImports,
|
|
22
23
|
header,
|
|
24
|
+
'no-effect-run-promise': noEffectRunPromise,
|
|
23
25
|
'no-empty-promise-catch': noEmptyPromiseCatch,
|
|
24
26
|
},
|
|
25
27
|
configs: {
|
|
@@ -30,6 +32,7 @@ const plugin = {
|
|
|
30
32
|
rules: {
|
|
31
33
|
'dxos-plugin/effect-subpath-imports': 'error',
|
|
32
34
|
'dxos-plugin/header': 'error',
|
|
35
|
+
'dxos-plugin/no-effect-run-promise': 'error',
|
|
33
36
|
'dxos-plugin/no-empty-promise-catch': 'error',
|
|
34
37
|
// TODO(dmaretskyi): Turned off due to large number of errors and no auto-fix.
|
|
35
38
|
// 'dxos-plugin/comment': 'error',
|
package/package.json
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/eslint-plugin-rules",
|
|
3
|
-
"version": "0.8.4-main.
|
|
3
|
+
"version": "0.8.4-main.69d29f4",
|
|
4
4
|
"homepage": "https://dxos.org",
|
|
5
5
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/dxos/dxos"
|
|
9
|
+
},
|
|
6
10
|
"license": "MIT",
|
|
7
11
|
"author": "info@dxos.org",
|
|
8
12
|
"sideEffects": true,
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
'use strict';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* ESLint rule to prevent usage of Effect.runPromise and Effect.runPromiseExit,
|
|
9
|
+
* and suggest runAndForwardErrors instead.
|
|
10
|
+
* @example
|
|
11
|
+
* // bad
|
|
12
|
+
* await Effect.runPromise(myEffect);
|
|
13
|
+
* await Effect.runPromiseExit(myEffect);
|
|
14
|
+
*
|
|
15
|
+
* // good
|
|
16
|
+
* await runAndForwardErrors(myEffect);
|
|
17
|
+
*/
|
|
18
|
+
export default {
|
|
19
|
+
meta: {
|
|
20
|
+
type: 'problem',
|
|
21
|
+
docs: {
|
|
22
|
+
description: 'Disallow Effect.runPromise; suggest runAndForwardErrors instead.',
|
|
23
|
+
recommended: true,
|
|
24
|
+
},
|
|
25
|
+
messages: {
|
|
26
|
+
noRunPromise: 'Use runAndForwardErrors from @dxos/effect instead of Effect.runPromise.',
|
|
27
|
+
},
|
|
28
|
+
schema: [],
|
|
29
|
+
},
|
|
30
|
+
create(context) {
|
|
31
|
+
return {
|
|
32
|
+
CallExpression(node) {
|
|
33
|
+
// Check if this is Effect.runPromise or Effect.runPromiseExit
|
|
34
|
+
const isEffectMethod =
|
|
35
|
+
node.callee.type === 'MemberExpression' &&
|
|
36
|
+
node.callee.object.type === 'Identifier' &&
|
|
37
|
+
node.callee.object.name === 'Effect' &&
|
|
38
|
+
node.callee.property.type === 'Identifier';
|
|
39
|
+
|
|
40
|
+
if (isEffectMethod) {
|
|
41
|
+
const methodName = node.callee.property.name;
|
|
42
|
+
if (methodName === 'runPromise') {
|
|
43
|
+
context.report({
|
|
44
|
+
node,
|
|
45
|
+
messageId: 'noRunPromise',
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
},
|
|
52
|
+
};
|