@atlaskit/eslint-plugin-platform 2.9.2 → 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.
@@ -0,0 +1,321 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = exports.RULE_NAME = void 0;
8
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
+ var _fs = _interopRequireDefault(require("fs"));
10
+ var _path = _interopRequireDefault(require("path"));
11
+ var _utils = require("@typescript-eslint/utils");
12
+ 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; } } }; }
13
+ 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; } }
14
+ 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; }
15
+ var RULE_NAME = exports.RULE_NAME = 'editor-example-type-import-required';
16
+
17
+ /**
18
+ * Spec files that are excluded from this rule because they don't use visitExample
19
+ * or have their own test harness that doesn't follow the exampleName fixture pattern.
20
+ *
21
+ * Paths are matched as suffixes of the file path (platform-relative).
22
+ */
23
+ var EXCLUDED_SPEC_FILES = [
24
+ // Meta-tests for the testing infrastructure itself
25
+ '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',
26
+ // Tests the a11y decorator itself, no visitExample
27
+ 'packages/accessibility/axe-integration/a11y-playwright-testing/src/auto-a11y-setup/__tests__/playwright/skip-decorator.spec.ts',
28
+ // Stub test (expect(true).toBe(true)), no visitExample
29
+ 'packages/ai-mate/rovo-content-bridge-api/__tests__/playwright/index.spec.tsx',
30
+ // Page-object's visitExample call carries the typeof import(...) generic,
31
+ // so the typed example reference lives in _helpers/page-object.ts rather
32
+ // than in test.use({ exampleName }) in the spec itself.
33
+ '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',
34
+ // Spec runs through a page-object (pages/generic-form-renderer.ts) whose
35
+ // visitExample call already carries the typeof import(...) generic. The
36
+ // typed reference therefore lives in the colocated page-object, not in
37
+ // test.use({ exampleName }) in the spec.
38
+ 'packages/proforma/proforma-common-core/__tests__/playwright/json-test-cases.spec.ts', 'packages/proforma/proforma-form-renderer/__tests__/playwright/json-test-cases.spec.ts',
39
+ // Spec runs through a page-object that still uses raw page.goto() against
40
+ // /examples.html. Migrating these requires reworking the page-object to
41
+ // route through visitExample<typeof import(...)>(...).
42
+ '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',
43
+ // Tests the website itself, not examples
44
+ 'website/src/__tests__/playwright/examples.spec.ts', 'website/src/__tests__/playwright/home.spec.ts',
45
+ // react-ufo: uses an `examplePage: string` fixture where the name (e.g. 'basic') is
46
+ // resolved to the example file internally by visitExample — the name does not match
47
+ // the file name (e.g. '01-basic.tsx'), so a typeof import assertion is not possible
48
+ // without refactoring the fixture to use keyof typeof import directly. Specs that
49
+ // happen to also use the inline `visitExample<typeof import(...)>` pattern alongside
50
+ // the fixture pass via the file-level typeof import check above and don't appear here.
51
+ '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',
52
+ // editor-performance-metrics: same pattern as react-ufo — uses an `examplePage: string` fixture
53
+ // where the name resolves internally and does not match the example file name.
54
+ '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',
55
+ // generative-ai-modal: the example name is passed dynamically at examplePage.goto({ example: '...' })
56
+ // time rather than via test.use(), so a static typeof import assertion in the spec is not possible.
57
+ 'packages/editor/generative-ai-modal/src/ui/screens/Preview/__tests__/playwright/tab-navigation.spec.ts'];
58
+ function isExcluded(filename) {
59
+ var normalised = filename.replace(/\\/g, '/');
60
+ return EXCLUDED_SPEC_FILES.some(function (excluded) {
61
+ return normalised.endsWith(excluded);
62
+ });
63
+ }
64
+ var messages = {
65
+ 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') ",
66
+ missingTypeAssertion: 'exampleName must include a typeof import type assertion for the static import graph. ' + "Use: exampleName: '{{ value }}' as keyof typeof import('{{ expectedPath }}') ",
67
+ pathMismatch: 'The import path "{{ importPath }}" does not resolve to the expected example file ' + "for exampleName '{{ exampleName }}'. Expected: {{ expectedPath }}"
68
+ };
69
+ function isTargetFile(filename) {
70
+ return (filename.endsWith('.spec.tsx') || filename.endsWith('.spec.ts')) && !isExcluded(filename);
71
+ }
72
+
73
+ /**
74
+ * Resolves the example file path from the spec file's location and the example name.
75
+ * Editor specs follow: packages/{groupId}/{packageId}/src/__tests__/playwright/*.spec.ts
76
+ * Examples live at: packages/{groupId}/{packageId}/examples/{exampleName}.tsx
77
+ */
78
+ function resolveExamplePath(testFilePath, exampleName) {
79
+ var testFileDir = _path.default.dirname(testFilePath);
80
+ var segments = testFileDir.split(_path.default.sep);
81
+ var packagesIndex = segments.findIndex(function (seg) {
82
+ return seg === 'packages';
83
+ });
84
+ if (packagesIndex === -1) {
85
+ return null;
86
+ }
87
+ var groupId = segments[packagesIndex + 1];
88
+ var packageId = segments[packagesIndex + 2];
89
+ if (!groupId || !packageId) {
90
+ return null;
91
+ }
92
+ var basePath = _path.default.isAbsolute(testFilePath) ? _path.default.resolve.apply(_path.default, ['/'].concat((0, _toConsumableArray2.default)(segments.slice(0, packagesIndex + 1)))) : _path.default.resolve.apply(_path.default, [process.cwd()].concat((0, _toConsumableArray2.default)(segments.slice(0, packagesIndex + 1))));
93
+ var examplesDir = _path.default.resolve(basePath, groupId, packageId, 'examples');
94
+ var candidateRe = new RegExp("^(?:\\d+-)?".concat(exampleName, "(?:\\.examples?)?\\.tsx$"));
95
+ try {
96
+ var match = _fs.default.readdirSync(examplesDir).find(function (f) {
97
+ return candidateRe.test(f);
98
+ });
99
+ if (match) {
100
+ return _path.default.resolve(examplesDir, match);
101
+ }
102
+ } catch (_unused) {
103
+ // Directory doesn't exist (e.g. test environments)
104
+ }
105
+ return _path.default.resolve(examplesDir, "".concat(exampleName, ".tsx"));
106
+ }
107
+ function computeRelativeImportPath(fromFile, toFile) {
108
+ var fromDir = _path.default.dirname(fromFile);
109
+ var relativePath = _path.default.relative(fromDir, toFile);
110
+ relativePath = relativePath.replace(/\\/g, '/');
111
+ if (!relativePath.startsWith('.') && !relativePath.startsWith('/')) {
112
+ relativePath = "./".concat(relativePath);
113
+ }
114
+ return relativePath;
115
+ }
116
+
117
+ /**
118
+ * Check if a property value has a `keyof typeof import(...)` type assertion.
119
+ * Handles both:
120
+ * 'name' as keyof typeof import('...')
121
+ */
122
+ function extractTypeofImportPath(node) {
123
+ if (node.type !== _utils.AST_NODE_TYPES.TSAsExpression) {
124
+ return null;
125
+ }
126
+ var typeAnnotation = node.typeAnnotation;
127
+ if (typeAnnotation.type === _utils.AST_NODE_TYPES.TSTypeOperator && typeAnnotation.operator === 'keyof') {
128
+ return extractFromTypeQuery(typeAnnotation.typeAnnotation);
129
+ }
130
+ if (typeAnnotation.type === _utils.AST_NODE_TYPES.TSUnionType) {
131
+ var _iterator = _createForOfIteratorHelper(typeAnnotation.types),
132
+ _step;
133
+ try {
134
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
135
+ var member = _step.value;
136
+ if (member.type === _utils.AST_NODE_TYPES.TSTypeOperator && member.operator === 'keyof') {
137
+ var result = extractFromTypeQuery(member.typeAnnotation);
138
+ if (result) {
139
+ return result;
140
+ }
141
+ }
142
+ }
143
+ } catch (err) {
144
+ _iterator.e(err);
145
+ } finally {
146
+ _iterator.f();
147
+ }
148
+ }
149
+ return null;
150
+ }
151
+ function extractFromTypeQuery(node) {
152
+ if (!node || node.type !== _utils.AST_NODE_TYPES.TSTypeQuery) {
153
+ return null;
154
+ }
155
+ var exprName = node.exprName;
156
+ if (exprName.type !== _utils.AST_NODE_TYPES.TSImportType) {
157
+ return null;
158
+ }
159
+ var argument = exprName.argument;
160
+ if (argument.type === _utils.AST_NODE_TYPES.TSLiteralType && argument.literal.type === _utils.AST_NODE_TYPES.Literal && typeof argument.literal.value === 'string') {
161
+ return argument.literal.value;
162
+ }
163
+ return null;
164
+ }
165
+
166
+ /**
167
+ * Extract the string value from a property value, ignoring type assertions.
168
+ */
169
+ function getStringValue(node) {
170
+ if (node.type === _utils.AST_NODE_TYPES.Literal && typeof node.value === 'string') {
171
+ return node.value;
172
+ }
173
+ if (node.type === _utils.AST_NODE_TYPES.TSAsExpression) {
174
+ return getStringValue(node.expression);
175
+ }
176
+ return null;
177
+ }
178
+ var rule = {
179
+ meta: {
180
+ type: 'problem',
181
+ docs: {
182
+ 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).'
183
+ },
184
+ fixable: 'code',
185
+ messages: messages,
186
+ schema: []
187
+ },
188
+ create: function create(context) {
189
+ var filename = context.filename;
190
+ if (!isTargetFile(filename)) {
191
+ return {};
192
+ }
193
+ return {
194
+ 'Program:exit': function ProgramExit(estreeNode) {
195
+ var program = estreeNode;
196
+
197
+ // Single AST walk: collect all test.use() calls AND detect whether the
198
+ // file contains any `typeof import('...')` reference at all (a TSImportType
199
+ // node). Either signal is sufficient evidence that the spec ties at least
200
+ // one example file into its TypeScript import graph.
201
+ var testUseCalls = [];
202
+ var hasAnyTypeofImport = false;
203
+ var visited = new Set();
204
+ var queue = [program];
205
+ while (queue.length > 0) {
206
+ var node = queue.shift();
207
+ if (visited.has(node)) {
208
+ continue;
209
+ }
210
+ visited.add(node);
211
+ if (node.type === _utils.AST_NODE_TYPES.CallExpression && node.callee.type === _utils.AST_NODE_TYPES.MemberExpression && node.callee.property.type === _utils.AST_NODE_TYPES.Identifier && node.callee.property.name === 'use' && node.arguments.length > 0 && node.arguments[0].type === _utils.AST_NODE_TYPES.ObjectExpression) {
212
+ testUseCalls.push(node);
213
+ }
214
+ if (node.type === _utils.AST_NODE_TYPES.TSImportType) {
215
+ hasAnyTypeofImport = true;
216
+ }
217
+ for (var _i = 0, _Object$keys = Object.keys(node); _i < _Object$keys.length; _i++) {
218
+ var key = _Object$keys[_i];
219
+ if (key === 'parent') {
220
+ continue;
221
+ }
222
+ var child = node[key];
223
+ if (Array.isArray(child)) {
224
+ var _iterator2 = _createForOfIteratorHelper(child),
225
+ _step2;
226
+ try {
227
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
228
+ var item = _step2.value;
229
+ if (item && typeof item.type === 'string') {
230
+ queue.push(item);
231
+ }
232
+ }
233
+ } catch (err) {
234
+ _iterator2.e(err);
235
+ } finally {
236
+ _iterator2.f();
237
+ }
238
+ } else if (child && typeof child.type === 'string') {
239
+ queue.push(child);
240
+ }
241
+ }
242
+ }
243
+
244
+ // Any `typeof import('...')` anywhere in the spec — including the
245
+ // `page.visitExample<typeof import('...')>(...)` and
246
+ // `page.visitMockedExample<typeof import('...')>(...)` patterns used
247
+ // outside of test.use() — satisfies the same goal as the canonical
248
+ // `test.use({ exampleName: '...' as keyof typeof import('...') })`
249
+ // pattern: the example file is referenced from the spec's TypeScript
250
+ // import graph.
251
+ if (hasAnyTypeofImport) {
252
+ return;
253
+ }
254
+
255
+ // Check if any test.use() call anywhere in the file has exampleName with a typeof import assertion
256
+ var fileHasExampleName = testUseCalls.some(function (call) {
257
+ var obj = call.arguments[0];
258
+ return obj.properties.some(function (prop) {
259
+ if (prop.type !== _utils.AST_NODE_TYPES.Property || prop.key.type !== _utils.AST_NODE_TYPES.Identifier || prop.key.name !== 'exampleName') {
260
+ return false;
261
+ }
262
+ return extractTypeofImportPath(prop.value) !== null;
263
+ });
264
+ });
265
+ if (fileHasExampleName) {
266
+ return;
267
+ }
268
+
269
+ // Find the first test.use() call that has exampleName without the typeof import assertion
270
+ // (if any), otherwise use the first test.use() call
271
+ var targetCall = testUseCalls[0];
272
+ var existingExampleNameProp = null;
273
+ for (var _i2 = 0, _testUseCalls = testUseCalls; _i2 < _testUseCalls.length; _i2++) {
274
+ var call = _testUseCalls[_i2];
275
+ var obj = call.arguments[0];
276
+ var prop = obj.properties.find(function (p) {
277
+ return p.type === _utils.AST_NODE_TYPES.Property && p.key.type === _utils.AST_NODE_TYPES.Identifier && p.key.name === 'exampleName';
278
+ });
279
+ if (prop) {
280
+ targetCall = call;
281
+ existingExampleNameProp = prop;
282
+ break;
283
+ }
284
+ }
285
+ if (!targetCall) {
286
+ return;
287
+ }
288
+ var objectArg = targetCall.arguments[0];
289
+
290
+ // Determine the example name to use for the import path
291
+ var exampleNameValue = existingExampleNameProp ? getStringValue(existingExampleNameProp.value) : null;
292
+ var defaultName = exampleNameValue !== null && exampleNameValue !== void 0 ? exampleNameValue : 'testing';
293
+ var examplePath = resolveExamplePath(filename, defaultName);
294
+ if (!examplePath) {
295
+ return;
296
+ }
297
+ var importPath = computeRelativeImportPath(filename, examplePath);
298
+ context.report({
299
+ node: targetCall,
300
+ messageId: 'missingExampleName',
301
+ fix: function fix(fixer) {
302
+ // If exampleName exists but lacks typeof import, replace its value
303
+ if (existingExampleNameProp) {
304
+ return fixer.replaceText(existingExampleNameProp.value, "'".concat(defaultName, "' as keyof typeof import('").concat(importPath, "') "));
305
+ }
306
+ // Otherwise insert exampleName as the first property
307
+ var firstProp = objectArg.properties[0];
308
+ if (!firstProp) {
309
+ return fixer.replaceText(targetCall.arguments[0], "{\n\texampleName: '".concat(defaultName, "' as keyof typeof import('").concat(importPath, "'),\n}"));
310
+ }
311
+ var sourceCode = context.sourceCode;
312
+ var token = sourceCode.getFirstToken(firstProp);
313
+ var indent = token ? '\t'.repeat(token.loc.start.column) : '\t';
314
+ return fixer.insertTextBefore(firstProp, "exampleName: '".concat(defaultName, "' as keyof typeof import('").concat(importPath, "') ,\n").concat(indent));
315
+ }
316
+ });
317
+ }
318
+ };
319
+ }
320
+ };
321
+ var _default = exports.default = rule;
@@ -26,6 +26,8 @@ import validGateName from './rules/feature-gating/valid-gate-name';
26
26
  import expandBackgroundShorthand from './rules/compiled/expand-background-shorthand';
