@jupyter/eslint-plugin 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -8,34 +8,9 @@ ESLint plugin for Jupyter core and extensions with early error catching and best
8
8
  npm install --save-dev @jupyter/eslint-plugin
9
9
  ```
10
10
 
11
- ## Rules
12
-
13
- - `command-described-by` - Ensure JupyterLab commands include describedBy property
14
- - `plugin-activation-args` - Ensure JupyterLab plugin activation function arguments match requires and optional tokens in order
15
- - `plugin-description` - Ensure JupyterLab plugins have a description property
16
-
17
11
  ## Usage
18
12
 
19
- Add `jupyter` to the plugins section of your ESLint configuration:
20
-
21
- ```javascript
22
- // eslint.config.js
23
- import jupyterPlugin from '@jupyter/eslint-plugin';
24
-
25
- export default [
26
- {
27
- files: ['**/*.ts', '**/*.tsx'],
28
- plugins: {
29
- jupyter: jupyterPlugin
30
- },
31
- rules: {
32
- 'jupyter/command-described-by': 'warn',
33
- 'jupyter/plugin-activation-args': 'warn',
34
- 'jupyter/plugin-description': 'warn'
35
- }
36
- }
37
- ];
38
- ```
13
+ Add `@jupyter/eslint-plugin` to the plugins section of your ESLint configuration. For detailed usage instructions and available rules, see the [documentation](https://eslint-plugin.readthedocs.io/en/latest/).
39
14
 
40
15
  ## License
41
16
 
package/lib/index.d.ts CHANGED
@@ -1,8 +1,16 @@
1
1
  declare const plugin: {
2
2
  rules: {
3
- 'plugin-activation-args': import("eslint").Rule.RuleModule;
4
- 'command-described-by': import("eslint").Rule.RuleModule;
5
- 'plugin-description': import("eslint").Rule.RuleModule;
3
+ 'plugin-activation-args': import("@typescript-eslint/utils/dist/ts-eslint").RuleModule<"mismatchedOrder" | "missingArgument" | "extraArgument" | "appNotFirst" | "serviceManagerFirstArgNotNull" | "invalidAppType" | "wrongArgumentCount" | "unresolvableTokenType", [{
4
+ allowedFirstArgumentNames: string[];
5
+ }], unknown, import("@typescript-eslint/utils/dist/ts-eslint").RuleListener> & {
6
+ name: string;
7
+ };
8
+ 'command-described-by': import("@typescript-eslint/utils/dist/ts-eslint").RuleModule<"missingDescribedBy", [], unknown, import("@typescript-eslint/utils/dist/ts-eslint").RuleListener> & {
9
+ name: string;
10
+ };
11
+ 'plugin-description': import("@typescript-eslint/utils/dist/ts-eslint").RuleModule<"missingDescription" | "emptyDescription", [], unknown, import("@typescript-eslint/utils/dist/ts-eslint").RuleListener> & {
12
+ name: string;
13
+ };
6
14
  };
7
15
  configs: {
8
16
  recommended: {
@@ -13,6 +21,13 @@ declare const plugin: {
13
21
  'jupyter/plugin-description': string;
14
22
  };
15
23
  };
24
+ 'recommended-legacy': {
25
+ rules: {
26
+ 'jupyter/plugin-activation-args': string;
27
+ 'jupyter/command-described-by': string;
28
+ 'jupyter/plugin-description': string;
29
+ };
30
+ };
16
31
  };
17
32
  };
18
33
  export = plugin;
package/lib/index.js CHANGED
@@ -20,8 +20,15 @@ const plugin = {
20
20
  files: ['**/*.js', '**/*.ts', '**/*.jsx', '**/*.tsx'],
21
21
  rules: {
22
22
  'jupyter/plugin-activation-args': 'error',
23
- 'jupyter/command-described-by': 'error',
24
- 'jupyter/plugin-description': 'error'
23
+ 'jupyter/command-described-by': 'warn',
24
+ 'jupyter/plugin-description': 'warn'
25
+ }
26
+ },
27
+ 'recommended-legacy': {
28
+ rules: {
29
+ 'jupyter/plugin-activation-args': 'error',
30
+ 'jupyter/command-described-by': 'warn',
31
+ 'jupyter/plugin-description': 'warn'
25
32
  }
26
33
  }
27
34
  }
@@ -1,3 +1,4 @@
1
- import { Rule } from 'eslint';
2
- declare const jupyterCommandDescribedBy: Rule.RuleModule;
1
+ declare const jupyterCommandDescribedBy: import("@typescript-eslint/utils/dist/ts-eslint").RuleModule<"missingDescribedBy", [], unknown, import("@typescript-eslint/utils/dist/ts-eslint").RuleListener> & {
2
+ name: string;
3
+ };
3
4
  export = jupyterCommandDescribedBy;
@@ -5,33 +5,34 @@
5
5
  */
6
6
  const plugin_utils_1 = require("../utils/plugin-utils");
7
7
  const commands_1 = require("../utils/commands");
8
- const jupyterCommandDescribedBy = {
8
+ const create_rule_1 = require("../utils/create-rule");
9
+ const jupyterCommandDescribedBy = (0, create_rule_1.createRule)({
10
+ name: 'command-described-by',
9
11
  meta: {
10
12
  type: 'problem',
11
13
  docs: {
12
14
  description: 'Ensure JupyterLab commands include describedBy property',
13
- recommended: 'recommended',
14
- url: 'https://github.com/jupyterlab/eslint-plugin'
15
+ url: 'https://eslint-plugin.readthedocs.io/en/latest/rules/command-described-by/'
15
16
  },
16
17
  messages: {
17
18
  missingDescribedBy: 'Command "{{ commandId }}" is missing the "describedBy" property.'
18
19
  },
19
20
  schema: []
20
21
  },
22
+ defaultOptions: [],
21
23
  create(context) {
22
24
  return {
23
25
  CallExpression(node) {
24
- const callExpr = node;
25
26
  // Check if this is <something>.addCommand()
26
- if (!(0, commands_1.isAddCommandCall)(callExpr)) {
27
+ if (!(0, commands_1.isAddCommandCall)(node)) {
27
28
  return;
28
29
  }
29
30
  // Get the command ID and options
30
- if (callExpr.arguments.length < 2) {
31
+ if (node.arguments.length < 2) {
31
32
  return;
32
33
  }
33
- const commandIdArg = callExpr.arguments[0];
34
- const optionsArg = callExpr.arguments[1];
34
+ const commandIdArg = node.arguments[0];
35
+ const optionsArg = node.arguments[1];
35
36
  // Extract command ID for error message
36
37
  let commandId = 'unknown';
37
38
  if (commandIdArg.type === 'Literal' &&
@@ -51,8 +52,7 @@ const jupyterCommandDescribedBy = {
51
52
  if (optionsArg.type !== 'ObjectExpression') {
52
53
  return;
53
54
  }
54
- const options = optionsArg;
55
- const properties = (0, plugin_utils_1.getObjectProperties)(options);
55
+ const properties = (0, plugin_utils_1.getObjectProperties)(optionsArg);
56
56
  // Check if execute function exists and has parameters
57
57
  const executeProp = properties.get('execute');
58
58
  if (!executeProp || executeProp.value.type === 'Literal') {
@@ -61,7 +61,7 @@ const jupyterCommandDescribedBy = {
61
61
  const describedByProp = properties.get('describedBy');
62
62
  if (!describedByProp) {
63
63
  context.report({
64
- node: callExpr,
64
+ node,
65
65
  messageId: 'missingDescribedBy',
66
66
  data: { commandId }
67
67
  });
@@ -73,5 +73,5 @@ const jupyterCommandDescribedBy = {
73
73
  }
74
74
  };
75
75
  }
76
- };
76
+ });
77
77
  module.exports = jupyterCommandDescribedBy;
@@ -1,3 +1,7 @@
1
- import { Rule } from 'eslint';
2
- declare const jupyterPluginActivationArgs: Rule.RuleModule;
1
+ import { ESLintUtils } from '@typescript-eslint/utils';
2
+ declare const jupyterPluginActivationArgs: ESLintUtils.RuleModule<"mismatchedOrder" | "missingArgument" | "extraArgument" | "appNotFirst" | "serviceManagerFirstArgNotNull" | "invalidAppType" | "wrongArgumentCount" | "unresolvableTokenType", [{
3
+ allowedFirstArgumentNames: string[];
4
+ }], unknown, ESLintUtils.RuleListener> & {
5
+ name: string;
6
+ };
3
7
  export = jupyterPluginActivationArgs;
@@ -3,33 +3,69 @@
3
3
  * Copyright (c) Jupyter Development Team.
4
4
  * Distributed under the terms of the Modified BSD License.
5
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
+ const utils_1 = require("@typescript-eslint/utils");
40
+ const ts = __importStar(require("typescript"));
6
41
  const plugin_utils_1 = require("../utils/plugin-utils");
42
+ const create_rule_1 = require("../utils/create-rule");
7
43
  const DEFAULT_ALLOWED_FIRST_ARGUMENT_NAMES = ['app', '_app', '_'];
8
44
  /**
9
45
  * Finds the activate function in the plugin object
10
46
  */
11
47
  function findActivateFunction(node) {
12
- const activateProp = node.properties.find(prop => ((prop.type === 'Property' || prop.type === 'SpreadElement') &&
13
- prop.type === 'Property' &&
48
+ const activateProp = node.properties.find((prop) => prop.type === 'Property' &&
14
49
  ((prop.key.type === 'Identifier' && prop.key.name === 'activate') ||
15
- (prop.key.type === 'Literal' && prop.key.value === 'activate'))) ||
16
- prop.type === 'SpreadElement');
17
- if (!activateProp || activateProp.type !== 'Property') {
50
+ (prop.key.type === 'Literal' && prop.key.value === 'activate')));
51
+ if (!activateProp) {
18
52
  return null;
19
53
  }
20
54
  const activateValue = activateProp.value;
21
55
  // Handle both arrow functions and regular functions
22
- if ((activateValue.type === 'ArrowFunctionExpression' ||
23
- activateValue.type === 'FunctionExpression') &&
24
- activateValue.params) {
56
+ if (activateValue.type === 'ArrowFunctionExpression' ||
57
+ activateValue.type === 'FunctionExpression') {
25
58
  const params = activateValue.params
26
59
  .filter((param) => param.type === 'Identifier')
27
60
  .map(param => param.name);
28
- // Extract type annotations if available
29
- const paramTypes = activateValue.params
30
- .filter((param) => param.type === 'Identifier')
31
- .map(param => (0, plugin_utils_1.extractParameterType)(param));
32
- return { node: activateProp, params, paramTypes };
61
+ const paramTypes = activateValue.params.map(param => param.type === 'Identifier' ? (0, plugin_utils_1.extractParameterType)(param) : null);
62
+ const paramNodes = activateValue.params.map(param => param.type === 'Identifier' ? param : null);
63
+ return {
64
+ node: activateProp,
65
+ params,
66
+ paramTypes,
67
+ paramNodes
68
+ };
33
69
  }
34
70
  return null;
35
71
  }
@@ -41,8 +77,7 @@ function extractRequiresOptional(node) {
41
77
  requires: [],
42
78
  optional: []
43
79
  };
44
- const props = node.properties;
45
- for (const prop of props) {
80
+ for (const prop of node.properties) {
46
81
  if (prop.type !== 'Property')
47
82
  continue;
48
83
  let keyName = null;
@@ -54,11 +89,11 @@ function extractRequiresOptional(node) {
54
89
  keyName = prop.key.value;
55
90
  }
56
91
  if (keyName === 'requires' && prop.value.type === 'ArrayExpression') {
57
- result.requires = (0, plugin_utils_1.extractIdentifierNames)(prop.value);
92
+ result.requires = (0, plugin_utils_1.extractArrayTokens)(prop.value);
58
93
  }
59
94
  else if (keyName === 'optional' &&
60
95
  prop.value.type === 'ArrayExpression') {
61
- result.optional = (0, plugin_utils_1.extractIdentifierNames)(prop.value);
96
+ result.optional = (0, plugin_utils_1.extractArrayTokens)(prop.value);
62
97
  }
63
98
  }
64
99
  return result;
@@ -70,28 +105,26 @@ function isCompatibleWithJupyterFrontEnd(typeName) {
70
105
  if (!typeName) {
71
106
  return true; // If we can't check, we allow it
72
107
  }
73
- const compatibleTypes = [
74
- 'JupyterFrontEnd',
75
- 'JupyterLab',
76
- 'Application'
77
- ];
108
+ const compatibleTypes = ['JupyterFrontEnd', 'JupyterLab', 'Application'];
78
109
  return compatibleTypes.includes(typeName);
79
110
  }
80
- const jupyterPluginActivationArgs = {
111
+ const jupyterPluginActivationArgs = (0, create_rule_1.createRule)({
112
+ name: 'plugin-activation-args',
81
113
  meta: {
82
114
  type: 'problem',
83
115
  docs: {
84
116
  description: 'Ensure JupyterLab plugin activation function arguments match requires and optional tokens in order',
85
- recommended: 'recommended',
86
- url: 'https://github.com/jupyterlab/eslint-plugin'
117
+ url: 'https://eslint-plugin.readthedocs.io/en/latest/rules/plugin-activation-args/'
87
118
  },
88
119
  messages: {
89
120
  mismatchedOrder: 'Activation argument "{{ arg }}" does not match the order of requires/optional tokens.',
90
121
  missingArgument: 'Token "{{ token }}" from requires/optional is missing in activation arguments.',
91
122
  extraArgument: 'Activation argument "{{ arg }}" is not in requires/optional tokens.',
92
123
  appNotFirst: 'First activation argument must be one of [{{ allowedNames }}] (JupyterFrontEnd), got "{{ arg }}".',
124
+ serviceManagerFirstArgNotNull: 'First activation argument for ServiceManagerPlugin must be null, got "{{ arg }}".',
93
125
  invalidAppType: 'First activation argument "{{ arg }}" has invalid type "{{ type }}". Expected JupyterFrontEnd, JupyterLab, or Application.',
94
- wrongArgumentCount: 'Expected {{ expected }} activation arguments (app + {{ tokenCount }} tokens), got {{ actual }}.'
126
+ wrongArgumentCount: 'Expected {{ expected }} activation arguments (app + {{ tokenCount }} tokens), got {{ actual }}.',
127
+ unresolvableTokenType: 'Token "{{ token }}" type could not be resolved — package may be unbuilt. Build it for accurate type checking.'
95
128
  },
96
129
  fixable: 'code',
97
130
  schema: [
@@ -111,52 +144,176 @@ const jupyterPluginActivationArgs = {
111
144
  }
112
145
  ]
113
146
  },
114
- create(context) {
115
- // Get configuration options
116
- const options = context.options[0] || {};
147
+ defaultOptions: [
148
+ {
149
+ allowedFirstArgumentNames: DEFAULT_ALLOWED_FIRST_ARGUMENT_NAMES
150
+ }
151
+ ],
152
+ create(context, [options]) {
117
153
  const allowedFirstArgumentNames = options.allowedFirstArgumentNames || DEFAULT_ALLOWED_FIRST_ARGUMENT_NAMES;
154
+ // Try to obtain the TypeScript type checker for type-aware comparisons.
155
+ let services = null;
156
+ let checker = null;
157
+ try {
158
+ services = utils_1.ESLintUtils.getParserServices(context, true);
159
+ checker = services.program ? services.program.getTypeChecker() : null;
160
+ }
161
+ catch {
162
+ // Parser services unavailable (e.g., non-TS file or misconfigured parser)
163
+ services = null;
164
+ }
165
+ /**
166
+ * Given the AST node for a token in requires/optional, uses the TypeScript checker to extract T from
167
+ * `Token<T>` and returns the TypeScript type object for T.
168
+ * Returns null when type information is unavailable or extraction fails.
169
+ */
170
+ function resolveTokenInnerType(tokenNode) {
171
+ if (!checker) {
172
+ return null;
173
+ }
174
+ try {
175
+ const tsNode = services?.esTreeNodeToTSNodeMap.get(tokenNode);
176
+ if (!tsNode) {
177
+ return null;
178
+ }
179
+ const tokenType = checker.getTypeAtLocation(tsNode);
180
+ const typeArgs = checker.getTypeArguments(tokenType);
181
+ if (typeArgs && typeArgs.length > 0) {
182
+ return typeArgs[0];
183
+ }
184
+ }
185
+ catch {
186
+ // Fall through
187
+ }
188
+ return null;
189
+ }
190
+ /**
191
+ * Given the AST node for an activate parameter identifier, uses the
192
+ * TypeScript checker to get its type.
193
+ * Returns null when type information is unavailable or extraction fails.
194
+ */
195
+ function resolveParamType(paramNode) {
196
+ if (!checker)
197
+ return null;
198
+ try {
199
+ const tsNode = services?.esTreeNodeToTSNodeMap.get(paramNode);
200
+ if (!tsNode)
201
+ return null;
202
+ const type = checker.getTypeAtLocation(tsNode);
203
+ // Handle `T | null/undefined` (optional token pattern)
204
+ if (type.isUnion()) {
205
+ const nonNullTypes = type.types.filter(t => !(t.flags & ts.TypeFlags.Null) &&
206
+ !(t.flags & ts.TypeFlags.Undefined));
207
+ if (nonNullTypes.length === 1) {
208
+ return nonNullTypes[0];
209
+ }
210
+ }
211
+ return type;
212
+ }
213
+ catch {
214
+ // Fall through
215
+ }
216
+ return null;
217
+ }
218
+ /**
219
+ * Returns true when two TypeScript types refer to the same type.
220
+ */
221
+ function isSameType(a, b) {
222
+ if (a === b)
223
+ return true;
224
+ if (a.symbol && b.symbol && a.symbol === b.symbol)
225
+ return true;
226
+ return checker.typeToString(a) === checker.typeToString(b);
227
+ }
228
+ /**
229
+ * Returns [matches, tokenUnresolved] where:
230
+ * - matches: true when the activate parameter type is compatible with the token's type.
231
+ * - tokenUnresolved: true when the token's inner type could not be resolved (null, undefined, or any),
232
+ * meaning the result is inconclusive (e.g. package is unbuilt).
233
+ */
234
+ function tokenMatchesParam(token, paramType, paramNode) {
235
+ // For most cases this check is sufficient
236
+ if (paramType === token.name)
237
+ return [true, false];
238
+ if (checker && paramNode) {
239
+ const resolvedToken = resolveTokenInnerType(token.node);
240
+ const tokenUnresolved = resolvedToken === null ||
241
+ resolvedToken === undefined ||
242
+ !!(resolvedToken.flags & ts.TypeFlags.Any);
243
+ if (tokenUnresolved) {
244
+ return [true, true];
245
+ }
246
+ const resolvedParam = resolveParamType(paramNode);
247
+ if (resolvedParam !== null) {
248
+ return [isSameType(resolvedToken, resolvedParam), false];
249
+ }
250
+ }
251
+ // Without a checker we cannot resolve namespace patterns like
252
+ // `IDebugger.ISidebar` ↔ `IDebuggerSidebar`.
253
+ if (!checker && paramType && paramType.includes('.'))
254
+ return [true, false];
255
+ return [false, false];
256
+ }
118
257
  return {
119
258
  VariableDeclarator(node) {
120
- const varDecl = node;
121
- if (!(0, plugin_utils_1.hasJupyterPluginType)(varDecl)) {
259
+ const pluginKind = (0, plugin_utils_1.getJupyterPluginKind)(node);
260
+ if (!pluginKind) {
122
261
  return;
123
262
  }
124
- if (varDecl.init && varDecl.init.type === 'ObjectExpression') {
125
- const pluginObj = varDecl.init;
263
+ if (node.init && node.init.type === 'ObjectExpression') {
264
+ const pluginObj = node.init;
126
265
  const { requires, optional } = extractRequiresOptional(pluginObj);
127
266
  const activateInfo = findActivateFunction(pluginObj);
128
267
  if (!activateInfo) {
129
268
  return;
130
269
  }
131
- const { params, paramTypes } = activateInfo;
270
+ const { params, paramTypes, paramNodes } = activateInfo;
132
271
  const expectedCount = 1 + requires.length + optional.length;
133
272
  const expectedTokensWithoutApp = [...requires, ...optional];
134
273
  if (expectedCount === 1 && params.length === 0) {
135
274
  // Special case, not invalid
136
275
  return;
137
276
  }
138
- // Validation 1a: Check if first argument is one of the allowed names
139
- if (params.length > 0 && !allowedFirstArgumentNames.includes(params[0])) {
140
- context.report({
141
- node: activateInfo.node,
142
- messageId: 'appNotFirst',
143
- data: {
144
- arg: params[0],
145
- allowedNames: allowedFirstArgumentNames.map(name => `"${name}"`).join(', ')
277
+ if (pluginKind === 'frontend') {
278
+ // Validation 1a: Check if first argument is one of the allowed names
279
+ if (params.length > 0 &&
280
+ !allowedFirstArgumentNames.includes(params[0])) {
281
+ context.report({
282
+ node: activateInfo.node,
283
+ messageId: 'appNotFirst',
284
+ data: {
285
+ arg: params[0],
286
+ allowedNames: allowedFirstArgumentNames
287
+ .map(name => `"${name}"`)
288
+ .join(', ')
289
+ }
290
+ });
291
+ return;
292
+ }
293
+ // Validation 1b: Check if first argument type is compatible with JupyterFrontEnd
294
+ if (params.length > 0 && paramTypes.length > 0) {
295
+ const firstParamType = paramTypes[0];
296
+ if (!isCompatibleWithJupyterFrontEnd(firstParamType)) {
297
+ context.report({
298
+ node: activateInfo.node,
299
+ messageId: 'invalidAppType',
300
+ data: {
301
+ arg: params[0],
302
+ type: firstParamType || 'unknown'
303
+ }
304
+ });
305
+ return;
146
306
  }
147
- });
148
- return;
307
+ }
149
308
  }
150
- // Validation 1b: Check if first argument type is compatible with JupyterFrontEnd
151
- if (params.length > 0 && paramTypes.length > 0) {
152
- const firstParamType = paramTypes[0];
153
- if (!isCompatibleWithJupyterFrontEnd(firstParamType)) {
309
+ else if (pluginKind === 'service-manager') {
310
+ // Validation 1: First argument must be literal null
311
+ if (params.length === 0 || paramTypes[0] !== null) {
154
312
  context.report({
155
313
  node: activateInfo.node,
156
- messageId: 'invalidAppType',
314
+ messageId: 'serviceManagerFirstArgNotNull',
157
315
  data: {
158
- arg: params[0],
159
- type: firstParamType || 'unknown'
316
+ arg: paramTypes[0]
160
317
  }
161
318
  });
162
319
  return;
@@ -175,12 +332,14 @@ const jupyterPluginActivationArgs = {
175
332
  });
176
333
  }
177
334
  // Validation 3: If parameters have type annotations, validate order
178
- const actualParamTypes = paramTypes.slice(1); // Already validated above
179
- const hasTypeInfo = actualParamTypes.some((t) => t !== null);
335
+ const actualParamTypes = paramTypes.slice(1); // First arg already validated above
336
+ const actualParamNodes = paramNodes.slice(1);
337
+ const hasTypeInfo = actualParamTypes.some(t => t !== null);
180
338
  if (hasTypeInfo) {
181
339
  // Validate that parameter types match expected token types in order
182
340
  for (let i = 0; i < actualParamTypes.length; i++) {
183
341
  const paramType = actualParamTypes[i];
342
+ const paramNode = actualParamNodes[i];
184
343
  const expectedToken = expectedTokensWithoutApp[i];
185
344
  if (expectedToken === undefined) {
186
345
  // Extra argument
@@ -192,13 +351,22 @@ const jupyterPluginActivationArgs = {
192
351
  });
193
352
  }
194
353
  }
195
- else if (paramType !== null && paramType !== expectedToken) {
196
- // Type mismatch
197
- context.report({
198
- node: activateInfo.node,
199
- messageId: 'mismatchedOrder',
200
- data: { arg: params[i + 1] }
201
- });
354
+ else {
355
+ const [matches, tokenUnresolved] = tokenMatchesParam(expectedToken, paramType, paramNode);
356
+ if (tokenUnresolved) {
357
+ context.report({
358
+ node: activateInfo.node,
359
+ messageId: 'unresolvableTokenType',
360
+ data: { token: expectedToken.name }
361
+ });
362
+ }
363
+ else if (!matches) {
364
+ context.report({
365
+ node: activateInfo.node,
366
+ messageId: 'mismatchedOrder',
367
+ data: { arg: params[i + 1] }
368
+ });
369
+ }
202
370
  }
203
371
  }
204
372
  }
@@ -215,12 +383,12 @@ const jupyterPluginActivationArgs = {
215
383
  }
216
384
  // Validation 4: Check for missing arguments (only if counts don't match)
217
385
  if (params.length < expectedCount) {
218
- for (let i = params.length - 1; i < expectedTokensWithoutApp.length; i++) {
386
+ for (let i = Math.max(params.length - 1, 0); i < expectedTokensWithoutApp.length; i++) {
219
387
  const missingToken = expectedTokensWithoutApp[i];
220
388
  context.report({
221
389
  node: activateInfo.node,
222
390
  messageId: 'missingArgument',
223
- data: { token: missingToken }
391
+ data: { token: missingToken.name }
224
392
  });
225
393
  }
226
394
  }
@@ -228,5 +396,5 @@ const jupyterPluginActivationArgs = {
228
396
  }
229
397
  };
230
398
  }
231
- };
399
+ });
232
400
  module.exports = jupyterPluginActivationArgs;
@@ -1,3 +1,4 @@
1
- import { Rule } from 'eslint';
2
- declare const jupyterPluginDescription: Rule.RuleModule;
1
+ declare const jupyterPluginDescription: import("@typescript-eslint/utils/dist/ts-eslint").RuleModule<"missingDescription" | "emptyDescription", [], unknown, import("@typescript-eslint/utils/dist/ts-eslint").RuleListener> & {
2
+ name: string;
3
+ };
3
4
  export = jupyterPluginDescription;
@@ -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 create_rule_1 = require("../utils/create-rule");
6
7
  const plugin_utils_1 = require("../utils/plugin-utils");
7
8
  /**
8
9
  * Checks if an object expression has a description property
@@ -30,13 +31,13 @@ function hasDescriptionProperty(obj) {
30
31
  }
31
32
  return false;
32
33
  }
33
- const jupyterPluginDescription = {
34
+ const jupyterPluginDescription = (0, create_rule_1.createRule)({
35
+ name: 'plugin-description',
34
36
  meta: {
35
37
  type: 'problem',
36
38
  docs: {
37
39
  description: 'Ensure all JupyterLab plugins have a description property',
38
- recommended: 'recommended',
39
- url: 'https://github.com/jupyterlab/eslint-plugin'
40
+ url: 'https://eslint-plugin.readthedocs.io/en/latest/rules/plugin-description/'
40
41
  },
41
42
  messages: {
42
43
  missingDescription: 'JupyterLab plugin{{ pluginId }} is missing a "description" property.',
@@ -44,25 +45,24 @@ const jupyterPluginDescription = {
44
45
  },
45
46
  schema: []
46
47
  },
48
+ defaultOptions: [],
47
49
  create(context) {
48
50
  return {
49
- VariableDeclarator(node) {
50
- const varDecl = node;
51
+ VariableDeclarator(varDecl) {
51
52
  // Check if this has a JupyterFrontEndPlugin type annotation
52
- if (!(0, plugin_utils_1.hasJupyterPluginType)(varDecl)) {
53
+ if (!(0, plugin_utils_1.getJupyterPluginKind)(varDecl)) {
53
54
  return;
54
55
  }
55
56
  // Check if init is an object expression
56
57
  if (!varDecl.init || varDecl.init.type !== 'ObjectExpression') {
57
58
  return;
58
59
  }
59
- const pluginObj = varDecl.init;
60
- const pluginId = (0, plugin_utils_1.getPluginId)(pluginObj);
60
+ const pluginId = (0, plugin_utils_1.getPluginId)(varDecl.init);
61
61
  const pluginIdSuffix = pluginId ? ` "${pluginId}"` : '';
62
62
  // Check if description property exists
63
- if (!hasDescriptionProperty(pluginObj)) {
63
+ if (!hasDescriptionProperty(varDecl.init)) {
64
64
  context.report({
65
- node: pluginObj,
65
+ node: varDecl.init,
66
66
  messageId: 'missingDescription',
67
67
  data: { pluginId: pluginIdSuffix }
68
68
  });
@@ -70,5 +70,5 @@ const jupyterPluginDescription = {
70
70
  }
71
71
  };
72
72
  }
73
- };
73
+ });
74
74
  module.exports = jupyterPluginDescription;
@@ -1,5 +1,5 @@
1
- import * as ESTree from 'estree';
1
+ import { TSESTree } from '@typescript-eslint/types';
2
2
  /**
3
3
  * Checks if a node represents *.addCommand()
4
4
  */
5
- export declare function isAddCommandCall(node: ESTree.CallExpression): boolean;
5
+ export declare function isAddCommandCall(node: TSESTree.CallExpression): boolean;
@@ -0,0 +1,4 @@
1
+ import { ESLintUtils } from '@typescript-eslint/utils';
2
+ export declare const createRule: <Options extends readonly unknown[], MessageIds extends string>({ meta, name, ...rule }: Readonly<ESLintUtils.RuleWithMetaAndName<Options, MessageIds, unknown>>) => ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener> & {
3
+ name: string;
4
+ };
@@ -0,0 +1,9 @@
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.createRule = void 0;
8
+ const utils_1 = require("@typescript-eslint/utils");
9
+ exports.createRule = utils_1.ESLintUtils.RuleCreator(name => `https://eslint-plugin.readthedocs.io/en/latest/rules/${name}/`);
@@ -1,23 +1,23 @@
1
- import * as ESTree from 'estree';
1
+ import { TSESTree } from '@typescript-eslint/types';
2
+ export type JupyterPluginKind = 'frontend' | 'service-manager';
2
3
  /**
3
- * Extracts properties from an object expression
4
+ * Gets plugin kind from a variable declaration type annotation.
4
5
  */
