@atlaskit/eslint-plugin-platform 2.7.2 → 2.9.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 (85) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/cjs/index.js +19 -3
  3. package/dist/cjs/rules/ensure-use-sync-external-store-server-snapshot/index.js +41 -0
  4. package/dist/cjs/rules/feature-gating/valid-gate-name/index.js +60 -0
  5. package/dist/cjs/rules/import/no-barrel-entry-imports/index.js +1279 -0
  6. package/dist/cjs/rules/import/no-barrel-entry-jest-mock/index.js +1659 -0
  7. package/dist/cjs/rules/import/no-conversation-assistant-barrel-imports/index.js +43 -0
  8. package/dist/cjs/rules/import/no-jest-mock-barrel-files/index.js +1402 -0
  9. package/dist/cjs/rules/import/no-relative-barrel-file-imports/index.js +781 -0
  10. package/dist/cjs/rules/import/shared/barrel-parsing.js +511 -0
  11. package/dist/cjs/rules/import/shared/file-system.js +186 -0
  12. package/dist/cjs/rules/import/shared/jest-utils.js +244 -0
  13. package/dist/cjs/rules/import/shared/package-registry.js +263 -0
  14. package/dist/cjs/rules/import/shared/package-resolution.js +318 -0
  15. package/dist/cjs/rules/import/shared/perf.js +89 -0
  16. package/dist/cjs/rules/import/shared/types.js +67 -0
  17. package/dist/cjs/rules/visit-example-type-import-required/index.js +409 -0
  18. package/dist/es2019/index.js +19 -3
  19. package/dist/es2019/rules/ensure-use-sync-external-store-server-snapshot/index.js +43 -0
  20. package/dist/es2019/rules/feature-gating/valid-gate-name/index.js +52 -0
  21. package/dist/es2019/rules/import/no-barrel-entry-imports/index.js +1158 -0
  22. package/dist/es2019/rules/import/no-barrel-entry-jest-mock/index.js +1341 -0
  23. package/dist/es2019/rules/import/no-conversation-assistant-barrel-imports/index.js +37 -0
  24. package/dist/es2019/rules/import/no-jest-mock-barrel-files/index.js +1180 -0
  25. package/dist/es2019/rules/import/no-relative-barrel-file-imports/index.js +742 -0
  26. package/dist/es2019/rules/import/shared/barrel-parsing.js +433 -0
  27. package/dist/es2019/rules/import/shared/file-system.js +174 -0
  28. package/dist/es2019/rules/import/shared/jest-utils.js +203 -0
  29. package/dist/es2019/rules/import/shared/package-registry.js +240 -0
  30. package/dist/es2019/rules/import/shared/package-resolution.js +253 -0
  31. package/dist/es2019/rules/import/shared/perf.js +83 -0
  32. package/dist/es2019/rules/import/shared/types.js +57 -0
  33. package/dist/es2019/rules/visit-example-type-import-required/index.js +375 -0
  34. package/dist/esm/index.js +19 -3
  35. package/dist/esm/rules/ensure-use-sync-external-store-server-snapshot/index.js +35 -0
  36. package/dist/esm/rules/feature-gating/valid-gate-name/index.js +53 -0
  37. package/dist/esm/rules/import/no-barrel-entry-imports/index.js +1272 -0
  38. package/dist/esm/rules/import/no-barrel-entry-jest-mock/index.js +1650 -0
  39. package/dist/esm/rules/import/no-conversation-assistant-barrel-imports/index.js +37 -0
  40. package/dist/esm/rules/import/no-jest-mock-barrel-files/index.js +1392 -0
  41. package/dist/esm/rules/import/no-relative-barrel-file-imports/index.js +774 -0
  42. package/dist/esm/rules/import/shared/barrel-parsing.js +500 -0
  43. package/dist/esm/rules/import/shared/file-system.js +176 -0
  44. package/dist/esm/rules/import/shared/jest-utils.js +231 -0
  45. package/dist/esm/rules/import/shared/package-registry.js +256 -0
  46. package/dist/esm/rules/import/shared/package-resolution.js +306 -0
  47. package/dist/esm/rules/import/shared/perf.js +80 -0
  48. package/dist/esm/rules/import/shared/types.js +61 -0
  49. package/dist/esm/rules/visit-example-type-import-required/index.js +402 -0
  50. package/dist/types/index.d.ts +28 -2
  51. package/dist/types/rules/ensure-use-sync-external-store-server-snapshot/index.d.ts +3 -0
  52. package/dist/types/rules/feature-gating/valid-gate-name/index.d.ts +3 -0
  53. package/dist/types/rules/import/no-barrel-entry-imports/index.d.ts +9 -0
  54. package/dist/types/rules/import/no-barrel-entry-jest-mock/index.d.ts +9 -0
  55. package/dist/types/rules/import/no-conversation-assistant-barrel-imports/index.d.ts +3 -0
  56. package/dist/types/rules/import/no-jest-mock-barrel-files/index.d.ts +22 -0
  57. package/dist/types/rules/import/no-relative-barrel-file-imports/index.d.ts +5 -0
  58. package/dist/types/rules/import/shared/barrel-parsing.d.ts +30 -0
  59. package/dist/types/rules/import/shared/file-system.d.ts +38 -0
  60. package/dist/types/rules/import/shared/jest-utils.d.ts +55 -0
  61. package/dist/types/rules/import/shared/package-registry.d.ts +26 -0
  62. package/dist/types/rules/import/shared/package-resolution.d.ts +58 -0
  63. package/dist/types/rules/import/shared/perf.d.ts +13 -0
  64. package/dist/types/rules/import/shared/types.d.ts +131 -0
  65. package/dist/types/rules/visit-example-type-import-required/index.d.ts +4 -0
  66. package/dist/types-ts4.5/index.d.ts +28 -2
  67. package/dist/types-ts4.5/rules/import/no-barrel-entry-imports/index.d.ts +9 -0
  68. package/dist/types-ts4.5/rules/import/no-barrel-entry-jest-mock/index.d.ts +9 -0
  69. package/dist/types-ts4.5/rules/import/no-conversation-assistant-barrel-imports/index.d.ts +3 -0
  70. package/dist/types-ts4.5/rules/import/no-jest-mock-barrel-files/index.d.ts +22 -0
  71. package/dist/types-ts4.5/rules/import/no-relative-barrel-file-imports/index.d.ts +5 -0
  72. package/dist/types-ts4.5/rules/import/shared/barrel-parsing.d.ts +30 -0
  73. package/dist/types-ts4.5/rules/import/shared/file-system.d.ts +38 -0
  74. package/dist/types-ts4.5/rules/import/shared/jest-utils.d.ts +55 -0
  75. package/dist/types-ts4.5/rules/import/shared/package-registry.d.ts +26 -0
  76. package/dist/types-ts4.5/rules/import/shared/package-resolution.d.ts +58 -0
  77. package/dist/types-ts4.5/rules/import/shared/perf.d.ts +13 -0
  78. package/dist/types-ts4.5/rules/import/shared/types.d.ts +131 -0
  79. package/dist/types-ts4.5/rules/visit-example-type-import-required/index.d.ts +4 -0
  80. package/package.json +6 -2
  81. package/dist/cjs/rules/ensure-native-and-af-exports-synced/index.js +0 -158
  82. package/dist/es2019/rules/ensure-native-and-af-exports-synced/index.js +0 -146
  83. package/dist/esm/rules/ensure-native-and-af-exports-synced/index.js +0 -151
  84. /package/dist/types-ts4.5/rules/{ensure-native-and-af-exports-synced → ensure-use-sync-external-store-server-snapshot}/index.d.ts +0 -0
  85. /package/dist/{types/rules/ensure-native-and-af-exports-synced → types-ts4.5/rules/feature-gating/valid-gate-name}/index.d.ts +0 -0