27
27
  import expandSpacingShorthand from './rules/compiled/expand-spacing-shorthand';
28
28
  import noCssPropInObjectSpread from './rules/compiled/no-css-prop-in-object-spread';
29
+ import useMotionTokenValues from './rules/compiled/use-motion-token-values';
30
+ import expandMotionShorthand from './rules/compiled/expand-motion-shorthand';
29
31
  import noSparseCheckout from './rules/no-sparse-checkout';
30
32
  import noDirectDocumentUsage from './rules/no-direct-document-usage';
31
33
  import noSetImmediate from './rules/no-set-immediate';
@@ -37,6 +39,7 @@ import noJestMockBarrelFiles from './rules/import/no-jest-mock-barrel-files';
37
39
  import noRelativeBarrelFileImports from './rules/import/no-relative-barrel-file-imports';
38
40
  import noConversationAssistantBarrelImports from './rules/import/no-conversation-assistant-barrel-imports';
39
41
  import visitExampleTypeImportRequired from './rules/visit-example-type-import-required';
42
+ import editorExampleTypeImportRequired from './rules/editor-example-type-import-required';
40
43
  import ensureUseSyncExternalStoreServerSnapshot from './rules/ensure-use-sync-external-store-server-snapshot';
41
44
  import noXcssInCx from './rules/no-xcss-in-cx';
