@jupyter/eslint-plugin 1.2.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.
Files changed (48) hide show
  1. package/lib/index.d.ts +27 -1
  2. package/lib/index.js +21 -3
  3. package/lib/rules/command-id-convention.d.ts +5 -0
  4. package/lib/rules/command-id-convention.js +87 -0
  5. package/lib/rules/galata-prefer-context-menu-helper.d.ts +6 -0
  6. package/lib/rules/galata-prefer-context-menu-helper.js +394 -0
  7. package/lib/rules/galata-prefer-menu-helper.js +18 -102
  8. package/lib/rules/no-untranslated-string.d.ts +2 -1
  9. package/lib/rules/no-untranslated-string.js +191 -113
  10. package/lib/rules/plugin-activation-args.d.ts +3 -3
  11. package/lib/rules/plugin-activation-args.js +173 -142
  12. package/lib/rules/plugin-description.js +12 -9
  13. package/lib/rules/plugin-id-convention.d.ts +6 -0
  14. package/lib/rules/plugin-id-convention.js +199 -0
  15. package/lib/rules/prefer-lazy-imports.d.ts +2 -2
  16. package/lib/rules/prefer-lazy-imports.js +257 -58
  17. package/lib/rules/prefer-signal-this-arg.d.ts +2 -3
  18. package/lib/rules/prefer-signal-this-arg.js +2 -10
  19. package/lib/rules/require-disposable-ownership.d.ts +1 -2
  20. package/lib/rules/require-disposable-ownership.js +3 -26
  21. package/lib/rules/require-disposable-transfer.d.ts +1 -2
  22. package/lib/rules/require-disposable-transfer.js +14 -14
  23. package/lib/rules/require-signal-cleanup.d.ts +2 -3
  24. package/lib/rules/require-signal-cleanup.js +2 -10
  25. package/lib/rules/require-signal-this-arg.d.ts +1 -2
  26. package/lib/rules/require-signal-this-arg.js +2 -10
  27. package/lib/utils/ast.d.ts +12 -0
  28. package/lib/utils/ast.js +49 -0
  29. package/lib/utils/commands.d.ts +17 -0
  30. package/lib/utils/commands.js +205 -0
  31. package/lib/utils/disposables.d.ts +12 -0
  32. package/lib/utils/disposables.js +101 -10
  33. package/lib/utils/lazy-imports.d.ts +27 -3
  34. package/lib/utils/lazy-imports.js +130 -36
  35. package/lib/utils/module-size.d.ts +7 -1
  36. package/lib/utils/module-size.js +10 -1
  37. package/lib/utils/package-json.d.ts +8 -0
  38. package/lib/utils/package-json.js +76 -0
  39. package/lib/utils/playwright-selectors.d.ts +15 -0
  40. package/lib/utils/playwright-selectors.js +80 -0
  41. package/lib/utils/plugin-utils.d.ts +66 -6
  42. package/lib/utils/plugin-utils.js +485 -59
  43. package/lib/utils/shared-packages.js +6 -16
  44. package/lib/utils/signals.d.ts +2 -8
  45. package/lib/utils/signals.js +7 -42
  46. package/lib/utils/type-services.d.ts +13 -0
  47. package/lib/utils/type-services.js +27 -0
  48. package/package.json +1 -1
@@ -1,18 +1,13 @@
1
1
  import { TSESTree } from '@typescript-eslint/types';
2
2
  import { ParserServices } from '@typescript-eslint/utils';
3
3
  import * as ts from 'typescript';
4
+ export { walkFrom } from './ast';
5
+ export type { WalkAction } from './ast';
4
6
  export type ClassLike = TSESTree.ClassDeclaration | TSESTree.ClassExpression;
5
7
  export type SignalClassification = 'signal' | 'not-signal' | 'unknown';
6
8
  type ConnectCallExpression = TSESTree.CallExpression & {
7
9
  callee: TSESTree.MemberExpression;
8
10
  };
9
- export type WalkAction = 'skip-children' | 'stop' | undefined;
10
- /**
11
- * Iterative AST walk from `root`, visiting every node. The visitor may return
12
- * 'skip-children' to avoid descending into a node, or 'stop' to abort the
13
- * whole walk.
14
- */
15
- export declare function walkFrom(root: TSESTree.Node, visit: (node: TSESTree.Node) => WalkAction): void;
16
11
  /**
17
12
  * Checks if a node represents `<expr>.connect(...)`.
18
13
  */
@@ -140,4 +135,3 @@ export declare function looksLikeSignalByName(objectNode: TSESTree.Expression):
140
135
  * - 'unknown': no type information, `any`/`unknown`, or resolution failure
141
136
  */
142
137
  export declare function classifySignalReceiver(objectNode: TSESTree.Expression, checker: ts.TypeChecker | null, services: ParserServices | null): SignalClassification;
143
- export {};
@@ -37,7 +37,7 @@ var __importStar = (this && this.__importStar) || (function () {
37
37
  };
38
38
  })();
39
39
  Object.defineProperty(exports, "__esModule", { value: true });
40
- exports.walkFrom = walkFrom;
40
+ exports.walkFrom = void 0;
41
41
  exports.isConnectCall = isConnectCall;
42
42
  exports.isDisconnectCall = isDisconnectCall;
