@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.
@@ -1,7 +1,6 @@
1
- import { ESLintUtils } from '@typescript-eslint/utils';
2
- declare const pluginIdConvention: ESLintUtils.RuleModule<"mismatchedPrefix" | "idEqualsPackageName", [{
1
+ declare const pluginIdConvention: import("@typescript-eslint/utils/ts-eslint").RuleModule<"mismatchedPrefix" | "idEqualsPackageName", [{
3
2
  reportIdEqualToPackageName: boolean;
4
- }], unknown, ESLintUtils.RuleListener> & {
3
+ }], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
5
4
  name: string;
6
5
  };
7
6
  export = pluginIdConvention;
@@ -38,9 +38,9 @@ var __importStar = (this && this.__importStar) || (function () {
38
38
  })();
39
39
  const fs = __importStar(require("fs"));
40
40
  const path = __importStar(require("path"));
41
- const utils_1 = require("@typescript-eslint/utils");
42
41
  const create_rule_1 = require("../utils/create-rule");
43
42
  const plugin_utils_1 = require("../utils/plugin-utils");
43
+ const type_services_1 = require("../utils/type-services");
44
44
  const package_json_1 = require("../utils/package-json");
45
45
  const MAX_PACKAGE_LEVELS = 12;
46
46
  const packageManifestCache = new Map();