42
45
  import { join, normalize } from 'node:path';
@@ -97,7 +100,10 @@ const rules = {
97
100
  'no-conversation-assistant-barrel-imports': noConversationAssistantBarrelImports,
98
101
  'visit-example-type-import-required': visitExampleTypeImportRequired,
99
102
  'no-xcss-in-cx': noXcssInCx,
100
- 'ensure-use-sync-external-store-server-snapshot': ensureUseSyncExternalStoreServerSnapshot
103
+ 'editor-example-type-import-required': editorExampleTypeImportRequired,
104
+ 'ensure-use-sync-external-store-server-snapshot': ensureUseSyncExternalStoreServerSnapshot,
105
+ 'use-motion-token-values': useMotionTokenValues,
106
+ 'expand-motion-shorthand': expandMotionShorthand
101
107
  };
102
108
  const commonConfig = {
103
109
  '@atlaskit/platform/ensure-test-runner-arguments': 'error',
@@ -115,6 +121,8 @@ const commonConfig = {
115
121
  '@atlaskit/platform/expand-background-shorthand': 'error',
116
122
  '@atlaskit/platform/expand-spacing-shorthand': 'error',
117
123
  '@atlaskit/platform/no-css-prop-in-object-spread': 'error',
124
+ '@atlaskit/platform/use-motion-token-values': 'warn',
125
+ '@atlaskit/platform/expand-motion-shorthand': 'warn',
118
126
  '@compiled/jsx-pragma': ['error', {
119
127
  importSources: ['@atlaskit/css'],
120
128
  onlyRunIfImportingCompiled: true,
@@ -0,0 +1,239 @@
1
+ const EASING_KEYWORDS = ['ease', 'ease-in', 'ease-out', 'ease-in-out', 'linear', 'step-start', 'step-end'];
2
+ const KEYWORD_VALUES = ['none', 'all', 'inherit', 'initial', 'unset'];
3
+ const isDuration = token => /^\d+(?:\.\d+)?m?s$/.test(token);
4
+ const isEasing = token => EASING_KEYWORDS.includes(token) || token.startsWith('cubic-bezier(') || token.startsWith('steps(');
5
+ /**
6
+ * Tokenizes a CSS shorthand value string, respecting function boundaries.
7
+ * e.g. 'opacity 200ms cubic-bezier(0.4, 0, 0, 1) 0ms' →
8
+ * ['opacity', '200ms', 'cubic-bezier(0.4, 0, 0, 1)', '0ms']
9
+ * Splits on whitespace only when not inside parentheses.
10
+ */
11
+ const tokenizeShorthand = value => {
12
+ const tokens = [];
13
+ let depth = 0;
14
+ let current = '';
15
+ for (let i = 0; i < value.length; i++) {
16
+ const ch = value[i];
17
+ if (ch === '(') {
18
+ depth++;
19
+ current += ch;
20
+ } else if (ch === ')') {
21
+ depth--;
22
+ current += ch;
23
+ } else if (/\s/.test(ch) && depth === 0) {
24
+ if (current.length > 0) {
25
+ tokens.push(current);
26
+ current = '';
27
+ }
28
+ } else {
29
+ current += ch;
30
+ }
31
+ }
32
+ if (current.length > 0) {
33
+ tokens.push(current);
34
+ }
35
+ return tokens;
36
+ };
37
+
38
+ // Splits on top-level commas (outside function parens) — preserves cubic-bezier(...) commas.
39
+ const splitOnTopLevelCommas = value => {
40
+ const parts = [];
41
+ let depth = 0;
42
+ let current = '';
43
+ for (const ch of value) {
44
+ if (ch === '(') {
45
+ depth++;
46
+ current += ch;
47
+ } else if (ch === ')') {
48
+ depth--;
49
+ current += ch;
50
+ } else if (ch === ',' && depth === 0) {
51
+ parts.push(current.trim());
52
+ current = '';
53
+ } else {
54
+ current += ch;
55
+ }
56
+ }
57
+ if (current.trim().length > 0) {
58
+ parts.push(current.trim());
59
+ }
60
+ return parts;
61
+ };
62
+ const parseTransition = value => {
63
+ const parts = tokenizeShorthand(value.trim());
64
+ const result = {};
65
+ let durationCount = 0;
66
+ for (const part of parts) {
67
+ if (isDuration(part)) {
68
+ if (durationCount === 0) {
69
+ result.transitionDuration = part;
70
+ } else {
71
+ result.transitionDelay = part;
72
+ }
73
+ durationCount++;
74
+ } else if (isEasing(part)) {
75
+ result.transitionTimingFunction = part;
76
+ } else {
77
+ result.transitionProperty = part;
78
+ }
79
+ }
80
+ return result;
81
+ };
82
+ const parseAnimation = value => {
83
+ const parts = tokenizeShorthand(value.trim());
84
+ const result = {};
85
+ let durationCount = 0;
86
+ for (const part of parts) {
87
+ if (isDuration(part)) {
88
+ if (durationCount === 0) {
89
+ result.animationDuration = part;
90
+ } else {
91
+ result.animationDelay = part;
92
+ }
93
+ durationCount++;
94
+ } else if (isEasing(part)) {
95
+ result.animationTimingFunction = part;
96
+ } else if (part === 'infinite' || /^\d+(\.\d+)?$/.test(part)) {
97
+ result.animationIterationCount = part;
98
+ } else if (['normal', 'reverse', 'alternate', 'alternate-reverse'].includes(part)) {
99
+ result.animationDirection = part;
100
+ } else if (['none', 'forwards', 'backwards', 'both'].includes(part)) {
101
+ result.animationFillMode = part;
102
+ } else if (['running', 'paused'].includes(part)) {
103
+ result.animationPlayState = part;
104
+ } else {
105
+ result.animationName = part;
106
+ }
107
+ }
108
+ return result;
109
+ };
110
+
111
+ // Combine sub-property values across comma-separated transitions/animations.
112
+ // If no segment explicitly set this sub-property, omit it entirely.
113
+ // Otherwise, fill missing slots with the CSS spec default to preserve positional alignment.
114
+ const combineSubPropertyValues = (segments, subProperty, defaultValue) => {
115
+ if (segments.every(s => s[subProperty] === undefined)) {
116
+ return undefined;
117
+ }
118
+ return segments.map(s => {
119
+ var _s$subProperty;
120
+ return (_s$subProperty = s[subProperty]) !== null && _s$subProperty !== void 0 ? _s$subProperty : defaultValue;
121
+ }).join(', ');
122
+ };
123
+ const buildTransitionFix = (segments, indent) => {
124
+ const lines = [];
125
+ const property = combineSubPropertyValues(segments, 'transitionProperty', 'all');
126
+ const duration = combineSubPropertyValues(segments, 'transitionDuration', '0s');
127
+ const timing = combineSubPropertyValues(segments, 'transitionTimingFunction', 'ease');
128
+ const delay = combineSubPropertyValues(segments, 'transitionDelay', '0s');
129
+ if (property !== undefined) lines.push(`transitionProperty: '${property}'`);
130
+ if (duration !== undefined) lines.push(`transitionDuration: '${duration}'`);
131
+ if (timing !== undefined) lines.push(`transitionTimingFunction: '${timing}'`);
132
+ if (delay !== undefined) lines.push(`transitionDelay: '${delay}'`);
133
+ return lines.join(`,\n${indent}`);
134
+ };
135
+ const buildAnimationFix = (segments, indent) => {
136
+ const lines = [];
137
+ const name = combineSubPropertyValues(segments, 'animationName', 'none');
138
+ const duration = combineSubPropertyValues(segments, 'animationDuration', '0s');
139
+ const timing = combineSubPropertyValues(segments, 'animationTimingFunction', 'ease');
140
+ const delay = combineSubPropertyValues(segments, 'animationDelay', '0s');
141
+ const iter = combineSubPropertyValues(segments, 'animationIterationCount', '1');
142
+ const direction = combineSubPropertyValues(segments, 'animationDirection', 'normal');
143
+ const fill = combineSubPropertyValues(segments, 'animationFillMode', 'none');
144
+ const playState = combineSubPropertyValues(segments, 'animationPlayState', 'running');
145
+ if (name !== undefined) lines.push(`animationName: '${name}'`);
146
+ if (duration !== undefined) lines.push(`animationDuration: '${duration}'`);
147
+ if (timing !== undefined) lines.push(`animationTimingFunction: '${timing}'`);
148
+ if (delay !== undefined) lines.push(`animationDelay: '${delay}'`);
149
+ if (iter !== undefined) lines.push(`animationIterationCount: '${iter}'`);
150
+ if (direction !== undefined) lines.push(`animationDirection: '${direction}'`);
151
+ if (fill !== undefined) lines.push(`animationFillMode: '${fill}'`);
152
+ if (playState !== undefined) lines.push(`animationPlayState: '${playState}'`);
153
+ return lines.join(`,\n${indent}`);
154
+ };
155
+ const TRANSITION_SUB_PROPERTIES = ['transitionProperty', 'transitionDuration', 'transitionTimingFunction', 'transitionDelay'];
156
+ const ANIMATION_SUB_PROPERTIES = ['animationName', 'animationDuration', 'animationTimingFunction', 'animationDelay', 'animationIterationCount', 'animationDirection', 'animationFillMode', 'animationPlayState'];
157
+ const executeExpandTransitionRule = (context, node, property) => {
158
+ var _context$sourceCode, _node$loc;
159
+ if (node.value.type === 'CallExpression') {
160
+ return;
161
+ }
162
+ if (node.value.type === 'TemplateLiteral') {
163
+ return;
164
+ }
165
+ if (node.value.type !== 'Literal' || typeof node.value.value !== 'string') {
166
+ return;
167
+ }
168
+ const rawValue = node.value.value;
169
+ if (KEYWORD_VALUES.includes(rawValue)) {
170
+ return;
171
+ }
172
+ const subProperties = property === 'transition' ? TRANSITION_SUB_PROPERTIES : ANIMATION_SUB_PROPERTIES;
173
+
174
+ // Extract leading whitespace to preserve indentation style (tabs vs spaces)
175
+ const sourceCode = (_context$sourceCode = context.sourceCode) !== null && _context$sourceCode !== void 0 ? _context$sourceCode : context.getSourceCode();
176
+ const nodeStart = (_node$loc = node.loc) === null || _node$loc === void 0 ? void 0 : _node$loc.start;
177
+ let indent = '\t';
178
+ if (nodeStart) {
179
+ var _sourceCode$lines;
180
+ const lineText = (_sourceCode$lines = sourceCode.lines[nodeStart.line - 1]) !== null && _sourceCode$lines !== void 0 ? _sourceCode$lines : '';
181
+ const leadingWhitespace = lineText.match(/^(\s*)/);
182
+ if (leadingWhitespace) {
183
+ indent = leadingWhitespace[1];
184
+ }
185
+ }
186
+ const segmentStrings = splitOnTopLevelCommas(rawValue);
187
+ if (property === 'transition') {
188
+ const segments = segmentStrings.map(parseTransition);
189
+ const fixText = buildTransitionFix(segments, indent);
190
+ context.report({
191
+ node,
192
+ messageId: 'expandTransitionShorthand',
193
+ data: {
194
+ property,
195
+ subProperties: subProperties.join(', ')
196
+ },
197
+ fix(fixer) {
198
+ return fixer.replaceText(node, fixText);
199
+ }
200
+ });
201
+ } else {
202
+ const segments = segmentStrings.map(parseAnimation);
203
+ const fixText = buildAnimationFix(segments, indent);
204
+ context.report({
205
+ node,
206
+ messageId: 'expandTransitionShorthand',
207
+ data: {
208
+ property,
209
+ subProperties: subProperties.join(', ')
210
+ },
211
+ fix(fixer) {
212
+ return fixer.replaceText(node, fixText);
213
+ }
214
+ });
215
+ }
216
+ };
217
+ export const expandTransitionShorthand = {
218
+ meta: {
219
+ type: 'suggestion',
220
+ fixable: 'code',
221
+ docs: {
222
+ url: 'https://bitbucket.org/atlassian/atlassian-frontend-monorepo/src/master/platform/packages/platform/eslint-plugin/src/rules/compiled/expand-transition-shorthand/'
223
+ },
224
+ messages: {
225
+ expandTransitionShorthand: "Use {{ subProperties }} instead of the '{{ property }}' shorthand so that individual values can be replaced with motion tokens."
226
+ }
227
+ },
228
+ create(context) {
229
+ return {
230
+ 'Property[key.name="transition"]': function (node) {
231
+ executeExpandTransitionRule(context, node, 'transition');
232
+ },
233
+ 'Property[key.name="animation"]': function (node) {
234
+ executeExpandTransitionRule(context, node, 'animation');
235
+ }
236
+ };
237
+ }
238
+ };
239
+ export default expandTransitionShorthand;