@@ -0,0 +1,1272 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
3
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
4
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
5
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
6
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
7
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
8
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
9
+ import { dirname } from 'path';
10
+ import { parseBarrelExports } from '../shared/barrel-parsing';
11
+ import { DEFAULT_TARGET_FOLDERS, findWorkspaceRoot, isRelativeImport } from '../shared/file-system';
12
+ import { findPackageInRegistry, isPackageInApplyToImportsFrom } from '../shared/package-registry';
13
+ import { findExportForSourceFile, parsePackageExports } from '../shared/package-resolution';
14
+ import { realFileSystem } from '../shared/types';
15
+
16
+ /**
17
+ * Options for the no-barrel-entry-imports rule.
18
+ */
19
+
20
+ /**
21
+ * Represents a Jest automock call: jest.mock('path') with no additional arguments
22
+ */
23
+
24
+ /**
25
+ * Metadata for the ESLint rule
26
+ */
27
+ var ruleMeta = {
28
+ type: 'problem',
29
+ docs: {
30
+ description: 'Disallow importing from barrel files in entry points.',
31
+ category: 'Best Practices',
32
+ recommended: false
33
+ },
34
+ fixable: 'code',
35
+ schema: [{
36
+ type: 'object',
37
+ properties: {
38
+ applyToImportsFrom: {
39
+ type: 'array',
40
+ items: {
41
+ type: 'string'
42
+ },
43
+ description: 'The folder paths (relative to workspace root) containing packages whose imports will be checked and autofixed.'
44
+ }
45
+ },
46
+ additionalProperties: false
47
+ }],
48
+ messages: {
49
+ barrelEntryImport: "Importing from barrel file '{{path}}' is not allowed. Import directly from the source file using a more specific package.json export instead."
50
+ }
51
+ };
52
+
53
+ /**
54
+ * Get the imported name from an ImportSpecifier, handling both Identifier and Literal
55
+ */
56
+ function getImportedName(spec) {
57
+ var imported = spec.imported;
58
+ return imported.type === 'Identifier' ? imported.name : String(imported.value);
59
+ }
60
+
61
+ /**
62
+ * Build an import statement for a set of specifiers
63
+ */
64
+ function buildImportStatement(_ref) {
65
+ var specs = _ref.specs,
66
+ path = _ref.path,
67
+ quoteChar = _ref.quoteChar,
68
+ _ref$isTypeImport = _ref.isTypeImport,
69
+ isTypeImport = _ref$isTypeImport === void 0 ? false : _ref$isTypeImport;
70
+ var importNames = specs.map(function (spec) {
71
+ if (spec.type === 'ImportDefaultSpecifier') {
72
+ return spec.local.name;
73
+ } else if (spec.type === 'ImportSpecifier') {
74
+ var imported = getImportedName(spec);
75
+ var local = spec.local.name;
76
+ var isInlineType = spec.importKind === 'type' && !isTypeImport;
77
+ var prefix = isInlineType ? 'type ' : '';
78
+ return imported === local ? "".concat(prefix).concat(imported) : "".concat(prefix).concat(imported, " as ").concat(local);
79
+ }
80
+ return '';
81
+ }).filter(function (name) {
82
+ return name.length > 0;
83
+ });
84
+ if (importNames.length === 0) {
85
+ return '';
86
+ }
87
+ var typeKeyword = isTypeImport ? 'type ' : '';
88
+ var hasDefault = specs.some(function (spec) {
89
+ return spec.type === 'ImportDefaultSpecifier';
90
+ });
91
+ var hasNamed = specs.some(function (spec) {
92
+ return spec.type === 'ImportSpecifier';
93
+ });
94
+ if (hasDefault && hasNamed) {
95
+ var _specs$find;
96
+ var defaultName = (_specs$find = specs.find(function (spec) {
97
+ return spec.type === 'ImportDefaultSpecifier';
98
+ })) === null || _specs$find === void 0 ? void 0 : _specs$find.local.name;
99
+ var namedImports = specs.filter(function (spec) {
100
+ return spec.type === 'ImportSpecifier';
101
+ }).map(function (spec) {
102
+ var imported = getImportedName(spec);
103
+ var local = spec.local.name;
104
+ var isInlineType = spec.importKind === 'type' && !isTypeImport;
105
+ var prefix = isInlineType ? 'type ' : '';
106
+ return imported === local ? "".concat(prefix).concat(imported) : "".concat(prefix).concat(imported, " as ").concat(local);
107
+ }).join(', ');
108
+ return "import ".concat(typeKeyword).concat(defaultName, ", { ").concat(namedImports, " } from ").concat(quoteChar).concat(path).concat(quoteChar, ";");
109
+ } else if (hasDefault) {
110
+ var _specs$find2;
111
+ var _defaultName = (_specs$find2 = specs.find(function (spec) {
112
+ return spec.type === 'ImportDefaultSpecifier';
113
+ })) === null || _specs$find2 === void 0 ? void 0 : _specs$find2.local.name;
114
+ return "import ".concat(typeKeyword).concat(_defaultName, " from ").concat(quoteChar).concat(path).concat(quoteChar, ";");
115
+ } else {
116
+ return "import ".concat(typeKeyword, "{ ").concat(importNames.join(', '), " } from ").concat(quoteChar).concat(path).concat(quoteChar, ";");
117
+ }
118
+ }
119
+
120
+ /**
121
+ * Represents a specifier with its resolved target export path information.
122
+ */
123
+
124
+ /**
125
+ * Context resolved for an import that may be a barrel import.
126
+ */
127
+
128
+ /**
129
+ * Result of classifying specifiers by their target export paths.
130
+ */
131
+
132
+ /**
133
+ * Resolves import context for barrel file analysis from a module specifier string.
134
+ * Returns null if the import should not be processed (relative import, not in target folder, etc.)
135
+ */
136
+ function resolveImportContextFromModulePath(_ref2) {
137
+ var importPath = _ref2.importPath,
138
+ workspaceRoot = _ref2.workspaceRoot,
139
+ fs = _ref2.fs,
140
+ applyToImportsFrom = _ref2.applyToImportsFrom;
141
+ // Skip relative imports - this rule is for cross-package imports
142
+ if (isRelativeImport(importPath)) {
143
+ return null;
144
+ }
145
+
146
+ // Extract the base package name (without subpath)
147
+ // e.g., "@atlassian/conversation-assistant-instrumentation" from
148
+ // "@atlassian/conversation-assistant-instrumentation" or
149
+ // "@atlassian/conversation-assistant-instrumentation/controllers/analytics"
150
+ var packageNameMatch = importPath.match(/^(@[^/]+\/[^/]+)/);
151
+ if (!packageNameMatch) {
152
+ return null;
153
+ }
154
+ var packageName = packageNameMatch[1];
155
+ var subPath = importPath.slice(packageName.length); // e.g., "" or "/controllers/analytics"
156
+
157
+ // Find the package (resolution is not constrained by applyToImportsFrom)
158
+ var packageDir = findPackageInRegistry({
159
+ packageName: packageName,
160
+ workspaceRoot: workspaceRoot,
161
+ fs: fs
162
+ });
163
+ if (!packageDir) {
164
+ return null;
165
+ }
166
+
167
+ // Only check imports from packages in our applyToImportsFrom folders
168
+ if (!isPackageInApplyToImportsFrom({
169
+ packageDir: packageDir,
170
+ workspaceRoot: workspaceRoot,
171
+ applyToImportsFrom: applyToImportsFrom
172
+ })) {
173
+ return null;
174
+ }
175
+
176
+ // Get the exports map for this package
177
+ var exportsMap = parsePackageExports({
178
+ packageDir: packageDir,
179
+ fs: fs
180
+ });
181
+ if (exportsMap.size === 0) {
182
+ return null;
183
+ }
184
+
185
+ // Determine which export path we're importing from
186
+ // For bare package imports, it's ".", for subpath imports it's "./" + subPath
187
+ var currentExportPath = subPath ? '.' + subPath : '.';
188
+
189
+ // Get the resolved path for the current export (the entry point file for this import)
190
+ var entryFilePath = exportsMap.get(currentExportPath);
191
+ if (!entryFilePath) {
192
+ return null;
193
+ }
194
+
195
+ // Parse the entry file to find where each export originates
196
+ // Pass workspaceRoot to enable cross-package re-export resolution
197
+ var exportMap = parseBarrelExports({
198
+ barrelFilePath: entryFilePath,
199
+ fs: fs,
200
+ workspaceRoot: workspaceRoot
201
+ });
202
+ if (exportMap.size === 0) {
203
+ return null;
204
+ }
205
+ return {
206
+ importPath: importPath,
207
+ packageName: packageName,
208
+ currentExportPath: currentExportPath,
209
+ exportsMap: exportsMap,
210
+ exportMap: exportMap
211
+ };
212
+ }
213
+
214
+ /**
215
+ * Resolves import context for barrel file analysis.
216
+ * Returns null if the import should not be processed (relative import, not in target folder, etc.)
217
+ */
218
+ function resolveImportContext(_ref3) {
219
+ var node = _ref3.node,
220
+ workspaceRoot = _ref3.workspaceRoot,
221
+ fs = _ref3.fs,
222
+ applyToImportsFrom = _ref3.applyToImportsFrom;
223
+ if (!node.source || typeof node.source.value !== 'string') {
224
+ return null;
225
+ }
226
+ return resolveImportContextFromModulePath({
227
+ importPath: node.source.value,
228
+ workspaceRoot: workspaceRoot,
229
+ fs: fs,
230
+ applyToImportsFrom: applyToImportsFrom
231
+ });
232
+ }
233
+
234
+ /**
235
+ * Classifies import specifiers by their target export paths.
236
+ * Groups specifiers that can be remapped to more specific exports.
237
+ * For cross-package re-exports, suggests importing from the source package's most specific subpath.
238
+ */
239
+ function classifySpecifiers(_ref4) {
240
+ var node = _ref4.node,
241
+ importContext = _ref4.importContext,
242
+ workspaceRoot = _ref4.workspaceRoot,
243
+ fs = _ref4.fs;
244
+ var currentExportPath = importContext.currentExportPath,
245
+ exportsMap = importContext.exportsMap,
246
+ exportMap = importContext.exportMap;
247
+ var specifiers = node.specifiers;
248
+ var specifiersByTarget = new Map();
249
+ var unmappedSpecifiers = [];
250
+ var hasNamespaceImport = false;
251
+
252
+ // Cache for source package exports maps to avoid redundant parsing
253
+ var sourcePackageExportsMaps = new Map();
254
+ var _iterator = _createForOfIteratorHelper(specifiers),
255
+ _step;
256
+ try {
257
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
258
+ var spec = _step.value;
259
+ if (spec.type === 'ImportNamespaceSpecifier') {
260
+ hasNamespaceImport = true;
261
+ continue;
262
+ }
263
+ var nameInSource = void 0;
264
+ var kind = 'value';
265
+ if (spec.type === 'ImportDefaultSpecifier') {
266
+ nameInSource = 'default';
267
+ } else if (spec.type === 'ImportSpecifier') {
268
+ nameInSource = getImportedName(spec);
269
+ var parentImportKind = node.importKind;
270
+ kind = parentImportKind === 'type' || spec.importKind === 'type' ? 'type' : 'value';
271
+ } else {
272
+ continue;
273
+ }
274
+ var exportInfo = exportMap.get(nameInSource);
275
+ if (exportInfo) {
276
+ var _exportInfo$crossPack, _exportInfo$originalN2, _matchResult$exportPa2;
277
+ var effectiveKind = kind === 'type' || exportInfo.isTypeOnly ? 'type' : 'value';
278
+
279
+ // Check if this is a cross-package re-export
280
+ var sourcePackageName = (_exportInfo$crossPack = exportInfo.crossPackageSource) === null || _exportInfo$crossPack === void 0 ? void 0 : _exportInfo$crossPack.packageName;
281
+ if (sourcePackageName) {
282
+ // For cross-package re-exports, find the most specific subpath in the source package
283
+ // Note: Package resolution is not constrained by applyToImportsFrom - any package can be resolved
284
+ var sourcePackageExportsMap = sourcePackageExportsMaps.get(sourcePackageName);
285
+ if (!sourcePackageExportsMap) {
286
+ var sourcePackageDir = findPackageInRegistry({
287
+ packageName: sourcePackageName,
288
+ workspaceRoot: workspaceRoot,
289
+ fs: fs
290
+ });
291
+ if (sourcePackageDir) {
292
+ sourcePackageExportsMap = parsePackageExports({
293
+ packageDir: sourcePackageDir,
294
+ fs: fs
295
+ });
296
+ sourcePackageExportsMaps.set(sourcePackageName, sourcePackageExportsMap);
297
+ }
298
+ }
299
+
300
+ // Find the best export path in the source package
301
+ var _targetExportPath = null;
302
+ var resolvedOriginalName = exportInfo.originalName;
303
+ if (sourcePackageExportsMap) {
304
+ var _exportInfo$originalN, _matchResult$exportPa;
305
+ var _sourceExportName = (_exportInfo$originalN = exportInfo.originalName) !== null && _exportInfo$originalN !== void 0 ? _exportInfo$originalN : nameInSource;
306
+ var _matchResult = findExportForSourceFile({
307
+ sourceFilePath: exportInfo.path,
308
+ exportsMap: sourcePackageExportsMap,
309
+ fs: fs,
310
+ sourceExportName: _sourceExportName
311
+ });
312
+ _targetExportPath = (_matchResult$exportPa = _matchResult === null || _matchResult === void 0 ? void 0 : _matchResult.exportPath) !== null && _matchResult$exportPa !== void 0 ? _matchResult$exportPa : null;
313
+ if ((_matchResult === null || _matchResult === void 0 ? void 0 : _matchResult.entryPointExportName) !== undefined) {
314
+ resolvedOriginalName = _matchResult.entryPointExportName === nameInSource ? undefined : _matchResult.entryPointExportName;
315
+ }
316
+ }
317
+
318
+ // Build the full import path: @package/subpath or just @package if no subpath found
319
+ var targetKey = _targetExportPath ? sourcePackageName + _targetExportPath.slice(1) // Remove leading '.' from subpath
320
+ : sourcePackageName;
321
+ if (!specifiersByTarget.has(targetKey)) {
322
+ specifiersByTarget.set(targetKey, []);
323
+ }
324
+ specifiersByTarget.get(targetKey).push({
325
+ spec: _objectSpread(_objectSpread({}, spec), {}, {
326
+ importKind: effectiveKind
327
+ }),
328
+ originalName: resolvedOriginalName,
329
+ targetExportPath: targetKey,
330
+ kind: effectiveKind,
331
+ sourcePackageName: sourcePackageName
332
+ });
333
+ continue;
334
+ }
335
+
336
+ // Find if there's a package.json export that points to this source file
337
+ var sourceExportName = (_exportInfo$originalN2 = exportInfo.originalName) !== null && _exportInfo$originalN2 !== void 0 ? _exportInfo$originalN2 : nameInSource;
338
+ var matchResult = findExportForSourceFile({
339
+ sourceFilePath: exportInfo.path,
340
+ exportsMap: exportsMap,
341
+ fs: fs,
342
+ sourceExportName: sourceExportName
343
+ });
344
+ var targetExportPath = (_matchResult$exportPa2 = matchResult === null || matchResult === void 0 ? void 0 : matchResult.exportPath) !== null && _matchResult$exportPa2 !== void 0 ? _matchResult$exportPa2 : null;
345
+ var resolvedOriginalName2 = exportInfo.originalName;
346
+ if ((matchResult === null || matchResult === void 0 ? void 0 : matchResult.entryPointExportName) !== undefined) {
347
+ resolvedOriginalName2 = matchResult.entryPointExportName === nameInSource ? undefined : matchResult.entryPointExportName;
348
+ }
349
+
350
+ // Get the file that the current export path resolves to
351
+ var currentExportResolvedFile = exportsMap.get(currentExportPath);
352
+
353
+ // Skip if:
354
+ // 1. No target export path found
355
+ // 2. Target is same as current (no change needed)
356
+ // 3. Current export path already resolves to the same file as the source
357
+ // (handles multiple exports pointing to same file - avoid no-op changes)
358
+ var currentExportAlreadyPointsToSourceFile = currentExportResolvedFile !== undefined && currentExportResolvedFile === exportInfo.path;
359
+ if (targetExportPath && targetExportPath !== currentExportPath && !currentExportAlreadyPointsToSourceFile) {
360
+ if (!specifiersByTarget.has(targetExportPath)) {
361
+ specifiersByTarget.set(targetExportPath, []);
362
+ }
363
+ specifiersByTarget.get(targetExportPath).push({
364
+ spec: _objectSpread(_objectSpread({}, spec), {}, {
365
+ importKind: effectiveKind
366
+ }),
367
+ originalName: resolvedOriginalName2,
368
+ targetExportPath: targetExportPath,
369
+ kind: effectiveKind
370
+ });
371
+ } else {
372
+ // No more specific export available
373
+ unmappedSpecifiers.push({
374
+ spec: spec,
375
+ targetExportPath: null,
376
+ kind: kind
377
+ });
378
+ }
379
+ } else {
380
+ unmappedSpecifiers.push({
381
+ spec: spec,
382
+ targetExportPath: null,
383
+ kind: kind
384
+ });
385
+ }
386
+ }
387
+ } catch (err) {
388
+ _iterator.e(err);
389
+ } finally {
390
+ _iterator.f();
391
+ }
392
+ return {
393
+ specifiersByTarget: specifiersByTarget,
394
+ unmappedSpecifiers: unmappedSpecifiers,
395
+ hasNamespaceImport: hasNamespaceImport
396
+ };
397
+ }
398
+
399
+ /**
400
+ * Transforms a specifier to use the original export name (handling aliasing).
401
+ * Converts named imports of default exports to ImportDefaultSpecifier.
402
+ */
403
+ function transformSpecifierForExport(_ref5) {
404
+ var spec = _ref5.spec,
405
+ originalName = _ref5.originalName,
406
+ kind = _ref5.kind;
407
+ if (!originalName) {
408
+ return spec;
409
+ }
410
+ if (originalName === 'default') {
411
+ // Should be ImportDefaultSpecifier
412
+ if (spec.type === 'ImportDefaultSpecifier') {
413
+ return spec;
414
+ }
415
+ // Convert ImportSpecifier to ImportDefaultSpecifier
416
+ return {
417
+ type: 'ImportDefaultSpecifier',
418
+ local: spec.local,
419
+ range: spec.range,
420
+ loc: spec.loc,
421
+ parent: spec.parent
422
+ };
423
+ } else {
424
+ // Create synthetic ImportSpecifier with correct importKind
425
+ return {
426
+ type: 'ImportSpecifier',
427
+ local: spec.local,
428
+ imported: {
429
+ type: 'Identifier',
430
+ name: originalName,
431
+ range: [0, 0],
432
+ loc: {
433
+ start: {
434
+ line: 0,
435
+ column: 0
436
+ },
437
+ end: {
438
+ line: 0,
439
+ column: 0
440
+ }
441
+ }
442
+ },
443
+ importKind: kind,
444
+ range: spec.range,
445
+ loc: spec.loc,
446
+ parent: spec.parent
447
+ };
448
+ }
449
+ }
450
+
451
+ /**
452
+ * Merges new specifiers with an existing import declaration.
453
+ * Returns the new import statement string.
454
+ */
455
+ function buildMergedImportStatement(_ref6) {
456
+ var existingImport = _ref6.existingImport,
457
+ newSpecs = _ref6.newSpecs,
458
+ newImportPath = _ref6.newImportPath,
459
+ nodeImportKind = _ref6.nodeImportKind,
460
+ quoteChar = _ref6.quoteChar;
461
+ var existingSpecs = existingImport.specifiers.map(function (s) {
462
+ if (existingImport.importKind === 'type') {
463
+ return _objectSpread(_objectSpread({}, s), {}, {
464
+ importKind: 'type'
465
+ });
466
+ }
467
+ return s;
468
+ });
469
+ var augmentedNewSpecs = newSpecs.map(function (s) {
470
+ if (nodeImportKind === 'type') {
471
+ return _objectSpread(_objectSpread({}, s), {}, {
472
+ importKind: 'type'
473
+ });
474
+ }
475
+ return s;
476
+ });
477
+ var mergedSpecs = [].concat(_toConsumableArray(existingSpecs), _toConsumableArray(augmentedNewSpecs));
478
+
479
+ // Determine if we should use 'import type'
480
+ var allType = mergedSpecs.every(function (s) {
481
+ return s.importKind === 'type';
482
+ });
483
+ return buildImportStatement({
484
+ specs: mergedSpecs,
485
+ path: newImportPath,
486
+ quoteChar: quoteChar,
487
+ isTypeImport: allType
488
+ });
489
+ }
490
+
491
+ /**
492
+ * Check if an ExpressionStatement is a Jest automock: jest.mock('path') with exactly one string argument.
493
+ * Returns the JestAutomock info if it is, null otherwise.
494
+ */
495
+ function getJestAutomock(node) {
496
+ if (node.type !== 'ExpressionStatement') {
497
+ return null;
498
+ }
499
+ var statement = node;
500
+ var expr = statement.expression;
501
+ if (expr.type !== 'CallExpression') {
502
+ return null;
503
+ }
504
+
505
+ // Check for jest.mock(...)
506
+ var callee = expr.callee;
507
+ if (callee.type !== 'MemberExpression' || callee.object.type !== 'Identifier' || callee.object.name !== 'jest' || callee.property.type !== 'Identifier' || callee.property.name !== 'mock') {
508
+ return null;
509
+ }
510
+
511
+ // Must have exactly one argument (automock = no factory function)
512
+ if (expr.arguments.length !== 1) {
513
+ return null;
514
+ }
515
+ var arg = expr.arguments[0];
516
+ if (arg.type !== 'Literal' || typeof arg.value !== 'string') {
517
+ return null;
518
+ }
519
+
520
+ // Get the quote character from the raw value
521
+ var raw = arg.raw || "'".concat(arg.value, "'");
522
+ var quoteChar = raw[0];
523
+ return {
524
+ statementNode: statement,
525
+ path: arg.value,
526
+ quoteChar: quoteChar
527
+ };
528
+ }
529
+
530
+ /**
531
+ * Find all Jest automocks in the AST that match the given import path.
532
+ */
533
+ function findMatchingAutomocks(_ref7) {
534
+ var sourceCode = _ref7.sourceCode,
535
+ importPath = _ref7.importPath;
536
+ var automocks = [];
537
+ var ast = sourceCode.ast;
538
+ var _iterator2 = _createForOfIteratorHelper(ast.body),
539
+ _step2;
540
+ try {
541
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
542
+ var statement = _step2.value;
543
+ var automock = getJestAutomock(statement);
544
+ if (automock && automock.path === importPath) {
545
+ automocks.push(automock);
546
+ }
547
+ }
548
+ } catch (err) {
549
+ _iterator2.e(err);
550
+ } finally {
551
+ _iterator2.f();
552
+ }
553
+ return automocks;
554
+ }
555
+
556
+ /**
557
+ * Build a jest.mock() statement string
558
+ */
559
+ function buildAutomockStatement(_ref8) {
560
+ var path = _ref8.path,
561
+ quoteChar = _ref8.quoteChar;
562
+ return "jest.mock(".concat(quoteChar).concat(path).concat(quoteChar, ");");
563
+ }
564
+
565
+ /**
566
+ * Creates a fix to remove a node with proper whitespace handling.
567
+ * Removes surrounding newlines to avoid leaving blank lines.
568
+ */
569
+ function createNodeRemovalFix(_ref9) {
570
+ var fixer = _ref9.fixer,
571
+ node = _ref9.node,
572
+ sourceCode = _ref9.sourceCode;
573
+ var nodeStart = node.range[0];
574
+ var nodeEnd = node.range[1];
575
+
576
+ // Check for leading newline (prefer removing the line separator before the node)
577
+ var textBeforeNode = sourceCode.text.slice(0, nodeStart);
578
+ var leadingNewlineMatch = textBeforeNode.match(/(\r?\n)$/);
579
+ if (leadingNewlineMatch) {
580
+ // Remove the leading newline plus the node
581
+ return fixer.removeRange([nodeStart - leadingNewlineMatch[1].length, nodeEnd]);
582
+ }
583
+
584
+ // No leading newline - check for trailing newline
585
+ var textAfterNode = sourceCode.text.slice(nodeEnd);
586
+ var trailingNewlineMatch = textAfterNode.match(/^(\r?\n)/);
587
+ if (trailingNewlineMatch) {
588
+ return fixer.removeRange([nodeStart, nodeEnd + trailingNewlineMatch[1].length]);
589
+ }
590
+ return fixer.remove(node);
591
+ }
592
+
593
+ /**
594
+ * Creates the auto-fix for barrel import violations.
595
+ * Generates new import statements and handles merging with existing imports.
596
+ * Also updates Jest automocks (jest.mock calls with only a path) when present.
597
+ */
598
+ function createBarrelImportFix(_ref0) {
599
+ var fixer = _ref0.fixer,
600
+ node = _ref0.node,
601
+ context = _ref0.context,
602
+ importContext = _ref0.importContext,
603
+ specifiersByTarget = _ref0.specifiersByTarget,
604
+ unmappedSpecifiers = _ref0.unmappedSpecifiers;
605
+ var importPath = importContext.importPath,
606
+ packageName = importContext.packageName;
607
+ var sourceCode = context.sourceCode;
608
+ var quote = sourceCode.getText(node.source)[0]; // Get quote character
609
+
610
+ var fixes = [];
611
+ var newStatements = [];
612
+
613
+ // Find any Jest automocks that match this import path
614
+ var automocks = findMatchingAutomocks({
615
+ sourceCode: sourceCode,
616
+ importPath: importPath
617
+ });
618
+
619
+ // Track which new import paths need automocks (only value imports, not type-only)
620
+ var automockPaths = [];
621
+
622
+ // Track if we have any value imports at all (to determine if automocks should be updated)
623
+ var hasAnyValueImports = false;
624
+
625
+ // Get all existing imports to check for merging
626
+ var allImports = sourceCode.ast.body.filter(function (n) {
627
+ return n.type === 'ImportDeclaration' && n !== node;
628
+ });
629
+
630
+ // Generate new import statements for each target export path
631
+ var _iterator3 = _createForOfIteratorHelper(specifiersByTarget),
632
+ _step3;
633
+ try {
634
+ var _loop2 = function _loop2() {
635
+ var _step3$value = _slicedToArray(_step3.value, 2),
636
+ targetExportPath = _step3$value[0],
637
+ specsWithTarget = _step3$value[1];
638
+ // Check if this is a cross-package re-export (sourcePackageName is set)
639
+ var isCrossPackage = specsWithTarget.some(function (s) {
640
+ return s.sourcePackageName;
641
+ });
642
+ var newImportPath = isCrossPackage ? targetExportPath // For cross-package, targetExportPath is already the full import path (e.g., @package/subpath)
643
+ : packageName + targetExportPath.slice(1); // Remove leading '.' for same-package imports
644
+
645
+ // Transform specifiers if needed (handle aliasing)
646
+ var specs = specsWithTarget.map(function (_ref10) {
647
+ var spec = _ref10.spec,
648
+ originalName = _ref10.originalName,
649
+ kind = _ref10.kind;
650
+ return transformSpecifierForExport({
651
+ spec: spec,
652
+ originalName: originalName,
653
+ kind: kind
654
+ });
655
+ });
656
+
657
+ // Check if any specifier in this group is a value import (not type-only)
658
+ // Only add automock paths for value imports (types don't need mocking at runtime)
659
+ if (automocks.length > 0) {
660
+ var hasValueImport = specsWithTarget.some(function (_ref11) {
661
+ var kind = _ref11.kind,
662
+ spec = _ref11.spec;
663
+ return kind === 'value' && (spec.type !== 'ImportSpecifier' || spec.importKind !== 'type');
664
+ });
665
+ if (hasValueImport) {
666
+ hasAnyValueImports = true;
667
+ automockPaths.push(newImportPath);
668
+ }
669
+ }
670
+
671
+ // Check for existing import from the same path
672
+ var existingImport = allImports.find(function (n) {
673
+ return n.source.value === newImportPath;
674
+ });
675
+
676
+ // Skip merging if existing is namespace import
677
+ var isNamespace = existingImport === null || existingImport === void 0 ? void 0 : existingImport.specifiers.some(function (s) {
678
+ return s.type === 'ImportNamespaceSpecifier';
679
+ });
680
+ if (existingImport && !isNamespace) {
681
+ // Merge with existing import
682
+ var newImportStatement = buildMergedImportStatement({
683
+ existingImport: existingImport,
684
+ newSpecs: specs,
685
+ newImportPath: newImportPath,
686
+ nodeImportKind: node.importKind,
687
+ quoteChar: quote
688
+ });
689
+ if (newImportStatement.length > 0) {
690
+ fixes.push(fixer.replaceText(existingImport, newImportStatement));
691
+ }
692
+ } else {
693
+ // Create new import
694
+ var _isTypeImport = node.importKind === 'type';
695
+ var importStatement = buildImportStatement({
696
+ specs: specs,
697
+ path: newImportPath,
698
+ quoteChar: quote,
699
+ isTypeImport: _isTypeImport
700
+ });
701
+ if (importStatement.length > 0) {
702
+ newStatements.push(importStatement);
703
+ }
704
+ }
705
+ };
706
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
707
+ _loop2();
708
+ }
709
+
710
+ // Handle unmapped specifiers - they stay in the original import
711
+ } catch (err) {
712
+ _iterator3.e(err);
713
+ } finally {
714
+ _iterator3.f();
715
+ }
716
+ if (unmappedSpecifiers.length > 0) {
717
+ var unmappedSpecs = unmappedSpecifiers.map(function (u) {
718
+ return u.spec;
719
+ });
720
+ var isTypeImport = node.importKind === 'type';
721
+ var remainingImport = buildImportStatement({
722
+ specs: unmappedSpecs,
723
+ path: importPath,
724
+ quoteChar: quote,
725
+ isTypeImport: isTypeImport
726
+ });
727
+ if (remainingImport.length > 0) {
728
+ newStatements.push(remainingImport);
729
+ }
730
+
731
+ // If there are unmapped value specifiers and automocks, keep the original automock path too
732
+ if (automocks.length > 0) {
733
+ var hasUnmappedValueImport = unmappedSpecifiers.some(function (_ref1) {
734
+ var kind = _ref1.kind,
735
+ spec = _ref1.spec;
736
+ return kind === 'value' && (spec.type !== 'ImportSpecifier' || spec.importKind !== 'type');
737
+ });
738
+ if (hasUnmappedValueImport) {
739
+ hasAnyValueImports = true;
740
+ automockPaths.push(importPath);
741
+ }
742
+ }
743
+ }
744
+ if (newStatements.length > 0) {
745
+ fixes.push(fixer.replaceText(node, newStatements.join('\n')));
746
+ } else {
747
+ // If all were merged, remove the node including surrounding whitespace/newlines
748
+ fixes.push(createNodeRemovalFix({
749
+ fixer: fixer,
750
+ node: node,
751
+ sourceCode: sourceCode
752
+ }));
753
+ }
754
+
755
+ // Handle automock updates
756
+ // Only modify automocks if there are value imports being fixed
757
+ // Type-only imports don't need runtime mocking, so we preserve existing automocks
758
+ if (automocks.length > 0 && hasAnyValueImports && automockPaths.length > 0) {
759
+ var _iterator4 = _createForOfIteratorHelper(automocks),
760
+ _step4;
761
+ try {
762
+ var _loop = function _loop() {
763
+ var automock = _step4.value;
764
+ // Build new automock statements for all new paths
765
+ var newAutomockStatements = automockPaths.map(function (path) {
766
+ return buildAutomockStatement({
767
+ path: path,
768
+ quoteChar: automock.quoteChar
769
+ });
770
+ });
771
+
772
+ // Replace the original automock statement with the new automock(s)
773
+ fixes.push(fixer.replaceTextRange(automock.statementNode.range, newAutomockStatements.join('\n')));
774
+ };
775
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
776
+ _loop();
777
+ }
778
+ } catch (err) {
779
+ _iterator4.e(err);
780
+ } finally {
781
+ _iterator4.f();
782
+ }
783
+ }
784
+ return fixes;
785
+ }
786
+ function isPlainRequireCall(node) {
787
+ if (node.callee.type !== 'Identifier' || node.callee.name !== 'require') {
788
+ return false;
789
+ }
790
+ if (node.arguments.length !== 1) {
791
+ return false;
792
+ }
793
+ var arg = node.arguments[0];
794
+ return arg.type === 'Literal' && typeof arg.value === 'string';
795
+ }
796
+ function unwrapToRequireCall(expr) {
797
+ var e = expr;
798
+ for (;;) {
799
+ var wrapped = e;
800
+ if (wrapped.type !== 'ParenthesizedExpression' || !wrapped.expression) {
801
+ break;
802
+ }
803
+ e = wrapped.expression;
804
+ }
805
+ if (e.type !== 'CallExpression' || !isPlainRequireCall(e)) {
806
+ return null;
807
+ }
808
+ return e;
809
+ }
810
+ function buildSyntheticImportFromRequireAccess(exportPropertyName, modulePath) {
811
+ var specifiers = exportPropertyName === 'default' ? [{
812
+ type: 'ImportDefaultSpecifier',
813
+ local: {
814
+ type: 'Identifier',
815
+ name: '_r'
816
+ }
817
+ }] : [{
818
+ type: 'ImportSpecifier',
819
+ imported: {
820
+ type: 'Identifier',
821
+ name: exportPropertyName
822
+ },
823
+ local: {
824
+ type: 'Identifier',
825
+ name: exportPropertyName
826
+ }
827
+ }];
828
+ return {
829
+ type: 'ImportDeclaration',
830
+ source: {
831
+ type: 'Literal',
832
+ value: modulePath,
833
+ raw: "'".concat(modulePath, "'")
834
+ },
835
+ specifiers: specifiers,
836
+ importKind: 'value'
837
+ };
838
+ }
839
+ function fullNewImportPathForTarget(targetKey, specsWithTarget, packageName) {
840
+ var isCrossPackage = specsWithTarget.some(function (s) {
841
+ return s.sourcePackageName;
842
+ });
843
+ return isCrossPackage ? targetKey : packageName + targetKey.slice(1);
844
+ }
845
+ function getRhsPropertyAfterTransform(spec) {
846
+ if (spec.type === 'ImportDefaultSpecifier') {
847
+ return 'default';
848
+ }
849
+ return getImportedName(spec);
850
+ }
851
+ function appendAutomockFixesForPathMigration(_ref12) {
852
+ var fixer = _ref12.fixer,
853
+ sourceCode = _ref12.sourceCode,
854
+ oldBarrelPath = _ref12.oldBarrelPath,
855
+ newPaths = _ref12.newPaths;
856
+ var automocks = findMatchingAutomocks({
857
+ sourceCode: sourceCode,
858
+ importPath: oldBarrelPath
859
+ });
860
+ if (automocks.length === 0 || newPaths.length === 0) {
861
+ return [];
862
+ }
863
+ var fixes = [];
864
+ var _iterator5 = _createForOfIteratorHelper(automocks),
865
+ _step5;
866
+ try {
867
+ var _loop3 = function _loop3() {
868
+ var automock = _step5.value;
869
+ var newAutomockStatements = newPaths.map(function (path) {
870
+ return buildAutomockStatement({
871
+ path: path,
872
+ quoteChar: automock.quoteChar
873
+ });
874
+ });
875
+ fixes.push(fixer.replaceTextRange(automock.statementNode.range, newAutomockStatements.join('\n')));
876
+ };
877
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
878
+ _loop3();
879
+ }
880
+ } catch (err) {
881
+ _iterator5.e(err);
882
+ } finally {
883
+ _iterator5.f();
884
+ }
885
+ return fixes;
886
+ }
887
+
888
+ /**
889
+ * `require('barrel').default` or `require('barrel').namedExport`
890
+ */
891
+ function handleRequireMemberExpression(_ref13) {
892
+ var node = _ref13.node,
893
+ context = _ref13.context,
894
+ workspaceRoot = _ref13.workspaceRoot,
895
+ fs = _ref13.fs,
896
+ applyToImportsFrom = _ref13.applyToImportsFrom;
897
+ if (node.computed || node.property.type !== 'Identifier') {
898
+ return;
899
+ }
900
+ var reqCall = unwrapToRequireCall(node.object);
901
+ if (!reqCall) {
902
+ return;
903
+ }
904
+ var modulePath = reqCall.arguments[0].value;
905
+ var importContext = resolveImportContextFromModulePath({
906
+ importPath: modulePath,
907
+ workspaceRoot: workspaceRoot,
908
+ fs: fs,
909
+ applyToImportsFrom: applyToImportsFrom
910
+ });
911
+ if (!importContext) {
912
+ return;
913
+ }
914
+ var exportPropertyName = node.property.name;
915
+ var synthetic = buildSyntheticImportFromRequireAccess(exportPropertyName, modulePath);
916
+ var _classifySpecifiers = classifySpecifiers({
917
+ node: synthetic,
918
+ importContext: importContext,
919
+ workspaceRoot: workspaceRoot,
920
+ fs: fs
921
+ }),
922
+ specifiersByTarget = _classifySpecifiers.specifiersByTarget,
923
+ hasNamespaceImport = _classifySpecifiers.hasNamespaceImport;
924
+ if (hasNamespaceImport || specifiersByTarget.size === 0) {
925
+ return;
926
+ }
927
+ var entries = _toConsumableArray(specifiersByTarget.entries());
928
+ if (entries.length !== 1) {
929
+ return;
930
+ }
931
+ var _ref14 = entries[0],
932
+ _ref15 = _slicedToArray(_ref14, 2),
933
+ targetKey = _ref15[0],
934
+ specsWithTarget = _ref15[1];
935
+ if (specsWithTarget.length !== 1) {
936
+ return;
937
+ }
938
+ var st = specsWithTarget[0];
939
+ var newImportPath = fullNewImportPathForTarget(targetKey, specsWithTarget, importContext.packageName);
940
+ var transformed = transformSpecifierForExport({
941
+ spec: st.spec,
942
+ originalName: st.originalName,
943
+ kind: st.kind
944
+ });
945
+ var newRhs = getRhsPropertyAfterTransform(transformed);
946
+ var sourceCode = context.getSourceCode();
947
+ var quote = sourceCode.getText(reqCall.arguments[0])[0];
948
+ context.report({
949
+ node: node,
950
+ messageId: 'barrelEntryImport',
951
+ data: {
952
+ path: importContext.importPath
953
+ },
954
+ fix: function fix(fixer) {
955
+ var fixes = [];
956
+ fixes.push(fixer.replaceText(node, "require(".concat(quote).concat(newImportPath).concat(quote, ").").concat(newRhs)));
957
+ if (st.kind === 'value') {
958
+ fixes.push.apply(fixes, _toConsumableArray(appendAutomockFixesForPathMigration({
959
+ fixer: fixer,
960
+ sourceCode: sourceCode,
961
+ oldBarrelPath: modulePath,
962
+ newPaths: [newImportPath]
963
+ })));
964
+ }
965
+ return fixes;
966
+ }
967
+ });
968
+ }
969
+
970
+ /**
971
+ * `const { a, b } = require('barrel')`
972
+ */
973
+ function handleRequireDestructuringDeclarator(_ref16) {
974
+ var node = _ref16.node,
975
+ context = _ref16.context,
976
+ workspaceRoot = _ref16.workspaceRoot,
977
+ fs = _ref16.fs,
978
+ applyToImportsFrom = _ref16.applyToImportsFrom;
979
+ if (node.id.type !== 'ObjectPattern' || !node.init || node.init.type !== 'CallExpression') {
980
+ return;
981
+ }
982
+ var initCall = node.init;
983
+ if (!isPlainRequireCall(initCall)) {
984
+ return;
985
+ }
986
+ var modulePath = initCall.arguments[0].value;
987
+ var importContext = resolveImportContextFromModulePath({
988
+ importPath: modulePath,
989
+ workspaceRoot: workspaceRoot,
990
+ fs: fs,
991
+ applyToImportsFrom: applyToImportsFrom
992
+ });
993
+ if (!importContext) {
994
+ return;
995
+ }
996
+ var specifiers = [];
997
+ var _iterator6 = _createForOfIteratorHelper(node.id.properties),
998
+ _step6;
999
+ try {
1000
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
1001
+ var prop = _step6.value;
1002
+ if (prop.type !== 'Property' || prop.computed) {
1003
+ continue;
1004
+ }
1005
+ if (prop.key.type !== 'Identifier' || prop.value.type !== 'Identifier') {
1006
+ continue;
1007
+ }
1008
+ var importedName = prop.key.name;
1009
+ var localName = prop.value.name;
1010
+ specifiers.push({
1011
+ type: 'ImportSpecifier',
1012
+ imported: {
1013
+ type: 'Identifier',
1014
+ name: importedName
1015
+ },
1016
+ local: {
1017
+ type: 'Identifier',
1018
+ name: localName
1019
+ }
1020
+ });
1021
+ }
1022
+ } catch (err) {
1023
+ _iterator6.e(err);
1024
+ } finally {
1025
+ _iterator6.f();
1026
+ }
1027
+ if (specifiers.length === 0) {
1028
+ return;
1029
+ }
1030
+ var synthetic = {
1031
+ type: 'ImportDeclaration',
1032
+ source: {
1033
+ type: 'Literal',
1034
+ value: modulePath,
1035
+ raw: "'".concat(modulePath, "'")
1036
+ },
1037
+ specifiers: specifiers,
1038
+ importKind: 'value'
1039
+ };
1040
+ var _classifySpecifiers2 = classifySpecifiers({
1041
+ node: synthetic,
1042
+ importContext: importContext,
1043
+ workspaceRoot: workspaceRoot,
1044
+ fs: fs
1045
+ }),
1046
+ specifiersByTarget = _classifySpecifiers2.specifiersByTarget,
1047
+ unmappedSpecifiers = _classifySpecifiers2.unmappedSpecifiers,
1048
+ hasNamespaceImport = _classifySpecifiers2.hasNamespaceImport;
1049
+ if (hasNamespaceImport || specifiersByTarget.size === 0 || unmappedSpecifiers.length > 0) {
1050
+ return;
1051
+ }
1052
+ var parentDecl = node.parent;
1053
+ if (parentDecl.type !== 'VariableDeclaration') {
1054
+ return;
1055
+ }
1056
+ if (specifiersByTarget.size > 1 && parentDecl.declarations.length !== 1) {
1057
+ return;
1058
+ }
1059
+ var sourceCode = context.getSourceCode();
1060
+ var quote = sourceCode.getText(initCall.arguments[0])[0];
1061
+ var pkg = importContext.packageName;
1062
+ var buildFixes = function buildFixes(fixer) {
1063
+ var fixes = [];
1064
+ var hasValue = false;
1065
+ var automockPaths = [];
1066
+ if (specifiersByTarget.size === 1) {
1067
+ var _ref17 = _toConsumableArray(specifiersByTarget.entries())[0],
1068
+ _ref18 = _slicedToArray(_ref17, 2),
1069
+ targetKey = _ref18[0],
1070
+ specsWithTarget = _ref18[1];
1071
+ var newImportPath = fullNewImportPathForTarget(targetKey, specsWithTarget, pkg);
1072
+ if (specsWithTarget.some(function (s) {
1073
+ return s.kind === 'value';
1074
+ })) {
1075
+ hasValue = true;
1076
+ automockPaths.push(newImportPath);
1077
+ }
1078
+ fixes.push(fixer.replaceText(initCall.arguments[0], "".concat(quote).concat(newImportPath).concat(quote)));
1079
+ } else {
1080
+ var lines = [];
1081
+ var _iterator7 = _createForOfIteratorHelper(specifiersByTarget),
1082
+ _step7;
1083
+ try {
1084
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
1085
+ var _step7$value = _slicedToArray(_step7.value, 2),
1086
+ _targetKey = _step7$value[0],
1087
+ _specsWithTarget = _step7$value[1];
1088
+ var _newImportPath = fullNewImportPathForTarget(_targetKey, _specsWithTarget, pkg);
1089
+ if (_specsWithTarget.some(function (s) {
1090
+ return s.kind === 'value';
1091
+ })) {
1092
+ hasValue = true;
1093
+ automockPaths.push(_newImportPath);
1094
+ }
1095
+ var _iterator8 = _createForOfIteratorHelper(_specsWithTarget),
1096
+ _step8;
1097
+ try {
1098
+ for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
1099
+ var st = _step8.value;
1100
+ var transformed = transformSpecifierForExport({
1101
+ spec: st.spec,
1102
+ originalName: st.originalName,
1103
+ kind: st.kind
1104
+ });
1105
+ var rhs = getRhsPropertyAfterTransform(transformed);
1106
+ var local = st.spec.local.name;
1107
+ lines.push("".concat(local, " = require(").concat(quote).concat(_newImportPath).concat(quote, ").").concat(rhs));
1108
+ }
1109
+ } catch (err) {
1110
+ _iterator8.e(err);
1111
+ } finally {
1112
+ _iterator8.f();
1113
+ }
1114
+ }
1115
+ } catch (err) {
1116
+ _iterator7.e(err);
1117
+ } finally {
1118
+ _iterator7.f();
1119
+ }
1120
+ var declText = lines.map(function (l) {
1121
+ return "".concat(parentDecl.kind, " ").concat(l, ";");
1122
+ }).join('\n');
1123
+ fixes.push(fixer.replaceText(parentDecl, declText));
1124
+ }
1125
+ if (hasValue) {
1126
+ fixes.push.apply(fixes, _toConsumableArray(appendAutomockFixesForPathMigration({
1127
+ fixer: fixer,
1128
+ sourceCode: sourceCode,
1129
+ oldBarrelPath: modulePath,
1130
+ newPaths: _toConsumableArray(new Set(automockPaths))
1131
+ })));
1132
+ }
1133
+ return fixes;
1134
+ };
1135
+ context.report({
1136
+ node: initCall,
1137
+ messageId: 'barrelEntryImport',
1138
+ data: {
1139
+ path: importContext.importPath
1140
+ },
1141
+ fix: buildFixes
1142
+ });
1143
+ }
1144
+
1145
+ /**
1146
+ * Handles an ImportDeclaration node to check for barrel file imports.
1147
+ * Reports and auto-fixes imports that could use more specific export paths.
1148
+ */
1149
+ function handleImportDeclaration(_ref19) {
1150
+ var node = _ref19.node,
1151
+ context = _ref19.context,
1152
+ workspaceRoot = _ref19.workspaceRoot,
1153
+ fs = _ref19.fs,
1154
+ applyToImportsFrom = _ref19.applyToImportsFrom;
1155
+ // Resolve import context (validates and extracts package/export info)
1156
+ // applyToImportsFrom is used here to filter which packages the rule applies to
1157
+ var importContext = resolveImportContext({
1158
+ node: node,
1159
+ workspaceRoot: workspaceRoot,
1160
+ fs: fs,
1161
+ applyToImportsFrom: applyToImportsFrom
1162
+ });
1163
+ if (!importContext) {
1164
+ return;
1165
+ }
1166
+
1167
+ // Check each imported specifier to see if we can find a more specific export
1168
+ if (node.specifiers.length === 0) {
1169
+ return;
1170
+ }
1171
+
1172
+ // Classify specifiers by their target export paths
1173
+ var _classifySpecifiers3 = classifySpecifiers({
1174
+ node: node,
1175
+ importContext: importContext,
1176
+ workspaceRoot: workspaceRoot,
1177
+ fs: fs
1178
+ }),
1179
+ specifiersByTarget = _classifySpecifiers3.specifiersByTarget,
1180
+ unmappedSpecifiers = _classifySpecifiers3.unmappedSpecifiers,
1181
+ hasNamespaceImport = _classifySpecifiers3.hasNamespaceImport;
1182
+
1183
+ // If namespace import, report without auto-fix if there are specific exports available
1184
+ if (hasNamespaceImport) {
1185
+ if (specifiersByTarget.size > 0) {
1186
+ context.report({
1187
+ node: node,
1188
+ messageId: 'barrelEntryImport',
1189
+ data: {
1190
+ path: importContext.importPath
1191
+ }
1192
+ });
1193
+ }
1194
+ return;
1195
+ }
1196
+
1197
+ // If no specifiers can be remapped to more specific imports, don't report
1198
+ if (specifiersByTarget.size === 0) {
1199
+ return;
1200
+ }
1201
+
1202
+ // Report with auto-fix
1203
+ context.report({
1204
+ node: node,
1205
+ messageId: 'barrelEntryImport',
1206
+ data: {
1207
+ path: importContext.importPath
1208
+ },
1209
+ fix: function fix(fixer) {
1210
+ return createBarrelImportFix({
1211
+ fixer: fixer,
1212
+ node: node,
1213
+ context: context,
1214
+ importContext: importContext,
1215
+ specifiersByTarget: specifiersByTarget,
1216
+ unmappedSpecifiers: unmappedSpecifiers
1217
+ });
1218
+ }
1219
+ });
1220
+ }
1221
+
1222
+ /**
1223
+ * Factory function to create the ESLint rule with a given file system.
1224
+ * This enables testing with mock file systems.
1225
+ */
1226
+ export function createRule(fs) {
1227
+ return {
1228
+ meta: ruleMeta,
1229
+ create: function create(context) {
1230
+ var _options$applyToImpor;
1231
+ var options = context.options[0] || {};
1232
+ var applyToImportsFrom = (_options$applyToImpor = options.applyToImportsFrom) !== null && _options$applyToImpor !== void 0 ? _options$applyToImpor : DEFAULT_TARGET_FOLDERS;
1233
+ var workspaceRoot = findWorkspaceRoot({
1234
+ startPath: dirname(context.filename),
1235
+ fs: fs,
1236
+ applyToImportsFrom: applyToImportsFrom
1237
+ });
1238
+ return {
1239
+ ImportDeclaration: function ImportDeclaration(rawNode) {
1240
+ var node = rawNode;
1241
+ handleImportDeclaration({
1242
+ node: node,
1243
+ context: context,
1244
+ workspaceRoot: workspaceRoot,
1245
+ fs: fs,
1246
+ applyToImportsFrom: applyToImportsFrom
1247
+ });
1248
+ },
1249
+ MemberExpression: function MemberExpression(rawNode) {
1250
+ handleRequireMemberExpression({
1251
+ node: rawNode,
1252
+ context: context,
1253
+ workspaceRoot: workspaceRoot,
1254
+ fs: fs,
1255
+ applyToImportsFrom: applyToImportsFrom
1256
+ });
1257
+ },
1258
+ VariableDeclarator: function VariableDeclarator(rawNode) {
1259
+ handleRequireDestructuringDeclarator({
1260
+ node: rawNode,
1261
+ context: context,
1262
+ workspaceRoot: workspaceRoot,
1263
+ fs: fs,
1264
+ applyToImportsFrom: applyToImportsFrom
1265
+ });
1266
+ }
1267
+ };
1268
+ }
1269
+ };
1270
+ }
1271
+ var rule = createRule(realFileSystem);
1272
+ export default rule;