@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.
Files changed (48) hide show
  1. package/lib/index.d.ts +27 -1
  2. package/lib/index.js +21 -3
  3. package/lib/rules/command-id-convention.d.ts +5 -0
  4. package/lib/rules/command-id-convention.js +87 -0
  5. package/lib/rules/galata-prefer-context-menu-helper.d.ts +6 -0
  6. package/lib/rules/galata-prefer-context-menu-helper.js +394 -0
  7. package/lib/rules/galata-prefer-menu-helper.js +18 -102
  8. package/lib/rules/no-untranslated-string.d.ts +2 -1
  9. package/lib/rules/no-untranslated-string.js +191 -113
  10. package/lib/rules/plugin-activation-args.d.ts +3 -3
  11. package/lib/rules/plugin-activation-args.js +173 -142
  12. package/lib/rules/plugin-description.js +12 -9
  13. package/lib/rules/plugin-id-convention.d.ts +6 -0
  14. package/lib/rules/plugin-id-convention.js +199 -0
  15. package/lib/rules/prefer-lazy-imports.d.ts +2 -2
  16. package/lib/rules/prefer-lazy-imports.js +257 -58
  17. package/lib/rules/prefer-signal-this-arg.d.ts +2 -3
  18. package/lib/rules/prefer-signal-this-arg.js +2 -10
  19. package/lib/rules/require-disposable-ownership.d.ts +1 -2
  20. package/lib/rules/require-disposable-ownership.js +3 -26
  21. package/lib/rules/require-disposable-transfer.d.ts +1 -2
  22. package/lib/rules/require-disposable-transfer.js +14 -14
  23. package/lib/rules/require-signal-cleanup.d.ts +2 -3
  24. package/lib/rules/require-signal-cleanup.js +2 -10
  25. package/lib/rules/require-signal-this-arg.d.ts +1 -2
  26. package/lib/rules/require-signal-this-arg.js +2 -10
  27. package/lib/utils/ast.d.ts +12 -0
  28. package/lib/utils/ast.js +49 -0
  29. package/lib/utils/commands.d.ts +17 -0
  30. package/lib/utils/commands.js +205 -0
  31. package/lib/utils/disposables.d.ts +12 -0
  32. package/lib/utils/disposables.js +101 -10
  33. package/lib/utils/lazy-imports.d.ts +27 -3
  34. package/lib/utils/lazy-imports.js +130 -36
  35. package/lib/utils/module-size.d.ts +7 -1
  36. package/lib/utils/module-size.js +10 -1
  37. package/lib/utils/package-json.d.ts +8 -0
  38. package/lib/utils/package-json.js +76 -0
  39. package/lib/utils/playwright-selectors.d.ts +15 -0
  40. package/lib/utils/playwright-selectors.js +80 -0
  41. package/lib/utils/plugin-utils.d.ts +66 -6
  42. package/lib/utils/plugin-utils.js +485 -59
  43. package/lib/utils/shared-packages.js +6 -16
  44. package/lib/utils/signals.d.ts +2 -8
  45. package/lib/utils/signals.js +7 -42
  46. package/lib/utils/type-services.d.ts +13 -0
  47. package/lib/utils/type-services.js +27 -0
  48. package/package.json +1 -1
@@ -4,9 +4,9 @@
4
4
  * Distributed under the terms of the Modified BSD License.
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.ALWAYS_IGNORED_IMPORTS = exports.DEFAULT_ALLOWED_PACKAGES = exports.DEFAULT_MINIMUM_SIZE = void 0;
7
+ exports.ALWAYS_IGNORED_IMPORTS = exports.DEFAULT_DEFERRED_PACKAGES = exports.DEFAULT_ALLOWED_PACKAGES = exports.DEFAULT_MINIMUM_SIZE = void 0;
8
8
  exports.matchesPatterns = matchesPatterns;
9
- exports.isEagerlyReached = isEagerlyReached;
9
+ exports.getReach = getReach;
10
10
  exports.isInInteractionCallback = isInInteractionCallback;
11
11
  exports.isInPluginTokenList = isInPluginTokenList;
12
12
  exports.buildDeferredImportSnippet = buildDeferredImportSnippet;
