@jupyter/eslint-plugin 0.0.2 → 0.0.4

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.
@@ -3,33 +3,68 @@
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
- .filter((param) => param.type === 'Identifier')
27
- .map(param => param.name);
28
- const paramTypes = activateValue.params.map(param => param.type === 'Identifier' ? (0, plugin_utils_1.extractParameterType)(param) : null);
59
+ .filter((param) => param.type === 'Identifier');
60
+ const paramNames = params.map(param => param.name);
61
+ const paramTypes = params.map(param => param.type === 'Identifier' ? (0, plugin_utils_1.extractParameterType)(param) : null);
62
+ const paramNodes = params.map(param => param.type === 'Identifier' ? param : null);
29
63
  return {
30
64
  node: activateProp,
31
- params,
65
+ paramNames,
32
66
  paramTypes,
67
+ paramNodes
33
68
  };
34
69
  }
35
70
  return null;
@@ -42,8 +77,7 @@ function extractRequiresOptional(node) {
42
77
  requires: [],
43
78
  optional: []
44
79
  };
45
- const props = node.properties;
46
- for (const prop of props) {
80
+ for (const prop of node.properties) {
47
81
  if (prop.type !== 'Property')
48
82
  continue;
49
83
  let keyName = null;
@@ -55,11 +89,11 @@ function extractRequiresOptional(node) {
55
89
  keyName = prop.key.value;
56
90
  }
57
91
  if (keyName === 'requires' && prop.value.type === 'ArrayExpression') {
58
- result.requires = (0, plugin_utils_1.extractArrayElements)(prop.value);
92
+ result.requires = (0, plugin_utils_1.extractArrayTokens)(prop.value);
59
93
  }
60
94
  else if (keyName === 'optional' &&
61
95
  prop.value.type === 'ArrayExpression') {
62
- result.optional = (0, plugin_utils_1.extractArrayElements)(prop.value);
96
+ result.optional = (0, plugin_utils_1.extractArrayTokens)(prop.value);
63
97
  }
64
98
  }
65
99
  return result;
@@ -71,29 +105,27 @@ function isCompatibleWithJupyterFrontEnd(typeName) {
71
105
  if (!typeName) {
72
106
  return true; // If we can't check, we allow it
73
107
  }
74
- const compatibleTypes = [
75
- 'JupyterFrontEnd',
76
- 'JupyterLab',
77
- 'Application'
78
- ];
108
+ const compatibleTypes = ['JupyterFrontEnd', 'JupyterLab', 'Application'];
79
109
  return compatibleTypes.includes(typeName);
80
110
  }
81
- const jupyterPluginActivationArgs = {
111
+ const jupyterPluginActivationArgs = (0, create_rule_1.createRule)({
112
+ name: 'plugin-activation-args',
82
113
  meta: {
83
114
  type: 'problem',
84
115
  docs: {
85
116
  description: 'Ensure JupyterLab plugin activation function arguments match requires and optional tokens in order',
86
- recommended: 'recommended',
87
- url: 'https://github.com/jupyterlab/eslint-plugin'
117
+ url: 'https://eslint-plugin.readthedocs.io/en/latest/rules/plugin-activation-args/'
88
118
  },
89
119
  messages: {
90
120
  mismatchedOrder: 'Activation argument "{{ arg }}" does not match the order of requires/optional tokens.',
121
+ incorrectType: 'Activation argument "{{ arg }}" has incorrect type annotation "{{ type }}". Expected type "{{ expected }}".',
91
122
  missingArgument: 'Token "{{ token }}" from requires/optional is missing in activation arguments.',
92
123
  extraArgument: 'Activation argument "{{ arg }}" is not in requires/optional tokens.',
93
124
  appNotFirst: 'First activation argument must be one of [{{ allowedNames }}] (JupyterFrontEnd), got "{{ arg }}".',
94
125
  serviceManagerFirstArgNotNull: 'First activation argument for ServiceManagerPlugin must be null, got "{{ arg }}".',
95
126
  invalidAppType: 'First activation argument "{{ arg }}" has invalid type "{{ type }}". Expected JupyterFrontEnd, JupyterLab, or Application.',
96
- wrongArgumentCount: 'Expected {{ expected }} activation arguments (app + {{ tokenCount }} tokens), got {{ actual }}.'
127
+ wrongArgumentCount: 'Expected {{ expected }} activation arguments (app + {{ tokenCount }} tokens), got {{ actual }}.',
128
+ unresolvableTokenType: 'Token "{{ token }}" type could not be resolved. The package may be unbuilt or type checking may not be configured.'
97
129
  },
98
130
  fixable: 'code',
99
131
  schema: [
@@ -113,40 +145,148 @@ const jupyterPluginActivationArgs = {
113
145
  }
114
146
  ]
115
147
  },
116
- create(context) {
117
- // Get configuration options
118
- const options = context.options[0] || {};
148
+ defaultOptions: [
149
+ {
150
+ allowedFirstArgumentNames: DEFAULT_ALLOWED_FIRST_ARGUMENT_NAMES
151
+ }
152
+ ],
153
+ create(context, [options]) {
119
154
  const allowedFirstArgumentNames = options.allowedFirstArgumentNames || DEFAULT_ALLOWED_FIRST_ARGUMENT_NAMES;
155
+ // Try to obtain the TypeScript type checker for type-aware comparisons.
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
+ }
166
+ /**
167
+ * Given the AST node for a token in requires/optional, uses the TypeScript checker to extract T from
168
+ * `Token<T>` and returns the TypeScript type object for T.
169
+ * Returns null when type information is unavailable or extraction fails.
170
+ */
171
+ function resolveTokenInnerType(tokenNode) {
172
+ if (!checker) {
173
+ return null;
174
+ }
175
+ try {
176
+ const tsNode = services?.esTreeNodeToTSNodeMap.get(tokenNode);
177
+ if (!tsNode) {
178
+ return null;
179
+ }
180
+ const tokenType = checker.getTypeAtLocation(tsNode);
181
+ const typeArgs = checker.getTypeArguments(tokenType);
182
+ if (typeArgs && typeArgs.length > 0) {
183
+ return typeArgs[0];
184
+ }
185
+ }
186
+ catch {
187
+ // Fall through
188
+ }
189
+ return null;
190
+ }
191
+ /**
192
+ * Given the AST node for an activate parameter identifier, uses the
193
+ * TypeScript checker to get its type.
194
+ * Returns null when type information is unavailable or extraction fails.
195
+ */
196
+ function resolveParamType(paramNode) {
197
+ if (!checker)
198
+ return null;
199
+ try {
200
+ const tsNode = services?.esTreeNodeToTSNodeMap.get(paramNode);
201
+ if (!tsNode)
202
+ return null;
203
+ const type = checker.getTypeAtLocation(tsNode);
204
+ // Handle `T | null/undefined` (optional token pattern)
205
+ if (type.isUnion()) {
206
+ const nonNullTypes = type.types.filter(t => !(t.flags & ts.TypeFlags.Null) &&
207
+ !(t.flags & ts.TypeFlags.Undefined));
208
+ if (nonNullTypes.length === 1) {
209
+ return nonNullTypes[0];
210
+ }
211
+ }
212
+ return type;
213
+ }
214
+ catch {
215
+ // Fall through
216
+ }
217
+ return null;
218
+ }
219
+ /**
220
+ * Returns true when two TypeScript types refer to the same type.
221
+ */
222
+ function isSameType(a, b) {
223
+ if (a === b)
224
+ return true;
225
+ if (a.symbol && b.symbol && a.symbol === b.symbol)
226
+ return true;
227
+ return checker.typeToString(a) === checker.typeToString(b);
228
+ }
229
+ /**
230
+ * Returns [matches, tokenUnresolved] where:
231
+ * - matches: true when the activate parameter type is compatible with the token's type.
232
+ * - tokenUnresolved: true when the token's inner type could not be resolved (null, undefined, or any),
233
+ * meaning the result is inconclusive (e.g. package is unbuilt).
234
+ */
235
+ function tokenMatchesParam(token, paramType, paramNode) {
236
+ // For most cases this check is sufficient
237
+ if (paramType === token.name)
238
+ return [true, false];
239
+ // Without a checker we cannot resolve namespace patterns like
240
+ // `IDebugger.ISidebar` ↔ `IDebuggerSidebar`, so we cannot distinguish
241
+ // a genuine mismatch from a valid aliasing convention.
242
+ // Users wanting full type-aware checks should configure
243
+ // `parserOptions.project`.
244
+ if (!checker)
245
+ return [false, true];
246
+ if (paramNode) {
247
+ const resolvedToken = resolveTokenInnerType(token.node);
248
+ const tokenUnresolved = resolvedToken === null ||
249
+ resolvedToken === undefined ||
250
+ !!(resolvedToken.flags & ts.TypeFlags.Any);
251
+ if (tokenUnresolved) {
252
+ return [true, true];
253
+ }
254
+ const resolvedParam = resolveParamType(paramNode);
255
+ if (resolvedParam !== null) {
256
+ return [isSameType(resolvedToken, resolvedParam), false];
257
+ }
258
+ }
259
+ return [false, false];
260
+ }
120
261
  return {
121
262
  VariableDeclarator(node) {
122
- const varDecl = node;
123
- const pluginKind = (0, plugin_utils_1.getJupyterPluginKind)(varDecl);
263
+ const pluginKind = (0, plugin_utils_1.getJupyterPluginKind)(node);
124
264
  if (!pluginKind) {
125
265
  return;
126
266
  }
127
- if (varDecl.init && varDecl.init.type === 'ObjectExpression') {
128
- const pluginObj = varDecl.init;
267
+ if (node.init && node.init.type === 'ObjectExpression') {
268
+ const pluginObj = node.init;
129
269
  const { requires, optional } = extractRequiresOptional(pluginObj);
130
270
  const activateInfo = findActivateFunction(pluginObj);
131
271
  if (!activateInfo) {
132
272
  return;
133
273
  }
134
- const { params, paramTypes } = activateInfo;
274
+ const { paramNames, paramTypes, paramNodes } = activateInfo;
135
275
  const expectedCount = 1 + requires.length + optional.length;
136
276
  const expectedTokensWithoutApp = [...requires, ...optional];
137
- if (expectedCount === 1 && params.length === 0) {
277
+ if (expectedCount === 1 && paramNames.length === 0) {
138
278
  // Special case, not invalid
139
279
  return;
140
280
  }
141
281
  if (pluginKind === 'frontend') {
142
282
  // Validation 1a: Check if first argument is one of the allowed names
143
- if (params.length > 0 &&
144
- (params[0] === null || !allowedFirstArgumentNames.includes(params[0]))) {
283
+ if (paramNames.length > 0 &&
284
+ !allowedFirstArgumentNames.includes(paramNames[0])) {
145
285
  context.report({
146
286
  node: activateInfo.node,
147
287
  messageId: 'appNotFirst',
148
288
  data: {
149
- arg: params[0],
289
+ arg: paramNames[0],
150
290
  allowedNames: allowedFirstArgumentNames
151
291
  .map(name => `"${name}"`)
152
292
  .join(', ')
@@ -155,14 +295,14 @@ const jupyterPluginActivationArgs = {
155
295
  return;
156
296
  }
157
297
  // Validation 1b: Check if first argument type is compatible with JupyterFrontEnd
158
- if (params.length > 0 && paramTypes.length > 0) {
298
+ if (paramNames.length > 0 && paramTypes.length > 0) {
159
299
  const firstParamType = paramTypes[0];
160
300
  if (!isCompatibleWithJupyterFrontEnd(firstParamType)) {
161
301
  context.report({
162
302
  node: activateInfo.node,
163
303
  messageId: 'invalidAppType',
164
304
  data: {
165
- arg: params[0],
305
+ arg: paramNames[0],
166
306
  type: firstParamType || 'unknown'
167
307
  }
168
308
  });
@@ -172,92 +312,91 @@ const jupyterPluginActivationArgs = {
172
312
  }
173
313
  else if (pluginKind === 'service-manager') {
174
314
  // Validation 1: First argument must be literal null
175
- if (params.length === 0 || paramTypes[0] !== null) {
176
- const firstArg = params[0] ?? 'missing';
315
+ if (paramNames.length === 0 || paramTypes[0] !== null) {
177
316
  context.report({
178
317
  node: activateInfo.node,
179
318
  messageId: 'serviceManagerFirstArgNotNull',
180
319
  data: {
181
- arg: firstArg
182
- }
183
- });
184
- return;
185
- }
186
- }
187
- // Validation 1b: Check if first argument type is compatible with JupyterFrontEnd
188
- if (params.length > 0 && paramTypes.length > 0) {
189
- const firstParamType = paramTypes[0];
190
- if (!isCompatibleWithJupyterFrontEnd(firstParamType)) {
191
- context.report({
192
- node: activateInfo.node,
193
- messageId: 'invalidAppType',
194
- data: {
195
- arg: params[0],
196
- type: firstParamType || 'unknown'
320
+ arg: paramTypes[0]
197
321
  }
198
322
  });
199
323
  return;
200
324
  }
201
325
  }
202
326
  // Validation 2: Check if argument count matches
203
- if (params.length !== expectedCount) {
327
+ if (paramNames.length !== expectedCount) {
204
328
  context.report({
205
329
  node: activateInfo.node,
206
330
  messageId: 'wrongArgumentCount',
207
331
  data: {
208
332
  expected: String(expectedCount),
209
333
  tokenCount: String(requires.length + optional.length),
210
- actual: String(params.length)
334
+ actual: String(paramNames.length)
211
335
  }
212
336
  });
213
337
  }
214
- // Validation 3: If parameters have type annotations, validate order
338
+ // Validation 3: Validate remaining parameters against expected token order
215
339
  const actualParamTypes = paramTypes.slice(1); // First arg already validated above
216
- const hasTypeInfo = actualParamTypes.some((t) => t !== null);
217
- if (hasTypeInfo) {
218
- // Validate that parameter types match expected token types in order
219
- for (let i = 0; i < actualParamTypes.length; i++) {
220
- const paramType = actualParamTypes[i];
221
- const expectedToken = expectedTokensWithoutApp[i];
222
- if (expectedToken === undefined) {
223
- // Extra argument
224
- if (paramType) {
340
+ const actualParamNodes = paramNodes.slice(1);
341
+ // Validate that parameter types match expected token types in order
342
+ for (let i = 0; i < actualParamTypes.length; i++) {
343
+ const paramType = actualParamTypes[i];
344
+ const paramNode = actualParamNodes[i];
345
+ const expectedToken = expectedTokensWithoutApp[i];
346
+ if (expectedToken === undefined) {
347
+ // Extra argument
348
+ context.report({
349
+ node: activateInfo.node,
350
+ messageId: 'extraArgument',
351
+ data: { arg: paramNames[i + 1] }
352
+ });
353
+ }
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
+ // Distinguish token-order conflict vs. invalid type annotation.
365
+ const matchesAnyOtherToken = expectedTokensWithoutApp.some((otherToken, j) => {
366
+ if (j === i)
367
+ return false;
368
+ const [otherMatches, tokenUnresolved] = tokenMatchesParam(otherToken, paramType, paramNode);
369
+ return otherMatches && !tokenUnresolved;
370
+ });
371
+ if (matchesAnyOtherToken) {
225
372
  context.report({
226
373
  node: activateInfo.node,
227
- messageId: 'extraArgument',
228
- data: { arg: params[i + 1] }
374
+ messageId: 'mismatchedOrder',
375
+ data: { arg: paramNames[i + 1] }
376
+ });
377
+ }
378
+ else {
379
+ context.report({
380
+ node: activateInfo.node,
381
+ messageId: 'incorrectType',
382
+ data: {
383
+ arg: paramNames[i + 1],
384
+ type: paramType,
385
+ expected: expectedToken.name
386
+ }
229
387
  });
230
388
  }
231
389
  }
232
- else if (paramType !== expectedToken) {
233
- // Type mismatch
234
- context.report({
235
- node: activateInfo.node,
236
- messageId: 'mismatchedOrder',
237
- data: { arg: params[i + 1] }
238
- });
239
- }
240
- }
241
- }
242
- else {
243
- // Without type information, we only check for extra arguments
244
- const actualParams = params.slice(1);
245
- for (let i = expectedTokensWithoutApp.length; i < actualParams.length; i++) {
246
- context.report({
247
- node: activateInfo.node,
248
- messageId: 'extraArgument',
249
- data: { arg: actualParams[i + 1] }
250
- });
251
390
  }
252
391
  }
253
392
  // Validation 4: Check for missing arguments (only if counts don't match)
254
- if (params.length < expectedCount) {
255
- for (let i = params.length - 1; i < expectedTokensWithoutApp.length; i++) {
393
+ if (paramNames.length < expectedCount) {
394
+ for (let i = Math.max(paramNames.length - 1, 0); i < expectedTokensWithoutApp.length; i++) {
256
395
  const missingToken = expectedTokensWithoutApp[i];
257
396
  context.report({
258
397
  node: activateInfo.node,
259
398
  messageId: 'missingArgument',
260
- data: { token: missingToken }
399
+ data: { token: missingToken.name }
261
400
  });
262
401
  }
263
402
  }
@@ -265,5 +404,5 @@ const jupyterPluginActivationArgs = {
265
404
  }
266
405
  };
267
406
  }
268
- };
407
+ });
269
408
  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,11 +3,17 @@
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
- * Checks if an object expression has a description property
9
+ * Returns whether the object expression has a description property and whether
10
+ * it is non-empty.
11
+ *
12
+ * - 'missing' – no description key found
13
+ * - 'empty' – key exists but its literal value is empty / whitespace-only
14
+ * - 'present' – key exists with a non-empty value (or a non-literal value)
9
15
  */
10
- function hasDescriptionProperty(obj) {
16
+ function checkDescriptionProperty(obj) {
11
17
  for (const prop of obj.properties) {
12
18
  if (prop.type === 'Property') {
13
19
  let keyName = null;
@@ -19,24 +25,25 @@ function hasDescriptionProperty(obj) {
19
25
  keyName = prop.key.value;
20
26
  }
21
27
  if (keyName === 'description') {
22
- // Check if description value is not empty
23
28
  if (prop.value.type === 'Literal') {
24
29
  const value = prop.value.value;
25
- return typeof value === 'string' && value.trim().length > 0;
30
+ return typeof value === 'string' && value.trim().length > 0
31
+ ? 'present'
32
+ : 'empty';
26
33
  }
27
- return true; // Non-literal descriptions are assumed valid
34
+ return 'present';
28
35
  }
29
36
  }
30
37
  }
31
- return false;
38
+ return 'missing';
32
39
  }
33
- const jupyterPluginDescription = {
40
+ const jupyterPluginDescription = (0, create_rule_1.createRule)({
41
+ name: 'plugin-description',
34
42
  meta: {
35
43
  type: 'problem',
36
44
  docs: {
37
45
  description: 'Ensure all JupyterLab plugins have a description property',
38
- recommended: 'recommended',
39
- url: 'https://github.com/jupyterlab/eslint-plugin'
46
+ url: 'https://eslint-plugin.readthedocs.io/en/latest/rules/plugin-description/'
40
47
  },
41
48
  messages: {
42
49
  missingDescription: 'JupyterLab plugin{{ pluginId }} is missing a "description" property.',
@@ -44,10 +51,10 @@ const jupyterPluginDescription = {
44
51
  },
45
52
  schema: []
46
53
  },
54
+ defaultOptions: [],
47
55
  create(context) {
48
56
  return {
49
- VariableDeclarator(node) {
50
- const varDecl = node;
57
+ VariableDeclarator(varDecl) {
51
58
  // Check if this has a JupyterFrontEndPlugin type annotation
52
59
  if (!(0, plugin_utils_1.getJupyterPluginKind)(varDecl)) {
53
60
  return;
@@ -56,19 +63,21 @@ const jupyterPluginDescription = {
56
63
  if (!varDecl.init || varDecl.init.type !== 'ObjectExpression') {
57
64
  return;
58
65
  }
59
- const pluginObj = varDecl.init;
60
- const pluginId = (0, plugin_utils_1.getPluginId)(pluginObj);
66
+ const pluginId = (0, plugin_utils_1.getPluginId)(varDecl.init);
61
67
  const pluginIdSuffix = pluginId ? ` "${pluginId}"` : '';
62
- // Check if description property exists
63
- if (!hasDescriptionProperty(pluginObj)) {
68
+ // Check if description property exists and is non-empty
69
+ const descriptionStatus = checkDescriptionProperty(varDecl.init);
70
+ if (descriptionStatus !== 'present') {
64
71
  context.report({
65
- node: pluginObj,
66
- messageId: 'missingDescription',
72
+ node: varDecl.init,
73
+ messageId: descriptionStatus === 'empty'
74
+ ? 'emptyDescription'
75
+ : 'missingDescription',
67
76
  data: { pluginId: pluginIdSuffix }
68
77
  });
69
78
  }
70
79
  }
71
80
  };
72
81
  }
73
- };
82
+ });
74
83
  module.exports = jupyterPluginDescription;
@@ -0,0 +1,4 @@
1
+ declare const tokenFormat: import("@typescript-eslint/utils/dist/ts-eslint").RuleModule<"missingColon" | "invalidTokenSymbol", [], unknown, import("@typescript-eslint/utils/dist/ts-eslint").RuleListener> & {
2
+ name: string;
3
+ };
4
+ export = tokenFormat;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) Jupyter Development Team.
4
+ * Distributed under the terms of the Modified BSD License.
5
+ */
6
+ const create_rule_1 = require("../utils/create-rule");
7
+ /**
8
+ * Token symbol (part after the first ':') must be a valid JavaScript identifier.
9
+ */
10
+ const VALID_TOKEN_SYMBOL = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
11
+ const tokenFormat = (0, create_rule_1.createRule)({
12
+ name: 'token-format',
13
+ meta: {
14
+ type: 'problem',
15
+ docs: {
16
+ description: 'Ensure JupyterLab Token ids follow the <package>:<TokenSymbol> naming convention',
17
+ url: 'https://eslint-plugin.readthedocs.io/en/latest/rules/token-format/'
18
+ },
19
+ messages: {
20
+ missingColon: 'Token id "{{ tokenId }}" must follow the format "<package>:<TokenSymbol>" (no colon found).',
21
+ invalidTokenSymbol: 'Token id "{{ tokenId }}" has an invalid symbol "{{ symbol }}". ' +
22
+ 'The part after ":" must be a valid JavaScript identifier.'
23
+ },
24
+ schema: []
25
+ },
26
+ defaultOptions: [],
27
+ create(context) {
28
+ return {
29
+ NewExpression(node) {
30
+ if (node.callee.type !== 'Identifier' ||
31
+ node.callee.name !== 'Token') {
32
+ return;
33
+ }
34
+ if (node.arguments.length === 0) {
35
+ return;
36
+ }
37
+ const firstArg = node.arguments[0];
38
+ if (firstArg.type !== 'Literal' || typeof firstArg.value !== 'string') {
39
+ return;
40
+ }
41
+ const tokenId = firstArg.value;
42
+ const colonIndex = tokenId.indexOf(':');
43
+ if (colonIndex === -1) {
44
+ context.report({
45
+ node: firstArg,
46
+ messageId: 'missingColon',
47
+ data: { tokenId }
48
+ });
49
+ return;
50
+ }
51
+ const symbol = tokenId.slice(colonIndex + 1);
52
+ if (!VALID_TOKEN_SYMBOL.test(symbol)) {
53
+ context.report({
54
+ node: firstArg,
55
+ messageId: 'invalidTokenSymbol',
56
+ data: { tokenId, symbol }
57
+ });
58
+ }
59
+ }
60
+ };
61
+ }
62
+ });
63
+ module.exports = tokenFormat;
@@ -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
+ };