@atlaskit/eslint-plugin-platform 2.9.1 → 2.9.3

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 (35) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/cjs/index.js +15 -3
  3. package/dist/cjs/rules/compiled/expand-motion-shorthand/index.js +281 -0
  4. package/dist/cjs/rules/compiled/no-css-prop-in-object-spread/index.js +162 -0
  5. package/dist/cjs/rules/compiled/use-motion-token-values/index.js +506 -0
  6. package/dist/cjs/rules/editor-example-type-import-required/index.js +321 -0
  7. package/dist/cjs/rules/no-xcss-in-cx/index.js +221 -0
  8. package/dist/cjs/rules/visit-example-type-import-required/index.js +23 -13
  9. package/dist/es2019/index.js +15 -3
  10. package/dist/es2019/rules/compiled/expand-motion-shorthand/index.js +239 -0
  11. package/dist/es2019/rules/compiled/no-css-prop-in-object-spread/index.js +136 -0
  12. package/dist/es2019/rules/compiled/use-motion-token-values/index.js +444 -0
  13. package/dist/es2019/rules/editor-example-type-import-required/index.js +286 -0
  14. package/dist/es2019/rules/no-xcss-in-cx/index.js +187 -0
  15. package/dist/es2019/rules/visit-example-type-import-required/index.js +23 -14
  16. package/dist/esm/index.js +15 -3
  17. package/dist/esm/rules/compiled/expand-motion-shorthand/index.js +275 -0
  18. package/dist/esm/rules/compiled/no-css-prop-in-object-spread/index.js +156 -0
  19. package/dist/esm/rules/compiled/use-motion-token-values/index.js +499 -0
  20. package/dist/esm/rules/editor-example-type-import-required/index.js +314 -0
  21. package/dist/esm/rules/no-xcss-in-cx/index.js +216 -0
  22. package/dist/esm/rules/visit-example-type-import-required/index.js +23 -13
  23. package/dist/types/index.d.ts +282 -243
  24. package/dist/types/rules/compiled/expand-motion-shorthand/index.d.ts +3 -0
  25. package/dist/types/rules/compiled/no-css-prop-in-object-spread/index.d.ts +3 -0
  26. package/dist/types/rules/compiled/use-motion-token-values/index.d.ts +3 -0
  27. package/dist/types/rules/editor-example-type-import-required/index.d.ts +4 -0
  28. package/dist/types/rules/no-xcss-in-cx/index.d.ts +31 -0
  29. package/dist/types-ts4.5/index.d.ts +226 -211
  30. package/dist/types-ts4.5/rules/compiled/expand-motion-shorthand/index.d.ts +3 -0
  31. package/dist/types-ts4.5/rules/compiled/no-css-prop-in-object-spread/index.d.ts +3 -0
  32. package/dist/types-ts4.5/rules/compiled/use-motion-token-values/index.d.ts +3 -0
  33. package/dist/types-ts4.5/rules/editor-example-type-import-required/index.d.ts +4 -0
  34. package/dist/types-ts4.5/rules/no-xcss-in-cx/index.d.ts +31 -0
  35. package/package.json +2 -1