5
- export declare function getObjectProperties(obj: ESTree.ObjectExpression): Map<string, ESTree.Property>;
6
+ export declare function getJupyterPluginKind(node: TSESTree.VariableDeclarator): JupyterPluginKind | null;
6
7
  /**
7
- * Checks if a variable declaration has a JupyterFrontEndPlugin type annotation
8
+ * Extracts properties from an object expression
8
9
  */
9
- export declare function hasJupyterPluginType(node: ESTree.VariableDeclarator): boolean;
10
+ export declare function getObjectProperties(obj: TSESTree.ObjectExpression): Map<string, TSESTree.Property>;
10
11
  /**
11
12
  * Gets the plugin ID from an object expression
12
13
  */
13
- export declare function getPluginId(obj: ESTree.ObjectExpression): string | null;
14
- /**
15
- * Extracts identifier names from an array expression
16
- * Useful for extracting token names from requires/optional arrays
17
- */
18
- export declare function extractIdentifierNames(arrayNode: ESTree.ArrayExpression): string[];
14
+ export declare function getPluginId(obj: TSESTree.ObjectExpression): string | null;
15
+ export interface TokenEntry {
16
+ name: string;
17
+ node: TSESTree.Node;
18
+ }
19
19
  /**
20
- * Extracts type annotation from a function parameter
21
- * Returns the type name if it has a type annotation, null otherwise
20
+ * Extracts token names and nodes from an array, including member expressions like JupyterFrontEnd.IPaths
22
21
  */
