eslint-plugin-effector 0.8.1 → 0.8.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-effector",
3
- "version": "0.8.1",
3
+ "version": "0.8.2",
4
4
  "description": "Enforcing best practices for Effector",
5
5
  "keywords": [
6
6
  "eslint",
@@ -11,6 +11,7 @@ const {
11
11
  } = require("../../utils/get-corrected-store-name");
12
12
  const { createLinkToRule } = require("../../utils/create-link-to-rule");
13
13
  const { nodeTypeIs } = require("../../utils/node-type-is");
14
+ const { traverseParentByType } = require("../../utils/traverse-parent-by-type");
14
15
 
15
16
  module.exports = {
16
17
  meta: {
@@ -75,31 +76,31 @@ module.exports = {
75
76
  // Store creation with method
76
77
  const STORE_CREATION_METHODS = ["createStore", "restore", "combine"];
77
78
  for (const method of STORE_CREATION_METHODS) {
78
- const localMethod = importedFromEffector.get(method);
79
+ const localMethod = importedFromEffector.get(method);
79
80
  if (!localMethod) {
80
81
  continue;
81
82
  }
82
-
83
+
83
84
  const isEffectorStoreCreation = node.callee.name === localMethod;
84
85
  if (!isEffectorStoreCreation) {
85
86
  continue;
86
87
  }
87
88
 
88
- const resultSavedInVariable =
89
- node.parent.type === "VariableDeclarator";
89
+ const parentNode = traverseParentByType(node, "VariableDeclarator", ["Program"]);
90
+
91
+ const resultSavedInVariable = parentNode.type === "VariableDeclarator";
90
92
  if (!resultSavedInVariable) {
91
93
  continue;
92
94
  }
93
95
 
94
- const storeName = node.parent.id.name;
95
-
96
+ const storeName = parentNode.id.name;
96
97
  if (namingOf.store.isValid({ name: storeName, context })) {
97
98
  continue;
98
99
  }
99
100
 
100
101
  reportStoreNameConventionViolation({
101
102
  context,
102
- node: node.parent,
103
+ node: parentNode,
103
104
  storeName,
104
105
  });
105
106
  return;
@@ -115,8 +116,8 @@ module.exports = {
115
116
  return;
116
117
  }
117
118
 
118
- const resultSavedInVariable =
119
- node.parent.type === "VariableDeclarator";
119
+ const resultSavedInVariable = node.parent.type === "VariableDeclarator";
120
+
120
121
  if (!resultSavedInVariable) {
121
122
  return;
122
123
  }
@@ -140,13 +141,15 @@ module.exports = {
140
141
  if (
141
142
  STORE_IN_DOMAIN_CREATION_METHODS.includes(node.callee?.property?.name)
142
143
  ) {
143
- const resultSavedInVariable =
144
- node.parent.type === "VariableDeclarator";
144
+
145
+ const parentNode = traverseParentByType(node, "VariableDeclarator", ["Program"]);
146
+
147
+ const resultSavedInVariable = parentNode.type === "VariableDeclarator";
145
148
  if (!resultSavedInVariable) {
146
149
  return;
147
150
  }
148
151
 
149
- const storeName = node.parent.id.name;
152
+ const storeName = parentNode.id.name;
150
153
 
151
154
  if (namingOf.store.isValid({ name: storeName, context })) {
152
155
  return;
@@ -154,7 +157,7 @@ module.exports = {
154
157
 
155
158
  reportStoreNameConventionViolation({
156
159
  context,
157
- node: node.parent,
160
+ node: parentNode,
158
161
  storeName,
159
162
  });
160
163
  return;