@lvce-editor/eslint-plugin-rpc 18.12.0 → 18.13.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 +20 -17
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,11 +1,13 @@
1
1
  const rpcRegistryModule = '@lvce-editor/rpc-registry';
2
- const rendererWorkerName = 'RendererWorker';
2
+ const isWorkerName = name => {
3
+ return typeof name === 'string' && (/(?:Worker|Process)$/.test(name) || name === 'ExtensionHost' || name === 'ProcessExplorer');
4
+ };
3
5
  const meta$1 = {
4
6
  docs: {
5
- description: 'Disallow destructuring RendererWorker to preserve tree shaking'
7
+ description: 'Disallow destructuring RPC registry workers to preserve tree shaking'
6
8
  },
7
9
  messages: {
8
- noRendererWorkerDestructuring: 'Do not destructure `RendererWorker`; call its methods directly so they can be tree-shaken.'
10
+ noRpcRegistryDestructuring: 'Do not destructure RPC registry workers; access their methods directly so they can be tree-shaken.'
9
11
  },
10
12
  type: 'problem'
11
13
  };
@@ -23,7 +25,7 @@ const findVariable = (scope, name) => {
23
25
  const isImportFromRpcRegistry = definition => {
24
26
  return definition.type === 'ImportBinding' && definition.parent?.source?.value === rpcRegistryModule;
25
27
  };
26
- const isRendererWorkerImport = variable => {
28
+ const isWorkerImport = variable => {
27
29
  return variable?.defs.some(definition => {
28
30
  if (!isImportFromRpcRegistry(definition) || definition.node?.type !== 'ImportSpecifier') {
29
31
  return false;
@@ -31,7 +33,7 @@ const isRendererWorkerImport = variable => {
31
33
  const {
32
34
  imported
33
35
  } = definition.node;
34
- return imported?.name === rendererWorkerName || imported?.value === rendererWorkerName;
36
+ return isWorkerName(imported?.name ?? imported?.value);
35
37
  });
36
38
  };
37
39
  const isRpcRegistryNamespaceImport = variable => {
@@ -45,45 +47,45 @@ const unwrapExpression = node => {
45
47
  }
46
48
  return node;
47
49
  };
48
- const isRendererWorkerProperty = node => {
50
+ const isWorkerProperty = node => {
49
51
  if (node.computed) {
50
- return node.property?.type === 'Literal' && node.property.value === rendererWorkerName;
52
+ return node.property?.type === 'Literal' && isWorkerName(node.property.value);
51
53
  }
52
- return node.property?.type === 'Identifier' && node.property.name === rendererWorkerName;
54
+ return node.property?.type === 'Identifier' && isWorkerName(node.property.name);
53
55
  };
54
- const isRendererWorkerExpression = (context, expression, node) => {
56
+ const isWorkerExpression = (context, expression, node) => {
55
57
  const unwrappedExpression = unwrapExpression(expression);
56
58
  const scope = context.sourceCode.getScope(node);
57
59
  if (unwrappedExpression?.type === 'Identifier') {
58
- return isRendererWorkerImport(findVariable(scope, unwrappedExpression.name));
60
+ return isWorkerImport(findVariable(scope, unwrappedExpression.name));
59
61
  }
60
- if (unwrappedExpression?.type !== 'MemberExpression' || unwrappedExpression.object?.type !== 'Identifier' || !isRendererWorkerProperty(unwrappedExpression)) {
62
+ if (unwrappedExpression?.type !== 'MemberExpression' || unwrappedExpression.object?.type !== 'Identifier' || !isWorkerProperty(unwrappedExpression)) {
61
63
  return false;
62
64
  }
63
65
  return isRpcRegistryNamespaceImport(findVariable(scope, unwrappedExpression.object.name));
64
66
  };
65
67
  const reportObjectPattern = (context, pattern) => {
66
68
  context.report({
67
- messageId: 'noRendererWorkerDestructuring',
69
+ messageId: 'noRpcRegistryDestructuring',
68
70
  node: pattern
69
71
  });
70
72
  };
71
73
  const create$1 = context => {
72
74
  return {
73
75
  AssignmentExpression(node) {
74
- if (node.left.type === 'ObjectPattern' && isRendererWorkerExpression(context, node.right, node)) {
76
+ if (node.left.type === 'ObjectPattern' && isWorkerExpression(context, node.right, node)) {
75
77
  reportObjectPattern(context, node.left);
76
78
  }
77
79
  },
78
80
  VariableDeclarator(node) {
79
- if (node.id.type === 'ObjectPattern' && isRendererWorkerExpression(context, node.init, node)) {
81
+ if (node.id.type === 'ObjectPattern' && isWorkerExpression(context, node.init, node)) {
80
82
  reportObjectPattern(context, node.id);
81
83
  }
82
84
  }
83
85
  };
84
86
  };
85
87
 
86
- const noRendererWorkerDestructuring = {
88
+ const noRpcRegistryDestructuring = {
87
89
  __proto__: null,
88
90
  create: create$1,
89
91
  meta: meta$1
@@ -137,7 +139,8 @@ const plugin = {
137
139
  version: '0.0.1'
138
140
  },
139
141
  rules: {
140
- 'no-renderer-worker-destructuring': noRendererWorkerDestructuring,
142
+ 'no-renderer-worker-destructuring': noRpcRegistryDestructuring,
143
+ 'no-rpc-registry-destructuring': noRpcRegistryDestructuring,
141
144
  'prefer-using-mock-rpc': preferUsingMockRpc
142
145
  }
143
146
  };
@@ -147,7 +150,7 @@ const recommended = [{
147
150
  rpc: plugin
148
151
  },
149
152
  rules: {
150
- 'rpc/no-renderer-worker-destructuring': 'error',
153
+ 'rpc/no-rpc-registry-destructuring': 'error',
151
154
  'rpc/prefer-using-mock-rpc': 'error'
152
155
  }
153
156
  }];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/eslint-plugin-rpc",
3
- "version": "18.12.0",
3
+ "version": "18.13.0",
4
4
  "main": "dist/index.js",
5
5
  "repository": {
6
6
  "type": "git",