@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.
- package/CHANGELOG.md +8 -0
- package/dist/cjs/index.js +9 -1
- package/dist/cjs/rules/compiled/expand-motion-shorthand/index.js +281 -0
- package/dist/cjs/rules/compiled/use-motion-token-values/index.js +506 -0
- package/dist/cjs/rules/editor-example-type-import-required/index.js +321 -0
- package/dist/es2019/index.js +9 -1
- package/dist/es2019/rules/compiled/expand-motion-shorthand/index.js +239 -0
- package/dist/es2019/rules/compiled/use-motion-token-values/index.js +444 -0
- package/dist/es2019/rules/editor-example-type-import-required/index.js +286 -0
- package/dist/esm/index.js +9 -1
- package/dist/esm/rules/compiled/expand-motion-shorthand/index.js +275 -0
- package/dist/esm/rules/compiled/use-motion-token-values/index.js +499 -0
- package/dist/esm/rules/editor-example-type-import-required/index.js +314 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/rules/compiled/expand-motion-shorthand/index.d.ts +3 -0
- package/dist/types/rules/compiled/use-motion-token-values/index.d.ts +3 -0
- package/dist/types/rules/editor-example-type-import-required/index.d.ts +4 -0
- package/dist/types-ts4.5/index.d.ts +4 -0
- package/dist/types-ts4.5/rules/compiled/expand-motion-shorthand/index.d.ts +3 -0
- package/dist/types-ts4.5/rules/compiled/use-motion-token-values/index.d.ts +3 -0
- package/dist/types-ts4.5/rules/editor-example-type-import-required/index.d.ts +4 -0
- 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;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -38,7 +38,10 @@ declare const rules: {
|
|
|
38
38
|
'no-conversation-assistant-barrel-imports': Rule.RuleModule;
|
|
39
39
|
'visit-example-type-import-required': Rule.RuleModule;
|
|
40
40
|
'no-xcss-in-cx': Rule.RuleModule;
|
|
41
|
+
'editor-example-type-import-required': Rule.RuleModule;
|
|
41
42
|
'ensure-use-sync-external-store-server-snapshot': Rule.RuleModule;
|
|
43
|
+
'use-motion-token-values': Rule.RuleModule;
|
|
44
|
+
'expand-motion-shorthand': Rule.RuleModule;
|
|
42
45
|
};
|
|
43
46
|
declare const plugin: {
|
|
44
47
|
meta: {
|
|
@@ -83,6 +86,7 @@ declare const plugin: {
|
|
|
83
86
|
'no-relative-barrel-file-imports': Rule.RuleModule;
|
|
84
87
|
'no-conversation-assistant-barrel-imports': Rule.RuleModule;
|
|
85
88
|
'visit-example-type-import-required': Rule.RuleModule;
|
|
89
|
+
'editor-example-type-import-required': Rule.RuleModule;
|
|
86
90
|
'ensure-use-sync-external-store-server-snapshot': Rule.RuleModule;
|
|
87
91
|
};
|
|
88
92
|
configs: {
|
|
@@ -38,7 +38,10 @@ declare const rules: {
|
|
|
38
38
|
'no-conversation-assistant-barrel-imports': Rule.RuleModule;
|
|
39
39
|
'visit-example-type-import-required': Rule.RuleModule;
|
|
40
40
|
'no-xcss-in-cx': Rule.RuleModule;
|
|
41
|
+
'editor-example-type-import-required': Rule.RuleModule;
|
|
41
42
|
'ensure-use-sync-external-store-server-snapshot': Rule.RuleModule;
|
|
43
|
+
'use-motion-token-values': Rule.RuleModule;
|
|
44
|
+
'expand-motion-shorthand': Rule.RuleModule;
|
|
42
45
|
};
|
|
43
46
|
declare const plugin: {
|
|
44
47
|
meta: {
|
|
@@ -83,6 +86,7 @@ declare const plugin: {
|
|
|
83
86
|
'no-relative-barrel-file-imports': Rule.RuleModule;
|
|
84
87
|
'no-conversation-assistant-barrel-imports': Rule.RuleModule;
|
|
85
88
|
'visit-example-type-import-required': Rule.RuleModule;
|
|
89
|
+
'editor-example-type-import-required': Rule.RuleModule;
|
|
86
90
|
'ensure-use-sync-external-store-server-snapshot': Rule.RuleModule;
|
|
87
91
|
};
|
|
88
92
|
configs: {
|
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.
|
|
4
|
+
"version": "2.9.3",
|
|
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",
|