23
- export declare function extractParameterType(param: ESTree.Identifier): string | null;
22
+ export declare function extractArrayTokens(arrayExpr: TSESTree.ArrayExpression): TokenEntry[];
23
+ export declare function extractParameterType(param: TSESTree.Identifier): string | null;
@@ -4,11 +4,32 @@
4
4
  * Distributed under the terms of the Modified BSD License.
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.getJupyterPluginKind = getJupyterPluginKind;
7
8
  exports.getObjectProperties = getObjectProperties;
8
- exports.hasJupyterPluginType = hasJupyterPluginType;
9
9
  exports.getPluginId = getPluginId;
10
- exports.extractIdentifierNames = extractIdentifierNames;
10
+ exports.extractArrayTokens = extractArrayTokens;
11
11
  exports.extractParameterType = extractParameterType;
12
+ /**
13
+ * Gets plugin kind from a variable declaration type annotation.
14
+ */
15
+ function getJupyterPluginKind(node) {
16
+ const id = node.id;
17
+ if (id.type !== 'Identifier' || !id.typeAnnotation) {
18
+ return null;
19
+ }
20
+ const typeNode = id.typeAnnotation.typeAnnotation;
21
+ if (typeNode.type !== 'TSTypeReference') {
22
+ return null;
23
+ }
24
+ const pluginTypeName = extractTypeName(typeNode.typeName);
25
+ if (pluginTypeName === 'JupyterFrontEndPlugin') {
26
+ return 'frontend';
27
+ }
28
+ if (pluginTypeName === 'ServiceManagerPlugin') {
29
+ return 'service-manager';
30
+ }
31
+ return null;
32
+ }
12
33
  /**
13
34
  * Extracts properties from an object expression
14
35
  */
