@atlaskit/eslint-plugin-platform 2.9.2 → 2.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/cjs/index.js +11 -1
  3. package/dist/cjs/rules/compiled/expand-motion-shorthand/index.js +281 -0
  4. package/dist/cjs/rules/compiled/use-motion-token-values/index.js +506 -0
  5. package/dist/cjs/rules/editor-example-type-import-required/index.js +321 -0
  6. package/dist/cjs/rules/import/one-value-export-per-file/index.js +203 -0
  7. package/dist/es2019/index.js +11 -1
  8. package/dist/es2019/rules/compiled/expand-motion-shorthand/index.js +239 -0
  9. package/dist/es2019/rules/compiled/use-motion-token-values/index.js +444 -0
  10. package/dist/es2019/rules/editor-example-type-import-required/index.js +286 -0
  11. package/dist/es2019/rules/import/one-value-export-per-file/index.js +191 -0
  12. package/dist/esm/index.js +11 -1
  13. package/dist/esm/rules/compiled/expand-motion-shorthand/index.js +275 -0
  14. package/dist/esm/rules/compiled/use-motion-token-values/index.js +499 -0
  15. package/dist/esm/rules/editor-example-type-import-required/index.js +314 -0
  16. package/dist/esm/rules/import/one-value-export-per-file/index.js +196 -0
  17. package/dist/types/index.d.ts +6 -0
  18. package/dist/types/rules/compiled/expand-motion-shorthand/index.d.ts +3 -0
  19. package/dist/types/rules/compiled/use-motion-token-values/index.d.ts +3 -0
  20. package/dist/types/rules/editor-example-type-import-required/index.d.ts +4 -0
  21. package/dist/types/rules/import/one-value-export-per-file/index.d.ts +3 -0
  22. package/dist/types-ts4.5/index.d.ts +6 -0
  23. package/dist/types-ts4.5/rules/compiled/expand-motion-shorthand/index.d.ts +3 -0
  24. package/dist/types-ts4.5/rules/compiled/use-motion-token-values/index.d.ts +3 -0
  25. package/dist/types-ts4.5/rules/editor-example-type-import-required/index.d.ts +4 -0
  26. package/dist/types-ts4.5/rules/import/one-value-export-per-file/index.d.ts +3 -0
  27. 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,196 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