@@ -150,108 +150,7 @@ const pluginIdConvention = (0, create_rule_1.createRule)({
150
150
  },
151
151
  defaultOptions: [{ reportIdEqualToPackageName: false }],
152
152
  create(context, [options]) {
153
- let services = null;
154
- let checker = null;
155
- try {
156
- services = utils_1.ESLintUtils.getParserServices(context, true);
157
- checker = services.program ? services.program.getTypeChecker() : null;
158
- }
159
- catch {
160
- services = null;
161
- }
162
- const getTSNode = services
163
- ? (node) => services?.esTreeNodeToTSNodeMap.get(node)
164
- : null;
165
- /**
166
- * Returns true when a type annotation refers to a plugin descriptor or to
167
- * a MIME renderer extension entry, which JupyterLab registers as a plugin
168
- * under the entry's `id`.
169
- */
170
- function mentionsPluginType(typeNode) {
171
- return ((0, plugin_utils_1.typeMentionsJupyterPlugin)(typeNode, checker, getTSNode) ||
172
- (0, plugin_utils_1.typeMentionsMimeExtension)(typeNode, checker, getTSNode));
173
- }
174
- /**
175
- * Checks whether an object literal is typed as a plugin descriptor or as
176
- * a MIME renderer extension entry.
177
- */
178
- function hasPluginType(node) {
179
- const parent = node.parent;
180
- if (!parent) {
181
- return false;
182
- }
183
- if (parent.type === 'VariableDeclarator') {
184
- return ((0, plugin_utils_1.getJupyterPluginKind)(parent, checker, getTSNode) !== null ||
185
- (parent.id.type === 'Identifier' &&
186
- mentionsPluginType(parent.id.typeAnnotation?.typeAnnotation)));
187
- }
188
- if (parent.type === 'TSAsExpression' ||
189
- parent.type === 'TSSatisfiesExpression' ||
190
- parent.type === 'TSTypeAssertion') {
191
- return (mentionsPluginType(parent.typeAnnotation) ||
192
- isReturnedFromPluginFactory(node));
193
- }
194
- if (isReturnedFromPluginFactory(node)) {
195
- return true;
196
- }
197
- if (parent.type !== 'ArrayExpression') {
198
- return false;
199
- }
200
- const grandparent = parent.parent;
201
- if (!grandparent) {
202
- return false;
203
- }
204
- if (grandparent.type === 'VariableDeclarator') {
205
- return (grandparent.id.type === 'Identifier' &&
206
- mentionsPluginType(grandparent.id.typeAnnotation?.typeAnnotation));
207
- }
208
- if (grandparent.type === 'TSAsExpression' ||
209
- grandparent.type === 'TSSatisfiesExpression' ||
210
- grandparent.type === 'TSTypeAssertion') {
211
- return (mentionsPluginType(grandparent.typeAnnotation) ||
212
- isReturnedFromPluginFactory(parent));
213
- }
214
- return isReturnedFromPluginFactory(parent);
215
- }
216
- /**
217
- * Checks whether an object or array literal is returned by a factory whose
218
- * return type is a plugin descriptor.
219
- */
220
- function isReturnedFromPluginFactory(node) {
221
- let expression = node;
222
- let parent = expression.parent;
223
- while (parent?.type === 'TSAsExpression' ||
224
- parent?.type === 'TSSatisfiesExpression' ||
225
- parent?.type === 'TSTypeAssertion') {
226
- expression = parent;
227
- parent = parent.parent;
228
- }
229
- if (parent?.type === 'ReturnStatement' &&
230
- parent.argument === expression) {
231
- const fn = getEnclosingFunction(parent);
232
- return mentionsPluginType(fn?.returnType?.typeAnnotation);
233
- }
234
- if (parent?.type === 'ArrowFunctionExpression' &&
235
- parent.body === expression) {
236
- return mentionsPluginType(parent.returnType?.typeAnnotation);
237
- }
238
- return false;
239
- }
240
- /**
241
- * Finds the function that owns a return statement.
242
- */
243
- function getEnclosingFunction(node) {
244
- let current = node.parent;
245
- while (current) {
246
- if (current.type === 'FunctionDeclaration' ||
247
- current.type === 'FunctionExpression' ||
248
- current.type === 'ArrowFunctionExpression') {
249
- return current;
250
- }
251
- current = current.parent;
252
- }
253
- return null;
254
- }
153
+ const { checker, getTSNode } = (0, type_services_1.getTypeServices)(context);
255
154
  /**
256
155
  * Reports plugin IDs that do not use the owning extension package prefix.
257
156
  */
@@ -260,10 +159,14 @@ const pluginIdConvention = (0, create_rule_1.createRule)({
260
159
  // ID is resolved: resolving may ask the type checker, and most object
261
160
  // literals with an `id` are commands, menu items or DOM nodes.
262
161
  const hasId = (0, plugin_utils_1.getObjectProperties)(node).has('id');
263
- if (!hasId ||
264
- (!(0, plugin_utils_1.looksLikePluginObject)(node, hasId) &&
265
- !(0, plugin_utils_1.looksLikeMimeExtensionObject)(node, hasId) &&
266
- !hasPluginType(node))) {
162
+ if (!hasId) {
163
+ return;
164
+ }
165
+ const pluginKind = (0, plugin_utils_1.getPluginObjectKind)(node, checker, getTSNode, {
166
+ allowUntyped: true,
167
+ matchMime: true
168
+ });
169
+ if (!pluginKind) {
267
170
  return;
268
171
  }
269
172
  const pluginId = (0, plugin_utils_1.getPluginId)(node, context.sourceCode.getScope(node), checker, getTSNode);
@@ -1,6 +1,6 @@
1
- import { ESLintUtils } from '@typescript-eslint/utils';
1
+ import { TSESLint } from '@typescript-eslint/utils';
2
2
  import { LazyImportOptions } from '../utils/lazy-imports';
3
- declare const jupyterPreferLazyImports: ESLintUtils.RuleModule<string, [LazyImportOptions], unknown, ESLintUtils.RuleListener> & {
3
+ declare const jupyterPreferLazyImports: TSESLint.RuleModule<string, [LazyImportOptions], unknown, TSESLint.RuleListener> & {
4
4
  name: string;
5
5
  };
6
6
  export = jupyterPreferLazyImports;
@@ -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,6 @@
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
+ }], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
5
4
  name: string;
6
5
  };
7
6
  export = preferSignalThisArg;
@@ -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 signal_lifetime_1 = require("../utils/signal-lifetime");
10
10
  const preferSignalThisArg = (0, create_rule_1.createRule)({
@@ -45,15 +45,7 @@ const preferSignalThisArg = (0, create_rule_1.createRule)({
45
45
  ],
46
46
  create(context, [options]) {
47
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
- }
48
+ const { services, checker } = (0, type_services_1.getTypeServices)(context);
57
49
  const sourceCode = context.sourceCode;
58
50
  let program = null;
59
51
  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,7 @@
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
+ }], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
6
5
  name: string;
7
6
  };
8
7
  export = requireSignalCleanup;
@@ -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 signal_lifetime_1 = require("../utils/signal-lifetime");
10
10
  const requireSignalCleanup = (0, create_rule_1.createRule)({
@@ -51,15 +51,7 @@ const requireSignalCleanup = (0, create_rule_1.createRule)({
51
51
  create(context, [options]) {
52
52
  const additionalCleanupMethods = options.additionalCleanupMethods || [];
53
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
- }
54
+ const { services, checker } = (0, type_services_1.getTypeServices)(context);
63
55
  const sourceCode = context.sourceCode;
64
56
  let program = null;
65
57
  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) {
@@ -1,5 +1,22 @@
1
1
  import { TSESTree } from '@typescript-eslint/types';
2
+ import { TSESLint } from '@typescript-eslint/utils';
3
+ import * as ts from 'typescript';
2
4
  /**
3
5
  * Checks if a node represents *.addCommand()
4
6
  */
5
7
  export declare function isAddCommandCall(node: TSESTree.CallExpression): boolean;
8
+ /**
9
+ * Resolves a command ID expression to the string it holds at lint time.
10
+ *
11
+ * On top of `resolveStaticString`, this reads a member of a namespace or enum
12
+ * declared in the same file without type information, since
13
+ * `namespace CommandIDs { export const open = '...'; }` is how JupyterLab and
14
+ * most extensions declare their command IDs.
15
+ */
16
+ 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;
17
+ /**
18
+ * Checks whether an `addCommand` receiver is a registry the code created
19
+ * itself with `new CommandRegistry()`, such as the throw-away registry behind
20
+ * a context menu, rather than the application's shared `app.commands`.
21
+ */
22
+ export declare function isPrivateCommandRegistry(receiver: TSESTree.Expression, scope: TSESLint.Scope.Scope): boolean;