@@ -45,6 +45,32 @@ exports.DEFAULT_ALLOWED_PACKAGES = [
45
45
  'react-dom',
46
46
  'yjs'
47
47
  ];
48
+ /**
49
+ * Packages which JupyterLab itself loads only with `import()`, so a static
50
+ * import anywhere in an extension puts them back on the startup path.
51
+ *
52
+ * A subpath such as `@codemirror/legacy-modes/mode/python` matches through its
53
+ * owning package. Entries prefixed with `!` are exempt even when another
54
+ * pattern matches them.
55
+ */
56
+ exports.DEFAULT_DEFERRED_PACKAGES = [
57
+ '@lumino/datagrid',
58
+ '@codemirror/lang-*',
59
+ '@codemirror/legacy-modes',
60
+ '@codemirror/search',
61
+ '@mermaid-js/layout-elk',
62
+ '@plutojl/lang-julia',
63
+ '@rjsf/validator-ajv8',
64
+ '@xterm/xterm',
65
+ '@xterm/addon-*',
66
+ 'marked',
67
+ 'marked-gfm-heading-id',
68
+ 'marked-mangle',
69
+ 'mathjax-full',
70
+ 'mermaid',
71
+ 'react-toastify',
72
+ 'vega-embed'
73
+ ];
48
74
  /**
49
75
  * Assets which a bundler turns into a URL or a style side effect rather than
50
76
  * into bundled bytes, so deferring the import saves nothing.
@@ -243,54 +269,122 @@ function getFunctionVariable(fn, sourceCode) {
243
269
  }
244
270
  return null;
245
271
  }
246
- const MAX_CALL_DEPTH = 6;
247
272
  /**
248
- * Returns true when the node runs while the module is evaluated, either
249
- * directly or through a named function which is called at module level.
273
+ * Returns true when the node is the `activate` entry of a plugin object which
274
+ * declares `autoStart: true`. Only the literal `true` counts: a plugin with
275
+ * `autoStart: 'defer'` is activated after the shell is attached. The object is
276
+ * read as written, so a spread or a computed key is not followed, as in every
277
+ * other plugin-shape check in this plugin.
250
278
  */
