@lvce-editor/eslint-plugin-rpc 7.1.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.
Files changed (2) hide show
  1. package/dist/index.js +62 -0
  2. package/package.json +13 -0
package/dist/index.js ADDED
@@ -0,0 +1,62 @@
1
+ const isMockRpcVariable = declaration => {
2
+ return declaration?.id?.type === 'Identifier' && declaration.id.name === 'mockRpc';
3
+ };
4
+ const isRegisterMockRpcCall = expression => {
5
+ return expression?.type === 'CallExpression' && expression.callee?.type === 'MemberExpression' && expression.callee.property?.type === 'Identifier' && expression.callee.property.name === 'registerMockRpc';
6
+ };
7
+ const shouldUseUsing = node => {
8
+ return node.declarations.some(declaration => isMockRpcVariable(declaration) && isRegisterMockRpcCall(declaration.init));
9
+ };
10
+ const meta = {
11
+ type: 'problem',
12
+ docs: {
13
+ description: 'Enforce using with mockRpc registration'
14
+ },
15
+ messages: {
16
+ preferUsingMockRpc: 'Use `using` with `mockRpc`.'
17
+ }
18
+ };
19
+ const create = context => {
20
+ return {
21
+ VariableDeclaration(node) {
22
+ if (!shouldUseUsing(node)) {
23
+ return;
24
+ }
25
+ if (node.kind === 'using') {
26
+ return;
27
+ }
28
+ context.report({
29
+ node,
30
+ messageId: 'preferUsingMockRpc'
31
+ });
32
+ }
33
+ };
34
+ };
35
+
36
+ const preferUsingMockRpc = {
37
+ __proto__: null,
38
+ create,
39
+ meta
40
+ };
41
+
42
+ const plugin = {
43
+ meta: {
44
+ name: 'rpc',
45
+ version: '0.0.1'
46
+ },
47
+ rules: {
48
+ 'prefer-using-mock-rpc': preferUsingMockRpc
49
+ },
50
+ configs: {}
51
+ };
52
+ const recommended = [{
53
+ files: ['**/*.{js,mjs,cjs,ts,mts,cts}'],
54
+ plugins: {
55
+ rpc: plugin
56
+ },
57
+ rules: {
58
+ 'rpc/prefer-using-mock-rpc': 'error'
59
+ }
60
+ }];
61
+
62
+ export { recommended as default };
package/package.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "@lvce-editor/eslint-plugin-rpc",
3
+ "version": "7.1.0",
4
+ "main": "dist/index.js",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/lvce-editor/eslint-config.git"
8
+ },
9
+ "type": "module",
10
+ "keywords": [],
11
+ "license": "MIT",
12
+ "description": ""
13
+ }