@jupyter/eslint-plugin 1.3.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 +8 -0
- package/lib/index.js +11 -4
- package/lib/rules/command-id-convention.d.ts +5 -0
- package/lib/rules/command-id-convention.js +87 -0
- 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 +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 +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 +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 +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/commands.d.ts +17 -0
- package/lib/utils/commands.js +205 -0
- package/lib/utils/lazy-imports.d.ts +1 -0
- package/lib/utils/lazy-imports.js +10 -1
- package/lib/utils/plugin-utils.d.ts +38 -8
- package/lib/utils/plugin-utils.js +376 -25
- package/lib/utils/type-services.d.ts +13 -0
- package/lib/utils/type-services.js +27 -0
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -9,6 +9,9 @@ declare const plugin: {
|
|
|
9
9
|
'command-described-by': import("@typescript-eslint/utils/ts-eslint").RuleModule<"missingDescribedBy", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
|
|
10
10
|
name: string;
|
|
11
11
|
};
|
|
12
|
+
'command-id-convention': import("@typescript-eslint/utils/ts-eslint").RuleModule<"missingNamespace" | "emptySegment", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
|
|
13
|
+
name: string;
|
|
14
|
+
};
|
|
12
15
|
'plugin-description': import("@typescript-eslint/utils/ts-eslint").RuleModule<"missingDescription" | "emptyDescription", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
|
|
13
16
|
name: string;
|
|
14
17
|
};
|
|
@@ -89,6 +92,7 @@ declare const plugin: {
|
|
|
89
92
|
rules: {
|
|
90
93
|
'jupyter/plugin-activation-args': string;
|
|
91
94
|
'jupyter/command-described-by': string;
|
|
95
|
+
'jupyter/command-id-convention': string;
|
|
92
96
|
'jupyter/plugin-description': string;
|
|
93
97
|
'jupyter/plugin-id-convention': string;
|
|
94
98
|
'jupyter/no-translation-concatenation': string;
|
|
@@ -121,6 +125,7 @@ declare const plugin: {
|
|
|
121
125
|
'jupyter/no-schema-enum': string;
|
|
122
126
|
'jupyter/plugin-activation-args'?: undefined;
|
|
123
127
|
'jupyter/command-described-by'?: undefined;
|
|
128
|
+
'jupyter/command-id-convention'?: undefined;
|
|
124
129
|
'jupyter/plugin-description'?: undefined;
|
|
125
130
|
'jupyter/plugin-id-convention'?: undefined;
|
|
126
131
|
'jupyter/no-translation-concatenation'?: undefined;
|
|
@@ -153,6 +158,7 @@ declare const plugin: {
|
|
|
153
158
|
'jupyter/galata-prefer-sidebar-activity-helper': string;
|
|
154
159
|
'jupyter/prefer-lazy-imports': string;
|
|
155
160
|
'jupyter/plugin-id-convention': string;
|
|
161
|
+
'jupyter/command-id-convention': string;
|
|
156
162
|
'jupyter/plugin-activation-args'?: undefined;
|
|
157
163
|
'jupyter/command-described-by'?: undefined;
|
|
158
164
|
'jupyter/plugin-description'?: undefined;
|
|
@@ -175,6 +181,7 @@ declare const plugin: {
|
|
|
175
181
|
rules: {
|
|
176
182
|
'jupyter/plugin-activation-args': string;
|
|
177
183
|
'jupyter/command-described-by': string;
|
|
184
|
+
'jupyter/command-id-convention': string;
|
|
178
185
|
'jupyter/plugin-description': string;
|
|
179
186
|
'jupyter/plugin-id-convention': string;
|
|
180
187
|
'jupyter/no-translation-concatenation': string;
|
|
@@ -202,6 +209,7 @@ declare const plugin: {
|
|
|
202
209
|
'jupyter/galata-prefer-sidebar-activity-helper': string;
|
|
203
210
|
'jupyter/prefer-lazy-imports': string;
|
|
204
211
|
'jupyter/plugin-id-convention': string;
|
|
212
|
+
'jupyter/command-id-convention': string;
|
|
205
213
|
};
|
|
206
214
|
}[];
|
|
207
215
|
};
|
package/lib/index.js
CHANGED
|
@@ -42,6 +42,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
42
42
|
const jsoncParser = __importStar(require("jsonc-eslint-parser"));
|
|
43
43
|
const plugin_activation_args_1 = __importDefault(require("./rules/plugin-activation-args"));
|
|
44
44
|
const command_described_by_1 = __importDefault(require("./rules/command-described-by"));
|
|
45
|
+
const command_id_convention_1 = __importDefault(require("./rules/command-id-convention"));
|
|
45
46
|
const plugin_description_1 = __importDefault(require("./rules/plugin-description"));
|
|
46
47
|
const plugin_id_convention_1 = __importDefault(require("./rules/plugin-id-convention"));
|
|
47
48
|
const no_translation_concatenation_1 = __importDefault(require("./rules/no-translation-concatenation"));
|
|
@@ -67,6 +68,7 @@ const plugin = {
|
|
|
67
68
|
rules: {
|
|
68
69
|
'plugin-activation-args': plugin_activation_args_1.default,
|
|
69
70
|
'command-described-by': command_described_by_1.default,
|
|
71
|
+
'command-id-convention': command_id_convention_1.default,
|
|
70
72
|
'plugin-description': plugin_description_1.default,
|
|
71
73
|
'plugin-id-convention': plugin_id_convention_1.default,
|
|
72
74
|
'no-translation-concatenation': no_translation_concatenation_1.default,
|
|
@@ -96,6 +98,7 @@ const plugin = {
|
|
|
96
98
|
rules: {
|
|
97
99
|
'jupyter/plugin-activation-args': 'error',
|
|
98
100
|
'jupyter/command-described-by': 'warn',
|
|
101
|
+
'jupyter/command-id-convention': 'warn',
|
|
99
102
|
'jupyter/plugin-description': 'warn',
|
|
100
103
|
'jupyter/plugin-id-convention': 'warn',
|
|
101
104
|
'jupyter/no-translation-concatenation': 'error',
|
|
@@ -128,10 +131,12 @@ const plugin = {
|
|
|
128
131
|
'jupyter/galata-prefer-menu-helper': 'warn',
|
|
129
132
|
'jupyter/galata-prefer-notebook-cell-helper': 'warn',
|
|
130
133
|
'jupyter/galata-prefer-sidebar-activity-helper': 'warn',
|
|
131
|
-
// Test files declare mock plugins; deferring their
|
|
132
|
-
// pointless and their IDs are never used to disable an
|
|
134
|
+
// Test files declare mock plugins and commands; deferring their
|
|
135
|
+
// imports is pointless and their IDs are never used to disable an
|
|
136
|
+
// extension or to query commands.
|
|
133
137
|
'jupyter/prefer-lazy-imports': 'off',
|
|
134
|
-
'jupyter/plugin-id-convention': 'off'
|
|
138
|
+
'jupyter/plugin-id-convention': 'off',
|
|
139
|
+
'jupyter/command-id-convention': 'off'
|
|
135
140
|
}
|
|
136
141
|
}
|
|
137
142
|
],
|
|
@@ -139,6 +144,7 @@ const plugin = {
|
|
|
139
144
|
rules: {
|
|
140
145
|
'jupyter/plugin-activation-args': 'error',
|
|
141
146
|
'jupyter/command-described-by': 'warn',
|
|
147
|
+
'jupyter/command-id-convention': 'warn',
|
|
142
148
|
'jupyter/plugin-description': 'warn',
|
|
143
149
|
'jupyter/plugin-id-convention': 'warn',
|
|
144
150
|
'jupyter/no-translation-concatenation': 'error',
|
|
@@ -171,7 +177,8 @@ const plugin = {
|
|
|
171
177
|
'jupyter/galata-prefer-notebook-cell-helper': 'warn',
|
|
172
178
|
'jupyter/galata-prefer-sidebar-activity-helper': 'warn',
|
|
173
179
|
'jupyter/prefer-lazy-imports': 'off',
|
|
174
|
-
'jupyter/plugin-id-convention': 'off'
|
|
180
|
+
'jupyter/plugin-id-convention': 'off',
|
|
181
|
+
'jupyter/command-id-convention': 'off'
|
|
175
182
|
}
|
|
176
183
|
}
|
|
177
184
|
]
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) Jupyter Development Team.
|
|
4
|
+
* Distributed under the terms of the Modified BSD License.
|
|
5
|
+
*/
|
|
6
|
+
const utils_1 = require("@typescript-eslint/utils");
|
|
7
|
+
const commands_1 = require("../utils/commands");
|
|
8
|
+
const create_rule_1 = require("../utils/create-rule");
|
|
9
|
+
const commandIdConvention = (0, create_rule_1.createRule)({
|
|
10
|
+
name: 'command-id-convention',
|
|
11
|
+
meta: {
|
|
12
|
+
type: 'suggestion',
|
|
13
|
+
docs: {
|
|
14
|
+
description: 'Ensure JupyterLab command IDs follow the "namespace:name" convention',
|
|
15
|
+
url: 'https://eslint-plugin.readthedocs.io/en/latest/rules/command-id-convention/'
|
|
16
|
+
},
|
|
17
|
+
messages: {
|
|
18
|
+
missingNamespace: 'Command ID "{{ commandId }}" has no namespace; use the "namespace:name" form, e.g. "my-extension:{{ commandId }}".',
|
|
19
|
+
emptySegment: 'Command ID "{{ commandId }}" has an empty {{ segment }}; use the "namespace:name" form.'
|
|
20
|
+
},
|
|
21
|
+
schema: []
|
|
22
|
+
},
|
|
23
|
+
defaultOptions: [],
|
|
24
|
+
create(context) {
|
|
25
|
+
let services = null;
|
|
26
|
+
let checker = null;
|
|
27
|
+
try {
|
|
28
|
+
services = utils_1.ESLintUtils.getParserServices(context, true);
|
|
29
|
+
checker = services.program ? services.program.getTypeChecker() : null;
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
services = null;
|
|
33
|
+
}
|
|
34
|
+
const getTSNode = services
|
|
35
|
+
? (node) => services?.esTreeNodeToTSNodeMap.get(node)
|
|
36
|
+
: null;
|
|
37
|
+
return {
|
|
38
|
+
CallExpression(node) {
|
|
39
|
+
// `addCommand(id, options)`: the arity filters out unrelated methods
|
|
40
|
+
// that happen to share the name.
|
|
41
|
+
if (!(0, commands_1.isAddCommandCall)(node) || node.arguments.length < 2) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const idArg = node.arguments[0];
|
|
45
|
+
if (idArg.type === 'SpreadElement') {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
// A registry created on the spot, such as one backing a context
|
|
49
|
+
// menu, is never listed or queried alongside the application's.
|
|
50
|
+
const callee = node.callee;
|
|
51
|
+
if (callee.object.type !== 'Super' &&
|
|
52
|
+
(0, commands_1.isPrivateCommandRegistry)(callee.object, context.sourceCode.getScope(node))) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const commandId = (0, commands_1.resolveCommandId)(idArg, context.sourceCode, checker, getTSNode);
|
|
56
|
+
if (commandId === null) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
// The namespace is everything before the first `:`, as in the
|
|
60
|
+
// `namespace:name` form used by JupyterLab's own commands; the name
|
|
61
|
+
// itself may contain further colons.
|
|
62
|
+
const separator = commandId.indexOf(':');
|
|
63
|
+
if (separator === -1) {
|
|
64
|
+
context.report({
|
|
65
|
+
node: idArg,
|
|
66
|
+
messageId: 'missingNamespace',
|
|
67
|
+
data: { commandId }
|
|
68
|
+
});
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const segment = separator === 0
|
|
72
|
+
? 'namespace'
|
|
73
|
+
: separator === commandId.length - 1
|
|
74
|
+
? 'name'
|
|
75
|
+
: null;
|
|
76
|
+
if (segment) {
|
|
77
|
+
context.report({
|
|
78
|
+
node: idArg,
|
|
79
|
+
messageId: 'emptySegment',
|
|
80
|
+
data: { commandId, segment }
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
module.exports = commandIdConvention;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
declare const jupyterPluginActivationArgs:
|
|
1
|
+
import { TSESLint } from '@typescript-eslint/utils';
|
|
2
|
+
declare const jupyterPluginActivationArgs: TSESLint.RuleModule<"mismatchedOrder" | "incorrectType" | "missingArgument" | "extraArgument" | "appNotFirst" | "serviceManagerFirstArgNotNull" | "invalidAppType" | "wrongArgumentCount" | "unresolvableTokenType" | "optionalNotNullable", [{
|
|
3
3
|
allowedFirstArgumentNames: string[];
|
|
4
|
-
}], unknown,
|
|
4
|
+
}], unknown, TSESLint.RuleListener> & {
|
|
5
5
|
name: string;
|
|
6
6
|
};
|
|
7
7
|
export = jupyterPluginActivationArgs;
|
|
@@ -36,15 +36,36 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
36
36
|
return result;
|
|
37
37
|
};
|
|
38
38
|
})();
|
|
39
|
-
const utils_1 = require("@typescript-eslint/utils");
|
|
40
39
|
const ts = __importStar(require("typescript"));
|
|
41
40
|
const plugin_utils_1 = require("../utils/plugin-utils");
|
|
41
|
+
const type_services_1 = require("../utils/type-services");
|
|
42
42
|
const create_rule_1 = require("../utils/create-rule");
|
|
43
43
|
const DEFAULT_ALLOWED_FIRST_ARGUMENT_NAMES = ['app', '_app', '_'];
|
|
44
|
+
function unwrapParentheses(node) {
|
|
45
|
+
let current = node;
|
|
46
|
+
while (current.type === 'TSAsExpression' ||
|
|
47
|
+
current.type === 'TSTypeAssertion' ||
|
|
48
|
+
current.type === 'TSSatisfiesExpression') {
|
|
49
|
+
current = current.expression;
|
|
50
|
+
}
|
|
51
|
+
return current;
|
|
52
|
+
}
|
|
53
|
+
function extractFunctionInfo(node, fn) {
|
|
54
|
+
const params = fn.params.filter((param) => param.type === 'Identifier');
|
|
55
|
+
const paramNames = params.map(param => param.name);
|
|
56
|
+
const paramTypes = params.map(param => param.type === 'Identifier' ? (0, plugin_utils_1.extractParameterType)(param) : null);
|
|
57
|
+
const paramNodes = params.map(param => param.type === 'Identifier' ? param : null);
|
|
58
|
+
return {
|
|
59
|
+
node,
|
|
60
|
+
paramNames,
|
|
61
|
+
paramTypes,
|
|
62
|
+
paramNodes
|
|
63
|
+
};
|
|
64
|
+
}
|
|
44
65
|
/**
|
|
45
66
|
* Finds the activate function in the plugin object
|
|
46
67
|
*/
|
|
47
|
-
function findActivateFunction(node) {
|
|
68
|
+
function findActivateFunction(node, sourceCode) {
|
|
48
69
|
const activateProp = node.properties.find((prop) => prop.type === 'Property' &&
|
|
49
70
|
((prop.key.type === 'Identifier' && prop.key.name === 'activate') ||
|
|
50
71
|
(prop.key.type === 'Literal' && prop.key.value === 'activate')));
|
|
@@ -52,19 +73,38 @@ function findActivateFunction(node) {
|
|
|
52
73
|
return null;
|
|
53
74
|
}
|
|
54
75
|
const activateValue = activateProp.value;
|
|
55
|
-
// Handle both arrow functions and regular functions
|
|
76
|
+
// Handle both arrow functions and regular functions inline
|
|
56
77
|
if (activateValue.type === 'ArrowFunctionExpression' ||
|
|
57
78
|
activateValue.type === 'FunctionExpression') {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
79
|
+
return extractFunctionInfo(activateProp, activateValue);
|
|
80
|
+
}
|
|
81
|
+
// Handle referenced functions: `activate` or `activate: activatePlugin`
|
|
82
|
+
if (activateValue.type === 'Identifier' && sourceCode) {
|
|
83
|
+
const scope = sourceCode.getScope(activateValue);
|
|
84
|
+
let currentScope = scope;
|
|
85
|
+
let variable = null;
|
|
86
|
+
while (currentScope) {
|
|
87
|
+
const found = currentScope.set.get(activateValue.name);
|
|
88
|
+
if (found) {
|
|
89
|
+
variable = found;
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
currentScope = currentScope.upper;
|
|
93
|
+
}
|
|
94
|
+
if (variable && variable.defs.length > 0) {
|
|
95
|
+
const def = variable.defs[0];
|
|
96
|
+
if (def.type === 'FunctionName' &&
|
|
97
|
+
def.node.type === 'FunctionDeclaration') {
|
|
98
|
+
return extractFunctionInfo(activateProp, def.node);
|
|
99
|
+
}
|
|
100
|
+
if (def.type === 'Variable' && def.node.init) {
|
|
101
|
+
const init = unwrapParentheses(def.node.init);
|
|
102
|
+
if (init.type === 'ArrowFunctionExpression' ||
|
|
103
|
+
init.type === 'FunctionExpression') {
|
|
104
|
+
return extractFunctionInfo(activateProp, init);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
68
108
|
}
|
|
69
109
|
return null;
|
|
70
110
|
}
|
|
@@ -152,17 +192,7 @@ const jupyterPluginActivationArgs = (0, create_rule_1.createRule)({
|
|
|
152
192
|
],
|
|
153
193
|
create(context, [options]) {
|
|
154
194
|
const allowedFirstArgumentNames = options.allowedFirstArgumentNames || DEFAULT_ALLOWED_FIRST_ARGUMENT_NAMES;
|
|
155
|
-
|
|
156
|
-
let services = null;
|
|
157
|
-
let checker = null;
|
|
158
|
-
try {
|
|
159
|
-
services = utils_1.ESLintUtils.getParserServices(context, true);
|
|
160
|
-
checker = services.program ? services.program.getTypeChecker() : null;
|
|
161
|
-
}
|
|
162
|
-
catch {
|
|
163
|
-
// Parser services unavailable (e.g., non-TS file or misconfigured parser)
|
|
164
|
-
services = null;
|
|
165
|
-
}
|
|
195
|
+
const { services, checker, getTSNode } = (0, type_services_1.getTypeServices)(context);
|
|
166
196
|
/**
|
|
167
197
|
* Given the AST node for a token in requires/optional, uses the TypeScript checker to extract T from
|
|
168
198
|
* `Token<T>` and returns the TypeScript type object for T.
|
|
@@ -290,156 +320,157 @@ const jupyterPluginActivationArgs = (0, create_rule_1.createRule)({
|
|
|
290
320
|
return [false, false];
|
|
291
321
|
}
|
|
292
322
|
return {
|
|
293
|
-
|
|
294
|
-
const
|
|
295
|
-
if (!
|
|
323
|
+
ObjectExpression(pluginObj) {
|
|
324
|
+
const hasId = (0, plugin_utils_1.getObjectProperties)(pluginObj).has('id');
|
|
325
|
+
if (!hasId) {
|
|
296
326
|
return;
|
|
297
327
|
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
328
|
+
const pluginKind = (0, plugin_utils_1.getPluginObjectKind)(pluginObj, checker, getTSNode);
|
|
329
|
+
if (pluginKind !== 'frontend' && pluginKind !== 'service-manager') {
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
const { requires, optional } = extractRequiresOptional(pluginObj);
|
|
333
|
+
const activateInfo = findActivateFunction(pluginObj, context.sourceCode);
|
|
334
|
+
if (!activateInfo) {
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
const { paramNames, paramTypes, paramNodes } = activateInfo;
|
|
338
|
+
const expectedCount = 1 + requires.length + optional.length;
|
|
339
|
+
const expectedTokensWithoutApp = [...requires, ...optional];
|
|
340
|
+
if (expectedCount === 1 && paramNames.length === 0) {
|
|
341
|
+
// Special case, not invalid
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
if (pluginKind === 'frontend') {
|
|
345
|
+
// Validation 1a: Check if first argument is one of the allowed names
|
|
346
|
+
if (paramNames.length > 0 &&
|
|
347
|
+
!allowedFirstArgumentNames.includes(paramNames[0])) {
|
|
348
|
+
context.report({
|
|
349
|
+
node: activateInfo.node,
|
|
350
|
+
messageId: 'appNotFirst',
|
|
351
|
+
data: {
|
|
352
|
+
arg: paramNames[0],
|
|
353
|
+
allowedNames: allowedFirstArgumentNames
|
|
354
|
+
.map(name => `"${name}"`)
|
|
355
|
+
.join(', ')
|
|
356
|
+
}
|
|
357
|
+
});
|
|
310
358
|
return;
|
|
311
359
|
}
|
|
312
|
-
if
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
360
|
+
// Validation 1b: Check if first argument type is compatible with JupyterFrontEnd
|
|
361
|
+
if (paramNames.length > 0 && paramTypes.length > 0) {
|
|
362
|
+
const firstParamType = paramTypes[0];
|
|
363
|
+
if (!isCompatibleWithJupyterFrontEnd(firstParamType)) {
|
|
316
364
|
context.report({
|
|
317
365
|
node: activateInfo.node,
|
|
318
|
-
messageId: '
|
|
366
|
+
messageId: 'invalidAppType',
|
|
319
367
|
data: {
|
|
320
368
|
arg: paramNames[0],
|
|
321
|
-
|
|
322
|
-
.map(name => `"${name}"`)
|
|
323
|
-
.join(', ')
|
|
324
|
-
}
|
|
325
|
-
});
|
|
326
|
-
return;
|
|
327
|
-
}
|
|
328
|
-
// Validation 1b: Check if first argument type is compatible with JupyterFrontEnd
|
|
329
|
-
if (paramNames.length > 0 && paramTypes.length > 0) {
|
|
330
|
-
const firstParamType = paramTypes[0];
|
|
331
|
-
if (!isCompatibleWithJupyterFrontEnd(firstParamType)) {
|
|
332
|
-
context.report({
|
|
333
|
-
node: activateInfo.node,
|
|
334
|
-
messageId: 'invalidAppType',
|
|
335
|
-
data: {
|
|
336
|
-
arg: paramNames[0],
|
|
337
|
-
type: firstParamType || 'unknown'
|
|
338
|
-
}
|
|
339
|
-
});
|
|
340
|
-
return;
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
else if (pluginKind === 'service-manager') {
|
|
345
|
-
// Validation 1: First argument must be literal null
|
|
346
|
-
if (paramNames.length === 0 || paramTypes[0] !== null) {
|
|
347
|
-
context.report({
|
|
348
|
-
node: activateInfo.node,
|
|
349
|
-
messageId: 'serviceManagerFirstArgNotNull',
|
|
350
|
-
data: {
|
|
351
|
-
arg: paramTypes[0]
|
|
369
|
+
type: firstParamType || 'unknown'
|
|
352
370
|
}
|
|
353
371
|
});
|
|
354
372
|
return;
|
|
355
373
|
}
|
|
356
374
|
}
|
|
357
|
-
|
|
358
|
-
|
|
375
|
+
}
|
|
376
|
+
else if (pluginKind === 'service-manager') {
|
|
377
|
+
// Validation 1: First argument must be literal null
|
|
378
|
+
if (paramNames.length === 0 || paramTypes[0] !== null) {
|
|
359
379
|
context.report({
|
|
360
380
|
node: activateInfo.node,
|
|
361
|
-
messageId: '
|
|
381
|
+
messageId: 'serviceManagerFirstArgNotNull',
|
|
362
382
|
data: {
|
|
363
|
-
|
|
364
|
-
tokenCount: String(requires.length + optional.length),
|
|
365
|
-
actual: String(paramNames.length)
|
|
383
|
+
arg: paramTypes[0]
|
|
366
384
|
}
|
|
367
385
|
});
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
// Validation 2: Check if argument count matches
|
|
390
|
+
if (paramNames.length !== expectedCount) {
|
|
391
|
+
context.report({
|
|
392
|
+
node: activateInfo.node,
|
|
393
|
+
messageId: 'wrongArgumentCount',
|
|
394
|
+
data: {
|
|
395
|
+
expected: String(expectedCount),
|
|
396
|
+
tokenCount: String(requires.length + optional.length),
|
|
397
|
+
actual: String(paramNames.length)
|
|
398
|
+
}
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
// Validation 3: Validate remaining parameters against expected token order
|
|
402
|
+
const actualParamTypes = paramTypes.slice(1); // First arg already validated above
|
|
403
|
+
const actualParamNodes = paramNodes.slice(1);
|
|
404
|
+
// Validate that parameter types match expected token types in order
|
|
405
|
+
for (let i = 0; i < actualParamTypes.length; i++) {
|
|
406
|
+
const paramType = actualParamTypes[i];
|
|
407
|
+
const paramNode = actualParamNodes[i];
|
|
408
|
+
const expectedToken = expectedTokensWithoutApp[i];
|
|
409
|
+
if (expectedToken === undefined) {
|
|
410
|
+
// Extra argument
|
|
411
|
+
context.report({
|
|
412
|
+
node: activateInfo.node,
|
|
413
|
+
messageId: 'extraArgument',
|
|
414
|
+
data: { arg: paramNames[i + 1] }
|
|
415
|
+
});
|
|
368
416
|
}
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
// Validate that parameter types match expected token types in order
|
|
373
|
-
for (let i = 0; i < actualParamTypes.length; i++) {
|
|
374
|
-
const paramType = actualParamTypes[i];
|
|
375
|
-
const paramNode = actualParamNodes[i];
|
|
376
|
-
const expectedToken = expectedTokensWithoutApp[i];
|
|
377
|
-
if (expectedToken === undefined) {
|
|
378
|
-
// Extra argument
|
|
417
|
+
else {
|
|
418
|
+
const [matches, tokenUnresolved] = tokenMatchesParam(expectedToken, paramType, paramNode);
|
|
419
|
+
if (tokenUnresolved) {
|
|
379
420
|
context.report({
|
|
380
421
|
node: activateInfo.node,
|
|
381
|
-
messageId: '
|
|
382
|
-
data: {
|
|
422
|
+
messageId: 'unresolvableTokenType',
|
|
423
|
+
data: { token: expectedToken.name }
|
|
383
424
|
});
|
|
384
425
|
}
|
|
385
|
-
else {
|
|
386
|
-
|
|
387
|
-
|
|
426
|
+
else if (!matches) {
|
|
427
|
+
// Distinguish token-order conflict vs. invalid type annotation.
|
|
428
|
+
const matchesAnyOtherToken = expectedTokensWithoutApp.some((otherToken, j) => {
|
|
429
|
+
if (j === i)
|
|
430
|
+
return false;
|
|
431
|
+
const [otherMatches, tokenUnresolved] = tokenMatchesParam(otherToken, paramType, paramNode);
|
|
432
|
+
return otherMatches && !tokenUnresolved;
|
|
433
|
+
});
|
|
434
|
+
if (matchesAnyOtherToken) {
|
|
388
435
|
context.report({
|
|
389
436
|
node: activateInfo.node,
|
|
390
|
-
messageId: '
|
|
391
|
-
data: {
|
|
437
|
+
messageId: 'mismatchedOrder',
|
|
438
|
+
data: { arg: paramNames[i + 1] }
|
|
392
439
|
});
|
|
393
440
|
}
|
|
394
|
-
else
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
441
|
+
else {
|
|
442
|
+
context.report({
|
|
443
|
+
node: activateInfo.node,
|
|
444
|
+
messageId: 'incorrectType',
|
|
445
|
+
data: {
|
|
446
|
+
arg: paramNames[i + 1],
|
|
447
|
+
type: paramType,
|
|
448
|
+
expected: expectedToken.name
|
|
449
|
+
}
|
|
401
450
|
});
|
|
402
|
-
if (matchesAnyOtherToken) {
|
|
403
|
-
context.report({
|
|
404
|
-
node: activateInfo.node,
|
|
405
|
-
messageId: 'mismatchedOrder',
|
|
406
|
-
data: { arg: paramNames[i + 1] }
|
|
407
|
-
});
|
|
408
|
-
}
|
|
409
|
-
else {
|
|
410
|
-
context.report({
|
|
411
|
-
node: activateInfo.node,
|
|
412
|
-
messageId: 'incorrectType',
|
|
413
|
-
data: {
|
|
414
|
-
arg: paramNames[i + 1],
|
|
415
|
-
type: paramType,
|
|
416
|
-
expected: expectedToken.name
|
|
417
|
-
}
|
|
418
|
-
});
|
|
419
|
-
}
|
|
420
451
|
}
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
}
|
|
429
|
-
}
|
|
452
|
+
}
|
|
453
|
+
else if (i >= requires.length && paramNode) {
|
|
454
|
+
// Token matched and is optional — param must be nullable.
|
|
455
|
+
if (!isParamNullable(paramNode)) {
|
|
456
|
+
context.report({
|
|
457
|
+
node: activateInfo.node,
|
|
458
|
+
messageId: 'optionalNotNullable',
|
|
459
|
+
data: { arg: paramNames[i + 1], type: expectedToken.name }
|
|
460
|
+
});
|
|
430
461
|
}
|
|
431
462
|
}
|
|
432
463
|
}
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
}
|
|
442
|
-
}
|
|
464
|
+
}
|
|
465
|
+
// Validation 4: Check for missing arguments (only if counts don't match)
|
|
466
|
+
if (paramNames.length < expectedCount) {
|
|
467
|
+
for (let i = Math.max(paramNames.length - 1, 0); i < expectedTokensWithoutApp.length; i++) {
|
|
468
|
+
const missingToken = expectedTokensWithoutApp[i];
|
|
469
|
+
context.report({
|
|
470
|
+
node: activateInfo.node,
|
|
471
|
+
messageId: 'missingArgument',
|
|
472
|
+
data: { token: missingToken.name }
|
|
473
|
+
});
|
|
443
474
|
}
|
|
444
475
|
}
|
|
445
476
|
}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
const create_rule_1 = require("../utils/create-rule");
|
|
7
7
|
const plugin_utils_1 = require("../utils/plugin-utils");
|
|
8
|
+
const type_services_1 = require("../utils/type-services");
|
|
8
9
|
/**
|
|
9
10
|
* Returns whether the object expression has a description property and whether
|
|
10
11
|
* it is non-empty.
|
|
@@ -53,23 +54,25 @@ const jupyterPluginDescription = (0, create_rule_1.createRule)({
|
|
|
53
54
|
},
|
|
54
55
|
defaultOptions: [],
|
|
55
56
|
create(context) {
|
|
57
|
+
const { checker, getTSNode } = (0, type_services_1.getTypeServices)(context);
|
|
56
58
|
return {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
if (!
|
|
59
|
+
ObjectExpression(node) {
|
|
60
|
+
const hasId = (0, plugin_utils_1.getObjectProperties)(node).has('id');
|
|
61
|
+
if (!hasId) {
|
|
60
62
|
return;
|
|
61
63
|
}
|
|
62
|
-
|
|
63
|
-
if (
|
|
64
|
+
const pluginKind = (0, plugin_utils_1.getPluginObjectKind)(node, checker, getTSNode);
|
|
65
|
+
if (pluginKind !== 'frontend' &&
|
|
66
|
+
pluginKind !== 'service-manager' &&
|
|
67
|
+
pluginKind !== 'ambiguous') {
|
|
64
68
|
return;
|
|
65
69
|
}
|
|
66
|
-
const pluginId = (0, plugin_utils_1.getPluginId)(
|
|
70
|
+
const pluginId = (0, plugin_utils_1.getPluginId)(node, context.sourceCode.getScope(node), checker, getTSNode);
|
|
67
71
|
const pluginIdSuffix = pluginId ? ` "${pluginId}"` : '';
|
|
68
|
-
|
|
69
|
-
const descriptionStatus = checkDescriptionProperty(varDecl.init);
|
|
72
|
+
const descriptionStatus = checkDescriptionProperty(node);
|
|
70
73
|
if (descriptionStatus !== 'present') {
|
|
71
74
|
context.report({
|
|
72
|
-
node
|
|
75
|
+
node,
|
|
73
76
|
messageId: descriptionStatus === 'empty'
|
|
74
77
|
? 'emptyDescription'
|
|
75
78
|
: 'missingDescription',
|