@jupyter/eslint-plugin 1.3.0 → 1.5.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/README.md +12 -0
- package/lib/index.d.ts +6 -207
- package/lib/index.js +49 -28
- package/lib/rules/command-described-by.js +18 -27
- package/lib/rules/command-id-convention.d.ts +5 -0
- package/lib/rules/command-id-convention.js +87 -0
- package/lib/rules/no-untranslated-string.d.ts +2 -1
- package/lib/rules/no-untranslated-string.js +11 -3
- package/lib/rules/plugin-activation-args.d.ts +3 -3
- package/lib/rules/plugin-activation-args.js +183 -142
- package/lib/rules/plugin-description.js +12 -9
- package/lib/rules/plugin-id-convention.d.ts +2 -3
- package/lib/rules/plugin-id-convention.js +10 -107
- package/lib/rules/prefer-lazy-imports.d.ts +2 -2
- package/lib/rules/prefer-lazy-imports.js +59 -28
- package/lib/rules/prefer-signal-this-arg.d.ts +3 -3
- package/lib/rules/prefer-signal-this-arg.js +12 -13
- package/lib/rules/require-disposable-ownership.d.ts +1 -2
- package/lib/rules/require-disposable-ownership.js +2 -10
- package/lib/rules/require-disposable-transfer.d.ts +1 -2
- package/lib/rules/require-disposable-transfer.js +7 -12
- package/lib/rules/require-signal-cleanup.d.ts +3 -3
- package/lib/rules/require-signal-cleanup.js +12 -13
- package/lib/rules/require-signal-this-arg.d.ts +1 -2
- package/lib/rules/require-signal-this-arg.js +2 -10
- package/lib/rules/token-format.js +8 -2
- package/lib/utils/ast.d.ts +1 -1
- package/lib/utils/commands.d.ts +17 -1
- package/lib/utils/commands.js +205 -0
- package/lib/utils/disposables.d.ts +2 -13
- package/lib/utils/disposables.js +3 -18
- package/lib/utils/lazy-imports.d.ts +2 -2
- package/lib/utils/lazy-imports.js +10 -1
- package/lib/utils/options.d.ts +9 -0
- package/lib/utils/options.js +22 -0
- package/lib/utils/plugin-utils.d.ts +39 -10
- package/lib/utils/plugin-utils.js +376 -25
- package/lib/utils/signal-lifetime.d.ts +1 -2
- package/lib/utils/signals.d.ts +1 -2
- package/lib/utils/translation.d.ts +1 -1
- package/lib/utils/type-services.d.ts +12 -0
- package/lib/utils/type-services.js +27 -0
- package/package.json +4 -10
package/lib/utils/commands.js
CHANGED
|
@@ -5,6 +5,11 @@
|
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.isAddCommandCall = isAddCommandCall;
|
|
8
|
+
exports.resolveCommandId = resolveCommandId;
|
|
9
|
+
exports.isPrivateCommandRegistry = isPrivateCommandRegistry;
|
|
10
|
+
const utils_1 = require("@typescript-eslint/utils");
|
|
11
|
+
const ast_1 = require("./ast");
|
|
12
|
+
const plugin_utils_1 = require("./plugin-utils");
|
|
8
13
|
/**
|
|
9
14
|
* Checks if a node represents *.addCommand()
|
|
10
15
|
*/
|
|
@@ -18,3 +23,203 @@ function isAddCommandCall(node) {
|
|
|
18
23
|
}
|
|
19
24
|
return false;
|
|
20
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Resolves a command ID expression to the string it holds at lint time.
|
|
28
|
+
*
|
|
29
|
+
* On top of `resolveStaticString`, this reads a member of a namespace or enum
|
|
30
|
+
* declared in the same file without type information, since
|
|
31
|
+
* `namespace CommandIDs { export const open = '...'; }` is how JupyterLab and
|
|
32
|
+
* most extensions declare their command IDs.
|
|
33
|
+
*/
|
|
34
|
+
function resolveCommandId(node, sourceCode, checker, getTSNode) {
|
|
35
|
+
const scope = sourceCode.getScope(node);
|
|
36
|
+
const resolved = (0, plugin_utils_1.resolveStaticString)(node, scope, checker, getTSNode);
|
|
37
|
+
if (resolved !== null) {
|
|
38
|
+
return resolved;
|
|
39
|
+
}
|
|
40
|
+
if (node.type !== 'MemberExpression' ||
|
|
41
|
+
node.computed ||
|
|
42
|
+
node.object.type !== 'Identifier' ||
|
|
43
|
+
node.property.type !== 'Identifier') {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
const variable = utils_1.ASTUtils.findVariable(scope, node.object);
|
|
47
|
+
if (!variable) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
const memberName = node.property.name;
|
|
51
|
+
// Namespaces and enums can be declared in several merged blocks.
|
|
52
|
+
for (const def of variable.defs) {
|
|
53
|
+
const initializer = findDeclaredMember(def.node, memberName);
|
|
54
|
+
if (initializer) {
|
|
55
|
+
return (0, plugin_utils_1.resolveStaticString)(initializer, sourceCode.getScope(initializer), checker, getTSNode);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Finds the initializer of an exported `const` in a namespace block, or of a
|
|
62
|
+
* member of an enum.
|
|
63
|
+
*/
|
|
64
|
+
function findDeclaredMember(declaration, memberName) {
|
|
65
|
+
if (declaration.type === 'TSEnumDeclaration') {
|
|
66
|
+
for (const member of declaration.body.members) {
|
|
67
|
+
const key = member.id.type === 'Identifier' ? member.id.name : member.id.value;
|
|
68
|
+
if (key === memberName) {
|
|
69
|
+
return member.initializer ?? null;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
if (declaration.type !== 'TSModuleDeclaration' ||
|
|
75
|
+
declaration.body?.type !== 'TSModuleBlock') {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
for (const statement of declaration.body.body) {
|
|
79
|
+
if (statement.type !== 'ExportNamedDeclaration' ||
|
|
80
|
+
statement.declaration?.type !== 'VariableDeclaration' ||
|
|
81
|
+
statement.declaration.kind !== 'const') {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
for (const declarator of statement.declaration.declarations) {
|
|
85
|
+
if (declarator.id.type === 'Identifier' &&
|
|
86
|
+
declarator.id.name === memberName) {
|
|
87
|
+
return declarator.init;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Checks whether an `addCommand` receiver is a registry the code created
|
|
95
|
+
* itself with `new CommandRegistry()`, such as the throw-away registry behind
|
|
96
|
+
* a context menu, rather than the application's shared `app.commands`.
|
|
97
|
+
*/
|
|
98
|
+
function isPrivateCommandRegistry(receiver, scope) {
|
|
99
|
+
const values = getAssignedValues(receiver, scope);
|
|
100
|
+
return (values !== null &&
|
|
101
|
+
values.length > 0 &&
|
|
102
|
+
values.every(value => isNewCommandRegistry(value, scope)));
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Collects every value assigned to a variable or to a `this.<field>`, or
|
|
106
|
+
* returns null when the receiver is neither.
|
|
107
|
+
*/
|
|
108
|
+
function getAssignedValues(receiver, scope) {
|
|
109
|
+
if (receiver.type === 'Identifier') {
|
|
110
|
+
const variable = utils_1.ASTUtils.findVariable(scope, receiver);
|
|
111
|
+
if (!variable) {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
const values = [];
|
|
115
|
+
for (const reference of variable.references) {
|
|
116
|
+
if (reference.isWrite()) {
|
|
117
|
+
// A write without a value (`for (x of ...)`, destructuring) is not
|
|
118
|
+
// a known registry.
|
|
119
|
+
if (!reference.writeExpr) {
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
values.push(reference.writeExpr);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return values;
|
|
126
|
+
}
|
|
127
|
+
if (receiver.type !== 'MemberExpression' ||
|
|
128
|
+
receiver.computed ||
|
|
129
|
+
receiver.object.type !== 'ThisExpression') {
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
const property = receiver.property;
|
|
133
|
+
const classBody = getEnclosingClassBody(receiver);
|
|
134
|
+
if (!classBody) {
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
const values = [];
|
|
138
|
+
let unknownWrite = false;
|
|
139
|
+
(0, ast_1.walkFrom)(classBody, node => {
|
|
140
|
+
if ((node.type === 'ClassDeclaration' || node.type === 'ClassExpression') &&
|
|
141
|
+
node.body !== classBody) {
|
|
142
|
+
return 'skip-children';
|
|
143
|
+
}
|
|
144
|
+
if (node.type === 'PropertyDefinition' &&
|
|
145
|
+
!node.computed &&
|
|
146
|
+
isSameKey(node.key, property)) {
|
|
147
|
+
if (node.value) {
|
|
148
|
+
values.push(node.value);
|
|
149
|
+
}
|
|
150
|
+
return undefined;
|
|
151
|
+
}
|
|
152
|
+
if (node.type === 'AssignmentExpression' &&
|
|
153
|
+
node.left.type === 'MemberExpression' &&
|
|
154
|
+
node.left.object.type === 'ThisExpression' &&
|
|
155
|
+
!node.left.computed &&
|
|
156
|
+
isSameKey(node.left.property, property)) {
|
|
157
|
+
// In a nested regular function `this` is whatever the caller binds,
|
|
158
|
+
// which may or may not be this instance, so the write is unknown.
|
|
159
|
+
if (node.operator !== '=' || getEnclosingClassBody(node) !== classBody) {
|
|
160
|
+
unknownWrite = true;
|
|
161
|
+
return 'stop';
|
|
162
|
+
}
|
|
163
|
+
values.push(node.right);
|
|
164
|
+
}
|
|
165
|
+
return undefined;
|
|
166
|
+
});
|
|
167
|
+
return unknownWrite ? null : values;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Finds the class body whose instance `this` refers to at a node, looking
|
|
171
|
+
* through arrow functions.
|
|
172
|
+
*/
|
|
173
|
+
function getEnclosingClassBody(node) {
|
|
174
|
+
let current = node.parent;
|
|
175
|
+
while (current) {
|
|
176
|
+
if (current.type === 'FunctionExpression' ||
|
|
177
|
+
current.type === 'FunctionDeclaration') {
|
|
178
|
+
// Only a method keeps the class instance as `this`.
|
|
179
|
+
const owner = current.parent;
|
|
180
|
+
if (owner?.type !== 'MethodDefinition' &&
|
|
181
|
+
owner?.type !== 'PropertyDefinition') {
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
if (current.type === 'ClassBody') {
|
|
186
|
+
return current;
|
|
187
|
+
}
|
|
188
|
+
current = current.parent;
|
|
189
|
+
}
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
function isSameKey(key, property) {
|
|
193
|
+
return key.type === property.type && key.name === property.name;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Checks for `new CommandRegistry()`, `new <ns>.CommandRegistry()` or a
|
|
197
|
+
* renamed import of `CommandRegistry`.
|
|
198
|
+
*/
|
|
199
|
+
function isNewCommandRegistry(node, scope) {
|
|
200
|
+
while (node.type === 'TSAsExpression' ||
|
|
201
|
+
node.type === 'TSSatisfiesExpression' ||
|
|
202
|
+
node.type === 'TSNonNullExpression' ||
|
|
203
|
+
node.type === 'TSTypeAssertion') {
|
|
204
|
+
node = node.expression;
|
|
205
|
+
}
|
|
206
|
+
if (node.type !== 'NewExpression') {
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
209
|
+
const callee = node.callee;
|
|
210
|
+
if (callee.type === 'MemberExpression') {
|
|
211
|
+
return (!callee.computed &&
|
|
212
|
+
callee.property.type === 'Identifier' &&
|
|
213
|
+
callee.property.name === 'CommandRegistry');
|
|
214
|
+
}
|
|
215
|
+
if (callee.type !== 'Identifier') {
|
|
216
|
+
return false;
|
|
217
|
+
}
|
|
218
|
+
if (callee.name === 'CommandRegistry') {
|
|
219
|
+
return true;
|
|
220
|
+
}
|
|
221
|
+
const definition = utils_1.ASTUtils.findVariable(scope, callee)?.defs[0];
|
|
222
|
+
return (definition?.node.type === 'ImportSpecifier' &&
|
|
223
|
+
definition.node.imported.type === 'Identifier' &&
|
|
224
|
+
definition.node.imported.name === 'CommandRegistry');
|
|
225
|
+
}
|
|
@@ -1,16 +1,6 @@
|
|
|
1
|
-
import { TSESTree } from '@typescript-eslint/
|
|
2
|
-
import { ParserServices, TSESLint } from '@typescript-eslint/utils';
|
|
1
|
+
import { ParserServices, TSESLint, TSESTree } from '@typescript-eslint/utils';
|
|
3
2
|
import * as ts from 'typescript';
|
|
4
|
-
|
|
5
|
-
* Resolves a configurable name list option.
|
|
6
|
-
*
|
|
7
|
-
* A user-supplied list is *added* to the built-in defaults, so a project only
|
|
8
|
-
* has to name its own helpers rather than restate this plugin's list. Passing
|
|
9
|
-
* the matching `extendDefault...` option as `false` drops the defaults, whether
|
|
10
|
-
* or not a replacement list is given, which is also how to ask for the
|
|
11
|
-
* strictest possible checking.
|
|
12
|
-
*/
|
|
13
|
-
export declare function resolveNameListOption(provided: readonly string[] | undefined, defaults: readonly string[], extendDefaults: boolean): Set<string>;
|
|
3
|
+
export { resolveNameListOption } from './options';
|
|
14
4
|
export declare const DEFAULT_OWNERSHIP_FUNCTION_NAMES: string[];
|
|
15
5
|
interface PendingDisposable {
|
|
16
6
|
node: TSESTree.Node;
|
|
@@ -73,4 +63,3 @@ export declare function isDisposableType(type: ts.Type, checker: ts.TypeChecker,
|
|
|
73
63
|
*/
|
|
74
64
|
export declare function constructsDisposable(node: TSESTree.NewExpression, ownership: DisposableOwnershipContext): boolean;
|
|
75
65
|
export declare function shouldCheckReturnedDisposable(node: TSESTree.CallExpression): boolean;
|
|
76
|
-
export {};
|
package/lib/utils/disposables.js
CHANGED
|
@@ -37,8 +37,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
37
37
|
};
|
|
38
38
|
})();
|
|
39
39
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
-
exports.DEFAULT_OWNERSHIP_FUNCTION_NAMES = void 0;
|
|
41
|
-
exports.resolveNameListOption = resolveNameListOption;
|
|
40
|
+
exports.DEFAULT_OWNERSHIP_FUNCTION_NAMES = exports.resolveNameListOption = void 0;
|
|
42
41
|
exports.getCalleeName = getCalleeName;
|
|
43
42
|
exports.isDisposableConstructor = isDisposableConstructor;
|
|
44
43
|
exports.isDisposableSetFactoryCall = isDisposableSetFactoryCall;
|
|
@@ -65,22 +64,8 @@ const DISPOSABLE_CONSTRUCTOR_NAMES = [
|
|
|
65
64
|
];
|
|
66
65
|
const DISPOSABLE_SET_NAMES = ['DisposableSet', 'ObservableDisposableSet'];
|
|
67
66
|
const FLUENT_DISPOSABLE_METHOD_NAMES = ['initializeState'];
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
*
|
|
71
|
-
* A user-supplied list is *added* to the built-in defaults, so a project only
|
|
72
|
-
* has to name its own helpers rather than restate this plugin's list. Passing
|
|
73
|
-
* the matching `extendDefault...` option as `false` drops the defaults, whether
|
|
74
|
-
* or not a replacement list is given, which is also how to ask for the
|
|
75
|
-
* strictest possible checking.
|
|
76
|
-
*/
|
|
77
|
-
function resolveNameListOption(provided, defaults, extendDefaults) {
|
|
78
|
-
const names = extendDefaults ? [...defaults] : [];
|
|
79
|
-
if (provided) {
|
|
80
|
-
names.push(...provided);
|
|
81
|
-
}
|
|
82
|
-
return new Set(names);
|
|
83
|
-
}
|
|
67
|
+
var options_1 = require("./options");
|
|
68
|
+
Object.defineProperty(exports, "resolveNameListOption", { enumerable: true, get: function () { return options_1.resolveNameListOption; } });
|
|
84
69
|
exports.DEFAULT_OWNERSHIP_FUNCTION_NAMES = [
|
|
85
70
|
'add',
|
|
86
71
|
'addCell',
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { TSESTree } from '@typescript-eslint/
|
|
2
|
-
import { TSESLint } from '@typescript-eslint/utils';
|
|
1
|
+
import { TSESLint, TSESTree } from '@typescript-eslint/utils';
|
|
3
2
|
export interface LazyImportOptions {
|
|
4
3
|
allowedPackages: string[];
|
|
5
4
|
deferredPackages: string[];
|
|
@@ -7,6 +6,7 @@ export interface LazyImportOptions {
|
|
|
7
6
|
minimumSize: number;
|
|
8
7
|
reportInteractionCallbacks: boolean;
|
|
9
8
|
reportModuleLevelUsage: boolean;
|
|
9
|
+
reportReExports: boolean;
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
12
|
* An async chunk carries a few hundred bytes of bundler runtime, so around one
|
|
@@ -58,9 +58,18 @@ exports.DEFAULT_DEFERRED_PACKAGES = [
|
|
|
58
58
|
'@codemirror/lang-*',
|
|
59
59
|
'@codemirror/legacy-modes',
|
|
60
60
|
'@codemirror/search',
|
|
61
|
+
'@mermaid-js/layout-elk',
|
|
62
|
+
'@plutojl/lang-julia',
|
|
61
63
|
'@rjsf/validator-ajv8',
|
|
64
|
+
'@xterm/xterm',
|
|
65
|
+
'@xterm/addon-*',
|
|
66
|
+
'marked',
|
|
67
|
+
'marked-gfm-heading-id',
|
|
68
|
+
'marked-mangle',
|
|
69
|
+
'mathjax-full',
|
|
62
70
|
'mermaid',
|
|
63
|
-
'react-toastify'
|
|
71
|
+
'react-toastify',
|
|
72
|
+
'vega-embed'
|
|
64
73
|
];
|
|
65
74
|
/**
|
|
66
75
|
* Assets which a bundler turns into a URL or a style side effect rather than
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolves a configurable name list option.
|
|
3
|
+
*
|
|
4
|
+
* A user-supplied list is *added* to the built-in defaults, so a project only
|
|
5
|
+
* has to name its own entries rather than restate this plugin's list. Passing
|
|
6
|
+
* the matching `extendDefault...` option as `false` drops the defaults, whether
|
|
7
|
+
* or not a replacement list is given.
|
|
8
|
+
*/
|
|
9
|
+
export declare function resolveNameListOption(provided: readonly string[] | undefined, defaults: readonly string[], extendDefaults: boolean): Set<string>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) Jupyter Development Team.
|
|
4
|
+
* Distributed under the terms of the Modified BSD License.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.resolveNameListOption = resolveNameListOption;
|
|
8
|
+
/**
|
|
9
|
+
* Resolves a configurable name list option.
|
|
10
|
+
*
|
|
11
|
+
* A user-supplied list is *added* to the built-in defaults, so a project only
|
|
12
|
+
* has to name its own entries rather than restate this plugin's list. Passing
|
|
13
|
+
* the matching `extendDefault...` option as `false` drops the defaults, whether
|
|
14
|
+
* or not a replacement list is given.
|
|
15
|
+
*/
|
|
16
|
+
function resolveNameListOption(provided, defaults, extendDefaults) {
|
|
17
|
+
const names = extendDefaults ? [...defaults] : [];
|
|
18
|
+
if (provided) {
|
|
19
|
+
names.push(...provided);
|
|
20
|
+
}
|
|
21
|
+
return new Set(names);
|
|
22
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { TSESTree } from '@typescript-eslint/
|
|
2
|
-
import { TSESLint } from '@typescript-eslint/utils';
|
|
1
|
+
import { TSESLint, TSESTree } from '@typescript-eslint/utils';
|
|
3
2
|
import * as ts from 'typescript';
|
|
4
|
-
export type JupyterPluginKind = 'frontend' | 'service-manager';
|
|
3
|
+
export type JupyterPluginKind = 'frontend' | 'service-manager' | 'mime-renderer' | 'ambiguous';
|
|
5
4
|
/**
|
|
6
5
|
* Gets plugin kind from a variable declaration type annotation.
|
|
7
6
|
* Accepts an optional TS checker and node mapper to resolve import aliases
|
|
@@ -40,19 +39,27 @@ export interface TokenEntry {
|
|
|
40
39
|
export declare function extractArrayTokens(arrayExpr: TSESTree.ArrayExpression): TokenEntry[];
|
|
41
40
|
export declare function isNullableAnnotation(param: TSESTree.Identifier): boolean;
|
|
42
41
|
export declare function extractParameterType(param: TSESTree.Identifier): string | null;
|
|
42
|
+
/**
|
|
43
|
+
* Returns true when a type name refers to a JupyterLab plugin type. Only the
|
|
44
|
+
* last segment is compared, so a namespaced spelling such as
|
|
45
|
+
* `Private.JupyterFrontEndPlugin` or `app.JupyterFrontEndPlugin` matches too.
|
|
46
|
+
*/
|
|
47
|
+
export declare function isPluginTypeName(name: string | null): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Resolves the plugin kind ('frontend' or 'service-manager') from a type name.
|
|
50
|
+
* Compares the last segment so qualified names like `app.JupyterFrontEndPlugin` match.
|
|
51
|
+
*/
|
|
52
|
+
export declare function getPluginKindFromTypeName(name: string | null): JupyterPluginKind | null;
|
|
53
|
+
/**
|
|
54
|
+
* Resolves the plugin kind ('frontend' or 'service-manager') from a TypeScript Type.
|
|
55
|
+
*/
|
|
56
|
+
export declare function getPluginKindFromTsType(type: ts.Type, checker: ts.TypeChecker, depth?: number): JupyterPluginKind | null;
|
|
43
57
|
/**
|
|
44
58
|
* Returns true when a type annotation mentions a JupyterLab plugin type at any
|
|
45
59
|
* depth, so arrays, unions and wrappers such as `Promise<...>` are recognised.
|
|
46
60
|
* Resolves import aliases through the TypeScript checker when it is available.
|
|
47
61
|
*/
|
|
48
62
|
export declare function typeMentionsJupyterPlugin(typeNode: TSESTree.TypeNode | undefined | null, checker?: ts.TypeChecker | null, getTSNode?: ((n: TSESTree.Node) => ts.Node | undefined) | null): boolean;
|
|
49
|
-
/**
|
|
50
|
-
* Returns true when a type annotation mentions the MIME renderer extension
|
|
51
|
-
* entry type at any depth, with the same wrappers as
|
|
52
|
-
* `typeMentionsJupyterPlugin`. JupyterLab registers each entry as a plugin
|
|
53
|
-
* whose ID is the entry's `id`, so the entry follows the plugin ID convention.
|
|
54
|
-
*/
|
|
55
|
-
export declare function typeMentionsMimeExtension(typeNode: TSESTree.TypeNode | undefined | null, checker?: ts.TypeChecker | null, getTSNode?: ((n: TSESTree.Node) => ts.Node | undefined) | null): boolean;
|
|
56
63
|
/**
|
|
57
64
|
* Returns true when a property holds something callable: a function written in
|
|
58
65
|
* place, or a name referring to one declared elsewhere.
|
|
@@ -73,3 +80,25 @@ export declare function looksLikePluginObject(node: TSESTree.ObjectExpression, h
|
|
|
73
80
|
* passes whether one is present.
|
|
74
81
|
*/
|
|
75
82
|
export declare function looksLikeMimeExtensionObject(node: TSESTree.ObjectExpression, hasId?: boolean): boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Finds the function that owns a return statement.
|
|
85
|
+
*/
|
|
86
|
+
export declare function getEnclosingFunction(node: TSESTree.Node): TSESTree.FunctionDeclaration | TSESTree.FunctionExpression | TSESTree.ArrowFunctionExpression | null;
|
|
87
|
+
/**
|
|
88
|
+
* Resolves the plugin kind from a TypeScript type annotation node, unwrapping
|
|
89
|
+
* arrays, tuples, type operators (readonly), unions, and allowed generic containers.
|
|
90
|
+
* Returns 'ambiguous' if types are mixed (e.g. union or tuple containing multiple distinct plugin kinds).
|
|
91
|
+
*/
|
|
92
|
+
export declare function getPluginKindFromType(typeNode: TSESTree.TypeNode | undefined | null, checker?: ts.TypeChecker | null, getTSNode?: ((n: TSESTree.Node) => ts.Node | undefined) | null, options?: {
|
|
93
|
+
matchMime?: boolean;
|
|
94
|
+
}, depth?: number): JupyterPluginKind | null;
|
|
95
|
+
export interface PluginObjectKindOptions {
|
|
96
|
+
allowUntyped?: boolean;
|
|
97
|
+
matchMime?: boolean;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Returns the plugin kind ('frontend', 'service-manager', or 'mime-renderer')
|
|
101
|
+
* for an object literal expression by inspecting its type annotation, type cast,
|
|
102
|
+
* enclosing array/tuple, factory function return type, or shape (when allowUntyped is true).
|
|
103
|
+
*/
|
|
104
|
+
export declare function getPluginObjectKind(node: TSESTree.ObjectExpression, checker?: ts.TypeChecker | null, getTSNode?: ((n: TSESTree.Node) => ts.Node | undefined) | null, options?: PluginObjectKindOptions): JupyterPluginKind | null;
|