@plumeria/eslint-plugin 0.26.0 → 0.27.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.
@@ -4,6 +4,14 @@ exports.noUnusedKeys = void 0;
4
4
  function getFilename(context) {
5
5
  return context.getFilename ? context.getFilename() : context.filename;
6
6
  }
7
+ function getRootObject(node) {
8
+ if (node.type === 'Identifier') {
9
+ return node;
10
+ }
11
+ if (node.type === 'MemberExpression') {
12
+ return getRootObject(node.object);
13
+ }
14
+ }
7
15
  exports.noUnusedKeys = {
8
16
  meta: {
9
17
  type: 'problem',
@@ -22,6 +30,7 @@ exports.noUnusedKeys = {
22
30
  }
23
31
  const definedKeys = new Map();
24
32
  const referencedKeys = new Set();
33
+ const dynamicallyAccessedVars = new Set();
25
34
  return {
26
35
  CallExpression(node) {
27
36
  if (node.callee.type === 'MemberExpression' &&
@@ -49,10 +58,21 @@ exports.noUnusedKeys = {
49
58
  }
50
59
  },
51
60
  MemberExpression(node) {
52
- if (node.object.type === 'Identifier' &&
53
- node.property.type === 'Identifier') {
54
- const normalKey = `${node.object.name}.${node.property.name}`;
55
- referencedKeys.add(normalKey);
61
+ if (node.computed && node.property.type === 'Identifier') {
62
+ const rootObject = getRootObject(node.object);
63
+ if (rootObject && rootObject.type === 'Identifier') {
64
+ const variableName = rootObject.name;
65
+ dynamicallyAccessedVars.add(variableName);
66
+ definedKeys.delete(variableName);
67
+ }
68
+ return;
69
+ }
70
+ if (node.property.type === 'Identifier') {
71
+ const rootObject = getRootObject(node.object);
72
+ if (rootObject && rootObject.type === 'Identifier') {
73
+ const normalKey = `${rootObject.name}.${node.property.name}`;
74
+ referencedKeys.add(normalKey);
75
+ }
56
76
  }
57
77
  },
58
78
  'Program:exit'() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/eslint-plugin",
3
- "version": "0.26.0",
3
+ "version": "0.27.0",
4
4
  "description": "Plumeria ESLint plugin",
5
5
  "repository": {
6
6
  "type": "git",