+ function getPropertyName(node) {
3
+ if (!node) {
4
+ return null;
5
+ }
6
+ if (node.type === 'Identifier') {
7
+ return node.name;
8
+ }
9
+ if (node.type === 'Literal') {
10
+ return String(node.value);
11
+ }
12
+ return null;
13
+ }
14
+ function isPrimitiveLiteral(declarator) {
15
+ function isPrimitiveExpression(node) {
16
+ if (!node) {
17
+ return false;
18
+ }
19
+ switch (node.type) {
20
+ case 'Literal':
21
+ return typeof node.value === 'string' || typeof node.value === 'number' || typeof node.value === 'boolean' || node.value === null;
22
+ case 'TemplateLiteral':
23
+ return node.expressions.length === 0;
24
+ case 'Identifier':
25
+ return node.name === 'undefined';
26
+ case 'UnaryExpression':
27
+ return ['+', '-', '~', '!'].includes(node.operator) && isPrimitiveExpression(node.argument);
28
+ case 'BinaryExpression':
29
+ return isPrimitiveExpression(node.left) && isPrimitiveExpression(node.right);
30
+ case 'TSAsExpression':
31
+ case 'TSTypeAssertion':
32
+ case 'TSNonNullExpression':
33
+ return isPrimitiveExpression(node.expression);
34
+ default:
35
+ return false;
36
+ }
37
+ }
38
+ return isPrimitiveExpression(declarator.init);
39
+ }
40
+ function collectBindingExports(node) {
41
+ if (!node) {
42
+ return [];
43
+ }
44
+ switch (node.type) {
45
+ case 'Identifier':
46
+ return [{
47
+ name: node.name,
48
+ loc: node.loc
49
+ }];
50
+ case 'ObjectPattern':
51
+ return node.properties.flatMap(function (property) {
52
+ if (property.type === 'RestElement') {
53
+ return collectBindingExports(property.argument);
54
+ }
55
+ return collectBindingExports(property.value);
56
+ });
57
+ case 'ArrayPattern':
58
+ return node.elements.flatMap(function (element) {
59
+ return collectBindingExports(element);
60
+ });
61
+ case 'AssignmentPattern':
62
+ return collectBindingExports(node.left);
63
+ case 'RestElement':
64
+ return collectBindingExports(node.argument);
65
+ default:
66
+ return [];
67
+ }
68
+ }
69
+ function getDefaultExportName(node) {
70
+ var declaration = node.declaration;
71
+ if ((declaration.type === 'FunctionDeclaration' || declaration.type === 'ClassDeclaration') && declaration.id) {
72
+ return declaration.id.name;
73
+ }
74
+ return 'default';
75
+ }
76
+ function getDefaultExportLoc(node) {
77
+ var declaration = node.declaration;
78
+ if ((declaration.type === 'FunctionDeclaration' || declaration.type === 'ClassDeclaration') && declaration.id) {
79
+ return declaration.id.loc;
80
+ }
81
+ return node.loc;
82
+ }
83
+ function collectDeclarationExports(declaration, allowPrimitiveExports) {
84
+ if (!declaration) {
85
+ return [];
86
+ }
87
+ switch (declaration.type) {
88
+ case 'VariableDeclaration':
89
+ return declaration.declarations.flatMap(function (declarator) {
90
+ if (allowPrimitiveExports && isPrimitiveLiteral(declarator)) {
91
+ return [];
92
+ }
93
+ return collectBindingExports(declarator.id);
94
+ });
95
+ case 'FunctionDeclaration':
96
+ case 'ClassDeclaration':
97
+ return declaration.id ? [{
98
+ name: declaration.id.name,
99
+ loc: declaration.id.loc
100
+ }] : [];
101
+ case 'TSEnumDeclaration':
102
+ return [{
103
+ name: declaration.id.name,
104
+ loc: declaration.id.loc
105
+ }];
106
+ case 'TSInterfaceDeclaration':
107
+ case 'TSTypeAliasDeclaration':
108
+ return [];
109
+ default:
110
+ return [];
111
+ }
112
+ }
113
+ function collectNamedSpecifierExports(node) {
114
+ if (node.exportKind === 'type') {
115
+ return [];
116
+ }
117
+ return node.specifiers.flatMap(function (specifier) {
118
+ if (specifier.type !== 'ExportSpecifier' || specifier.exportKind === 'type') {
119
+ return [];
120
+ }
121
+ var exportedName = getPropertyName(specifier.exported);
122
+ return exportedName ? [{
123
+ name: exportedName,
124
+ loc: specifier.exported.loc
125
+ }] : [];
126
+ });
127
+ }
128
+ var rule = {
129
+ meta: {
130
+ type: 'suggestion',
131
+ docs: {
132
+ description: 'Disallow more than one local value export per file.',
133
+ category: 'Best Practices',
134
+ recommended: false
135
+ },
136
+ schema: [{
137
+ type: 'object',
138
+ properties: {
139
+ allowPrimitiveExports: {
140
+ type: 'boolean',
141
+ description: 'When true, primitive value exports (strings, numbers, booleans, null, undefined, and template literals) are ignored when counting local value exports.'
142
+ }
143
+ },
144
+ additionalProperties: false
145
+ }],
146
+ messages: {
147
+ multipleValueExports: 'This file exports {{count}} local values ({{names}}). Keep one value export per file https://hello.atlassian.net/wiki/spaces/DevInfra/pages/6809881812/One+Export+Per+File'
148
+ }
149
+ },
150
+ create: function create(context) {
151
+ var _, _options$allowPrimiti;
152
+ var options = (_ = context.options[0]) !== null && _ !== void 0 ? _ : {};
153
+ var allowPrimitiveExports = (_options$allowPrimiti = options.allowPrimitiveExports) !== null && _options$allowPrimiti !== void 0 ? _options$allowPrimiti : false;
154
+ var valueExports = [];
155
+ return {
156
+ ExportDefaultDeclaration: function ExportDefaultDeclaration(node) {
157
+ var exportNode = node;
158
+ valueExports.push({
159
+ name: getDefaultExportName(exportNode),
160
+ loc: getDefaultExportLoc(exportNode)
161
+ });
162
+ },
163
+ ExportNamedDeclaration: function ExportNamedDeclaration(node) {
164
+ var exportNode = node;
165
+
166
+ // Re-export-only barrel syntax is intentionally ignored.
167
+ if (exportNode.source) {
168
+ return;
169
+ }
170
+ valueExports.push.apply(valueExports, _toConsumableArray(collectDeclarationExports(exportNode.declaration, allowPrimitiveExports)));
171
+ valueExports.push.apply(valueExports, _toConsumableArray(collectNamedSpecifierExports(exportNode)));
172
+ },
173
+ 'Program:exit': function ProgramExit(node) {
174
+ if (valueExports.length <= 1) {
175
+ return;
176
+ }
177
+ var sampleNames = valueExports.slice(0, 5).map(function (valueExport) {
178
+ return valueExport.name;
179
+ }).join(', ');
180
+ var names = valueExports.length > 5 ? "".concat(sampleNames, ", and ").concat(valueExports.length - 5, " more") : sampleNames;
181
+ valueExports.forEach(function (valueExport) {
182
+ context.report({
183
+ node: node,
184
+ loc: valueExport.loc,
185
+ messageId: 'multipleValueExports',
186
+ data: {
187
+ count: String(valueExports.length),
188
+ names: names
189
+ }
190
+ });
191
+ });
192
+ }
193
+ };
194
+ }
195
+ };
196
+ export default rule;
@@ -36,9 +36,13 @@ declare const rules: {
36
36
  'no-jest-mock-barrel-files': Rule.RuleModule;
37
37
  'no-relative-barrel-file-imports': Rule.RuleModule;
38
38
  'no-conversation-assistant-barrel-imports': Rule.RuleModule;
39
+ 'one-value-export-per-file': Rule.RuleModule;
39
40
  'visit-example-type-import-required': Rule.RuleModule;
40
41
  'no-xcss-in-cx': Rule.RuleModule;
42
+ 'editor-example-type-import-required': Rule.RuleModule;
41
43
  'ensure-use-sync-external-store-server-snapshot': Rule.RuleModule;
44
+ 'use-motion-token-values': Rule.RuleModule;
45
+ 'expand-motion-shorthand': Rule.RuleModule;
42
46
  };