@@ -0,0 +1,314 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
+ 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; } } }; }
3
+ 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; } }
4
+ 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; }
5
+ import fs from 'fs';
6
+ import path from 'path';
7
+ import { AST_NODE_TYPES } from '@typescript-eslint/utils';
8
+ export var RULE_NAME = 'editor-example-type-import-required';
9
+
10
+ /**
11
+ * Spec files that are excluded from this rule because they don't use visitExample
12
+ * or have their own test harness that doesn't follow the exampleName fixture pattern.
13
+ *
14
+ * Paths are matched as suffixes of the file path (platform-relative).
15
+ */
16
+ var EXCLUDED_SPEC_FILES = [
17
+ // Meta-tests for the testing infrastructure itself
18
+ 'build/test-tooling/integration-testing/src/examples/__tests__/playwright/example.spec.ts', 'build/test-tooling/integration-testing/src/matchers/__tests__/playwright/to-have-height.spec.ts', 'build/test-tooling/integration-testing/src/matchers/__tests__/playwright/to-have-width.spec.ts',
19
+ // Tests the a11y decorator itself, no visitExample
20
+ 'packages/accessibility/axe-integration/a11y-playwright-testing/src/auto-a11y-setup/__tests__/playwright/skip-decorator.spec.ts',
21
+ // Stub test (expect(true).toBe(true)), no visitExample
22
+ 'packages/ai-mate/rovo-content-bridge-api/__tests__/playwright/index.spec.tsx',
23
+ // Page-object's visitExample call carries the typeof import(...) generic,
24
+ // so the typed example reference lives in _helpers/page-object.ts rather
25
+ // than in test.use({ exampleName }) in the spec itself.
26
+ 'packages/navigation/atlassian-switcher/src/__tests__/playwright/navigate-child-item.spec.ts', 'packages/navigation/atlassian-switcher/src/__tests__/playwright/navigate-link-item.spec.ts', 'packages/navigation/atlassian-switcher/src/__tests__/playwright/navigate-product-item.spec.ts',
27
+ // Spec runs through a page-object (pages/generic-form-renderer.ts) whose
28
+ // visitExample call already carries the typeof import(...) generic. The
29
+ // typed reference therefore lives in the colocated page-object, not in
30
+ // test.use({ exampleName }) in the spec.
31
+ 'packages/proforma/proforma-common-core/__tests__/playwright/json-test-cases.spec.ts', 'packages/proforma/proforma-form-renderer/__tests__/playwright/json-test-cases.spec.ts',
32
+ // Spec runs through a page-object that still uses raw page.goto() against
33
+ // /examples.html. Migrating these requires reworking the page-object to
34
+ // route through visitExample<typeof import(...)>(...).
35
+ 'packages/proforma/proforma-form-list/__tests__/playwright/form-list.spec.ts', 'packages/proforma/proforma-form-renderer/__tests__/playwright/form-renderer.spec.ts', 'packages/proforma/proforma-translations-editor/__tests__/playwright/translations-editor-with-form.spec.ts',
36
+ // Tests the website itself, not examples
37
+ 'website/src/__tests__/playwright/examples.spec.ts', 'website/src/__tests__/playwright/home.spec.ts',
38
+ // react-ufo: uses an `examplePage: string` fixture where the name (e.g. 'basic') is
39
+ // resolved to the example file internally by visitExample — the name does not match
40
+ // the file name (e.g. '01-basic.tsx'), so a typeof import assertion is not possible
41
+ // without refactoring the fixture to use keyof typeof import directly. Specs that
42
+ // happen to also use the inline `visitExample<typeof import(...)>` pattern alongside
43
+ // the fixture pass via the file-level typeof import check above and don't appear here.
44
+ 'packages/react-ufo/atlaskit/__tests__/playwright/apply-segments-threshold.spec.ts', 'packages/react-ufo/atlaskit/__tests__/playwright/bad-replacement-node.spec.ts', 'packages/react-ufo/atlaskit/__tests__/playwright/base-10-sections.spec.ts', 'packages/react-ufo/atlaskit/__tests__/playwright/base-100-sections.spec.ts', 'packages/react-ufo/atlaskit/__tests__/playwright/base-3-sections-ssr-timings.spec.ts', 'packages/react-ufo/atlaskit/__tests__/playwright/base-3-sections-unmount.spec.ts', 'packages/react-ufo/atlaskit/__tests__/playwright/css-display-contents.spec.ts', 'packages/react-ufo/atlaskit/__tests__/playwright/custom-cohort-data.spec.ts', 'packages/react-ufo/atlaskit/__tests__/playwright/custom-data.spec.ts', 'packages/react-ufo/atlaskit/__tests__/playwright/data-vc-ignore-if-no-layout-shift.spec.ts', 'packages/react-ufo/atlaskit/__tests__/playwright/full-pixel-horizontal.spec.ts', 'packages/react-ufo/atlaskit/__tests__/playwright/full-pixel.spec.ts', 'packages/react-ufo/atlaskit/__tests__/playwright/fy25_02.spec.ts', 'packages/react-ufo/atlaskit/__tests__/playwright/hold.spec.ts', 'packages/react-ufo/atlaskit/__tests__/playwright/interactions-responsiveness.spec.ts', 'packages/react-ufo/atlaskit/__tests__/playwright/interactions-unknown-element.spec.ts', 'packages/react-ufo/atlaskit/__tests__/playwright/interactions-vc.spec.ts', 'packages/react-ufo/atlaskit/__tests__/playwright/is-opened-in-background.spec.ts', 'packages/react-ufo/atlaskit/__tests__/playwright/is-tab-throttled.spec.ts', 'packages/react-ufo/atlaskit/__tests__/playwright/metric-variants.spec.ts', 'packages/react-ufo/atlaskit/__tests__/playwright/minor-interactions.spec.ts', 'packages/react-ufo/atlaskit/__tests__/playwright/non-visual-style.spec.ts', 'packages/react-ufo/atlaskit/__tests__/playwright/page-visibility-hidden-timestamp.spec.ts', 'packages/react-ufo/atlaskit/__tests__/playwright/payload-integrity.spec.ts', 'packages/react-ufo/atlaskit/__tests__/playwright/post-interaction-late-holds.spec.ts', 'packages/react-ufo/atlaskit/__tests__/playwright/post-interaction-log-always-send.spec.ts', 'packages/react-ufo/atlaskit/__tests__/playwright/replacement-node.spec.ts', 'packages/react-ufo/atlaskit/__tests__/playwright/revisions.spec.ts', 'packages/react-ufo/atlaskit/__tests__/playwright/same-attribute-value-mutation.spec.ts', 'packages/react-ufo/atlaskit/__tests__/playwright/speed-index.spec.ts', 'packages/react-ufo/atlaskit/__tests__/playwright/ssr-placeholder-v3.spec.ts', 'packages/react-ufo/atlaskit/__tests__/playwright/terminal-error.spec.ts', 'packages/react-ufo/atlaskit/__tests__/playwright/third-party-segment-extra-metrics.spec.ts', 'packages/react-ufo/atlaskit/__tests__/playwright/third-party-segment-iframe.spec.ts', 'packages/react-ufo/atlaskit/__tests__/playwright/third-party-segment-timings.spec.ts', 'packages/react-ufo/atlaskit/__tests__/playwright/third-party-segment.spec.ts', 'packages/react-ufo/atlaskit/__tests__/playwright/transition-vc.spec.ts', 'packages/react-ufo/atlaskit/__tests__/playwright/ttai.spec.ts', 'packages/react-ufo/atlaskit/__tests__/playwright/ufo-blindspot-watchdog.spec.ts', 'packages/react-ufo/atlaskit/__tests__/playwright/ufo-errors.spec.ts', 'packages/react-ufo/atlaskit/__tests__/playwright/vc-dirty.spec.ts',
45
+ // editor-performance-metrics: same pattern as react-ufo — uses an `examplePage: string` fixture
46
+ // where the name resolves internally and does not match the example file name.
47
+ 'packages/editor/editor-performance-metrics/__tests__/playwright/basic-editor-ttai.spec.ts', 'packages/editor/editor-performance-metrics/__tests__/playwright/basic-react-app.spec.ts', 'packages/editor/editor-performance-metrics/__tests__/playwright/latency-track.spec.ts', 'packages/editor/editor-performance-metrics/__tests__/playwright/ttai-timers.spec.ts', 'packages/editor/editor-performance-metrics/__tests__/playwright/vc-next-attribute-change.spec.ts', 'packages/editor/editor-performance-metrics/__tests__/playwright/vc-next-element-moving.spec.ts', 'packages/editor/editor-performance-metrics/__tests__/playwright/vc-next-moving-node.spec.ts', 'packages/editor/editor-performance-metrics/__tests__/playwright/vc-next-placeholder.spec.ts', 'packages/editor/editor-performance-metrics/__tests__/playwright/vc-next-react-remounting.spec.ts', 'packages/editor/editor-performance-metrics/__tests__/playwright/vc-next-track-user-events.spec.ts', 'packages/editor/editor-performance-metrics/__tests__/playwright/vc-next.spec.ts',
48
+ // generative-ai-modal: the example name is passed dynamically at examplePage.goto({ example: '...' })
49
+ // time rather than via test.use(), so a static typeof import assertion in the spec is not possible.
50
+ 'packages/editor/generative-ai-modal/src/ui/screens/Preview/__tests__/playwright/tab-navigation.spec.ts'];
51
+ function isExcluded(filename) {
52
+ var normalised = filename.replace(/\\/g, '/');
53
+ return EXCLUDED_SPEC_FILES.some(function (excluded) {
54
+ return normalised.endsWith(excluded);
55
+ });
56
+ }
57
+ var messages = {
58
+ missingExampleName: 'Playwright spec files must include exampleName with a ' + 'typeof import type assertion in test.use(). ' + "Add: exampleName: 'testing' as keyof typeof import('../../../examples/testing.tsx') ",
59
+ missingTypeAssertion: 'exampleName must include a typeof import type assertion for the static import graph. ' + "Use: exampleName: '{{ value }}' as keyof typeof import('{{ expectedPath }}') ",
60
+ pathMismatch: 'The import path "{{ importPath }}" does not resolve to the expected example file ' + "for exampleName '{{ exampleName }}'. Expected: {{ expectedPath }}"
61
+ };
62
+ function isTargetFile(filename) {
63
+ return (filename.endsWith('.spec.tsx') || filename.endsWith('.spec.ts')) && !isExcluded(filename);
64
+ }
65
+
66
+ /**
67
+ * Resolves the example file path from the spec file's location and the example name.
68
+ * Editor specs follow: packages/{groupId}/{packageId}/src/__tests__/playwright/*.spec.ts
69
+ * Examples live at: packages/{groupId}/{packageId}/examples/{exampleName}.tsx
70
+ */
71
+ function resolveExamplePath(testFilePath, exampleName) {
72
+ var testFileDir = path.dirname(testFilePath);
73
+ var segments = testFileDir.split(path.sep);
74
+ var packagesIndex = segments.findIndex(function (seg) {
75
+ return seg === 'packages';
76
+ });
77
+ if (packagesIndex === -1) {
78
+ return null;
79
+ }
80
+ var groupId = segments[packagesIndex + 1];
81
+ var packageId = segments[packagesIndex + 2];
82
+ if (!groupId || !packageId) {
83
+ return null;
84
+ }
85
+ var basePath = path.isAbsolute(testFilePath) ? path.resolve.apply(path, ['/'].concat(_toConsumableArray(segments.slice(0, packagesIndex + 1)))) : path.resolve.apply(path, [process.cwd()].concat(_toConsumableArray(segments.slice(0, packagesIndex + 1))));
86
+ var examplesDir = path.resolve(basePath, groupId, packageId, 'examples');
87
+ var candidateRe = new RegExp("^(?:\\d+-)?".concat(exampleName, "(?:\\.examples?)?\\.tsx$"));
88
+ try {
89
+ var match = fs.readdirSync(examplesDir).find(function (f) {
90
+ return candidateRe.test(f);
91
+ });
92
+ if (match) {
93
+ return path.resolve(examplesDir, match);
94
+ }
95
+ } catch (_unused) {
96
+ // Directory doesn't exist (e.g. test environments)
97
+ }
98
+ return path.resolve(examplesDir, "".concat(exampleName, ".tsx"));
99
+ }
100
+ function computeRelativeImportPath(fromFile, toFile) {
101
+ var fromDir = path.dirname(fromFile);
102
+ var relativePath = path.relative(fromDir, toFile);
103
+ relativePath = relativePath.replace(/\\/g, '/');
104
+ if (!relativePath.startsWith('.') && !relativePath.startsWith('/')) {
105
+ relativePath = "./".concat(relativePath);
106
+ }
107
+ return relativePath;
108
+ }
109
+
110
+ /**
111
+ * Check if a property value has a `keyof typeof import(...)` type assertion.
112
+ * Handles both:
113
+ * 'name' as keyof typeof import('...')
114
+ */
115
+ function extractTypeofImportPath(node) {
116
+ if (node.type !== AST_NODE_TYPES.TSAsExpression) {
117
+ return null;
118
+ }
119
+ var typeAnnotation = node.typeAnnotation;
120
+ if (typeAnnotation.type === AST_NODE_TYPES.TSTypeOperator && typeAnnotation.operator === 'keyof') {
121
+ return extractFromTypeQuery(typeAnnotation.typeAnnotation);
122
+ }
123
+ if (typeAnnotation.type === AST_NODE_TYPES.TSUnionType) {
124
+ var _iterator = _createForOfIteratorHelper(typeAnnotation.types),
125
+ _step;
126
+ try {
127
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
128
+ var member = _step.value;
129
+ if (member.type === AST_NODE_TYPES.TSTypeOperator && member.operator === 'keyof') {
130
+ var result = extractFromTypeQuery(member.typeAnnotation);
131
+ if (result) {
132
+ return result;
133
+ }
134
+ }
135
+ }
136
+ } catch (err) {
137
+ _iterator.e(err);
138
+ } finally {
139
+ _iterator.f();
140
+ }
141
+ }
142
+ return null;
143
+ }
144
+ function extractFromTypeQuery(node) {
145
+ if (!node || node.type !== AST_NODE_TYPES.TSTypeQuery) {
146
+ return null;
147
+ }
148
+ var exprName = node.exprName;
149
+ if (exprName.type !== AST_NODE_TYPES.TSImportType) {
150
+ return null;
151
+ }
152
+ var argument = exprName.argument;
153
+ if (argument.type === AST_NODE_TYPES.TSLiteralType && argument.literal.type === AST_NODE_TYPES.Literal && typeof argument.literal.value === 'string') {
154
+ return argument.literal.value;
155
+ }
156
+ return null;
157
+ }
158
+
159
+ /**
160
+ * Extract the string value from a property value, ignoring type assertions.
161
+ */
162
+ function getStringValue(node) {
163
+ if (node.type === AST_NODE_TYPES.Literal && typeof node.value === 'string') {
164
+ return node.value;
165
+ }
166
+ if (node.type === AST_NODE_TYPES.TSAsExpression) {
167
+ return getStringValue(node.expression);
168
+ }
169
+ return null;
170
+ }
171
+ var rule = {
172
+ meta: {
173
+ type: 'problem',
174
+ docs: {
175
+ description: 'Ensures that editor spec files using @af/editor-libra include exampleName with a ' + 'typeof import type assertion in test.use() for the static import graph (factsMap).'
176
+ },
177
+ fixable: 'code',
178
+ messages: messages,
179
+ schema: []
180
+ },
181
+ create: function create(context) {
182
+ var filename = context.filename;
183
+ if (!isTargetFile(filename)) {
184
+ return {};
185
+ }
186
+ return {
187
+ 'Program:exit': function ProgramExit(estreeNode) {
188
+ var program = estreeNode;
189
+
190
+ // Single AST walk: collect all test.use() calls AND detect whether the
191
+ // file contains any `typeof import('...')` reference at all (a TSImportType
192
+ // node). Either signal is sufficient evidence that the spec ties at least
193
+ // one example file into its TypeScript import graph.
194
+ var testUseCalls = [];
195
+ var hasAnyTypeofImport = false;
196
+ var visited = new Set();
197
+ var queue = [program];
198
+ while (queue.length > 0) {
199
+ var node = queue.shift();
200
+ if (visited.has(node)) {
201
+ continue;
202
+ }
203
+ visited.add(node);
204
+ if (node.type === AST_NODE_TYPES.CallExpression && node.callee.type === AST_NODE_TYPES.MemberExpression && node.callee.property.type === AST_NODE_TYPES.Identifier && node.callee.property.name === 'use' && node.arguments.length > 0 && node.arguments[0].type === AST_NODE_TYPES.ObjectExpression) {
205
+ testUseCalls.push(node);
206
+ }
207
+ if (node.type === AST_NODE_TYPES.TSImportType) {
208
+ hasAnyTypeofImport = true;
209
+ }
210
+ for (var _i = 0, _Object$keys = Object.keys(node); _i < _Object$keys.length; _i++) {
211
+ var key = _Object$keys[_i];
212
+ if (key === 'parent') {
213
+ continue;
214
+ }
215
+ var child = node[key];
216
+ if (Array.isArray(child)) {
217
+ var _iterator2 = _createForOfIteratorHelper(child),
218
+ _step2;
219
+ try {
220
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
221
+ var item = _step2.value;
222
+ if (item && typeof item.type === 'string') {
223
+ queue.push(item);
224
+ }
225
+ }
226
+ } catch (err) {
227
+ _iterator2.e(err);
228
+ } finally {
229
+ _iterator2.f();
230
+ }
231
+ } else if (child && typeof child.type === 'string') {
232
+ queue.push(child);
233
+ }
234
+ }
235
+ }
236
+
237
+ // Any `typeof import('...')` anywhere in the spec — including the
238
+ // `page.visitExample<typeof import('...')>(...)` and
239
+ // `page.visitMockedExample<typeof import('...')>(...)` patterns used
240
+ // outside of test.use() — satisfies the same goal as the canonical
241
+ // `test.use({ exampleName: '...' as keyof typeof import('...') })`
242
+ // pattern: the example file is referenced from the spec's TypeScript
243
+ // import graph.
244
+ if (hasAnyTypeofImport) {
245
+ return;
246
+ }
247
+
248
+ // Check if any test.use() call anywhere in the file has exampleName with a typeof import assertion
249
+ var fileHasExampleName = testUseCalls.some(function (call) {
250
+ var obj = call.arguments[0];
251
+ return obj.properties.some(function (prop) {
252
+ if (prop.type !== AST_NODE_TYPES.Property || prop.key.type !== AST_NODE_TYPES.Identifier || prop.key.name !== 'exampleName') {
253
+ return false;
254
+ }
255
+ return extractTypeofImportPath(prop.value) !== null;
256
+ });
257
+ });
258
+ if (fileHasExampleName) {
259
+ return;
260
+ }
261
+
262
+ // Find the first test.use() call that has exampleName without the typeof import assertion
263
+ // (if any), otherwise use the first test.use() call
264
+ var targetCall = testUseCalls[0];
265
+ var existingExampleNameProp = null;
266
+ for (var _i2 = 0, _testUseCalls = testUseCalls; _i2 < _testUseCalls.length; _i2++) {
267
+ var call = _testUseCalls[_i2];
268
+ var obj = call.arguments[0];
269
+ var prop = obj.properties.find(function (p) {
270
+ return p.type === AST_NODE_TYPES.Property && p.key.type === AST_NODE_TYPES.Identifier && p.key.name === 'exampleName';
271
+ });
272
+ if (prop) {
273
+ targetCall = call;
274
+ existingExampleNameProp = prop;
275
+ break;
276
+ }
277
+ }
278
+ if (!targetCall) {
279
+ return;
280
+ }
281
+ var objectArg = targetCall.arguments[0];
282
+
283
+ // Determine the example name to use for the import path
284
+ var exampleNameValue = existingExampleNameProp ? getStringValue(existingExampleNameProp.value) : null;
285
+ var defaultName = exampleNameValue !== null && exampleNameValue !== void 0 ? exampleNameValue : 'testing';
286
+ var examplePath = resolveExamplePath(filename, defaultName);
287
+ if (!examplePath) {
288
+ return;
289
+ }
290
+ var importPath = computeRelativeImportPath(filename, examplePath);
291
+ context.report({
292
+ node: targetCall,
293
+ messageId: 'missingExampleName',
294
+ fix: function fix(fixer) {
295
+ // If exampleName exists but lacks typeof import, replace its value
296
+ if (existingExampleNameProp) {
297
+ return fixer.replaceText(existingExampleNameProp.value, "'".concat(defaultName, "' as keyof typeof import('").concat(importPath, "') "));
298
+ }
299
+ // Otherwise insert exampleName as the first property
300
+ var firstProp = objectArg.properties[0];
301
+ if (!firstProp) {
302
+ return fixer.replaceText(targetCall.arguments[0], "{\n\texampleName: '".concat(defaultName, "' as keyof typeof import('").concat(importPath, "'),\n}"));
303
+ }
304
+ var sourceCode = context.sourceCode;
305
+ var token = sourceCode.getFirstToken(firstProp);
306
+ var indent = token ? '\t'.repeat(token.loc.start.column) : '\t';
307
+ return fixer.insertTextBefore(firstProp, "exampleName: '".concat(defaultName, "' as keyof typeof import('").concat(importPath, "') ,\n").concat(indent));
308
+ }
309
+ });
310
+ }
311
+ };
312
+ }
313
+ };
314
+ export default rule;
@@ -0,0 +1,216 @@
1
+ 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; } } }; }
2
+ 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; } }
3
+ 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; }
4
+ import { getImportSources, isCxFunction, isXcss } from '@atlaskit/eslint-utils/is-supported-import';
5
+ import { getScope } from '../util/context-compat';
6
+
7
+ /**
8
+ * Disallows passing xcss() results into cx() when used in an xcss prop.
9
+ *
10
+ * xcss() from @atlaskit/primitives and cx() from @atlaskit/css / @compiled/react
11
+ * are incompatible — xcss() produces an opaque StyleRule object, while cx()
12
+ * expects Compiled atomic class name strings. Mixing them causes runtime errors.
13
+ * xcss() results must never be passed to cx(), whether inline or pre-defined.
14
+ *
15
+ * ❌ Wrong — xcss() called inline inside cx():
16
+ * xcss={cx(xcss({ color: 'red' }), xcss({ fontWeight: 'bold' }))}
17
+ *
18
+ * ❌ Also wrong — xcss() results pre-defined but still passed into cx():
19
+ * const baseStyles = xcss({ color: 'red' });
20
+ * const boldStyles = xcss({ fontWeight: 'bold' });
21
+ * xcss={cx(baseStyles, boldStyles)}
22
+ *
23
+ * ✅ Correct — pass xcss() results directly to the xcss prop (no cx()):
24
+ * const baseStyles = xcss({ color: 'red' });
25
+ * xcss={baseStyles}
26
+ *
27
+ * ✅ Correct — use cssMap() + cx() (cssMap is compatible with cx()):
28
+ * const styles = cssMap({ base: { color: 'red' } });
29
+ * xcss={cx(styles.base, condition && styles.focused)}
30
+ *
31
+ * This rule is import-aware: it only flags xcss() calls (inline or via variable)
32
+ * imported from @atlaskit/primitives inside cx() calls imported from @atlaskit/css
33
+ * or @compiled/react that appear inside an xcss prop.
34
+ */
35
+ var rule = {
36
+ meta: {
37
+ type: 'problem',
38
+ docs: {
39
+ description: 'Disallow calling xcss() inline inside cx() in an xcss prop. Define styles at module level instead.'
40
+ },
41
+ messages: {
42
+ noXcssInCx: 'Do not pass xcss() results into cx(). ' + 'xcss() produces a StyleRule object that is incompatible with cx(), which expects Compiled atomic class names. ' + 'Pass xcss() results directly to the xcss prop instead: xcss={myStyles}. ' + 'To conditionally combine styles, use cssMap() + cx(): const styles = cssMap({...}); xcss={cx(styles.base, cond && styles.active)}'
43
+ },
44
+ schema: []
45
+ },
46
+ create: function create(context) {
47
+ return {
48
+ JSXAttribute: function JSXAttribute(node) {
49
+ // Narrow Rule.Node to JSXAttribute (estree-jsx augments the `estree` Node
50
+ // union with JSX members, so this discriminated narrowing is safe).
51
+ if (node.type !== 'JSXAttribute') {
52
+ return;
53
+ }
54
+
55
+ // Only check `xcss` props
56
+ if (node.name.type !== 'JSXIdentifier' || node.name.name !== 'xcss') {
57
+ return;
58
+ }
59
+ if (!node.value || node.value.type !== 'JSXExpressionContainer') {
60
+ return;
61
+ }
62
+ var expression = node.value.expression;
63
+ if (expression.type === 'JSXEmptyExpression') {
64
+ return;
65
+ }
66
+
67
+ // Early-return if the expression cannot possibly contain a cx() call —
68
+ // avoids the cost of getImportSources/getScope on simple references like xcss={baseStyles}.
69
+ var isCallOrArray = expression.type === 'CallExpression' || expression.type === 'ArrayExpression';
70
+ if (!isCallOrArray) {
71
+ return;
72
+ }
73
+ var importSources = getImportSources(context);
74
+ var _getScope = getScope(context, node),
75
+ references = _getScope.references;
76
+
77
+ /**
78
+ * Returns true if an Identifier node resolves to a variable whose
79
+ * initializer is a call to xcss() imported from @atlaskit/primitives.
80
+ *
81
+ * Walks up the scope chain from the current JSXAttribute scope to find
82
+ * the variable definition, since module-level variables are not in the
83
+ * local scope's references list.
84
+ *
85
+ * e.g. `const baseStyles = xcss({ color: 'red' })` — passing `baseStyles`
86
+ * here returns true.
87
+ */
88
+ var isXcssVariable = function isXcssVariable(identNode) {
89
+ if (identNode.type !== 'Identifier') {
90
+ return false;
91
+ }
92
+ var name = identNode.name;
93
+ // Walk up the scope chain to find the variable definition
94
+ var currentScope = getScope(context, node);
95
+ while (currentScope) {
96
+ var variable = currentScope.set.get(name);
97
+ if (variable) {
98
+ var _iterator = _createForOfIteratorHelper(variable.defs),
99
+ _step;
100
+ try {
101
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
102
+ var _def$node$init;
103
+ var def = _step.value;
104
+ if (def.type === 'Variable' && def.node.type === 'VariableDeclarator' && ((_def$node$init = def.node.init) === null || _def$node$init === void 0 ? void 0 : _def$node$init.type) === 'CallExpression') {
105
+ // isXcss checks the callee identifier against referencesInScope to
106
+ // find the import binding. The callee lives in the same scope as the
107
+ // variable definition, so use all references from that scope.
108
+ var defScopeRefs = currentScope.references;
109
+ if (isXcss(def.node.init.callee, defScopeRefs, importSources)) {
110
+ return true;
111
+ }
112
+ }
113
+ }
114
+ // Found the variable but it's not an xcss() call
115
+ } catch (err) {
116
+ _iterator.e(err);
117
+ } finally {
118
+ _iterator.f();
119
+ }
120
+ return false;
121
+ }
122
+ currentScope = currentScope.upper;
123
+ }
124
+ return false;
125
+ };
126
+
127
+ /**
128
+ * Recursively check a node that is an argument to cx() for xcss() results —
129
+ * both inline calls and references to variables initialised with xcss().
130
+ * Recurses into LogicalExpression (&&, ||) and ConditionalExpression (? :) so that
131
+ * patterns like cx(cond && xcss({...})) and cx(cond ? baseStyles : a) are caught.
132
+ */
133
+ var _checkArgForXcss = function checkArgForXcss(argNode) {
134
+ if (!argNode) {
135
+ return;
136
+ }
137
+ // Inline: cx(xcss({ color: 'red' }))
138
+ if (argNode.type === 'CallExpression' && isXcss(argNode.callee, references, importSources)) {
139
+ context.report({
140
+ node: argNode,
141
+ messageId: 'noXcssInCx'
142
+ });
143
+ return;
144
+ }
145
+ // Variable reference: cx(baseStyles) where baseStyles = xcss({...})
146
+ if (isXcssVariable(argNode)) {
147
+ context.report({
148
+ node: argNode,
149
+ messageId: 'noXcssInCx'
150
+ });
151
+ return;
152
+ }
153
+ // Recurse into `cond && xcss({...})` or `cond || xcss({...})`
154
+ if (argNode.type === 'LogicalExpression') {
155
+ _checkArgForXcss(argNode.left);
156
+ _checkArgForXcss(argNode.right);
157
+ }
158
+ // Recurse into `cond ? xcss({...}) : fallback`
159
+ if (argNode.type === 'ConditionalExpression') {
160
+ _checkArgForXcss(argNode.consequent);
161
+ _checkArgForXcss(argNode.alternate);
162
+ }
163
+ };
164
+
165
+ /**
166
+ * Check all arguments of a cx() call for inline xcss() calls.
167
+ * Reports each xcss() call found as a violation.
168
+ */
169
+ var checkCxArgs = function checkCxArgs(callNode) {
170
+ if (callNode.type !== 'CallExpression') {
171
+ return;
172
+ }
173
+ if (!isCxFunction(callNode.callee, references, importSources)) {
174
+ return;
175
+ }
176
+ var _iterator2 = _createForOfIteratorHelper(callNode.arguments),
177
+ _step2;
178
+ try {
179
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
180
+ var arg = _step2.value;
181
+ if (arg) {
182
+ _checkArgForXcss(arg.type === 'SpreadElement' ? arg.argument : arg);
183
+ }
184
+ }
185
+ } catch (err) {
186
+ _iterator2.e(err);
187
+ } finally {
188
+ _iterator2.f();
189
+ }
190
+ };
191
+
192
+ // Case 1: xcss={cx(...)} — cx() directly as the xcss value
193
+ checkCxArgs(expression);
194
+
195
+ // Case 2: xcss={[..., cx(...), ...]} — cx() inside an xcss array
196
+ if (expression.type === 'ArrayExpression') {
197
+ var _iterator3 = _createForOfIteratorHelper(expression.elements),
198
+ _step3;
199
+ try {
200
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
201
+ var element = _step3.value;
202
+ if (element) {
203
+ checkCxArgs(element.type === 'SpreadElement' ? element.argument : element);
204
+ }
205
+ }
206
+ } catch (err) {
207
+ _iterator3.e(err);
208
+ } finally {
209
+ _iterator3.f();
210
+ }
211
+ }
212
+ }
213
+ };
214
+ }
215
+ };
216
+ export default rule;
@@ -111,7 +111,8 @@ function resolveVariableToConstant(programBody, variableName, cache) {
111
111
  * Returns null for any argument that can't be statically resolved.
112
112
  */
113
113
  function extractCallArgs(node, programBody, variableCache) {
114
- if (node.arguments.length < 3) {
114
+ var argOffset = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
115
+ if (node.arguments.length < argOffset + 3) {
115
116
  return null;
116
117
  }
117
118
  function resolveArg(arg) {
@@ -123,9 +124,9 @@ function extractCallArgs(node, programBody, variableCache) {
123
124
  }
124
125
  return null;
125
126
  }
126
- var groupId = resolveArg(node.arguments[0]);
127
- var packageId = resolveArg(node.arguments[1]);
128
- var exampleId = resolveArg(node.arguments[2]);
127
+ var groupId = resolveArg(node.arguments[argOffset]);
128
+ var packageId = resolveArg(node.arguments[argOffset + 1]);
129
+ var exampleId = resolveArg(node.arguments[argOffset + 2]);
129
130
  if (!groupId || !packageId || !exampleId) {
130
131
  return null;
131
132
  }
@@ -173,8 +174,13 @@ function resolveExamplePathFromArgs(groupId, packageId, exampleId, testFilePath)
173
174
  var examplesDir = path.resolve(packagesBase.basePath, groupId, packageId, 'examples');
174
175
  var fallback = path.resolve(examplesDir, "".concat(exampleId, ".tsx"));
175
176
 
176
- // Match: exact name OR numeric-prefixed variant, with optional `.examples` infix
177
- var candidateRe = new RegExp("^(?:\\d+-)?".concat(exampleId, "(?:\\.examples?)?\\.tsx$"));
177
+ // Phase 4: loosen candidateRe to match both pre- and post-rename filename shapes.
178
+ // Pre-rename: ^(\d+-)?<id>(\.(examples?))?\.tsx$
179
+ // Post-rename: ^(\d+-)?<id>(\.<ident>){0,3}\.tsx$ (Volt prefix, optional .dup<N>, optional role)
180
+ // The {0,3} cap prevents matching arbitrary strings (e.g. 4-component names).
181
+ // Escape regex metacharacters in exampleId (ids are kebab-case today, but defensive).
182
+ var escapedId = exampleId.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
183
+ var candidateRe = new RegExp("^(?:\\d+-)?".concat(escapedId, "(?:\\.[A-Za-z][A-Za-z0-9_]*){0,3}\\.tsx$"));
178
184
  try {
179
185
  var match = fs.readdirSync(examplesDir).find(function (f) {
180
186
  return candidateRe.test(f);
@@ -272,20 +278,24 @@ var rule = {
272
278
  return;
273
279
  }
274
280
  var node = estreeNode;
275
- // Only handle `<anything>.visitExample(...)` calls
276
- if (node.callee.type !== AST_NODE_TYPES.MemberExpression || node.callee.property.type !== AST_NODE_TYPES.Identifier || node.callee.property.name !== 'visitExample') {
281
+ var calleeIdentifier = null;
282
+ var argOffset = 0;
283
+ if (node.callee.type === AST_NODE_TYPES.MemberExpression && node.callee.property.type === AST_NODE_TYPES.Identifier && node.callee.property.name === 'visitExample') {
284
+ calleeIdentifier = node.callee.property;
285
+ } else if (node.callee.type === AST_NODE_TYPES.Identifier && node.callee.name === 'visitMockedExample') {
286
+ calleeIdentifier = node.callee;
287
+ argOffset = 1; // first arg is `page`
288
+ } else {
277
289
  return;
278
290
  }
279
291
 
280
- // Narrow callee — we've confirmed property is an Identifier above
281
- var callee = node.callee;
282
292
  // reportCallee is typed as estree.Node for context.report compatibility
283
293
  var reportCallee = estreeNode.callee;
284
294
  var genericType = extractGenericType(node);
285
295
 
286
296
  // ── Case 1: No generic type parameter ────────────────────────────────
287
297
  if (genericType === null) {
288
- var _args = extractCallArgs(node, programBody, variableCache);
298
+ var _args = extractCallArgs(node, programBody, variableCache, argOffset);
289
299
  context.report({
290
300
  node: reportCallee,
291
301
  messageId: 'missingTypeofImport',
@@ -298,7 +308,7 @@ var rule = {
298
308
  return null;
299
309
  }
300
310
  var importPath = computeRelativeImportPath(filename, examplePath);
301
- var _ref2 = callee.property.range,
311
+ var _ref2 = calleeIdentifier.range,
302
312
  _ref3 = _slicedToArray(_ref2, 2),
303
313
  start = _ref3[0],
304
314
  end = _ref3[1];
@@ -360,7 +370,7 @@ var rule = {
360
370
  }
361
371
 
362
372
  // Validate that the import path matches the arguments
363
- var args = extractCallArgs(node, programBody, variableCache);
373
+ var args = extractCallArgs(node, programBody, variableCache, argOffset);
364
374
  if (!args) {
365
375
  // Dynamic arguments — can't validate statically
366
376
  return;