@jupyter/eslint-plugin 1.2.0 → 1.4.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.
- package/lib/index.d.ts +27 -1
- package/lib/index.js +21 -3
- package/lib/rules/command-id-convention.d.ts +5 -0
- package/lib/rules/command-id-convention.js +87 -0
- package/lib/rules/galata-prefer-context-menu-helper.d.ts +6 -0
- package/lib/rules/galata-prefer-context-menu-helper.js +394 -0
- package/lib/rules/galata-prefer-menu-helper.js +18 -102
- package/lib/rules/no-untranslated-string.d.ts +2 -1
- package/lib/rules/no-untranslated-string.js +191 -113
- package/lib/rules/plugin-activation-args.d.ts +3 -3
- package/lib/rules/plugin-activation-args.js +173 -142
- package/lib/rules/plugin-description.js +12 -9
- package/lib/rules/plugin-id-convention.d.ts +6 -0
- package/lib/rules/plugin-id-convention.js +199 -0
- package/lib/rules/prefer-lazy-imports.d.ts +2 -2
- package/lib/rules/prefer-lazy-imports.js +257 -58
- package/lib/rules/prefer-signal-this-arg.d.ts +2 -3
- package/lib/rules/prefer-signal-this-arg.js +2 -10
- package/lib/rules/require-disposable-ownership.d.ts +1 -2
- package/lib/rules/require-disposable-ownership.js +3 -26
- package/lib/rules/require-disposable-transfer.d.ts +1 -2
- package/lib/rules/require-disposable-transfer.js +14 -14
- package/lib/rules/require-signal-cleanup.d.ts +2 -3
- package/lib/rules/require-signal-cleanup.js +2 -10
- package/lib/rules/require-signal-this-arg.d.ts +1 -2
- package/lib/rules/require-signal-this-arg.js +2 -10
- package/lib/utils/ast.d.ts +12 -0
- package/lib/utils/ast.js +49 -0
- package/lib/utils/commands.d.ts +17 -0
- package/lib/utils/commands.js +205 -0
- package/lib/utils/disposables.d.ts +12 -0
- package/lib/utils/disposables.js +101 -10
- package/lib/utils/lazy-imports.d.ts +27 -3
- package/lib/utils/lazy-imports.js +130 -36
- package/lib/utils/module-size.d.ts +7 -1
- package/lib/utils/module-size.js +10 -1
- package/lib/utils/package-json.d.ts +8 -0
- package/lib/utils/package-json.js +76 -0
- package/lib/utils/playwright-selectors.d.ts +15 -0
- package/lib/utils/playwright-selectors.js +80 -0
- package/lib/utils/plugin-utils.d.ts +66 -6
- package/lib/utils/plugin-utils.js +485 -59
- package/lib/utils/shared-packages.js +6 -16
- package/lib/utils/signals.d.ts +2 -8
- package/lib/utils/signals.js +7 -42
- package/lib/utils/type-services.d.ts +13 -0
- package/lib/utils/type-services.js +27 -0
- package/package.json +1 -1
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) Jupyter Development Team.
|
|
4
|
+
* Distributed under the terms of the Modified BSD License.
|
|
5
|
+
*/
|
|
6
|
+
const ast_1 = require("../utils/ast");
|
|
7
|
+
const create_rule_1 = require("../utils/create-rule");
|
|
8
|
+
const playwright_selectors_1 = require("../utils/playwright-selectors");
|
|
9
|
+
// The label of the file browser context menu submenu that lists the document
|
|
10
|
+
// factories a file can be opened with.
|
|
11
|
+
const OPEN_WITH_LABEL_PATTERN = /^open with$/i;
|
|
12
|
+
// The factory `notebook-extension` adds to `Open With` for a notebook opened
|
|
13
|
+
// without starting a kernel.
|
|
14
|
+
const NO_KERNEL_FACTORY_PATTERN = /^notebook \(no kernel\)$/i;
|
|
15
|
+
// Markup proving a selector is scoped inside an open Lumino popup menu — the
|
|
16
|
+
// submenu, once `Open With` has been opened.
|
|
17
|
+
const POPUP_MENU_PATTERN = /\blm-Menu\b|role\s*=\s*["']menuitem(?:checkbox)?["']|role\s*=\s*["']menu["']/;
|
|
18
|
+
// The whole selector is a text query, `text=Markdown Preview`. Once the
|
|
19
|
+
// `Open With` submenu is open a bare label click lands in it, which is how
|
|
20
|
+
// every corpus site spells the factory click.
|
|
21
|
+
const BARE_TEXT_QUERY_PATTERN = /^text=/;
|
|
22
|
+
// A file browser listing item.
|
|
23
|
+
const FILE_BROWSER_ITEM_PATTERN = /\bjp-DirListing-item\b/;
|
|
24
|
+
// A label carried by a `text=` engine query, which `combineStaticSelectorText`
|
|
25
|
+
// also normalizes `getByText(…)` and `getByRole(role, { name })` into.
|
|
26
|
+
const TEXT_QUERY_LABEL_PATTERN = /(?:^|\s|>>\s*)text=\s*(.+)$/;
|
|
27
|
+
// The same label written with one of Playwright's text pseudo-classes:
|
|
28
|
+
// `:has-text("Editor")`, `:text("Editor")`, `:text-is("Editor")`. The quoted
|
|
29
|
+
// form is tried first so that a label containing a `)` survives.
|
|
30
|
+
const QUOTED_PSEUDO_LABEL_PATTERN = /:(?:has-)?text(?:-is)?\(\s*["'](.+?)["']\s*\)/;
|
|
31
|
+
const BARE_PSEUDO_LABEL_PATTERN = /:(?:has-)?text(?:-is)?\(\s*([^"')][^)]*?)\s*\)/;
|
|
32
|
+
// Keys that extend a file browser selection rather than moving it. A context
|
|
33
|
+
// menu opened over several selected files acts on all of them, and no helper
|
|
34
|
+
// opens more than one document, so the rule stays quiet there.
|
|
35
|
+
//
|
|
36
|
+
// Only these spellings count. `Shift+Enter` and `Control+Enter` are notebook
|
|
37
|
+
// run shortcuts and select nothing, so a blanket "any modified key" test would
|
|
38
|
+
// silence genuine findings.
|
|
39
|
+
const SELECTION_KEY_PATTERN = /^(?:Shift|Control|Meta|ControlOrMeta)\+(?:Arrow(?:Up|Down|Left|Right)|Home|End|[aA])$/;
|
|
40
|
+
// Modifiers that turn a click into a selection change: shift extends the
|
|
41
|
+
// range, control/meta toggles one item.
|
|
42
|
+
const SELECTION_MODIFIERS = new Set([
|
|
43
|
+
'Shift',
|
|
44
|
+
'Control',
|
|
45
|
+
'Meta',
|
|
46
|
+
'ControlOrMeta'
|
|
47
|
+
]);
|
|
48
|
+
// Interactions that only observe. A wait between the right-click and the
|
|
49
|
+
// factory click does not change what is on screen, so it must not break the
|
|
50
|
+
// sequence.
|
|
51
|
+
const OBSERVING_METHODS = new Set(['waitForSelector']);
|
|
52
|
+
/**
|
|
53
|
+
* The item label a selector looks for, or null when it carries none.
|
|
54
|
+
*
|
|
55
|
+
* A label is required to have a word character in it, so that the leftover
|
|
56
|
+
* static text of a fully interpolated name — `` `text=${factory}` `` reduces to
|
|
57
|
+
* `text=` — does not read as a label.
|
|
58
|
+
*/
|
|
59
|
+
function extractItemLabel(selectorText) {
|
|
60
|
+
const match = TEXT_QUERY_LABEL_PATTERN.exec(selectorText) ??
|
|
61
|
+
QUOTED_PSEUDO_LABEL_PATTERN.exec(selectorText) ??
|
|
62
|
+
BARE_PSEUDO_LABEL_PATTERN.exec(selectorText);
|
|
63
|
+
if (!match) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
const label = match[1]
|
|
67
|
+
.trim()
|
|
68
|
+
.replace(/^["']|["']$/g, '')
|
|
69
|
+
.trim();
|
|
70
|
+
return /\w/.test(label) ? label : null;
|
|
71
|
+
}
|
|
72
|
+
function isPageKeyboard(node) {
|
|
73
|
+
return (node.type === 'MemberExpression' &&
|
|
74
|
+
!node.computed &&
|
|
75
|
+
node.object.type === 'Identifier' &&
|
|
76
|
+
node.object.name === 'page' &&
|
|
77
|
+
node.property.type === 'Identifier' &&
|
|
78
|
+
node.property.name === 'keyboard');
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Whether a call's receiver is Galata's menu helper, `….menu`.
|
|
82
|
+
*/
|
|
83
|
+
function isMenuHelperReceiver(node) {
|
|
84
|
+
return (node.type === 'MemberExpression' &&
|
|
85
|
+
!node.computed &&
|
|
86
|
+
node.property.type === 'Identifier' &&
|
|
87
|
+
node.property.name === 'menu');
|
|
88
|
+
}
|
|
89
|
+
/** `page.menu.closeAll()`, which dismisses whatever menu is open. */
|
|
90
|
+
function isMenuCloseAll(callee) {
|
|
91
|
+
return (callee.property.type === 'Identifier' &&
|
|
92
|
+
callee.property.name === 'closeAll' &&
|
|
93
|
+
isMenuHelperReceiver(callee.object));
|
|
94
|
+
}
|
|
95
|
+
/** `page.click(sel, { modifiers: ['Shift'] })` and friends. */
|
|
96
|
+
function hasSelectionModifier(node) {
|
|
97
|
+
return node.arguments.some(arg => arg.type === 'ObjectExpression' &&
|
|
98
|
+
arg.properties.some(prop => prop.type === 'Property' &&
|
|
99
|
+
!prop.computed &&
|
|
100
|
+
((prop.key.type === 'Identifier' && prop.key.name === 'modifiers') ||
|
|
101
|
+
(prop.key.type === 'Literal' && prop.key.value === 'modifiers')) &&
|
|
102
|
+
prop.value.type === 'ArrayExpression' &&
|
|
103
|
+
prop.value.elements.some(element => element?.type === 'Literal' &&
|
|
104
|
+
typeof element.value === 'string' &&
|
|
105
|
+
SELECTION_MODIFIERS.has(element.value))));
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Reads one call as a step of the context menu flow, or null when the call
|
|
109
|
+
* changes nothing the rule tracks.
|
|
110
|
+
*/
|
|
111
|
+
function classifyGesture(node, resolveBinding) {
|
|
112
|
+
const gesture = (kind, label = null) => ({
|
|
113
|
+
kind,
|
|
114
|
+
start: node.range[0],
|
|
115
|
+
node,
|
|
116
|
+
label
|
|
117
|
+
});
|
|
118
|
+
const callee = node.callee;
|
|
119
|
+
if (callee.type === 'MemberExpression' &&
|
|
120
|
+
!callee.computed &&
|
|
121
|
+
callee.property.type === 'Identifier') {
|
|
122
|
+
// `page.menu.openContextMenu(selector)` / `openContextMenuLocator(selector)`
|
|
123
|
+
// right-click the target themselves, so they open the context menu exactly
|
|
124
|
+
// as a raw right-click does. A test that uses them and then walks
|
|
125
|
+
// `Open With` by hand is still the sequence this rule replaces.
|
|
126
|
+
if (callee.property.name.startsWith('openContextMenu') &&
|
|
127
|
+
isMenuHelperReceiver(callee.object)) {
|
|
128
|
+
return gesture('contextMenuOpen');
|
|
129
|
+
}
|
|
130
|
+
if (isMenuCloseAll(callee)) {
|
|
131
|
+
return gesture('menuClose');
|
|
132
|
+
}
|
|
133
|
+
if (callee.property.name === 'press' && isPageKeyboard(callee.object)) {
|
|
134
|
+
const keyArg = node.arguments[0];
|
|
135
|
+
const key = keyArg && keyArg.type !== 'SpreadElement'
|
|
136
|
+
? (0, playwright_selectors_1.extractStaticSelectorText)(keyArg, { allowPartialTemplate: false })
|
|
137
|
+
: null;
|
|
138
|
+
if (key === 'Escape') {
|
|
139
|
+
return gesture('menuClose');
|
|
140
|
+
}
|
|
141
|
+
if (key !== null && SELECTION_KEY_PATTERN.test(key)) {
|
|
142
|
+
return gesture('multiSelect');
|
|
143
|
+
}
|
|
144
|
+
return gesture('otherGesture');
|
|
145
|
+
}
|
|
146
|
+
// A right-click is the one gesture that opens the context menu, whatever it
|
|
147
|
+
// targets, so the receiver does not have to resolve to `page` first:
|
|
148
|
+
// `const item = page.locator(a); await item.click({ button: 'right' });`
|
|
149
|
+
// opens it just as `page.click(a, { button: 'right' })` does.
|
|
150
|
+
if (callee.property.name === 'click') {
|
|
151
|
+
if ((0, playwright_selectors_1.isRightClick)(node)) {
|
|
152
|
+
return gesture('contextMenuOpen');
|
|
153
|
+
}
|
|
154
|
+
if (hasSelectionModifier(node)) {
|
|
155
|
+
return gesture('multiSelect');
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
const match = (0, playwright_selectors_1.matchSelectorInteraction)(node, resolveBinding);
|
|
160
|
+
if (!match) {
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
if (OBSERVING_METHODS.has(match.interactionMethod)) {
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
const selectorText = (0, playwright_selectors_1.combineStaticSelectorText)(match);
|
|
167
|
+
if (selectorText === null) {
|
|
168
|
+
// An interaction on a selector the rule cannot read still happened, and it
|
|
169
|
+
// may have dismissed the menu, so it counts as a gesture.
|
|
170
|
+
return gesture('otherGesture');
|
|
171
|
+
}
|
|
172
|
+
const label = extractItemLabel(selectorText);
|
|
173
|
+
// The submenu opens on hover and on click alike: Lumino opens a submenu when
|
|
174
|
+
// the pointer rests on its parent item, and clicking the item opens it too.
|
|
175
|
+
// Both spellings appear in the corpus.
|
|
176
|
+
if (label !== null &&
|
|
177
|
+
OPEN_WITH_LABEL_PATTERN.test(label) &&
|
|
178
|
+
(match.interactionMethod === 'hover' || match.interactionMethod === 'click')) {
|
|
179
|
+
return gesture('openWith');
|
|
180
|
+
}
|
|
181
|
+
// A menu item is activated with a single click. A hover on a factory item is
|
|
182
|
+
// deliberately not one: it opens nothing, and the tests that hover a factory
|
|
183
|
+
// are screenshotting the submenu, which no helper can do.
|
|
184
|
+
if (match.interactionMethod === 'click') {
|
|
185
|
+
if (POPUP_MENU_PATTERN.test(selectorText)) {
|
|
186
|
+
return gesture('menuItemClick', label);
|
|
187
|
+
}
|
|
188
|
+
// A null label here means the whole name was interpolated,
|
|
189
|
+
// `` page.click(`text=${factory}`) ``. The click is still the one that
|
|
190
|
+
// activates an item, so the flow is complete and the message falls back to
|
|
191
|
+
// naming the helpers without an argument.
|
|
192
|
+
if (BARE_TEXT_QUERY_PATTERN.test(selectorText)) {
|
|
193
|
+
return gesture('menuItemClick', label);
|
|
194
|
+
}
|
|
195
|
+
// A plain click on a listing item leaves that one file selected, so a
|
|
196
|
+
// right-click after it acts on a single document again even if an earlier
|
|
197
|
+
// statement had extended the selection.
|
|
198
|
+
if (FILE_BROWSER_ITEM_PATTERN.test(selectorText)) {
|
|
199
|
+
return gesture('singleSelect');
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return gesture('otherGesture');
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Every gesture inside `scope`, in source order.
|
|
206
|
+
*
|
|
207
|
+
* Nested test callbacks and named helpers are not entered: their statements do
|
|
208
|
+
* not run where they are written, so one test's menu state must not reach the
|
|
209
|
+
* next. Gestures inside an `if` or a loop *are*
|
|
210
|
+
* collected, because the flow the rule looks for is a fixed three-step sequence
|
|
211
|
+
* that no corpus site splits across branches.
|
|
212
|
+
*/
|
|
213
|
+
function collectGestures(scope, resolveBinding) {
|
|
214
|
+
const gestures = [];
|
|
215
|
+
(0, ast_1.walkFrom)(scope, node => {
|
|
216
|
+
if (node !== scope && (0, playwright_selectors_1.isTestScopeBoundary)(node)) {
|
|
217
|
+
return 'skip-children';
|
|
218
|
+
}
|
|
219
|
+
if (node.type === 'CallExpression') {
|
|
220
|
+
const gesture = classifyGesture(node, resolveBinding);
|
|
221
|
+
if (gesture) {
|
|
222
|
+
gestures.push(gesture);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
// A gesture can sit inside another call's arguments — `Promise.all([…,
|
|
226
|
+
// page.click(…)])` — so children are visited whether or not this node was
|
|
227
|
+
// itself a gesture.
|
|
228
|
+
return undefined;
|
|
229
|
+
});
|
|
230
|
+
return gestures.sort((left, right) => left.start - right.start);
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Whether the call is the whole of its statement, `await page.click(…);`.
|
|
234
|
+
*/
|
|
235
|
+
function isOwnStatement(node) {
|
|
236
|
+
let current = node;
|
|
237
|
+
let parent = current.parent;
|
|
238
|
+
while (parent &&
|
|
239
|
+
(parent.type === 'AwaitExpression' ||
|
|
240
|
+
parent.type === 'TSNonNullExpression' ||
|
|
241
|
+
parent.type === 'TSAsExpression')) {
|
|
242
|
+
current = parent;
|
|
243
|
+
parent = current.parent;
|
|
244
|
+
}
|
|
245
|
+
return parent?.type === 'ExpressionStatement';
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Replays the gestures of one test and returns the factory clicks that complete
|
|
249
|
+
* a raw `Open With` sequence, keyed by the call to report.
|
|
250
|
+
*
|
|
251
|
+
* The flow is three steps: something opens the context menu, `Open With` opens
|
|
252
|
+
* the factory submenu, and a click on a factory opens the document. The factory
|
|
253
|
+
* click has to be the first item click after `Open With` — an item clicked
|
|
254
|
+
* later is in some other menu, because activating an item closes the one it was
|
|
255
|
+
* in.
|
|
256
|
+
*/
|
|
257
|
+
function findOpenWithFlows(scope, resolveBinding) {
|
|
258
|
+
const findings = new Map();
|
|
259
|
+
// The open context menu, and whether more than one file was selected when it
|
|
260
|
+
// was opened.
|
|
261
|
+
let contextMenu = null;
|
|
262
|
+
let multiSelectSeen = false;
|
|
263
|
+
let openWithOpen = false;
|
|
264
|
+
for (const gesture of collectGestures(scope, resolveBinding)) {
|
|
265
|
+
switch (gesture.kind) {
|
|
266
|
+
case 'multiSelect':
|
|
267
|
+
multiSelectSeen = true;
|
|
268
|
+
break;
|
|
269
|
+
case 'singleSelect':
|
|
270
|
+
multiSelectSeen = false;
|
|
271
|
+
// Clicking in the file browser also dismisses whatever menu was open.
|
|
272
|
+
contextMenu = null;
|
|
273
|
+
openWithOpen = false;
|
|
274
|
+
break;
|
|
275
|
+
case 'contextMenuOpen':
|
|
276
|
+
// The selection outlives the menu, so `multiSelectSeen` is not reset
|
|
277
|
+
// here. A right-click on an item that is already part of a multi-file
|
|
278
|
+
// selection keeps the whole selection, and only a plain click narrows
|
|
279
|
+
// it back to one. Which of the two a right-click is cannot be read off
|
|
280
|
+
// the selector: `Shift+ArrowDown` extends the selection to a neighbour
|
|
281
|
+
// the test never names, so the item right-clicked next may well be
|
|
282
|
+
// that neighbour. Staying with the wider selection is the answer that
|
|
283
|
+
// does not invent a report.
|
|
284
|
+
contextMenu = { multiSelect: multiSelectSeen };
|
|
285
|
+
openWithOpen = false;
|
|
286
|
+
break;
|
|
287
|
+
case 'menuClose':
|
|
288
|
+
contextMenu = null;
|
|
289
|
+
openWithOpen = false;
|
|
290
|
+
break;
|
|
291
|
+
case 'openWith':
|
|
292
|
+
// `Open With` only exists in the file browser context menu, so with
|
|
293
|
+
// nothing having opened one the hover is on something else, or on a
|
|
294
|
+
// context menu opened outside this test — either way the rule has no
|
|
295
|
+
// sequence to replace.
|
|
296
|
+
openWithOpen = contextMenu !== null;
|
|
297
|
+
break;
|
|
298
|
+
case 'menuItemClick': {
|
|
299
|
+
if (openWithOpen && contextMenu) {
|
|
300
|
+
const finding = describeFlow(gesture, contextMenu.multiSelect);
|
|
301
|
+
if (finding) {
|
|
302
|
+
findings.set(gesture.node, finding);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
// Activating an item closes the menu it was in.
|
|
306
|
+
contextMenu = null;
|
|
307
|
+
openWithOpen = false;
|
|
308
|
+
break;
|
|
309
|
+
}
|
|
310
|
+
case 'otherGesture':
|
|
311
|
+
// A gesture the rule cannot place may have dismissed the menu, so what
|
|
312
|
+
// is on screen is no longer known.
|
|
313
|
+
contextMenu = null;
|
|
314
|
+
openWithOpen = false;
|
|
315
|
+
break;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
return findings;
|
|
319
|
+
}
|
|
320
|
+
function describeFlow(gesture, multiSelect) {
|
|
321
|
+
// Every helper opens exactly one document. A context menu opened over a
|
|
322
|
+
// multi-file selection opens one per file, which is what the test is there
|
|
323
|
+
// to check, so there is nothing to recommend.
|
|
324
|
+
if (multiSelect) {
|
|
325
|
+
return null;
|
|
326
|
+
}
|
|
327
|
+
if (!isOwnStatement(gesture.node)) {
|
|
328
|
+
return null;
|
|
329
|
+
}
|
|
330
|
+
const { label } = gesture;
|
|
331
|
+
if (label !== null && NO_KERNEL_FACTORY_PATTERN.test(label)) {
|
|
332
|
+
return { messageId: 'preferNotebookOpenNoKernel', factory: label };
|
|
333
|
+
}
|
|
334
|
+
return label === null
|
|
335
|
+
? { messageId: 'preferFilebrowserOpen', factory: null }
|
|
336
|
+
: { messageId: 'preferFilebrowserOpenFactory', factory: label };
|
|
337
|
+
}
|
|
338
|
+
const galataPreferContextMenuHelper = (0, create_rule_1.createRule)({
|
|
339
|
+
name: 'galata-prefer-context-menu-helper',
|
|
340
|
+
meta: {
|
|
341
|
+
type: 'suggestion',
|
|
342
|
+
docs: {
|
|
343
|
+
description: 'Prefer the Galata filebrowser and notebook open helpers over a raw right-click `Open With` context menu sequence'
|
|
344
|
+
},
|
|
345
|
+
messages: {
|
|
346
|
+
preferNotebookOpenNoKernel: 'Prefer `page.notebook.open(name, { noKernel: true })` over a raw right-click, `Open With`, `Notebook (no kernel)` sequence.',
|
|
347
|
+
preferFilebrowserOpenFactory: "Prefer `page.filebrowser.open(path, '{{factory}}')` over a raw right-click, `Open With`, factory sequence.",
|
|
348
|
+
preferFilebrowserOpen: 'Prefer `page.filebrowser.open(path, factory)` (or `page.notebook.open(name, { noKernel: true })`) over a raw right-click, `Open With`, factory sequence.'
|
|
349
|
+
},
|
|
350
|
+
schema: []
|
|
351
|
+
},
|
|
352
|
+
defaultOptions: [],
|
|
353
|
+
create(context) {
|
|
354
|
+
// One replay per test, keyed by its scope node, so a file that opens
|
|
355
|
+
// several documents this way does not re-read the same statements once per
|
|
356
|
+
// click.
|
|
357
|
+
const scopeCache = new WeakMap();
|
|
358
|
+
const resolveBinding = (identifier) => {
|
|
359
|
+
const scope = context.sourceCode.getScope(identifier);
|
|
360
|
+
return (0, playwright_selectors_1.resolveLocatorBinding)(identifier, scope);
|
|
361
|
+
};
|
|
362
|
+
return {
|
|
363
|
+
CallExpression(node) {
|
|
364
|
+
// The reported call is always a click on a factory item, so everything
|
|
365
|
+
// else can be skipped before any scope is walked.
|
|
366
|
+
const callee = node.callee;
|
|
367
|
+
if (callee.type !== 'MemberExpression' ||
|
|
368
|
+
callee.computed ||
|
|
369
|
+
callee.property.type !== 'Identifier' ||
|
|
370
|
+
callee.property.name !== 'click') {
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
const scope = (0, playwright_selectors_1.enclosingTestScope)(node);
|
|
374
|
+
let findings = scopeCache.get(scope);
|
|
375
|
+
if (!findings) {
|
|
376
|
+
findings = findOpenWithFlows(scope, resolveBinding);
|
|
377
|
+
scopeCache.set(scope, findings);
|
|
378
|
+
}
|
|
379
|
+
const finding = findings.get(node);
|
|
380
|
+
if (!finding) {
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
context.report({
|
|
384
|
+
node,
|
|
385
|
+
messageId: finding.messageId,
|
|
386
|
+
...(finding.factory !== null
|
|
387
|
+
? { data: { factory: finding.factory } }
|
|
388
|
+
: {})
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
});
|
|
394
|
+
module.exports = galataPreferContextMenuHelper;
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Copyright (c) Jupyter Development Team.
|
|
4
4
|
* Distributed under the terms of the Modified BSD License.
|
|
5
5
|
*/
|
|
6
|
+
const ast_1 = require("../utils/ast");
|
|
6
7
|
const create_rule_1 = require("../utils/create-rule");
|
|
7
8
|
const playwright_selectors_1 = require("../utils/playwright-selectors");
|
|
8
9
|
// JupyterLab's main menu bar
|
|
@@ -141,83 +142,19 @@ function menuOriginOf(node) {
|
|
|
141
142
|
? 'menubar'
|
|
142
143
|
: null;
|
|
143
144
|
}
|
|
144
|
-
function
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}
|
|
149
|
-
// Calls whose callback is stored and run later. Statements next to such a call
|
|
150
|
-
// say nothing about the state its body starts in.
|
|
151
|
-
const DEFERRED_CALLBACK_CALLEES = new Set([
|
|
152
|
-
'test',
|
|
153
|
-
'it',
|
|
154
|
-
'describe',
|
|
155
|
-
'suite',
|
|
156
|
-
'beforeAll',
|
|
157
|
-
'beforeEach',
|
|
158
|
-
'afterAll',
|
|
159
|
-
'afterEach'
|
|
160
|
-
]);
|
|
161
|
-
function rootCalleeName(node) {
|
|
162
|
-
let current = node;
|
|
163
|
-
while (current.type === 'MemberExpression') {
|
|
164
|
-
current = current.object;
|
|
165
|
-
}
|
|
166
|
-
return current.type === 'Identifier' ? current.name : null;
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Whether the lookback must stop before leaving `node`, and whether the scan of
|
|
170
|
-
* preceding statements must stop before entering it.
|
|
171
|
-
*
|
|
172
|
-
* A callback written inline runs where it stands, so the statements above it
|
|
173
|
-
* did run first and the walk continues through it: `perf.measure(async () => {
|
|
174
|
-
* … })` keeps the menu its caller opened. A named helper and a test callback do
|
|
175
|
-
* not. `async function openMenu(page) { … }` can be called from anywhere, and
|
|
176
|
-
* `test('b', …)` does not run after the body of `test('a', …)`, so a
|
|
177
|
-
* right-click in one test must not silence the next one.
|
|
178
|
-
*/
|
|
179
|
-
function isLookbackBoundary(node) {
|
|
180
|
-
if (node.type === 'FunctionDeclaration') {
|
|
181
|
-
return true;
|
|
182
|
-
}
|
|
183
|
-
if (node.type !== 'FunctionExpression' &&
|
|
184
|
-
node.type !== 'ArrowFunctionExpression') {
|
|
185
|
-
return false;
|
|
186
|
-
}
|
|
187
|
-
const parent = node.parent;
|
|
188
|
-
if (parent?.type === 'VariableDeclarator' || parent?.type === 'Property') {
|
|
189
|
-
return true;
|
|
190
|
-
}
|
|
191
|
-
return (parent?.type === 'CallExpression' &&
|
|
192
|
-
parent.arguments.includes(node) &&
|
|
193
|
-
DEFERRED_CALLBACK_CALLEES.has(rootCalleeName(parent.callee) ?? ''));
|
|
194
|
-
}
|
|
195
|
-
function collectMenuOrigins(node, found) {
|
|
196
|
-
if (isLookbackBoundary(node)) {
|
|
197
|
-
return;
|
|
198
|
-
}
|
|
199
|
-
if (node.type === 'CallExpression') {
|
|
200
|
-
const origin = menuOriginOf(node);
|
|
201
|
-
if (origin) {
|
|
202
|
-
found.push({ origin, start: node.range[0] });
|
|
145
|
+
function collectMenuOrigins(root, found) {
|
|
146
|
+
(0, ast_1.walkFrom)(root, node => {
|
|
147
|
+
if ((0, playwright_selectors_1.isTestScopeBoundary)(node)) {
|
|
148
|
+
return 'skip-children';
|
|
203
149
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
continue;
|
|
209
|
-
}
|
|
210
|
-
if (Array.isArray(value)) {
|
|
211
|
-
for (const item of value) {
|
|
212
|
-
if (isNode(item)) {
|
|
213
|
-
collectMenuOrigins(item, found);
|
|
214
|
-
}
|
|
150
|
+
if (node.type === 'CallExpression') {
|
|
151
|
+
const origin = menuOriginOf(node);
|
|
152
|
+
if (origin) {
|
|
153
|
+
found.push({ origin, start: node.range[0] });
|
|
215
154
|
}
|
|
216
155
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
}
|
|
220
|
-
}
|
|
156
|
+
return undefined;
|
|
157
|
+
});
|
|
221
158
|
}
|
|
222
159
|
/**
|
|
223
160
|
* The last menu-opening gesture among the first `index` statements of `block`.
|
|
@@ -257,7 +194,7 @@ function originBeforeStatement(block, body, index, cache) {
|
|
|
257
194
|
* preceding statements all come after an outer block's, so the innermost block
|
|
258
195
|
* with an answer holds the latest one and the walk can stop there. The walk
|
|
259
196
|
* also stops at the enclosing test callback or named helper, so one test's menu
|
|
260
|
-
* state never reaches the next (see `
|
|
197
|
+
* state never reaches the next (see `isTestScopeBoundary`).
|
|
261
198
|
*/
|
|
262
199
|
function findMenuOrigin(node, cache) {
|
|
263
200
|
let current = node;
|
|
@@ -277,7 +214,7 @@ function findMenuOrigin(node, cache) {
|
|
|
277
214
|
return origin;
|
|
278
215
|
}
|
|
279
216
|
}
|
|
280
|
-
if (
|
|
217
|
+
if ((0, playwright_selectors_1.isTestScopeBoundary)(parent)) {
|
|
281
218
|
return null;
|
|
282
219
|
}
|
|
283
220
|
current = parent;
|
|
@@ -305,10 +242,7 @@ const MENU_WORD_PATTERN = /menus?\b/i;
|
|
|
305
242
|
* or a file name says nothing.
|
|
306
243
|
*/
|
|
307
244
|
function testMentionsMenuMarkup(node) {
|
|
308
|
-
|
|
309
|
-
while (scope.parent && !isLookbackBoundary(scope)) {
|
|
310
|
-
scope = scope.parent;
|
|
311
|
-
}
|
|
245
|
+
const scope = (0, playwright_selectors_1.enclosingTestScope)(node);
|
|
312
246
|
// The title of a `test(…)` sits next to its callback rather than inside it.
|
|
313
247
|
// It is a sentence a person wrote about what the test does, so the bare word
|
|
314
248
|
// is enough there, where in a selector it would not be.
|
|
@@ -322,35 +256,17 @@ function testMentionsMenuMarkup(node) {
|
|
|
322
256
|
}
|
|
323
257
|
}
|
|
324
258
|
let found = false;
|
|
325
|
-
|
|
326
|
-
if (found) {
|
|
327
|
-
return;
|
|
328
|
-
}
|
|
259
|
+
(0, ast_1.walkFrom)(scope, current => {
|
|
329
260
|
if ((current.type === 'Literal' && typeof current.value === 'string'
|
|
330
261
|
? ANY_MENU_MARKUP_PATTERN.test(current.value)
|
|
331
262
|
: false) ||
|
|
332
263
|
(current.type === 'TemplateElement' &&
|
|
333
264
|
ANY_MENU_MARKUP_PATTERN.test(current.value.cooked ?? ''))) {
|
|
334
265
|
found = true;
|
|
335
|
-
return;
|
|
336
|
-
}
|
|
337
|
-
for (const [key, value] of Object.entries(current)) {
|
|
338
|
-
if (key === 'parent') {
|
|
339
|
-
continue;
|
|
340
|
-
}
|
|
341
|
-
if (Array.isArray(value)) {
|
|
342
|
-
for (const item of value) {
|
|
343
|
-
if (isNode(item)) {
|
|
344
|
-
visit(item);
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
else if (isNode(value)) {
|
|
349
|
-
visit(value);
|
|
350
|
-
}
|
|
266
|
+
return 'stop';
|
|
351
267
|
}
|
|
352
|
-
|
|
353
|
-
|
|
268
|
+
return undefined;
|
|
269
|
+
});
|
|
354
270
|
return found;
|
|
355
271
|
}
|
|
356
272
|
/**
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
declare const noUntranslatedString: import("@typescript-eslint/utils/ts-eslint").RuleModule<"untranslatedCommandProp" | "untranslatedSetAttribute" | "untranslatedPropertyAssign" | "
|
|
1
|
+
declare const noUntranslatedString: import("@typescript-eslint/utils/ts-eslint").RuleModule<"untranslatedCommandProp" | "untranslatedSetAttribute" | "untranslatedPropertyAssign" | "untranslatedDialogOption" | "untranslatedDialogButtonLabel" | "untranslatedJsxText" | "untranslatedJsxAttribute" | "untranslatedProperty", [{
|
|
2
2
|
enforcePunctuation: boolean;
|
|
3
|
+
checkProperties: string[];
|
|
3
4
|
}], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
|
|
4
5
|
name: string;
|
|
5
6
|
};
|