43
47
  declare const plugin: {
44
48
  meta: {
@@ -82,7 +86,9 @@ declare const plugin: {
82
86
  'no-jest-mock-barrel-files': Rule.RuleModule;
83
87
  'no-relative-barrel-file-imports': Rule.RuleModule;
84
88
  'no-conversation-assistant-barrel-imports': Rule.RuleModule;
89
+ 'one-value-export-per-file': Rule.RuleModule;
85
90
  'visit-example-type-import-required': Rule.RuleModule;
91
+ 'editor-example-type-import-required': Rule.RuleModule;
86
92
  'ensure-use-sync-external-store-server-snapshot': Rule.RuleModule;
87
93
  };
88
94
  configs: {
@@ -0,0 +1,3 @@
1
+ import type { Rule } from 'eslint';
2
+ export declare const expandTransitionShorthand: Rule.RuleModule;
3
+ export default expandTransitionShorthand;
@@ -0,0 +1,3 @@
1
+ import type { Rule } from 'eslint';
2
+ export declare const useMotionTokenValues: Rule.RuleModule;
3
+ export default useMotionTokenValues;
@@ -0,0 +1,4 @@
1
+ import type { Rule } from 'eslint';
2
+ export declare const RULE_NAME = "editor-example-type-import-required";
3
+ declare const rule: Rule.RuleModule;
4
+ export default rule;
@@ -0,0 +1,3 @@
1
+ import type { Rule } from 'eslint';
2
+ declare const rule: Rule.RuleModule;
3
+ export default rule;
@@ -36,9 +36,13 @@ declare const rules: {
36
36
  'no-jest-mock-barrel-files': Rule.RuleModule;
37
37
  'no-relative-barrel-file-imports': Rule.RuleModule;
38
38
  'no-conversation-assistant-barrel-imports': Rule.RuleModule;
39
+ 'one-value-export-per-file': Rule.RuleModule;
39
40
  'visit-example-type-import-required': Rule.RuleModule;
40
41
  'no-xcss-in-cx': Rule.RuleModule;
42
+ 'editor-example-type-import-required': Rule.RuleModule;
41
43
  'ensure-use-sync-external-store-server-snapshot': Rule.RuleModule;
44
+ 'use-motion-token-values': Rule.RuleModule;
45
+ 'expand-motion-shorthand': Rule.RuleModule;
42
46
  };
43
47
  declare const plugin: {
44
48
  meta: {
@@ -82,7 +86,9 @@ declare const plugin: {
82
86
  'no-jest-mock-barrel-files': Rule.RuleModule;
83
87
  'no-relative-barrel-file-imports': Rule.RuleModule;
84
88
  'no-conversation-assistant-barrel-imports': Rule.RuleModule;
89
+ 'one-value-export-per-file': Rule.RuleModule;
85
90
  'visit-example-type-import-required': Rule.RuleModule;
91
+ 'editor-example-type-import-required': Rule.RuleModule;
86
92
  'ensure-use-sync-external-store-server-snapshot': Rule.RuleModule;
87
93
  };
88
94
  configs: {
@@ -0,0 +1,3 @@
1
+ import type { Rule } from 'eslint';
2
+ export declare const expandTransitionShorthand: Rule.RuleModule;
3
+ export default expandTransitionShorthand;
@@ -0,0 +1,3 @@
1
+ import type { Rule } from 'eslint';
2
+ export declare const useMotionTokenValues: Rule.RuleModule;
3
+ export default useMotionTokenValues;
@@ -0,0 +1,4 @@
1
+ import type { Rule } from 'eslint';
2
+ export declare const RULE_NAME = "editor-example-type-import-required";
3
+ declare const rule: Rule.RuleModule;
4
+ export default rule;
@@ -0,0 +1,3 @@
1
+ import type { Rule } from 'eslint';
2
+ declare const rule: Rule.RuleModule;
3
+ export default rule;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@atlaskit/eslint-plugin-platform",
3
3
  "description": "The essential plugin for use with Atlassian frontend platform tools",
4
- "version": "2.9.2",
4
+ "version": "2.10.0",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "atlassian": {
7
7
  "team": "Build Infra",
@@ -31,6 +31,7 @@
31
31
  "atlaskit:src": "src/index.tsx",
32
32
  "dependencies": {
33
33
  "@atlaskit/eslint-utils": "^2.0.0",
34
+ "@atlaskit/tokens": "^13.0.0",
34
35
  "@babel/runtime": "^7.0.0",
35
36
  "@compiled/eslint-plugin": "^0.18.2",
36
37
  "@manypkg/find-root": "^1.1.0",