eslint-plugin-power-esrules 0.1.7 → 0.1.8

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.
@@ -44,23 +44,31 @@ function getImportType(node) {
44
44
 
45
45
  // Сторонние библиотеки (не относительные и не начинаются с внутренних путей)
46
46
  const internalPathPatterns = [
47
+ /^actions/,
48
+ /^api/,
49
+ /^base/,
47
50
  /^components/,
48
- /^utils/,
51
+ /^containers/,
52
+ /^hooks/,
53
+ /^layouts/,
54
+ /^locales/,
55
+ /^middlewares/,
49
56
  /^modules/,
50
57
  /^pages/,
58
+ /^reducers/,
59
+ /^sagas/,
60
+ /^selectors/,
61
+ /^theme/,
62
+ /^utils/,
63
+ //
51
64
  /^services/,
52
65
  /^store/,
53
66
  /^types/,
54
67
  /^constants/,
55
- /^hooks/,
56
68
  /^helpers/,
57
- /^selectors/,
58
- /^base/,
59
- /^actions/,
60
- /^containers/,
61
69
  ];
62
70
  const isInternalPath = internalPathPatterns.some((pattern) =>
63
- pattern.test(source)
71
+ pattern.test(source),
64
72
  );
65
73
  if (!isInternalPath) {
66
74
  return "external";
@@ -76,14 +84,14 @@ function getImportType(node) {
76
84
  }
77
85
  // Проверяем, является ли это компонентом
78
86
  const isDefaultImport = node.specifiers.some(
79
- (spec) => spec.type === "ImportDefaultSpecifier"
87
+ (spec) => spec.type === "ImportDefaultSpecifier",
80
88
  );
81
89
  const hasComponentName = node.specifiers.some(
82
90
  (spec) =>
83
91
  spec.type === "ImportSpecifier" &&
84
92
  spec.imported &&
85
93
  /^[A-Z][a-zA-Z]*$/.test(spec.imported.name) && // Имя начинается с большой буквы и не все заглавные
86
- spec.imported.name !== spec.imported.name.toUpperCase() // Не константа (не все заглавные)
94
+ spec.imported.name !== spec.imported.name.toUpperCase(), // Не константа (не все заглавные)
87
95
  );
88
96
  if (isDefaultImport || hasComponentName) {
89
97
  return "component";
@@ -95,7 +103,7 @@ function getImportType(node) {
95
103
  spec.type === "ImportSpecifier" &&
96
104
  spec.imported &&
97
105
  /^[A-Z][a-zA-Z]*$/.test(spec.imported.name) &&
98
- spec.imported.name !== spec.imported.name.toUpperCase() // Не константа
106
+ spec.imported.name !== spec.imported.name.toUpperCase(), // Не константа
99
107
  );
100
108
  if (hasComponentName) {
101
109
  return "component";
@@ -131,6 +139,9 @@ function compareImports(a, b) {
131
139
  // Затем по имени источника (алфавитно)
132
140
  const sourceA = a.source.value;
133
141
  const sourceB = b.source.value;
142
+ // импорты react всегда идут первые
143
+ if (sourceA === "react" && sourceB !== "react") return -1;
144
+ if (sourceB === "react" && sourceA !== "react") return 1;
134
145
  return sourceA.localeCompare(sourceB);
135
146
  }
136
147
 
@@ -166,7 +177,7 @@ module.exports = {
166
177
  return {
167
178
  Program(node) {
168
179
  const imports = node.body.filter(
169
- (stmt) => stmt.type === "ImportDeclaration"
180
+ (stmt) => stmt.type === "ImportDeclaration",
170
181
  );
171
182
 
172
183
  if (imports.length === 0) {
@@ -209,7 +220,7 @@ module.exports = {
209
220
  }
210
221
  return fixer.replaceTextRange(
211
222
  [firstToken.range[0], lastToken.range[1]],
212
- sortedText
223
+ sortedText,
213
224
  );
214
225
  },
215
226
  });
@@ -258,7 +269,7 @@ module.exports = {
258
269
  const fixedText = textBetween.replace(/\n\s*\n+/g, "\n");
259
270
  return fixer.replaceTextRange(
260
271
  [lastTokenOfPrev.range[1], firstToken.range[0]],
261
- fixedText
272
+ fixedText,
262
273
  );
263
274
  },
264
275
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-power-esrules",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "custom ESLint rules",
5
5
  "main": "index.js",
6
6
  "peerDependencies": {