43
43
  exports.isDisposedSignalWiring = isDisposedSignalWiring;
@@ -54,45 +54,10 @@ exports.typeExtendsLuminoWidget = typeExtendsLuminoWidget;
54
54
  exports.methodUsesThis = methodUsesThis;
55
55
  exports.looksLikeSignalByName = looksLikeSignalByName;
56
56
  exports.classifySignalReceiver = classifySignalReceiver;
57
- const visitor_keys_1 = require("@typescript-eslint/visitor-keys");
57
+ const ast_1 = require("./ast");
58
58
  const ts = __importStar(require("typescript"));
59
- /**
60
- * Iterative AST walk from `root`, visiting every node. The visitor may return
61
- * 'skip-children' to avoid descending into a node, or 'stop' to abort the
62
- * whole walk.
63
- */
64
- function walkFrom(root, visit) {
65
- const stack = [root];
66
- while (stack.length > 0) {
67
- const node = stack.pop();
68
- const action = visit(node);
69
- if (action === 'stop') {
70
- return;
71
- }
72
- if (action === 'skip-children') {
73
- continue;
74
- }
75
- const keys = visitor_keys_1.visitorKeys[node.type] ?? (0, visitor_keys_1.getKeys)(node);
76
- for (const key of keys) {
77
- const child = node[key];
78
- if (Array.isArray(child)) {
79
- for (const item of child) {
80
- if (isNode(item)) {
81
- stack.push(item);
82
- }
83
- }
84
- }
85
- else if (isNode(child)) {
86
- stack.push(child);
87
- }
88
- }
89
- }
90
- }
91
- function isNode(value) {
92
- return (typeof value === 'object' &&
93
- value !== null &&
94
- typeof value.type === 'string');
95
- }
59
+ var ast_2 = require("./ast");
60
+ Object.defineProperty(exports, "walkFrom", { enumerable: true, get: function () { return ast_2.walkFrom; } });
96
61
  /**
97
62
  * Checks if a call expression is a non-computed `<expr>.<name>(...)` call.
98
63
  */
@@ -354,7 +319,7 @@ function resolveUnboundThisMethodConnect(node) {
354
319
  */
355
320
  function classHasCleanupEvidence(classNode, signalLocalNames, extraMethodNames = []) {
356
321
  let found = false;
357
- walkFrom(classNode.body, node => {
322
+ (0, ast_1.walkFrom)(classNode.body, node => {
358
323
  if (node.type === 'ClassDeclaration' || node.type === 'ClassExpression') {
359
324
  return 'skip-children';
360
325
  }
@@ -385,7 +350,7 @@ const RECEIVER_CLEANUP_STATICS = [
385
350
  */
386
351
  function classUsesReceiverBasedCleanup(classNode, signalLocalNames) {
387
352
  let found = false;
388
- walkFrom(classNode.body, node => {
353
+ (0, ast_1.walkFrom)(classNode.body, node => {
389
354
  if (node.type === 'ClassDeclaration' || node.type === 'ClassExpression') {
390
355
  return 'skip-children';
391
356
  }
@@ -487,7 +452,7 @@ function typeExtendsLuminoWidget(type, checker) {
487
452
  */
488
453
  function methodUsesThis(fn) {
489
454
  let found = false;
490
- walkFrom(fn.body, node => {
455
+ (0, ast_1.walkFrom)(fn.body, node => {
491
456
  if (node.type === 'FunctionExpression' ||
492
457
  node.type === 'FunctionDeclaration' ||
493
458
  node.type === 'TSDeclareFunction' ||
@@ -0,0 +1,13 @@
1
+ import { TSESTree } from '@typescript-eslint/types';
2
+ import { ParserServices, TSESLint } from '@typescript-eslint/utils';
3
+ import * as ts from 'typescript';
4
+ export interface TypeServices {
5
+ services: ParserServices | null;
6
+ checker: ts.TypeChecker | null;
7
+ getTSNode: ((node: TSESTree.Node) => ts.Node | undefined) | null;
8
+ }
9
+ /**
10
+ * Retrieves the TypeScript parser services, type checker, and node mapper
11
+ * from the rule context, falling back gracefully if type information is unavailable.
12
+ */
13
+ export declare function getTypeServices(context: TSESLint.RuleContext<string, readonly unknown[]>): TypeServices;
@@ -0,0 +1,27 @@
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.getTypeServices = getTypeServices;
8
+ const utils_1 = require("@typescript-eslint/utils");
9
+ /**
10
+ * Retrieves the TypeScript parser services, type checker, and node mapper
11
+ * from the rule context, falling back gracefully if type information is unavailable.
12
+ */
13
+ function getTypeServices(context) {
14
+ let services = null;
15
+ let checker = null;
16
+ try {
17
+ services = utils_1.ESLintUtils.getParserServices(context, true);
18
+ checker = services.program ? services.program.getTypeChecker() : null;
19
+ }
20
+ catch {
21
+ services = null;
22
+ }
23
+ const getTSNode = services
24
+ ? (node) => services?.esTreeNodeToTSNodeMap.get(node)
25
+ : null;
26
+ return { services, checker, getTSNode };
27
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jupyter/eslint-plugin",
3
- "version": "1.2.0",
3
+ "version": "1.4.0",
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",