@@ -31,27 +52,6 @@ function getObjectProperties(obj) {
31
52
  }
32
53
  return props;
33
54
  }
34
- /**
35
- * Checks if a variable declaration has a JupyterFrontEndPlugin type annotation
36
- */
37
- function hasJupyterPluginType(node) {
38
- // Check if the variable declarator has a type annotation
39
- const id = node.id;
40
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
41
- if (id.typeAnnotation) {
42
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
43
- const typeAnnotation = id.typeAnnotation;
44
- if (typeAnnotation.typeAnnotation) {
45
- const typeNode = typeAnnotation.typeAnnotation;
46
- if (typeNode.type === 'TSTypeReference' && typeNode.typeName) {
47
- if (typeNode.typeName.type === 'Identifier') {
48
- return typeNode.typeName.name === 'JupyterFrontEndPlugin';
49
- }
50
- }
51
- }
52
- }
53
- return false;
54
- }
55
55
  /**
56
56
  * Gets the plugin ID from an object expression
57
57
  */
@@ -77,48 +77,59 @@ function getPluginId(obj) {
77
77
  return null;
78
78
  }
79
79
  /**
80
- * Extracts identifier names from an array expression
81
- * Useful for extracting token names from requires/optional arrays
80
+ * Extracts token names and nodes from an array, including member expressions like JupyterFrontEnd.IPaths
82
81
  */
