@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.
Files changed (43) hide show
  1. package/README.md +12 -0
  2. package/lib/index.d.ts +6 -207
  3. package/lib/index.js +49 -28
  4. package/lib/rules/command-described-by.js +18 -27
  5. package/lib/rules/command-id-convention.d.ts +5 -0
  6. package/lib/rules/command-id-convention.js +87 -0
  7. package/lib/rules/no-untranslated-string.d.ts +2 -1
  8. package/lib/rules/no-untranslated-string.js +11 -3
  9. package/lib/rules/plugin-activation-args.d.ts +3 -3
  10. package/lib/rules/plugin-activation-args.js +183 -142
  11. package/lib/rules/plugin-description.js +12 -9
  12. package/lib/rules/plugin-id-convention.d.ts +2 -3
  13. package/lib/rules/plugin-id-convention.js +10 -107
  14. package/lib/rules/prefer-lazy-imports.d.ts +2 -2
  15. package/lib/rules/prefer-lazy-imports.js +59 -28
  16. package/lib/rules/prefer-signal-this-arg.d.ts +3 -3
  17. package/lib/rules/prefer-signal-this-arg.js +12 -13
  18. package/lib/rules/require-disposable-ownership.d.ts +1 -2
  19. package/lib/rules/require-disposable-ownership.js +2 -10
  20. package/lib/rules/require-disposable-transfer.d.ts +1 -2
  21. package/lib/rules/require-disposable-transfer.js +7 -12
  22. package/lib/rules/require-signal-cleanup.d.ts +3 -3
  23. package/lib/rules/require-signal-cleanup.js +12 -13
  24. package/lib/rules/require-signal-this-arg.d.ts +1 -2
  25. package/lib/rules/require-signal-this-arg.js +2 -10
  26. package/lib/rules/token-format.js +8 -2
  27. package/lib/utils/ast.d.ts +1 -1
  28. package/lib/utils/commands.d.ts +17 -1
  29. package/lib/utils/commands.js +205 -0
  30. package/lib/utils/disposables.d.ts +2 -13
  31. package/lib/utils/disposables.js +3 -18
  32. package/lib/utils/lazy-imports.d.ts +2 -2
  33. package/lib/utils/lazy-imports.js +10 -1
  34. package/lib/utils/options.d.ts +9 -0
  35. package/lib/utils/options.js +22 -0
  36. package/lib/utils/plugin-utils.d.ts +39 -10
  37. package/lib/utils/plugin-utils.js +376 -25
  38. package/lib/utils/signal-lifetime.d.ts +1 -2
  39. package/lib/utils/signals.d.ts +1 -2
  40. package/lib/utils/translation.d.ts +1 -1
  41. package/lib/utils/type-services.d.ts +12 -0
  42. package/lib/utils/type-services.js +27 -0
  43. package/package.json +4 -10
@@ -3,7 +3,7 @@
3
3
  * Copyright (c) Jupyter Development Team.
4
4
  * Distributed under the terms of the Modified BSD License.
5
5
  */
6
- const utils_1 = require("@typescript-eslint/utils");
6
+ const type_services_1 = require("../utils/type-services");
7
7
  const plugin_utils_1 = require("../utils/plugin-utils");
8
8
  const lazy_imports_1 = require("../utils/lazy-imports");
9
9
  const module_size_1 = require("../utils/module-size");
@@ -15,7 +15,8 @@ const DEFAULT_OPTIONS = {
15
15
  ignoreImports: [],
16
16
  minimumSize: lazy_imports_1.DEFAULT_MINIMUM_SIZE,
17
17
  reportInteractionCallbacks: false,
18
- reportModuleLevelUsage: false
18
+ reportModuleLevelUsage: false,
19
+ reportReExports: false
19
20
  };