251
- function isEagerlyReached(node, sourceCode, seen = new Set(), depth = 0) {
279
+ function isAutostartActivateProperty(node) {
280
+ if (!node || node.type !== 'Property' || node.computed) {
281
+ return false;
282
+ }
283
+ const object = node.parent;
284
+ if (object?.type !== 'ObjectExpression') {
285
+ return false;
286
+ }
287
+ const properties = (0, plugin_utils_1.getObjectProperties)(object);
288
+ if (properties.get('activate') !== node) {
289
+ return false;
290
+ }
291
+ const autoStart = properties.get('autoStart');
292
+ return (!!autoStart &&
293
+ autoStart.value.type === 'Literal' &&
294
+ autoStart.value.value === true);
295
+ }
296
+ /**
297
+ * Returns true when a value sits directly in the `activate` entry of an
298
+ * autostart plugin: the function written in place, or the name of one
299
+ * declared elsewhere in the file, as in `activate: activateFoo` or the
300
+ * shorthand `{ activate }`.
301
+ */
302
+ function isAutostartActivateValue(node) {
303
+ const parent = node.parent;
304
+ return (parent?.type === 'Property' &&
305
+ parent.value === node &&
306
+ isAutostartActivateProperty(parent));
307
+ }
308
+ /**
309
+ * Returns the node whose position decides when the function referenced by
310
+ * `identifier` runs, or null when the reference does not call it. `run()` and
311
+ * `new Runner()` reach the body directly, `run.call()` and `run.apply()` do as
312
+ * well, and `list.map(run)` hands it to something which calls it straight
313
+ * away. Passing the function anywhere else does not say when, or whether, it
314
+ * runs.
315
+ */
316
+ function getInvocation(identifier) {
317
+ const parent = identifier.parent;
318
+ if (!parent) {
319
+ return null;
320
+ }
321
+ if ((parent.type === 'CallExpression' || parent.type === 'NewExpression') &&
322
+ parent.callee === identifier) {
323
+ return identifier;
324
+ }
325
+ if (parent.type === 'MemberExpression' &&
326
+ parent.object === identifier &&
327
+ !parent.computed &&
328
+ parent.property.type === 'Identifier' &&
329
+ (parent.property.name === 'call' || parent.property.name === 'apply') &&
330
+ parent.parent?.type === 'CallExpression' &&
331
+ parent.parent.callee === parent) {
332
+ return parent.parent;
333
+ }
334
+ if ((parent.type === 'CallExpression' || parent.type === 'NewExpression') &&
335
+ parent.arguments.includes(identifier) &&
336
+ invokesItsCallback(parent)) {
337
+ return identifier;
338
+ }
339
+ return null;
340
+ }
341
+ /**
342
+ * Finds when the node runs: while the module is evaluated, during the
343
+ * activation of an autostart plugin, or only later. A node inside a named
344
+ * function is placed by the function's call sites, followed transitively, and
345
+ * the earliest of them wins, so a helper called from both `activate` and a
346
+ * command runs during activation. Each function is explored once per walk,
347
+ * which ends a cycle and bounds the cost by the number of functions in the
348
+ * file, so a chain of helpers is followed however long it is.
349
+ */
350
+ function getReach(node, sourceCode, seen = new Set()) {
252
351
  const boundary = findDeferringBoundary(node);
253
352
  if (boundary === null) {
254
- return true;
353
+ return 'module';
255
354
  }
256
- if (boundary === 'field' || depth >= MAX_CALL_DEPTH || seen.has(boundary)) {
257
- return false;
355
+ if (boundary === 'field' || seen.has(boundary)) {
356
+ return 'deferred';
258
357
  }
259
358
  seen.add(boundary);
359
+ if (isAutostartActivateValue(boundary)) {
360
+ return 'activation';
361
+ }
260
362
  const variable = getFunctionVariable(boundary, sourceCode);
261
363
  if (!variable) {
262
- return false;
364
+ return 'deferred';
263
365
  }
264
- return variable.references.some(reference => {
265
- const identifier = reference.identifier;
266
- const parent = identifier.parent;
267
- if (!parent) {
268
- return false;
366
+ let reach = 'deferred';
367
+ for (const { identifier } of variable.references) {
368
+ let result;
369
+ const invocation = getInvocation(identifier);
370
+ if (invocation) {
371
+ result = getReach(invocation, sourceCode, seen);
269
372
  }
270
- // `run()` and `new Runner()` reach the body directly.
271
- if ((parent.type === 'CallExpression' || parent.type === 'NewExpression') &&
272
- parent.callee === identifier) {
273
- return isEagerlyReached(identifier, sourceCode, seen, depth + 1);
373
+ else if (isAutostartActivateValue(identifier)) {
374
+ // The plugin registry calls the function when the application starts.
375
+ result = 'activation';
274
376
  }
275
- // `run.call(...)` and `run.apply(...)` reach it as well.
276
- if (parent.type === 'MemberExpression' &&
277
- parent.object === identifier &&
278
- !parent.computed &&
279
- parent.property.type === 'Identifier' &&
280
- (parent.property.name === 'call' || parent.property.name === 'apply') &&
281
- parent.parent?.type === 'CallExpression' &&
282
- parent.parent.callee === parent) {
283
- return isEagerlyReached(parent.parent, sourceCode, seen, depth + 1);
377
+ else {
378
+ continue;
284
379
  }
285
- // `list.map(run)` passes it to something which calls it straight away.
286
- if ((parent.type === 'CallExpression' || parent.type === 'NewExpression') &&
287
- parent.arguments.includes(identifier) &&
288
- invokesItsCallback(parent)) {
289
- return isEagerlyReached(identifier, sourceCode, seen, depth + 1);
380
+ if (result === 'module') {
381
+ return 'module';
290
382
  }
291
- // Passing the function anywhere else does not say when, or whether, it runs.
292
- return false;
293
- });
383
+ if (result === 'activation') {
384
+ reach = 'activation';
385
+ }
386
+ }
387
+ return reach;
294
388
  }
295
389
  /**
296
390
  * DOM events which only fire on a user action, so a listener for one of them
@@ -8,5 +8,11 @@ export declare function resolveRelativeModule(specifier: string, fromFile: strin
8
8
  /**
9
9
  * Sums the code size of a module and of every relative module it statically
10
10
  * imports. Returns null when the file cannot be read.
11
+ *
12
+ * Callers which only compare the total against a threshold can pass it as
13
+ * `budget`. The walk then stops as soon as the running total reaches it and
14
+ * returns that partial sum, because a module already over the threshold stays
15
+ * over it however much more its imports hold. The files behind the threshold
16
+ * are never read.
11
17
  */
12
- export declare function getTransitiveCodeSize(entry: string): number | null;
18
+ export declare function getTransitiveCodeSize(entry: string, budget?: number): number | null;
@@ -206,8 +206,14 @@ function readFileInfo(filePath) {
206
206
  /**
207
207
  * Sums the code size of a module and of every relative module it statically
208
208
  * imports. Returns null when the file cannot be read.
209
+ *
210
+ * Callers which only compare the total against a threshold can pass it as
211
+ * `budget`. The walk then stops as soon as the running total reaches it and
212
+ * returns that partial sum, because a module already over the threshold stays
213
+ * over it however much more its imports hold. The files behind the threshold
214
+ * are never read.
209
215
  */
210
- function getTransitiveCodeSize(entry) {
216
+ function getTransitiveCodeSize(entry, budget = Number.POSITIVE_INFINITY) {
211
217
  const root = readFileInfo(entry);
212
218
  if (!root) {
213
219
  return null;
@@ -226,6 +232,9 @@ function getTransitiveCodeSize(entry) {
226
232
  return null;
227
233
  }
228
234
  total += info.size;
235
+ if (total >= budget) {
236
+ return total;
237
+ }
229
238
  if (depth >= MAX_DEPTH || seen.size >= MAX_FILES) {
230
239
  continue;
231
240
  }
@@ -0,0 +1,8 @@
1
+ export interface PackageJsonFile {
2
+ mtimeMs: number;
3
+ data: Record<string, unknown>;
4
+ }
5
+ /**
6
+ * Reads and caches a package.json file until its mtime changes.
7
+ */
8
+ export declare function readPackageJson(packagePath: string): PackageJsonFile | null;
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) Jupyter Development Team.
4
+ * Distributed under the terms of the Modified BSD License.
5
+ */
6
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
+ if (k2 === undefined) k2 = k;
8
+ var desc = Object.getOwnPropertyDescriptor(m, k);
9
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
+ desc = { enumerable: true, get: function() { return m[k]; } };
11
+ }
12
+ Object.defineProperty(o, k2, desc);
13
+ }) : (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ o[k2] = m[k];
16
+ }));
17
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
18
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
19
+ }) : function(o, v) {
20
+ o["default"] = v;
21
+ });
22
+ var __importStar = (this && this.__importStar) || (function () {
23
+ var ownKeys = function(o) {
24
+ ownKeys = Object.getOwnPropertyNames || function (o) {
25
+ var ar = [];
26
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
27
+ return ar;
28
+ };
29
+ return ownKeys(o);
30
+ };
31
+ return function (mod) {
32
+ if (mod && mod.__esModule) return mod;
33
+ var result = {};
34
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
35
+ __setModuleDefault(result, mod);
36
+ return result;
37
+ };
38
+ })();
39
+ Object.defineProperty(exports, "__esModule", { value: true });
40
+ exports.readPackageJson = readPackageJson;
41
+ const fs = __importStar(require("fs"));
42
+ const packageJsonCache = new Map();
43
+ /**
44
+ * Reads and caches a package.json file until its mtime changes.
45
+ */
46
+ function readPackageJson(packagePath) {
47
+ let mtimeMs;
48
+ try {
49
+ mtimeMs = fs.statSync(packagePath).mtimeMs;
50
+ }
51
+ catch {
52
+ return null;
53
+ }
54
+ const cached = packageJsonCache.get(packagePath);
55
+ if (cached?.mtimeMs === mtimeMs) {
56
+ return cached.data === null ? null : cached;
57
+ }
58
+ let parsed;
59
+ try {
60
+ parsed = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
61
+ }
62
+ catch {
63
+ packageJsonCache.set(packagePath, { mtimeMs, data: null });
64
+ return null;
65
+ }
66
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
67
+ packageJsonCache.set(packagePath, { mtimeMs, data: null });
68
+ return null;
69
+ }
70
+ const info = {
71
+ mtimeMs,
72
+ data: parsed
73
+ };
74
+ packageJsonCache.set(packagePath, info);
75
+ return info;
76
+ }
@@ -100,3 +100,18 @@ export declare function extractStaticSelectorText(node: TSESTree.Expression, opt
100
100
  * is static.
101
101
  */
102
102
  export declare function combineStaticSelectorText(match: SelectorInteractionMatch): string | null;
103
+ /**
104
+ * Whether `node` bounds the statements a rule may read as "what ran before".
105
+ *
106
+ * A rule that reasons about UI state — which menu is open, what was selected —
107
+ * reads the statements preceding a gesture. That reading has to stop somewhere,
108
+ * and the boundary is the unit that runs as one: a test callback or a named
109
+ * function.
110
+ */
111
+ export declare function isTestScopeBoundary(node: TSESTree.Node): boolean;
112
+ /**
113
+ * The innermost test callback or named function containing `node`, which is
114
+ * where a lookback over preceding statements has to stop. Falls back to the
115
+ * `Program` for a gesture written at the top level of a file.
116
+ */
117
+ export declare function enclosingTestScope(node: TSESTree.Node): TSESTree.Node;
@@ -10,6 +10,8 @@ exports.isRightClick = isRightClick;
10
10
  exports.matchSelectorInteraction = matchSelectorInteraction;
11
11
  exports.extractStaticSelectorText = extractStaticSelectorText;
12
12
  exports.combineStaticSelectorText = combineStaticSelectorText;
13
+ exports.isTestScopeBoundary = isTestScopeBoundary;
14
+ exports.enclosingTestScope = enclosingTestScope;
13
15
  const utils_1 = require("@typescript-eslint/utils");
14
16
  /**
15
17
  * Playwright locator-producing methods.
@@ -304,3 +306,81 @@ function combineStaticSelectorText(match) {
304
306
  }
305
307
  return parts.length > 0 ? parts.join(' ') : null;
306
308
  }
309
+ /**
310
+ * Calls whose callback is stored and run later. Statements next to such a call
311
+ * say nothing about the state its body starts in.
312
+ */
313
+ const DEFERRED_CALLBACK_CALLEES = new Set([
314
+ 'test',
315
+ 'it',
316
+ 'describe',
317
+ 'suite',
318
+ 'beforeAll',
319
+ 'beforeEach',
320
+ 'afterAll',
321
+ 'afterEach'
322
+ ]);
323
+ /**
324
+ * The expression a callee is written on, or null once the name itself is
325
+ * reached. A parameterized test is called twice, `test.each(cases)('name',
326
+ * cb)`, and the table form tags a template first, `` test.each`a | b`('name',
327
+ * cb) ``. Stopping at the inner call would read no name and leave `cb` outside
328
+ * any test scope, so one test's state would reach the next.
329
+ */
330
+ function calleeReceiver(node) {
331
+ switch (node.type) {
332
+ case 'MemberExpression':
333
+ return node.object;
334
+ case 'CallExpression':
335
+ return node.callee;
336
+ case 'TaggedTemplateExpression':
337
+ return node.tag;
338
+ default:
339
+ return null;
340
+ }
341
+ }
342
+ function rootCalleeName(node) {
343
+ let current = node;
344
+ let receiver = calleeReceiver(current);
345
+ while (receiver) {
346
+ current = receiver;
347
+ receiver = calleeReceiver(current);
348
+ }
349
+ return current.type === 'Identifier' ? current.name : null;
350
+ }
351
+ /**
352
+ * Whether `node` bounds the statements a rule may read as "what ran before".
353
+ *
354
+ * A rule that reasons about UI state — which menu is open, what was selected —
355
+ * reads the statements preceding a gesture. That reading has to stop somewhere,
356
+ * and the boundary is the unit that runs as one: a test callback or a named
357
+ * function.
358
+ */
359
+ function isTestScopeBoundary(node) {
360
+ if (node.type === 'FunctionDeclaration') {
361
+ return true;
362
+ }
363
+ if (node.type !== 'FunctionExpression' &&
364
+ node.type !== 'ArrowFunctionExpression') {
365
+ return false;
366
+ }
367
+ const parent = node.parent;
368
+ if (parent?.type === 'VariableDeclarator' || parent?.type === 'Property') {
369
+ return true;
370
+ }
371
+ return (parent?.type === 'CallExpression' &&
372
+ parent.arguments.includes(node) &&
373
+ DEFERRED_CALLBACK_CALLEES.has(rootCalleeName(parent.callee) ?? ''));
374
+ }
375
+ /**
376
+ * The innermost test callback or named function containing `node`, which is
377
+ * where a lookback over preceding statements has to stop. Falls back to the
378
+ * `Program` for a gesture written at the top level of a file.
379
+ */
380
+ function enclosingTestScope(node) {
381
+ let scope = node;
382
+ while (scope.parent && !isTestScopeBoundary(scope)) {
383
+ scope = scope.parent;
384
+ }
385
+ return scope;
386
+ }
@@ -1,6 +1,7 @@
1
1
  import { TSESTree } from '@typescript-eslint/types';
2
+ import { TSESLint } from '@typescript-eslint/utils';
2
3
  import * as ts from 'typescript';
3
- export type JupyterPluginKind = 'frontend' | 'service-manager';
4
+ export type JupyterPluginKind = 'frontend' | 'service-manager' | 'mime-renderer' | 'ambiguous';
4
5
  /**
5
6
  * Gets plugin kind from a variable declaration type annotation.
6
7
  * Accepts an optional TS checker and node mapper to resolve import aliases
@@ -12,9 +13,23 @@ export declare function getJupyterPluginKind(node: TSESTree.VariableDeclarator,
12
13
  */
13
14
  export declare function getObjectProperties(obj: TSESTree.ObjectExpression): Map<string, TSESTree.Property>;
14
15
  /**
15
- * Gets the plugin ID from an object expression
16
+ * Gets the plugin ID from an object expression. Without a scope only a
17
+ * literal, a template literal without substitutions or a `+` chain of literals
18
+ * resolves. With a scope, a `const` string and a member of a `const` object
19
+ * resolve too, and with a checker so does anything with a string literal
20
+ * type, such as a `const` imported from another module.
16
21
  */
17
- export declare function getPluginId(obj: TSESTree.ObjectExpression): string | null;
22
+ export declare function getPluginId(obj: TSESTree.ObjectExpression, scope?: TSESLint.Scope.Scope | null, checker?: ts.TypeChecker | null, getTSNode?: ((n: TSESTree.Node) => ts.Node | undefined) | null): string | null;
23
+ /**
24
+ * Resolves an expression to the string it holds at lint time.
25
+ * `getStaticValue` folds the plain JavaScript part: a literal, a template
26
+ * literal, a `+` chain, a variable that is never reassigned and a member of an
27
+ * object literal that is never mutated, with TypeScript casts stripped. The
28
+ * checker then answers for the TypeScript part: a `const` imported from
29
+ * another module, a namespace member, an enum member or a `static readonly`
30
+ * class property.
31
+ */
32
+ export declare function resolveStaticString(node: TSESTree.Node, scope?: TSESLint.Scope.Scope | null, checker?: ts.TypeChecker | null, getTSNode?: ((n: TSESTree.Node) => ts.Node | undefined) | null): string | null;
18
33
  export interface TokenEntry {
19
34
  name: string;
20
35
  node: TSESTree.Node;
@@ -25,12 +40,27 @@ export interface TokenEntry {
25
40
  export declare function extractArrayTokens(arrayExpr: TSESTree.ArrayExpression): TokenEntry[];
26
41
  export declare function isNullableAnnotation(param: TSESTree.Identifier): boolean;
27
42
  export declare function extractParameterType(param: TSESTree.Identifier): string | null;
43
+ /**
44
+ * Returns true when a type name refers to a JupyterLab plugin type. Only the
45
+ * last segment is compared, so a namespaced spelling such as
46
+ * `Private.JupyterFrontEndPlugin` or `app.JupyterFrontEndPlugin` matches too.
47
+ */
48
+ export declare function isPluginTypeName(name: string | null): boolean;
49
+ /**
50
+ * Resolves the plugin kind ('frontend' or 'service-manager') from a type name.
51
+ * Compares the last segment so qualified names like `app.JupyterFrontEndPlugin` match.
52
+ */
53
+ export declare function getPluginKindFromTypeName(name: string | null): JupyterPluginKind | null;
54
+ /**
55
+ * Resolves the plugin kind ('frontend' or 'service-manager') from a TypeScript Type.
56
+ */
57
+ export declare function getPluginKindFromTsType(type: ts.Type, checker: ts.TypeChecker, depth?: number): JupyterPluginKind | null;
28
58
  /**
29
59
  * Returns true when a type annotation mentions a JupyterLab plugin type at any
30
60
  * depth, so arrays, unions and wrappers such as `Promise<...>` are recognised.
31
61
  * Resolves import aliases through the TypeScript checker when it is available.
32
62
  */
33
- export declare function typeMentionsJupyterPlugin(typeNode: TSESTree.TypeNode | undefined | null, checker?: ts.TypeChecker | null, getTSNode?: ((n: TSESTree.Node) => ts.Node | undefined) | null, depth?: number): boolean;
63
+ export declare function typeMentionsJupyterPlugin(typeNode: TSESTree.TypeNode | undefined | null, checker?: ts.TypeChecker | null, getTSNode?: ((n: TSESTree.Node) => ts.Node | undefined) | null): boolean;
34
64
  /**
35
65
  * Returns true when a property holds something callable: a function written in
36
66
  * place, or a name referring to one declared elsewhere.
@@ -40,6 +70,36 @@ export declare function isCallableProperty(property: TSESTree.Property | undefin
40
70
  * Returns true when an object literal has the shape of a JupyterLab plugin:
41
71
  * a string `id`, an `activate` function, and at least one of the properties
42
72
  * which only plugins carry. Used for plugin objects written without a type
43
- * annotation.
73
+ * annotation. A caller that resolves the ID itself passes whether one is
74
+ * present, so this check needs no type information.
75
+ */
76
+ export declare function looksLikePluginObject(node: TSESTree.ObjectExpression, hasId?: boolean): boolean;
77
+ /**
78
+ * Returns true when an object literal has the shape of a MIME renderer
79
+ * extension entry: a string `id` and a `rendererFactory`. Used for entries
80
+ * written without a type annotation. A caller that resolves the ID itself
81
+ * passes whether one is present.
82
+ */
83
+ export declare function looksLikeMimeExtensionObject(node: TSESTree.ObjectExpression, hasId?: boolean): boolean;
84
+ /**
85
+ * Finds the function that owns a return statement.
86
+ */
87
+ export declare function getEnclosingFunction(node: TSESTree.Node): TSESTree.FunctionDeclaration | TSESTree.FunctionExpression | TSESTree.ArrowFunctionExpression | null;
88
+ /**
89
+ * Resolves the plugin kind from a TypeScript type annotation node, unwrapping
90
+ * arrays, tuples, type operators (readonly), unions, and allowed generic containers.
91
+ * Returns 'ambiguous' if types are mixed (e.g. union or tuple containing multiple distinct plugin kinds).
92
+ */
93
+ export declare function getPluginKindFromType(typeNode: TSESTree.TypeNode | undefined | null, checker?: ts.TypeChecker | null, getTSNode?: ((n: TSESTree.Node) => ts.Node | undefined) | null, options?: {
94
+ matchMime?: boolean;
95
+ }, depth?: number): JupyterPluginKind | null;
96
+ export interface PluginObjectKindOptions {
97
+ allowUntyped?: boolean;
98
+ matchMime?: boolean;
99
+ }
100
+ /**
101
+ * Returns the plugin kind ('frontend', 'service-manager', or 'mime-renderer')
102
+ * for an object literal expression by inspecting its type annotation, type cast,
103
+ * enclosing array/tuple, factory function return type, or shape (when allowUntyped is true).
44
104
  */
45
- export declare function looksLikePluginObject(node: TSESTree.ObjectExpression): boolean;
105
+ export declare function getPluginObjectKind(node: TSESTree.ObjectExpression, checker?: ts.TypeChecker | null, getTSNode?: ((n: TSESTree.Node) => ts.Node | undefined) | null, options?: PluginObjectKindOptions): JupyterPluginKind | null;