83
- function extractIdentifierNames(arrayNode) {
84
- return arrayNode.elements
85
- .filter((elem) => {
86
- return elem !== null && elem.type === 'Identifier';
87
- })
88
- .map(id => id.name);
82
+ function extractArrayTokens(arrayExpr) {
83
+ const entries = [];
84
+ for (const element of arrayExpr.elements) {
85
+ if (element === null)
86
+ continue;
87
+ if (element.type === 'Identifier') {
88
+ entries.push({ name: element.name, node: element });
89
+ }
90
+ else if (element.type === 'MemberExpression') {
91
+ if (element.object.type === 'Identifier' &&
92
+ element.property.type === 'Identifier') {
93
+ entries.push({
94
+ name: `${element.object.name}.${element.property.name}`,
95
+ node: element
96
+ });
97
+ }
98
+ }
99
+ }
100
+ return entries;
101
+ }
102
+ function extractParameterType(param) {
103
+ if (!param.typeAnnotation) {
104
+ return null;
105
+ }
106
+ const typeNode = param.typeAnnotation.typeAnnotation;
107
+ // Handle TSTypeReference (like JupyterFrontEnd.IPaths)
108
+ if (typeNode.type === 'TSTypeReference') {
109
+ return extractTypeName(typeNode.typeName);
110
+ }
111
+ if (typeNode.type === 'TSUnionType') {
112
+ const nonNullType = typeNode.types.find(t => t.type !== 'TSNullKeyword');
113
+ if (nonNullType && nonNullType.type === 'TSTypeReference') {
114
+ return extractTypeName(nonNullType.typeName);
115
+ }
116
+ }
117
+ return null;
89
118
  }
90
119
  /**
91
- * Extracts type annotation from a function parameter
92
- * Returns the type name if it has a type annotation, null otherwise
120
+ * Recursively extracts the full name from a TSTypeReference typeName node,
121
+ * handling both simple Identifiers and qualified names (TSQualifiedName)
122
+ * e.g. `IType` -> "IType", `JupyterFrontEnd.IPaths` -> "JupyterFrontEnd.IPaths"
93
123
  */
94
- function extractParameterType(param) {
95
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
96
- if (param.typeAnnotation) {
97
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
98
- const annotation = param.typeAnnotation;
99
- if (annotation && annotation.typeAnnotation) {
100
- const typeNode = annotation.typeAnnotation;
101
- // Handle TSTypeReference (e.g., type: IType)
102
- if (typeNode.type === 'TSTypeReference' && typeNode.typeName) {
103
- if (typeNode.typeName.type === 'Identifier') {
104
- return typeNode.typeName.name;
105
- }
106
- }
107
- // Handle TSUnionType (e.g., type: IType | null)
108
- if (typeNode.type === 'TSUnionType') {
109
- const types = typeNode.types;
110
- if (Array.isArray(types) && types.length > 0) {
111
- const nonNullType = types.find(
112
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
113
- (t) => t.type !== 'TSNullKeyword');
114
- if (nonNullType && nonNullType.type === 'TSTypeReference') {
115
- if (nonNullType.typeName &&
116
- nonNullType.typeName.type === 'Identifier') {
117
- return nonNullType.typeName.name;
118
- }
119
- }
120
- }
121
- }
124
+ function extractTypeName(typeName) {
125
+ if (typeName.type === 'Identifier') {
126
+ return typeName.name;
127
+ }
128
+ if (typeName.type === 'TSQualifiedName') {
129
+ const left = extractTypeName(typeName.left);
130
+ const right = typeName.right?.name;
131
+ if (left && right) {
132
+ return `${left}.${right}`;
122
133
  }
123
134
  }
124
135
  return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jupyter/eslint-plugin",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "ESLint plugin for Jupyter core and extensions with early error catching and best practices enforcement",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -15,7 +15,11 @@
15
15
  "lint": "eslint",
16
16
  "lint:fix": "eslint --fix",
17
17
  "format": "prettier --write .",
18
- "format:check": "prettier --check ."
18
+ "format:check": "prettier --check .",
19
+ "docs:start": "npm --prefix website run start",
20
+ "docs:build": "npm --prefix website run build",
21
+ "docs:serve": "npm --prefix website run serve",
22
+ "docs:clear": "npm --prefix website run clear"
19
23
  },
20
24
  "keywords": [
21
25
  "eslint",
@@ -48,10 +52,10 @@
48
52
  "@types/eslint": "^9.6.1",
49
53
  "@types/estree": "^1.0.8",
50
54
  "@types/jest": "^30.0.0",
51
- "@types/node": "^25.2.0",
55
+ "@types/node": "^25.3.5",
52
56
  "@typescript-eslint/eslint-plugin": "^8.54.0",
53
57
  "@typescript-eslint/parser": "^8.54.0",
54
- "@typescript-eslint/utils": "^8.54.0",
58
+ "@typescript-eslint/rule-tester": "^8.57.0",
55
59
  "eslint": "^9.39.2",
56
60
  "eslint-plugin": "^1.0.1",
57
61
  "jest": "^30.2.0",
@@ -60,6 +64,9 @@
60
64
  "ts-jest": "^29.4.6",
61
65
  "typescript": "^5.9.3"
62
66
  },
67
+ "dependencies": {
68
+ "@typescript-eslint/utils": "^8.54.0"
69
+ },
63
70
  "peerDependencies": {
64
71
  "eslint": ">=9.0.0"
65
72
  },