@lvce-editor/eslint-plugin-virtual-dom 17.0.1 → 17.0.3

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 +37 -0
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -150,6 +150,35 @@ const isStaticIdentifier = (sourceCode, node) => {
150
150
  const variable = findVariable(sourceCode, node);
151
151
  return Boolean(variable && isStaticModuleVariable(variable));
152
152
  };
153
+ const isPropertyMutation = (sourceCode, identifier) => {
154
+ const ancestors = sourceCode.getAncestors(identifier);
155
+ let current = identifier;
156
+ for (let i = ancestors.length - 1; i >= 0; i--) {
157
+ const parent = ancestors[i];
158
+ if (parent.type === 'MemberExpression' && parent.object === current) {
159
+ current = parent;
160
+ continue;
161
+ }
162
+ return parent.type === 'AssignmentExpression' && parent.left === current || parent.type === 'UpdateExpression' && parent.argument === current || parent.type === 'UnaryExpression' && parent.operator === 'delete' && parent.argument === current;
163
+ }
164
+ return false;
165
+ };
166
+ const isMutatedVariable = (sourceCode, variable) => {
167
+ return variable.references.some(reference => {
168
+ if (!reference.init && reference.isWrite()) {
169
+ return true;
170
+ }
171
+ return reference.identifier.type === 'Identifier' && isPropertyMutation(sourceCode, reference.identifier);
172
+ });
173
+ };
174
+ const isMutatedObject = (sourceCode, node) => {
175
+ const parent = sourceCode.getAncestors(node).at(-1);
176
+ if (parent?.type !== 'VariableDeclarator' || parent.init !== node || parent.id.type !== 'Identifier') {
177
+ return false;
178
+ }
179
+ const variable = findVariable(sourceCode, parent.id);
180
+ return Boolean(variable && isMutatedVariable(sourceCode, variable));
181
+ };
153
182
  const isVirtualDomElement = node => {
154
183
  if (!isVirtualDomNode(node) || !hasProperty(node, 'childCount')) {
155
184
  return false;
@@ -206,6 +235,9 @@ const create$b = context => {
206
235
  if (!isStaticExpression(context.sourceCode, node)) {
207
236
  return;
208
237
  }
238
+ if (isMutatedObject(context.sourceCode, node)) {
239
+ return;
240
+ }
209
241
  context.report({
210
242
  messageId: 'hoistStaticNode',
211
243
  node
@@ -856,6 +888,11 @@ const recommended = [{
856
888
  'virtual-dom/prefer-state-destructuring': 'error',
857
889
  'virtual-dom/valid-child-count': 'error'
858
890
  }
891
+ }, {
892
+ files: ['**/test/**/*.{js,mjs,cjs,ts,mts,cts}', '**/tests/**/*.{js,mjs,cjs,ts,mts,cts}', '**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts}'],
893
+ rules: {
894
+ 'virtual-dom/hoist-static-nodes': 'off'
895
+ }
859
896
  }];
860
897
 
861
898
  export { recommended as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/eslint-plugin-virtual-dom",
3
- "version": "17.0.1",
3
+ "version": "17.0.3",
4
4
  "main": "dist/index.js",
5
5
  "repository": {
6
6
  "type": "git",