@atlaskit/eslint-plugin-platform 2.8.0 → 2.9.1
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/CHANGELOG.md +16 -0
- package/dist/cjs/index.js +8 -1
- package/dist/cjs/rules/ensure-critical-dependency-resolutions/index.js +0 -1
- package/dist/cjs/rules/ensure-use-sync-external-store-server-snapshot/index.js +41 -0
- package/dist/cjs/rules/import/no-barrel-entry-imports/index.js +534 -74
- package/dist/cjs/rules/import/no-barrel-entry-jest-mock/index.js +428 -119
- package/dist/cjs/rules/import/no-jest-mock-barrel-files/index.js +3 -2
- package/dist/cjs/rules/import/no-relative-barrel-file-imports/index.js +7 -3
- package/dist/cjs/rules/import/shared/jest-utils.js +62 -9
- package/dist/cjs/rules/import/shared/package-resolution.js +300 -22
- package/dist/cjs/rules/no-restricted-fedramp-imports/index.js +65 -0
- package/dist/cjs/rules/visit-example-type-import-required/index.js +409 -0
- package/dist/es2019/index.js +8 -1
- package/dist/es2019/rules/ensure-critical-dependency-resolutions/index.js +0 -1
- package/dist/es2019/rules/ensure-use-sync-external-store-server-snapshot/index.js +43 -0
- package/dist/es2019/rules/import/no-barrel-entry-imports/index.js +431 -25
- package/dist/es2019/rules/import/no-barrel-entry-jest-mock/index.js +287 -25
- package/dist/es2019/rules/import/no-jest-mock-barrel-files/index.js +3 -2
- package/dist/es2019/rules/import/no-relative-barrel-file-imports/index.js +7 -3
- package/dist/es2019/rules/import/shared/jest-utils.js +44 -0
- package/dist/es2019/rules/import/shared/package-resolution.js +211 -4
- package/dist/es2019/rules/no-restricted-fedramp-imports/index.js +47 -0
- package/dist/es2019/rules/visit-example-type-import-required/index.js +375 -0
- package/dist/esm/index.js +8 -1
- package/dist/esm/rules/ensure-critical-dependency-resolutions/index.js +0 -1
- package/dist/esm/rules/ensure-use-sync-external-store-server-snapshot/index.js +35 -0
- package/dist/esm/rules/import/no-barrel-entry-imports/index.js +535 -75
- package/dist/esm/rules/import/no-barrel-entry-jest-mock/index.js +430 -121
- package/dist/esm/rules/import/no-jest-mock-barrel-files/index.js +3 -2
- package/dist/esm/rules/import/no-relative-barrel-file-imports/index.js +7 -3
- package/dist/esm/rules/import/shared/jest-utils.js +61 -9
- package/dist/esm/rules/import/shared/package-resolution.js +298 -24
- package/dist/esm/rules/no-restricted-fedramp-imports/index.js +59 -0
- package/dist/esm/rules/visit-example-type-import-required/index.js +402 -0
- package/dist/types/index.d.ts +14 -0
- package/dist/types/rules/ensure-use-sync-external-store-server-snapshot/index.d.ts +3 -0
- package/dist/types/rules/import/shared/jest-utils.d.ts +8 -0
- package/dist/types/rules/import/shared/package-resolution.d.ts +47 -2
- package/dist/types/rules/no-restricted-fedramp-imports/index.d.ts +3 -0
- package/dist/types/rules/visit-example-type-import-required/index.d.ts +4 -0
- package/dist/types-ts4.5/index.d.ts +14 -0
- package/dist/types-ts4.5/rules/ensure-use-sync-external-store-server-snapshot/index.d.ts +3 -0
- package/dist/types-ts4.5/rules/import/shared/jest-utils.d.ts +8 -0
- package/dist/types-ts4.5/rules/import/shared/package-resolution.d.ts +47 -2
- package/dist/types-ts4.5/rules/no-restricted-fedramp-imports/index.d.ts +3 -0
- package/dist/types-ts4.5/rules/visit-example-type-import-required/index.d.ts +4 -0
- package/package.json +3 -1
|
@@ -232,6 +232,7 @@ function getImportPathForSourceFile(_ref) {
|
|
|
232
232
|
fs = _ref.fs;
|
|
233
233
|
var crossPackageName = exportInfo === null || exportInfo === void 0 || (_exportInfo$crossPack = exportInfo.crossPackageSource) === null || _exportInfo$crossPack === void 0 ? void 0 : _exportInfo$crossPack.packageName;
|
|
234
234
|
if (crossPackageName) {
|
|
235
|
+
var _findExportForSourceF;
|
|
235
236
|
var sourcePackageExportsMaps = getSourcePackageExportsMaps(fs);
|
|
236
237
|
var exportsMap = sourcePackageExportsMaps.get(crossPackageName);
|
|
237
238
|
if (!exportsMap) {
|
|
@@ -248,10 +249,10 @@ function getImportPathForSourceFile(_ref) {
|
|
|
248
249
|
sourcePackageExportsMaps.set(crossPackageName, exportsMap);
|
|
249
250
|
}
|
|
250
251
|
}
|
|
251
|
-
var targetExportPath = exportsMap ? (0, _packageResolution.findExportForSourceFile)({
|
|
252
|
+
var targetExportPath = exportsMap ? (_findExportForSourceF = (0, _packageResolution.findExportForSourceFile)({
|
|
252
253
|
sourceFilePath: sourceFilePath,
|
|
253
254
|
exportsMap: exportsMap
|
|
254
|
-
}) : null;
|
|
255
|
+
})) === null || _findExportForSourceF === void 0 ? void 0 : _findExportForSourceF.exportPath : null;
|
|
255
256
|
return targetExportPath ? crossPackageName + targetExportPath.slice(1) : crossPackageName;
|
|
256
257
|
}
|
|
257
258
|
return getRelativeImportPath({
|
|
@@ -68,6 +68,7 @@ function getImportPathForSourceFile(_ref) {
|
|
|
68
68
|
fs = _ref.fs;
|
|
69
69
|
var crossPackageName = exportInfo === null || exportInfo === void 0 || (_exportInfo$crossPack = exportInfo.crossPackageSource) === null || _exportInfo$crossPack === void 0 ? void 0 : _exportInfo$crossPack.packageName;
|
|
70
70
|
if (crossPackageName) {
|
|
71
|
+
var _findExportForSourceF;
|
|
71
72
|
var sourcePackageExportsMaps = getSourcePackageExportsMaps(fs);
|
|
72
73
|
var exportsMap = sourcePackageExportsMaps.get(crossPackageName);
|
|
73
74
|
if (!exportsMap) {
|
|
@@ -84,10 +85,10 @@ function getImportPathForSourceFile(_ref) {
|
|
|
84
85
|
sourcePackageExportsMaps.set(crossPackageName, exportsMap);
|
|
85
86
|
}
|
|
86
87
|
}
|
|
87
|
-
var targetExportPath = exportsMap ? (0, _packageResolution.findExportForSourceFile)({
|
|
88
|
+
var targetExportPath = exportsMap ? (_findExportForSourceF = (0, _packageResolution.findExportForSourceFile)({
|
|
88
89
|
sourceFilePath: sourceFilePath,
|
|
89
90
|
exportsMap: exportsMap
|
|
90
|
-
}) : null;
|
|
91
|
+
})) === null || _findExportForSourceF === void 0 ? void 0 : _findExportForSourceF.exportPath : null;
|
|
91
92
|
return targetExportPath ? crossPackageName + targetExportPath.slice(1) : crossPackageName;
|
|
92
93
|
}
|
|
93
94
|
return getRelativeImportPath({
|
|
@@ -466,10 +467,13 @@ function transformExportSpecifiers(_ref1) {
|
|
|
466
467
|
var specsWithOriginal = _ref1.specsWithOriginal;
|
|
467
468
|
return specsWithOriginal.map(function (_ref10) {
|
|
468
469
|
var originalName = _ref10.originalName,
|
|
470
|
+
nameInSource = _ref10.nameInSource,
|
|
469
471
|
nameInLocal = _ref10.nameInLocal,
|
|
470
472
|
kind = _ref10.kind;
|
|
471
473
|
return {
|
|
472
|
-
|
|
474
|
+
// Use originalName if available (means there was an alias in the barrel),
|
|
475
|
+
// otherwise use nameInSource (the direct export name from the barrel)
|
|
476
|
+
nameInSource: originalName !== null && originalName !== void 0 ? originalName : nameInSource,
|
|
473
477
|
nameInLocal: nameInLocal,
|
|
474
478
|
kind: kind
|
|
475
479
|
};
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.extractImportPath = extractImportPath;
|
|
8
|
+
exports.findJestRequireActualCalls = findJestRequireActualCalls;
|
|
8
9
|
exports.findJestRequireMockCalls = findJestRequireMockCalls;
|
|
9
10
|
exports.isJestMockCall = isJestMockCall;
|
|
10
11
|
exports.isJestRequireActual = isJestRequireActual;
|
|
@@ -136,6 +137,58 @@ function findJestRequireMockCalls(_ref) {
|
|
|
136
137
|
return results;
|
|
137
138
|
}
|
|
138
139
|
|
|
140
|
+
/**
|
|
141
|
+
* Find all jest.requireActual() calls in the AST whose import path matches a given target.
|
|
142
|
+
* Works identically to findJestRequireMockCalls but for requireActual.
|
|
143
|
+
*/
|
|
144
|
+
function findJestRequireActualCalls(_ref2) {
|
|
145
|
+
var ast = _ref2.ast,
|
|
146
|
+
matchPath = _ref2.matchPath;
|
|
147
|
+
var results = [];
|
|
148
|
+
var visited = new WeakSet();
|
|
149
|
+
var skipKeys = new Set(['parent', 'loc', 'range', 'tokens', 'comments']);
|
|
150
|
+
function visit(node) {
|
|
151
|
+
if (visited.has(node)) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
visited.add(node);
|
|
155
|
+
if (node.type === 'CallExpression' && isJestRequireActual(node)) {
|
|
156
|
+
var path = extractImportPath(node);
|
|
157
|
+
if (path && matchPath(path)) {
|
|
158
|
+
results.push(node);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
for (var key in node) {
|
|
162
|
+
if (skipKeys.has(key)) {
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
var value = node[key];
|
|
166
|
+
if (value && (0, _typeof2.default)(value) === 'object') {
|
|
167
|
+
if (Array.isArray(value)) {
|
|
168
|
+
var _iterator2 = _createForOfIteratorHelper(value),
|
|
169
|
+
_step2;
|
|
170
|
+
try {
|
|
171
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
172
|
+
var child = _step2.value;
|
|
173
|
+
if (child && (0, _typeof2.default)(child) === 'object' && 'type' in child) {
|
|
174
|
+
visit(child);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
} catch (err) {
|
|
178
|
+
_iterator2.e(err);
|
|
179
|
+
} finally {
|
|
180
|
+
_iterator2.f();
|
|
181
|
+
}
|
|
182
|
+
} else if ('type' in value) {
|
|
183
|
+
visit(value);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
visit(ast);
|
|
189
|
+
return results;
|
|
190
|
+
}
|
|
191
|
+
|
|
139
192
|
/**
|
|
140
193
|
* Determine the best new import path for a jest.requireMock() call by inspecting
|
|
141
194
|
* the destructured symbols or property access at the call site.
|
|
@@ -144,20 +197,20 @@ function findJestRequireMockCalls(_ref) {
|
|
|
144
197
|
* @param symbolToNewPath - Map from symbol name to the new mock path that provides it
|
|
145
198
|
* @returns The resolved new path, or null if it cannot be determined
|
|
146
199
|
*/
|
|
147
|
-
function resolveNewPathForRequireMock(
|
|
148
|
-
var requireMockNode =
|
|
149
|
-
symbolToNewPath =
|
|
200
|
+
function resolveNewPathForRequireMock(_ref3) {
|
|
201
|
+
var requireMockNode = _ref3.requireMockNode,
|
|
202
|
+
symbolToNewPath = _ref3.symbolToNewPath;
|
|
150
203
|
var parent = requireMockNode.parent;
|
|
151
204
|
if (parent) {
|
|
152
205
|
var _parent;
|
|
153
206
|
// Check for destructuring pattern: const { foo } = jest.requireMock('...')
|
|
154
207
|
var declarator = parent.type === 'VariableDeclarator' ? parent : ((_parent = parent.parent) === null || _parent === void 0 ? void 0 : _parent.type) === 'VariableDeclarator' ? parent.parent : null;
|
|
155
208
|
if (declarator && declarator.type === 'VariableDeclarator' && declarator.id.type === 'ObjectPattern') {
|
|
156
|
-
var
|
|
157
|
-
|
|
209
|
+
var _iterator3 = _createForOfIteratorHelper(declarator.id.properties),
|
|
210
|
+
_step3;
|
|
158
211
|
try {
|
|
159
|
-
for (
|
|
160
|
-
var prop =
|
|
212
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
213
|
+
var prop = _step3.value;
|
|
161
214
|
if (prop.type === 'Property' && prop.key.type === 'Identifier') {
|
|
162
215
|
var matchedPath = symbolToNewPath.get(prop.key.name);
|
|
163
216
|
if (matchedPath) {
|
|
@@ -166,9 +219,9 @@ function resolveNewPathForRequireMock(_ref2) {
|
|
|
166
219
|
}
|
|
167
220
|
}
|
|
168
221
|
} catch (err) {
|
|
169
|
-
|
|
222
|
+
_iterator3.e(err);
|
|
170
223
|
} finally {
|
|
171
|
-
|
|
224
|
+
_iterator3.f();
|
|
172
225
|
}
|
|
173
226
|
}
|
|
174
227
|
|
|
@@ -1,27 +1,109 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _typeof3 = require("@babel/runtime/helpers/typeof");
|
|
4
5
|
Object.defineProperty(exports, "__esModule", {
|
|
5
6
|
value: true
|
|
6
7
|
});
|
|
7
8
|
exports.extractPackageNameFromImport = extractPackageNameFromImport;
|
|
9
|
+
exports.findCrossPackageBridgeExportPath = findCrossPackageBridgeExportPath;
|
|
8
10
|
exports.findExportForSourceFile = findExportForSourceFile;
|
|
11
|
+
exports.isKebabCaseExportKey = isKebabCaseExportKey;
|
|
9
12
|
exports.parsePackageExports = parsePackageExports;
|
|
10
13
|
exports.resolveCrossPackageImport = resolveCrossPackageImport;
|
|
11
14
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
12
15
|
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
13
16
|
var _path = require("path");
|
|
17
|
+
var ts = _interopRequireWildcard(require("typescript"));
|
|
14
18
|
var _fileSystem = require("./file-system");
|
|
15
19
|
var _packageRegistry = require("./package-registry");
|
|
20
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof3(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
16
21
|
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; } } }; }
|
|
17
22
|
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; } }
|
|
18
23
|
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; }
|
|
24
|
+
var ENTRY_POINT_FOLDER_NAMES = new Set(['entry-points', 'entrypoints', 'entrypoint', 'entry-point']);
|
|
25
|
+
function isInEntryPointsFolder(filePath) {
|
|
26
|
+
var parts = filePath.split(/[/\\]/);
|
|
27
|
+
return parts.some(function (part) {
|
|
28
|
+
return ENTRY_POINT_FOLDER_NAMES.has(part);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
19
31
|
/**
|
|
20
|
-
* Parse
|
|
32
|
+
* Parse an entry-point wrapper file and resolve the source files it re-exports from,
|
|
33
|
+
* along with name mappings (source export name → entry-point export name).
|
|
21
34
|
*/
|
|
22
|
-
function
|
|
23
|
-
var
|
|
35
|
+
function resolveEntryPointReExports(_ref) {
|
|
36
|
+
var entryPointFilePath = _ref.entryPointFilePath,
|
|
24
37
|
fs = _ref.fs;
|
|
38
|
+
var content = (0, _fileSystem.readFileContent)({
|
|
39
|
+
filePath: entryPointFilePath,
|
|
40
|
+
fs: fs
|
|
41
|
+
});
|
|
42
|
+
if (!content) {
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
46
|
+
var sourceFile = ts.createSourceFile(entryPointFilePath, content, ts.ScriptTarget.Latest, true);
|
|
47
|
+
var basedir = (0, _path.dirname)(entryPointFilePath);
|
|
48
|
+
var results = [];
|
|
49
|
+
var _iterator = _createForOfIteratorHelper(sourceFile.statements),
|
|
50
|
+
_step;
|
|
51
|
+
try {
|
|
52
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
53
|
+
var statement = _step.value;
|
|
54
|
+
if (ts.isExportDeclaration(statement) && statement.moduleSpecifier && ts.isStringLiteral(statement.moduleSpecifier)) {
|
|
55
|
+
var modulePath = statement.moduleSpecifier.text;
|
|
56
|
+
if (!(0, _fileSystem.isRelativeImport)(modulePath)) {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
var resolved = (0, _fileSystem.resolveImportPath)({
|
|
60
|
+
basedir: basedir,
|
|
61
|
+
importPath: modulePath,
|
|
62
|
+
fs: fs
|
|
63
|
+
});
|
|
64
|
+
if (!resolved) {
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
var nameMap = new Map();
|
|
68
|
+
if (statement.exportClause && ts.isNamedExports(statement.exportClause)) {
|
|
69
|
+
var _iterator2 = _createForOfIteratorHelper(statement.exportClause.elements),
|
|
70
|
+
_step2;
|
|
71
|
+
try {
|
|
72
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
73
|
+
var element = _step2.value;
|
|
74
|
+
var exportedName = element.name.text;
|
|
75
|
+
var sourceName = element.propertyName ? element.propertyName.text : exportedName;
|
|
76
|
+
nameMap.set(sourceName, exportedName);
|
|
77
|
+
}
|
|
78
|
+
} catch (err) {
|
|
79
|
+
_iterator2.e(err);
|
|
80
|
+
} finally {
|
|
81
|
+
_iterator2.f();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
results.push({
|
|
85
|
+
sourcePath: resolved,
|
|
86
|
+
nameMap: nameMap
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
} catch (err) {
|
|
91
|
+
_iterator.e(err);
|
|
92
|
+
} finally {
|
|
93
|
+
_iterator.f();
|
|
94
|
+
}
|
|
95
|
+
return results;
|
|
96
|
+
} catch (_unused) {
|
|
97
|
+
return [];
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Parse the package.json exports field and return a map of export paths to resolved file paths.
|
|
103
|
+
*/
|
|
104
|
+
function parsePackageExports(_ref2) {
|
|
105
|
+
var packageDir = _ref2.packageDir,
|
|
106
|
+
fs = _ref2.fs;
|
|
25
107
|
// Memoize per-package to avoid repeated reads/parses during IDE lint runs.
|
|
26
108
|
// Additionally, invalidate per-package if the package.json mtime changes
|
|
27
109
|
// (covers unstaged local edits in IDE).
|
|
@@ -33,7 +115,7 @@ function parsePackageExports(_ref) {
|
|
|
33
115
|
try {
|
|
34
116
|
var _fs$statSync$mtimeMs;
|
|
35
117
|
currentMtimeMs = (_fs$statSync$mtimeMs = fs.statSync(packageJsonPath).mtimeMs) !== null && _fs$statSync$mtimeMs !== void 0 ? _fs$statSync$mtimeMs : null;
|
|
36
|
-
} catch (
|
|
118
|
+
} catch (_unused2) {
|
|
37
119
|
// If package.json can't be stat'ed (missing/inaccessible), use null to force re-read
|
|
38
120
|
currentMtimeMs = null;
|
|
39
121
|
}
|
|
@@ -82,7 +164,7 @@ function parsePackageExports(_ref) {
|
|
|
82
164
|
}
|
|
83
165
|
}
|
|
84
166
|
}
|
|
85
|
-
} catch (
|
|
167
|
+
} catch (_unused3) {
|
|
86
168
|
// Ignore parsing errors
|
|
87
169
|
}
|
|
88
170
|
|
|
@@ -93,29 +175,225 @@ function parsePackageExports(_ref) {
|
|
|
93
175
|
});
|
|
94
176
|
return exportsMap;
|
|
95
177
|
}
|
|
178
|
+
/**
|
|
179
|
+
* Check whether a subpath export key (e.g. `"./checkbox-select"`) is kebab-case.
|
|
180
|
+
*
|
|
181
|
+
* A key is considered kebab-case when the portion after the leading `"./"` prefix
|
|
182
|
+
* consists only of lowercase letters, digits, hyphens, dots, and forward-slash
|
|
183
|
+
* separators — i.e. no uppercase letters, underscores, or camelCase humps.
|
|
184
|
+
*/
|
|
185
|
+
function isKebabCaseExportKey(key) {
|
|
186
|
+
var body = key.replace(/^\.\//, '');
|
|
187
|
+
if (body.length === 0) {
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
return /^[a-z0-9][a-z0-9\-./]*$/.test(body);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Given a list of candidate {@link ExportMatchResult}s that all resolve to the same
|
|
195
|
+
* source file, pick the best one. When any candidate's export path is kebab-case
|
|
196
|
+
* and points to an entry-point file, prefer it over non-kebab-case alternatives.
|
|
197
|
+
* Falls back to the first candidate if no kebab-case entry-point candidate is found.
|
|
198
|
+
*/
|
|
199
|
+
function pickBestMatch(candidates, exportsMap) {
|
|
200
|
+
if (candidates.length === 1) {
|
|
201
|
+
return candidates[0];
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// Among candidates whose value is an entry-point file, prefer kebab-case keys.
|
|
205
|
+
var entryPointKebab = candidates.filter(function (c) {
|
|
206
|
+
var resolved = exportsMap.get(c.exportPath);
|
|
207
|
+
return resolved && isInEntryPointsFolder(resolved) && isKebabCaseExportKey(c.exportPath);
|
|
208
|
+
});
|
|
209
|
+
if (entryPointKebab.length > 0) {
|
|
210
|
+
return entryPointKebab[0];
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// Fall back to the first candidate (preserves previous behaviour).
|
|
214
|
+
return candidates[0];
|
|
215
|
+
}
|
|
96
216
|
|
|
97
217
|
/**
|
|
98
218
|
* Find a matching export entry for a given source file path.
|
|
99
219
|
* Returns the export path (e.g., "./controllers/analytics") or null if not found.
|
|
220
|
+
*
|
|
221
|
+
* When multiple export paths resolve to the same source file **and** point to an
|
|
222
|
+
* entry-point file, kebab-case keys are preferred over other casing styles.
|
|
223
|
+
*
|
|
224
|
+
* When `fs` is provided, also checks entry-point wrapper files. If an export resolves
|
|
225
|
+
* to a file inside a recognized entry-points folder (entry-points, entrypoints, etc.),
|
|
226
|
+
* the wrapper is parsed to see if it re-exports from `sourceFilePath`.
|
|
227
|
+
*
|
|
228
|
+
* `sourceExportName` is the name under which the symbol is exported from the source file
|
|
229
|
+
* (e.g. `'default'`). Used to look up the corresponding entry-point export name so the
|
|
230
|
+
* caller can generate the correct import style.
|
|
100
231
|
*/
|
|
101
|
-
function findExportForSourceFile(
|
|
102
|
-
var sourceFilePath =
|
|
103
|
-
exportsMap =
|
|
104
|
-
|
|
105
|
-
|
|
232
|
+
function findExportForSourceFile(_ref3) {
|
|
233
|
+
var sourceFilePath = _ref3.sourceFilePath,
|
|
234
|
+
exportsMap = _ref3.exportsMap,
|
|
235
|
+
fs = _ref3.fs,
|
|
236
|
+
sourceExportName = _ref3.sourceExportName;
|
|
237
|
+
// --- Phase 1: direct matches (export value === sourceFilePath) ---
|
|
238
|
+
var directMatches = [];
|
|
239
|
+
var _iterator3 = _createForOfIteratorHelper(exportsMap),
|
|
240
|
+
_step3;
|
|
106
241
|
try {
|
|
107
|
-
for (
|
|
108
|
-
var
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
if (
|
|
112
|
-
|
|
242
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
243
|
+
var _step3$value = (0, _slicedToArray2.default)(_step3.value, 2),
|
|
244
|
+
_exportPath = _step3$value[0],
|
|
245
|
+
_resolvedPath = _step3$value[1];
|
|
246
|
+
if (_resolvedPath === sourceFilePath) {
|
|
247
|
+
directMatches.push({
|
|
248
|
+
exportPath: _exportPath
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
} catch (err) {
|
|
253
|
+
_iterator3.e(err);
|
|
254
|
+
} finally {
|
|
255
|
+
_iterator3.f();
|
|
256
|
+
}
|
|
257
|
+
if (directMatches.length > 0) {
|
|
258
|
+
return pickBestMatch(directMatches, exportsMap);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// --- Phase 2: entry-point wrapper re-export matches ---
|
|
262
|
+
if (fs) {
|
|
263
|
+
var entryPointMatches = [];
|
|
264
|
+
var _iterator4 = _createForOfIteratorHelper(exportsMap),
|
|
265
|
+
_step4;
|
|
266
|
+
try {
|
|
267
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
268
|
+
var _step4$value = (0, _slicedToArray2.default)(_step4.value, 2),
|
|
269
|
+
exportPath = _step4$value[0],
|
|
270
|
+
resolvedPath = _step4$value[1];
|
|
271
|
+
if (isInEntryPointsFolder(resolvedPath)) {
|
|
272
|
+
var reExports = resolveEntryPointReExports({
|
|
273
|
+
entryPointFilePath: resolvedPath,
|
|
274
|
+
fs: fs
|
|
275
|
+
});
|
|
276
|
+
var _iterator5 = _createForOfIteratorHelper(reExports),
|
|
277
|
+
_step5;
|
|
278
|
+
try {
|
|
279
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
280
|
+
var reExport = _step5.value;
|
|
281
|
+
if (reExport.sourcePath === sourceFilePath) {
|
|
282
|
+
var entryPointExportName = void 0;
|
|
283
|
+
if (sourceExportName !== undefined && reExport.nameMap.has(sourceExportName)) {
|
|
284
|
+
entryPointExportName = reExport.nameMap.get(sourceExportName);
|
|
285
|
+
}
|
|
286
|
+
entryPointMatches.push({
|
|
287
|
+
exportPath: exportPath,
|
|
288
|
+
entryPointExportName: entryPointExportName
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
} catch (err) {
|
|
293
|
+
_iterator5.e(err);
|
|
294
|
+
} finally {
|
|
295
|
+
_iterator5.f();
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
} catch (err) {
|
|
300
|
+
_iterator4.e(err);
|
|
301
|
+
} finally {
|
|
302
|
+
_iterator4.f();
|
|
303
|
+
}
|
|
304
|
+
if (entryPointMatches.length > 0) {
|
|
305
|
+
return pickBestMatch(entryPointMatches, exportsMap);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
return null;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* When a symbol reaches the consumer through a barrel package that re-exports from
|
|
313
|
+
* `crossPackageName`, find a `package.json` export subpath of that barrel whose entry
|
|
314
|
+
* file directly re-exports the symbol from `crossPackageName` (named exports only).
|
|
315
|
+
*
|
|
316
|
+
* This enables rewriting imports to `@scope/barrel/subpath` instead of
|
|
317
|
+
* `@scope/cross-package/...` when the barrel exposes such a subpath (e.g. `@atlaskit/select/react-select`).
|
|
318
|
+
*/
|
|
319
|
+
function findCrossPackageBridgeExportPath(_ref4) {
|
|
320
|
+
var exportsMap = _ref4.exportsMap,
|
|
321
|
+
crossPackageName = _ref4.crossPackageName,
|
|
322
|
+
exportedName = _ref4.exportedName,
|
|
323
|
+
fs = _ref4.fs;
|
|
324
|
+
var _iterator6 = _createForOfIteratorHelper(exportsMap),
|
|
325
|
+
_step6;
|
|
326
|
+
try {
|
|
327
|
+
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
328
|
+
var _step6$value = (0, _slicedToArray2.default)(_step6.value, 2),
|
|
329
|
+
exportPath = _step6$value[0],
|
|
330
|
+
resolvedPath = _step6$value[1];
|
|
331
|
+
var content = (0, _fileSystem.readFileContent)({
|
|
332
|
+
filePath: resolvedPath,
|
|
333
|
+
fs: fs
|
|
334
|
+
});
|
|
335
|
+
if (!content) {
|
|
336
|
+
continue;
|
|
337
|
+
}
|
|
338
|
+
try {
|
|
339
|
+
var sourceFile = ts.createSourceFile(resolvedPath, content, ts.ScriptTarget.Latest, true);
|
|
340
|
+
var _iterator7 = _createForOfIteratorHelper(sourceFile.statements),
|
|
341
|
+
_step7;
|
|
342
|
+
try {
|
|
343
|
+
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
|
344
|
+
var statement = _step7.value;
|
|
345
|
+
if (!ts.isExportDeclaration(statement) || statement.isTypeOnly) {
|
|
346
|
+
continue;
|
|
347
|
+
}
|
|
348
|
+
if (!statement.moduleSpecifier || !ts.isStringLiteral(statement.moduleSpecifier)) {
|
|
349
|
+
continue;
|
|
350
|
+
}
|
|
351
|
+
if (statement.moduleSpecifier.text !== crossPackageName) {
|
|
352
|
+
continue;
|
|
353
|
+
}
|
|
354
|
+
if (!statement.exportClause || ts.isNamespaceExport(statement.exportClause)) {
|
|
355
|
+
continue;
|
|
356
|
+
}
|
|
357
|
+
if (!ts.isNamedExports(statement.exportClause)) {
|
|
358
|
+
continue;
|
|
359
|
+
}
|
|
360
|
+
var _iterator8 = _createForOfIteratorHelper(statement.exportClause.elements),
|
|
361
|
+
_step8;
|
|
362
|
+
try {
|
|
363
|
+
for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
|
|
364
|
+
var element = _step8.value;
|
|
365
|
+
if (element.isTypeOnly) {
|
|
366
|
+
continue;
|
|
367
|
+
}
|
|
368
|
+
var publicName = element.name.text;
|
|
369
|
+
if (publicName !== exportedName) {
|
|
370
|
+
continue;
|
|
371
|
+
}
|
|
372
|
+
var entryPointExportName = element.propertyName ? element.propertyName.text : undefined;
|
|
373
|
+
return {
|
|
374
|
+
exportPath: exportPath,
|
|
375
|
+
entryPointExportName: entryPointExportName
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
} catch (err) {
|
|
379
|
+
_iterator8.e(err);
|
|
380
|
+
} finally {
|
|
381
|
+
_iterator8.f();
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
} catch (err) {
|
|
385
|
+
_iterator7.e(err);
|
|
386
|
+
} finally {
|
|
387
|
+
_iterator7.f();
|
|
388
|
+
}
|
|
389
|
+
} catch (_unused4) {
|
|
390
|
+
// Ignore parse errors for individual export entry files
|
|
113
391
|
}
|
|
114
392
|
}
|
|
115
393
|
} catch (err) {
|
|
116
|
-
|
|
394
|
+
_iterator6.e(err);
|
|
117
395
|
} finally {
|
|
118
|
-
|
|
396
|
+
_iterator6.f();
|
|
119
397
|
}
|
|
120
398
|
return null;
|
|
121
399
|
}
|
|
@@ -139,10 +417,10 @@ function extractPackageNameFromImport(moduleSpecifier) {
|
|
|
139
417
|
* Resolve a cross-package import to its package directory and export info.
|
|
140
418
|
* Returns null if the package is not in the target folder or cannot be resolved.
|
|
141
419
|
*/
|
|
142
|
-
function resolveCrossPackageImport(
|
|
143
|
-
var moduleSpecifier =
|
|
144
|
-
workspaceRoot =
|
|
145
|
-
fs =
|
|
420
|
+
function resolveCrossPackageImport(_ref5) {
|
|
421
|
+
var moduleSpecifier = _ref5.moduleSpecifier,
|
|
422
|
+
workspaceRoot = _ref5.workspaceRoot,
|
|
423
|
+
fs = _ref5.fs;
|
|
146
424
|
// Only handle @atlassian/* scoped packages
|
|
147
425
|
var parsed = extractPackageNameFromImport(moduleSpecifier);
|
|
148
426
|
if (!parsed) {
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
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; } } }; }
|
|
8
|
+
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; } }
|
|
9
|
+
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; }
|
|
10
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
11
|
+
|
|
12
|
+
var RESTRICTED_IMPORTS = {
|
|
13
|
+
'@atlassian/atl-context': ['isFedRamp', 'isIsolatedCloud'],
|
|
14
|
+
'@atlaskit/atlassian-context': ['isFedRamp', 'isIsolatedCloud'],
|
|
15
|
+
'@atlassian/teams-common': ['isFedramp']
|
|
16
|
+
};
|
|
17
|
+
var rule = {
|
|
18
|
+
meta: {
|
|
19
|
+
type: 'problem',
|
|
20
|
+
docs: {
|
|
21
|
+
description: 'Disallow importing deprecated FedRamp/IsolatedCloud context functions. Use isFeatureEnabled from AEM (Atlassian Environment Manager) instead.',
|
|
22
|
+
recommended: true
|
|
23
|
+
},
|
|
24
|
+
messages: {
|
|
25
|
+
noRestrictedFedrampImports: '{{name}} from {{source}} will be deprecated soon. Please use isFeatureEnabled from AEM (Atlassian Environment Manager) instead. See go/AEM for more details.'
|
|
26
|
+
},
|
|
27
|
+
schema: []
|
|
28
|
+
},
|
|
29
|
+
create: function create(context) {
|
|
30
|
+
return {
|
|
31
|
+
ImportDeclaration: function ImportDeclaration(node) {
|
|
32
|
+
var source = node.source.value;
|
|
33
|
+
if (typeof source !== 'string') {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
var restrictedNames = RESTRICTED_IMPORTS[source];
|
|
37
|
+
if (!restrictedNames) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
var _iterator = _createForOfIteratorHelper(node.specifiers),
|
|
41
|
+
_step;
|
|
42
|
+
try {
|
|
43
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
44
|
+
var specifier = _step.value;
|
|
45
|
+
if (specifier.type === 'ImportSpecifier' && restrictedNames.includes(specifier.imported.name)) {
|
|
46
|
+
context.report({
|
|
47
|
+
node: specifier,
|
|
48
|
+
messageId: 'noRestrictedFedrampImports',
|
|
49
|
+
data: {
|
|
50
|
+
name: specifier.imported.name,
|
|
51
|
+
source: source
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
} catch (err) {
|
|
57
|
+
_iterator.e(err);
|
|
58
|
+
} finally {
|
|
59
|
+
_iterator.f();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
var _default = exports.default = rule;
|