20
21
  const jupyterPreferLazyImports = (0, create_rule_1.createRule)({
21
22
  name: 'prefer-lazy-imports',
@@ -47,7 +48,9 @@ const jupyterPreferLazyImports = (0, create_rule_1.createRule)({
47
48
  deferredPackageNotTypeOnly: "'{{ source }}' is in `deferredPackages`, and this import has no runtime use, but it is not written as `import type`, so a build with `verbatimModuleSyntax` or plain JavaScript loads the package anyway. " +
48
49
  'Remove the import, or make it `import type`.',
49
50
  deferredPackageReExport: "'{{ source }}' is in `deferredPackages`, so it must only be loaded with `await import()`, but this re-export loads it together with the module. " +
50
- "Remove the re-export and use `await import('{{ source }}')` where the package is needed."
51
+ "Remove the re-export and use `await import('{{ source }}')` where the package is needed.",
52
+ reExportKeepsImportEager: "'{{ source }}' is imported only for use inside functions, but this re-export keeps it in the startup bundle. " +
53
+ "Export types with `export type` instead, or remove the re-export and import '{{ source }}' where it is used."
51
54
  },
52
55
  schema: [
53
56
  {
@@ -86,6 +89,11 @@ const jupyterPreferLazyImports = (0, create_rule_1.createRule)({
86
89
  type: 'boolean',
87
90
  default: false,
88
91
  description: 'Also report imports used at module level, excluding tokens referenced in `requires`, `optional` and `provides`.'
92
+ },
93
+ reportReExports: {
94
+ type: 'boolean',
95
+ default: false,
96
+ description: 'Also report value re-exports of modules whose imports are only used inside functions, which would otherwise keep the module in the startup bundle.'
89
97
  }
90
98
  },
91
99
  additionalProperties: false
@@ -94,24 +102,12 @@ const jupyterPreferLazyImports = (0, create_rule_1.createRule)({
94
102
  },
95
103
  defaultOptions: [DEFAULT_OPTIONS],
96
104
  create(context, [options]) {
97
- const { allowedPackages, deferredPackages, ignoreImports, minimumSize, reportInteractionCallbacks, reportModuleLevelUsage } = options;
98
- let services = null;
99
- let checker = null;
100
- try {
101
- services = utils_1.ESLintUtils.getParserServices(context, true);
102
- checker = services.program ? services.program.getTypeChecker() : null;
103
- }
104
- catch {
105
- // Parser services unavailable (non-TS file or no type information)
106
- services = null;
107
- }
108
- const getTSNode = services
109
- ? (node) => services?.esTreeNodeToTSNodeMap.get(node)
110
- : null;
105
+ const { allowedPackages, deferredPackages, ignoreImports, minimumSize, reportInteractionCallbacks, reportModuleLevelUsage, reportReExports } = options;
106
+ const { checker, getTSNode } = (0, type_services_1.getTypeServices)(context);
111
107
  let isPluginModule = false;
112
108
  const importDeclarations = [];
113
109
  // Sources kept in the startup bundle by a value re-export.
114
- const reExportedSources = new Set();
110
+ const reExportDeclarations = new Map();
115
111
  function mentionsPluginType(typeNode) {
116
112
  return (0, plugin_utils_1.typeMentionsJupyterPlugin)(typeNode, checker, getTSNode);
117
113
  }
@@ -213,7 +209,8 @@ const jupyterPreferLazyImports = (0, create_rule_1.createRule)({
213
209
  * deferring the others would not remove it.
214
210
  */
215
211
  function checkSource(source, declarations) {
216
- if (isExempt(source) || reExportedSources.has(source)) {
212
+ const reExports = reExportDeclarations.get(source);
213
+ if (isExempt(source) || (!reportReExports && reExports)) {
217
214
  return;
218
215
  }
219
216
  const references = declarations.flatMap(getValueReferences);
@@ -235,14 +232,25 @@ const jupyterPreferLazyImports = (0, create_rule_1.createRule)({
235
232
  // it may run while the application starts. Only a position which
236
233
  // provably waits for the user shows the import can load later.
237
234
  if (references.every(({ identifier }) => (0, lazy_imports_1.isInInteractionCallback)(identifier))) {
238
- reportUnlessTooSmall({
239
- node: declarations[0],
240
- messageId: 'preferLazyImportInteraction',
241
- data: {
242
- source,
243
- snippet: (0, lazy_imports_1.buildDeferredImportSnippet)(declarations)
235
+ if (reExports && reportReExports) {
236
+ for (const reExportNode of reExports) {
237
+ reportUnlessTooSmall({
238
+ node: reExportNode,
239
+ messageId: 'reExportKeepsImportEager',
240
+ data: { source }
241
+ });
244
242
  }
245
- });
243
+ }
244
+ else {
245
+ reportUnlessTooSmall({
246
+ node: declarations[0],
247
+ messageId: 'preferLazyImportInteraction',
248
+ data: {
249
+ source,
250
+ snippet: (0, lazy_imports_1.buildDeferredImportSnippet)(declarations)
251
+ }
252
+ });
253
+ }
246
254
  }
247
255
  return;
248
256
  }
@@ -269,6 +277,9 @@ const jupyterPreferLazyImports = (0, create_rule_1.createRule)({
269
277
  }
270
278
  }
271
279
  if (tokenList === 0 && eager === 0 && activation > 0) {
280
+ if (reExports) {
281
+ return;
282
+ }
272
283
  // `Application.start` waits for every autostart plugin before it
273
284
  // attaches the shell, so the module is fetched before the application
274
285
  // starts whatever this file does, and an `await import()` inside
@@ -283,6 +294,16 @@ const jupyterPreferLazyImports = (0, create_rule_1.createRule)({
283
294
  return;
284
295
  }
285
296
  if (tokenList === 0 && eager === 0 && deferrable > 0) {
297
+ if (reExports && reportReExports) {
298
+ for (const reExportNode of reExports) {
299
+ reportUnlessTooSmall({
300
+ node: reExportNode,
301
+ messageId: 'reExportKeepsImportEager',
302
+ data: { source }
303
+ });
304
+ }
305
+ return;
306
+ }
286
307
  reportUnlessTooSmall({
287
308
  node: declarations[0],
288
309
  messageId: 'preferLazyImport',
@@ -294,6 +315,9 @@ const jupyterPreferLazyImports = (0, create_rule_1.createRule)({
294
315
  return;
295
316
  }
296
317
  if (reportModuleLevelUsage && eager > 0 && tokenList === 0) {
318
+ if (reExports) {
319
+ return;
320
+ }
297
321
  reportUnlessTooSmall({
298
322
  node: declarations[0],
299
323
  messageId: 'eagerModuleLevelUse',
@@ -388,7 +412,8 @@ const jupyterPreferLazyImports = (0, create_rule_1.createRule)({
388
412
  * is erased under `verbatimModuleSyntax`, the rest stays as
389
413
  * `export {} from '...'` and loads the source. For any other source a
390
414
  * value re-export keeps it in the startup bundle, so deferring the
391
- * matching import would gain nothing and the usage check skips it.
415
+ * matching import would gain nothing and the usage check skips it, unless
416
+ * `reportReExports` is enabled to report the re-export instead.
392
417
  */
393
418
  function checkReExport(node, source, hasValueSpecifier) {
394
419
  if (isDeferredPackage(source)) {
@@ -399,7 +424,13 @@ const jupyterPreferLazyImports = (0, create_rule_1.createRule)({
399
424
  });
400
425
  }
401
426
  else if (hasValueSpecifier) {
402
- reExportedSources.add(source);
427
+ const list = reExportDeclarations.get(source);
428
+ if (list) {
429
+ list.push(node);
430
+ }
431
+ else {
432
+ reExportDeclarations.set(source, [node]);
433
+ }
403
434
  }
404
435
  }
405
436
  return {
@@ -1,7 +1,7 @@
1
- import { ESLintUtils } from '@typescript-eslint/utils';
2
- declare const preferSignalThisArg: ESLintUtils.RuleModule<"addThisArg" | "preferThisArg" | "boundCallback" | "unbindAndAddThisArg", [{
1
+ declare const preferSignalThisArg: import("@typescript-eslint/utils/ts-eslint").RuleModule<"addThisArg" | "preferThisArg" | "boundCallback" | "unbindAndAddThisArg", [{
3
2
  longLivedTypes: string[] | undefined;
4
- }], unknown, ESLintUtils.RuleListener> & {
3
+ extendDefaultLongLivedTypes: boolean;
4
+ }], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
5
5
  name: string;
6
6
  };
7
7
  export = preferSignalThisArg;
@@ -3,9 +3,10 @@
3
3
  * Copyright (c) Jupyter Development Team.
4
4
  * Distributed under the terms of the Modified BSD License.
5
5
  */
6
- const utils_1 = require("@typescript-eslint/utils");
7
6
  const create_rule_1 = require("../utils/create-rule");
7
+ const type_services_1 = require("../utils/type-services");
8
8
  const signals_1 = require("../utils/signals");
9
+ const options_1 = require("../utils/options");
9
10
  const signal_lifetime_1 = require("../utils/signal-lifetime");
10
11
  const preferSignalThisArg = (0, create_rule_1.createRule)({
11
12
  name: 'prefer-signal-this-arg',
@@ -31,7 +32,12 @@ const preferSignalThisArg = (0, create_rule_1.createRule)({
31
32
  items: {
32
33
  type: 'string'
33
34
  },
34
- description: 'Type names treated as application-lifetime services. Replaces the built-in list when provided.'
35
+ description: 'Type names treated as application-lifetime services. Added to the built-in defaults unless extendDefaultLongLivedTypes is false.'
36
+ },
37
+ extendDefaultLongLivedTypes: {
38
+ type: 'boolean',
39
+ default: true,
40
+ description: 'Whether longLivedTypes extends the built-in defaults. Set to false to replace them, or to drop them entirely when no list is given.'
35
41
  }
36
42
  },
37
43
  additionalProperties: false
@@ -40,20 +46,13 @@ const preferSignalThisArg = (0, create_rule_1.createRule)({
40
46
  },
41
47
  defaultOptions: [
42
48
  {
43
- longLivedTypes: undefined
49
+ longLivedTypes: undefined,
50
+ extendDefaultLongLivedTypes: true
44
51
  }
45
52
  ],
46
53
  create(context, [options]) {
47
- const longLivedTypes = new Set(options.longLivedTypes ?? signal_lifetime_1.DEFAULT_LONG_LIVED_TYPES);
48
- let services = null;
49
- let checker = null;
50
- try {
51
- services = utils_1.ESLintUtils.getParserServices(context, true);
52
- checker = services.program ? services.program.getTypeChecker() : null;
53
- }
54
- catch {
55
- services = null;
56
- }
54
+ const longLivedTypes = (0, options_1.resolveNameListOption)(options.longLivedTypes, signal_lifetime_1.DEFAULT_LONG_LIVED_TYPES, options.extendDefaultLongLivedTypes !== false);
55
+ const { services, checker } = (0, type_services_1.getTypeServices)(context);
57
56
  const sourceCode = context.sourceCode;
58
57
  let program = null;
59
58
  let signalLocalNames = new Set(['Signal']);
@@ -1,5 +1,4 @@
1
- import { ESLintUtils } from '@typescript-eslint/utils';
2
- declare const requireDisposableOwnership: ESLintUtils.RuleModule<"unmanagedDisposable" | "unmanagedDisposableVariable", [{}], unknown, ESLintUtils.RuleListener> & {
1
+ declare const requireDisposableOwnership: import("@typescript-eslint/utils/ts-eslint").RuleModule<"unmanagedDisposable" | "unmanagedDisposableVariable", [{}], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
3
2
  name: string;
4
3
  };
5
4
  export = requireDisposableOwnership;
@@ -3,8 +3,8 @@
3
3
  * Copyright (c) Jupyter Development Team.
4
4
  * Distributed under the terms of the Modified BSD License.
5
5
  */
6
- const utils_1 = require("@typescript-eslint/utils");
7
6
  const create_rule_1 = require("../utils/create-rule");
7
+ const type_services_1 = require("../utils/type-services");
8
8
  const disposables_1 = require("../utils/disposables");
9
9
  const requireDisposableOwnership = (0, create_rule_1.createRule)({
10
10
  name: 'require-disposable-ownership',
@@ -40,15 +40,7 @@ const requireDisposableOwnership = (0, create_rule_1.createRule)({
40
40
  defaultOptions: [{}],
41
41
  create(context, [options]) {
42
42
  const pending = new Map();
43
- let services = null;
44
- let checker = null;
45
- try {
46
- services = utils_1.ESLintUtils.getParserServices(context, true);
47
- checker = services.program ? services.program.getTypeChecker() : null;
48
- }
49
- catch {
50
- services = null;
51
- }
43
+ const { services, checker } = (0, type_services_1.getTypeServices)(context);
52
44
  const ownership = {
53
45
  sourceCode: context.sourceCode,
54
46
  checker,
@@ -1,5 +1,4 @@
1
- import { ESLintUtils } from '@typescript-eslint/utils';
2
- declare const requireDisposableTransfer: ESLintUtils.RuleModule<"unmanagedDisposableVariable" | "unhandledDisposable", [{}], unknown, ESLintUtils.RuleListener> & {
1
+ declare const requireDisposableTransfer: import("@typescript-eslint/utils/ts-eslint").RuleModule<"unmanagedDisposableVariable" | "unhandledDisposable", [{}], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
3
2
  name: string;
4
3
  };
5
4
  export = requireDisposableTransfer;
@@ -3,8 +3,8 @@
3
3
  * Copyright (c) Jupyter Development Team.
4
4
  * Distributed under the terms of the Modified BSD License.
5
5
  */
6
- const utils_1 = require("@typescript-eslint/utils");
7
6
  const create_rule_1 = require("../utils/create-rule");
7
+ const type_services_1 = require("../utils/type-services");
8
8
  const disposables_1 = require("../utils/disposables");
9
9
  const DEFAULT_IGNORED_RETURN_FUNCTION_NAMES = [
10
10
  '_adjacentBar',
@@ -114,24 +114,19 @@ const requireDisposableTransfer = (0, create_rule_1.createRule)({
114
114
  defaultOptions: [{}],
115
115
  create(context, [options]) {
116
116
  const pending = new Map();
117
- let services = null;
118
- let checker = null;
119
- try {
120
- services = utils_1.ESLintUtils.getParserServices(context, true);
121
- checker = services.program ? services.program.getTypeChecker() : null;
122
- }
123
- catch {
124
- services = null;
125
- }
117
+ const { services, checker, getTSNode } = (0, type_services_1.getTypeServices)(context);
126
118
  function returnsDisposable(node) {
127
119
  if ((0, disposables_1.isDisposableSetFactoryCall)(node)) {
128
120
  return true;
129
121
  }
130
- if (!checker || !services) {
122
+ if (!checker || !getTSNode) {
131
123
  return false;
132
124
  }
133
125
  try {
134
- const tsNode = services.esTreeNodeToTSNodeMap.get(node);
126
+ const tsNode = getTSNode(node);
127
+ if (!tsNode) {
128
+ return false;
129
+ }
135
130
  const type = checker.getTypeAtLocation(tsNode);
136
131
  return (0, disposables_1.isDisposableType)(type, checker);
137
132
  }
@@ -1,8 +1,8 @@
1
- import { ESLintUtils } from '@typescript-eslint/utils';
2
- declare const requireSignalCleanup: ESLintUtils.RuleModule<"serviceOutlivesReceiver", [{
1
+ declare const requireSignalCleanup: import("@typescript-eslint/utils/ts-eslint").RuleModule<"serviceOutlivesReceiver", [{
3
2
  additionalCleanupMethods: string[];
4
3
  longLivedTypes: string[] | undefined;
5
- }], unknown, ESLintUtils.RuleListener> & {
4
+ extendDefaultLongLivedTypes: boolean;
5
+ }], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
6
6
  name: string;
7
7
  };
8
8
  export = requireSignalCleanup;
@@ -3,9 +3,10 @@
3
3
  * Copyright (c) Jupyter Development Team.
4
4
  * Distributed under the terms of the Modified BSD License.
5
5
  */
6
- const utils_1 = require("@typescript-eslint/utils");
7
6
  const create_rule_1 = require("../utils/create-rule");
7
+ const type_services_1 = require("../utils/type-services");
8
8
  const signals_1 = require("../utils/signals");
9
+ const options_1 = require("../utils/options");
9
10
  const signal_lifetime_1 = require("../utils/signal-lifetime");
10
11
  const requireSignalCleanup = (0, create_rule_1.createRule)({
11
12
  name: 'require-signal-cleanup',
@@ -35,7 +36,12 @@ const requireSignalCleanup = (0, create_rule_1.createRule)({
35
36
  items: {
36
37
  type: 'string'
37
38
  },
38
- description: 'Type names treated as application-lifetime services. Replaces the built-in list when provided.'
39
+ description: 'Type names treated as application-lifetime services. Added to the built-in defaults unless extendDefaultLongLivedTypes is false.'
40
+ },
41
+ extendDefaultLongLivedTypes: {
42
+ type: 'boolean',
43
+ default: true,
44
+ description: 'Whether longLivedTypes extends the built-in defaults. Set to false to replace them, or to drop them entirely when no list is given.'
39
45
  }
40
46
  },
41
47
  additionalProperties: false
@@ -45,21 +51,14 @@ const requireSignalCleanup = (0, create_rule_1.createRule)({
45
51
  defaultOptions: [
46
52
  {
47
53
  additionalCleanupMethods: [],
48
- longLivedTypes: undefined
54
+ longLivedTypes: undefined,
55
+ extendDefaultLongLivedTypes: true
49
56
  }
50
57
  ],
51
58
  create(context, [options]) {
52
59
  const additionalCleanupMethods = options.additionalCleanupMethods || [];
53
- const longLivedTypes = new Set(options.longLivedTypes ?? signal_lifetime_1.DEFAULT_LONG_LIVED_TYPES);
54
- let services = null;
55
- let checker = null;
56
- try {
57
- services = utils_1.ESLintUtils.getParserServices(context, true);
58
- checker = services.program ? services.program.getTypeChecker() : null;
59
- }
60
- catch {
61
- services = null;
62
- }
60
+ const longLivedTypes = (0, options_1.resolveNameListOption)(options.longLivedTypes, signal_lifetime_1.DEFAULT_LONG_LIVED_TYPES, options.extendDefaultLongLivedTypes !== false);
61
+ const { services, checker } = (0, type_services_1.getTypeServices)(context);
63
62
  const sourceCode = context.sourceCode;
64
63
  let program = null;
65
64
  let signalLocalNames = new Set(['Signal']);
@@ -1,5 +1,4 @@
1
- import { ESLintUtils } from '@typescript-eslint/utils';
2
- declare const requireSignalThisArg: ESLintUtils.RuleModule<"missingThisArg" | "addThisArg", [], unknown, ESLintUtils.RuleListener> & {
1
+ declare const requireSignalThisArg: import("@typescript-eslint/utils/ts-eslint").RuleModule<"missingThisArg" | "addThisArg", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
3
2
  name: string;
4
3
  };
5
4
  export = requireSignalThisArg;
@@ -3,8 +3,8 @@
3
3
  * Copyright (c) Jupyter Development Team.
4
4
  * Distributed under the terms of the Modified BSD License.
5
5
  */
6
- const utils_1 = require("@typescript-eslint/utils");
7
6
  const create_rule_1 = require("../utils/create-rule");
7
+ const type_services_1 = require("../utils/type-services");
8
8
  const signals_1 = require("../utils/signals");
9
9
  const requireSignalThisArg = (0, create_rule_1.createRule)({
10
10
  name: 'require-signal-this-arg',
@@ -23,15 +23,7 @@ const requireSignalThisArg = (0, create_rule_1.createRule)({
23
23
  },
24
24
  defaultOptions: [],
25
25
  create(context) {
26
- let services = null;
27
- let checker = null;
28
- try {
29
- services = utils_1.ESLintUtils.getParserServices(context, true);
30
- checker = services.program ? services.program.getTypeChecker() : null;
31
- }
32
- catch {
33
- services = null;
34
- }
26
+ const { services, checker } = (0, type_services_1.getTypeServices)(context);
35
27
  return {
36
28
  CallExpression(node) {
37
29
  if (!(0, signals_1.isConnectCall)(node) || node.arguments.length !== 1) {
@@ -4,6 +4,8 @@
4
4
  * Distributed under the terms of the Modified BSD License.
5
5
  */
6
6
  const create_rule_1 = require("../utils/create-rule");
7
+ const plugin_utils_1 = require("../utils/plugin-utils");
8
+ const type_services_1 = require("../utils/type-services");
7
9
  /**
8
10
  * Token symbol (part after the first ':') must be a valid JavaScript identifier.
9
11
  */
@@ -25,6 +27,7 @@ const tokenFormat = (0, create_rule_1.createRule)({
25
27
  },
26
28
  defaultOptions: [],
27
29
  create(context) {
30
+ const { checker, getTSNode } = (0, type_services_1.getTypeServices)(context);
28
31
  return {
29
32
  NewExpression(node) {
30
33
  if (node.callee.type !== 'Identifier' || node.callee.name !== 'Token') {
@@ -34,10 +37,13 @@ const tokenFormat = (0, create_rule_1.createRule)({
34
37
  return;
35
38
  }
36
39
  const firstArg = node.arguments[0];
37
- if (firstArg.type !== 'Literal' || typeof firstArg.value !== 'string') {
40
+ if (firstArg.type === 'SpreadElement') {
41
+ return;
42
+ }
43
+ const tokenId = (0, plugin_utils_1.resolveStaticString)(firstArg, context.sourceCode.getScope(node), checker, getTSNode);
44
+ if (tokenId === null) {
38
45
  return;
39
46
  }
40
- const tokenId = firstArg.value;
41
47
  const colonIndex = tokenId.indexOf(':');
42
48
  if (colonIndex === -1) {
43
49
  context.report({
@@ -1,4 +1,4 @@
1
- import { TSESTree } from '@typescript-eslint/types';
1
+ import { TSESTree } from '@typescript-eslint/utils';
2
2
  export type WalkAction = 'skip-children' | 'stop' | undefined;
3
3
  export declare function isNode(value: unknown): value is TSESTree.Node;
4
4
  /**
@@ -1,5 +1,21 @@
1
- import { TSESTree } from '@typescript-eslint/types';
1
+ import { TSESLint, TSESTree } from '@typescript-eslint/utils';
2
+ import * as ts from 'typescript';
2
3
  /**
3
4
  * Checks if a node represents *.addCommand()
4
5
  */
5
6
  export declare function isAddCommandCall(node: TSESTree.CallExpression): boolean;
7
+ /**
8
+ * Resolves a command ID expression to the string it holds at lint time.
9
+ *
10
+ * On top of `resolveStaticString`, this reads a member of a namespace or enum
11
+ * declared in the same file without type information, since
12
+ * `namespace CommandIDs { export const open = '...'; }` is how JupyterLab and
13
+ * most extensions declare their command IDs.
14
+ */
15
+ export declare function resolveCommandId(node: TSESTree.Node, sourceCode: Readonly<TSESLint.SourceCode>, checker?: ts.TypeChecker | null, getTSNode?: ((n: TSESTree.Node) => ts.Node | undefined) | null): string | null;
16
+ /**
17
+ * Checks whether an `addCommand` receiver is a registry the code created
18
+ * itself with `new CommandRegistry()`, such as the throw-away registry behind
19
+ * a context menu, rather than the application's shared `app.commands`.
20
+ */
21
+ export declare function isPrivateCommandRegistry(receiver: TSESTree.Expression, scope: TSESLint.Scope.Scope): boolean;