@jupyter/eslint-plugin 1.1.0 → 1.3.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.
- package/lib/index.d.ts +49 -2
- package/lib/index.js +35 -5
- package/lib/rules/galata-prefer-context-menu-helper.d.ts +6 -0
- package/lib/rules/galata-prefer-context-menu-helper.js +394 -0
- package/lib/rules/galata-prefer-menu-helper.d.ts +6 -0
- package/lib/rules/galata-prefer-menu-helper.js +394 -0
- package/lib/rules/galata-prefer-notebook-cell-helper.d.ts +6 -0
- package/lib/rules/galata-prefer-notebook-cell-helper.js +403 -0
- package/lib/rules/galata-prefer-sidebar-activity-helper.d.ts +6 -0
- package/lib/rules/galata-prefer-sidebar-activity-helper.js +332 -0
- package/lib/rules/no-schema-enum.d.ts +1 -1
- package/lib/rules/no-schema-enum.js +54 -2
- package/lib/rules/no-untranslated-string.d.ts +2 -1
- package/lib/rules/no-untranslated-string.js +191 -113
- package/lib/rules/plugin-id-convention.d.ts +7 -0
- package/lib/rules/plugin-id-convention.js +296 -0
- package/lib/rules/prefer-lazy-imports.d.ts +6 -0
- package/lib/rules/prefer-lazy-imports.js +476 -0
- package/lib/rules/require-disposable-ownership.js +1 -16
- package/lib/rules/require-disposable-transfer.js +7 -2
- package/lib/utils/ast.d.ts +12 -0
- package/lib/utils/ast.js +49 -0
- package/lib/utils/disposables.d.ts +12 -0
- package/lib/utils/disposables.js +101 -10
- package/lib/utils/lazy-imports.d.ts +93 -0
- package/lib/utils/lazy-imports.js +600 -0
- package/lib/utils/module-size.d.ts +18 -0
- package/lib/utils/module-size.js +249 -0
- package/lib/utils/package-json.d.ts +8 -0
- package/lib/utils/package-json.js +76 -0
- package/lib/utils/playwright-selectors.d.ts +56 -5
- package/lib/utils/playwright-selectors.js +205 -12
- package/lib/utils/plugin-utils.d.ts +50 -2
- package/lib/utils/plugin-utils.js +221 -38
- package/lib/utils/shared-packages.d.ts +9 -0
- package/lib/utils/shared-packages.js +128 -0
- package/lib/utils/signal-lifetime.js +66 -5
- package/lib/utils/signals.d.ts +2 -8
- package/lib/utils/signals.js +7 -42
- package/package.json +1 -1
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) Jupyter Development Team.
|
|
4
|
+
* Distributed under the terms of the Modified BSD License.
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.getHostProvidedPackages = getHostProvidedPackages;
|
|
41
|
+
const fs = __importStar(require("fs"));
|
|
42
|
+
const path = __importStar(require("path"));
|
|
43
|
+
const package_json_1 = require("./package-json");
|
|
44
|
+
/** How far to look upwards for the labextension manifest. */
|
|
45
|
+
const MAX_LEVELS = 12;
|
|
46
|
+
const manifestCache = new Map();
|
|
47
|
+
/** Directory to the manifest which governs it, or null when there is none. */
|
|
48
|
+
const manifestPathCache = new Map();
|
|
49
|
+
/**
|
|
50
|
+
* Reads the packages which `jupyterlab.sharedPackages` marks as provided by
|
|
51
|
+
* the application rather than bundled here.
|
|
52
|
+
*
|
|
53
|
+
* `@jupyter/builder` turns `bundled: false` into `import: false`, which leaves
|
|
54
|
+
* the package to the host at runtime. Anything else stays in this extension's
|
|
55
|
+
* own bundle: `bundled: true`, an entry with no `bundled` key, and `false`,
|
|
56
|
+
* which removes the package from the shared scope altogether.
|
|
57
|
+
*/
|
|
58
|
+
function readManifest(manifestPath) {
|
|
59
|
+
const manifest = (0, package_json_1.readPackageJson)(manifestPath);
|
|
60
|
+
if (!manifest) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
const cached = manifestCache.get(manifestPath);
|
|
64
|
+
if (cached && cached.mtimeMs === manifest.mtimeMs) {
|
|
65
|
+
return cached;
|
|
66
|
+
}
|
|
67
|
+
const jupyterlab = manifest.data.jupyterlab;
|
|
68
|
+
if (!jupyterlab || typeof jupyterlab !== 'object') {
|
|
69
|
+
// Not a labextension manifest, so keep looking further up.
|
|
70
|
+
manifestCache.set(manifestPath, null);
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
const shared = jupyterlab.sharedPackages ?? {};
|
|
74
|
+
const hostProvided = [];
|
|
75
|
+
for (const [name, entry] of Object.entries(shared)) {
|
|
76
|
+
if (entry &&
|
|
77
|
+
typeof entry === 'object' &&
|
|
78
|
+
entry.bundled === false) {
|
|
79
|
+
hostProvided.push(name);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const info = { mtimeMs: manifest.mtimeMs, hostProvided };
|
|
83
|
+
manifestCache.set(manifestPath, info);
|
|
84
|
+
return info;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Walks up from a linted file to its labextension manifest and returns the
|
|
88
|
+
* packages the application provides at runtime. Importing one of those at the
|
|
89
|
+
* top of a plugin module adds nothing to the extension's own bundle.
|
|
90
|
+
*
|
|
91
|
+
* Returns an empty list when no manifest declares any, which is the common
|
|
92
|
+
* case outside a monorepo sharing packages between its extensions.
|
|
93
|
+
*/
|
|
94
|
+
function getHostProvidedPackages(fromFile) {
|
|
95
|
+
const start = path.dirname(path.resolve(fromFile));
|
|
96
|
+
const cachedPath = manifestPathCache.get(start);
|
|
97
|
+
if (cachedPath !== undefined) {
|
|
98
|
+
// Re-enter the reader so an edited manifest is picked up.
|
|
99
|
+
return cachedPath === null
|
|
100
|
+
? []
|
|
101
|
+
: (readManifest(cachedPath)?.hostProvided ?? []);
|
|
102
|
+
}
|
|
103
|
+
const visited = [];
|
|
104
|
+
let found = null;
|
|
105
|
+
let directory = start;
|
|
106
|
+
for (let level = 0; level < MAX_LEVELS; level++) {
|
|
107
|
+
visited.push(directory);
|
|
108
|
+
const manifestPath = path.join(directory, 'package.json');
|
|
109
|
+
if (readManifest(manifestPath)) {
|
|
110
|
+
found = manifestPath;
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
// A repository root bounds the search, so an unrelated manifest further up
|
|
114
|
+
// cannot change what this extension is allowed to import.
|
|
115
|
+
if (fs.existsSync(path.join(directory, '.git'))) {
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
const parent = path.dirname(directory);
|
|
119
|
+
if (parent === directory) {
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
directory = parent;
|
|
123
|
+
}
|
|
124
|
+
for (const seen of visited) {
|
|
125
|
+
manifestPathCache.set(seen, found);
|
|
126
|
+
}
|
|
127
|
+
return found === null ? [] : (readManifest(found)?.hostProvided ?? []);
|
|
128
|
+
}
|
|
@@ -64,6 +64,8 @@ exports.DEFAULT_LONG_LIVED_TYPES = [
|
|
|
64
64
|
'ILabShell',
|
|
65
65
|
'ILanguageServerManager',
|
|
66
66
|
'IRenderMimeRegistry',
|
|
67
|
+
'ISessionConnection',
|
|
68
|
+
'ISessionContext',
|
|
67
69
|
'ISettingRegistry',
|
|
68
70
|
'IShell',
|
|
69
71
|
'IStateDB',
|
|
@@ -354,8 +356,8 @@ function classHasDisposalProtocol(classNode) {
|
|
|
354
356
|
}
|
|
355
357
|
return false;
|
|
356
358
|
}
|
|
357
|
-
/** Resolves the symbol
|
|
358
|
-
function
|
|
359
|
+
/** Resolves the symbol of an expression's static type, if available. */
|
|
360
|
+
function typeSymbolOf(node, context) {
|
|
359
361
|
const { checker, services } = context;
|
|
360
362
|
if (!checker || !services || !services.esTreeNodeToTSNodeMap) {
|
|
361
363
|
return null;
|
|
@@ -385,12 +387,71 @@ function typeNameOf(node, context) {
|
|
|
385
387
|
// Keep the un-aliased symbol.
|
|
386
388
|
}
|
|
387
389
|
}
|
|
388
|
-
return symbol
|
|
390
|
+
return symbol;
|
|
389
391
|
}
|
|
390
392
|
catch {
|
|
391
393
|
return null;
|
|
392
394
|
}
|
|
393
395
|
}
|
|
396
|
+
/** Resolves the symbol name of an expression's static type, if available. */
|
|
397
|
+
function typeNameOf(node, context) {
|
|
398
|
+
const symbol = typeSymbolOf(node, context);
|
|
399
|
+
return symbol ? symbol.getName() : null;
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* The namespace path of an expression's static type, outermost first:
|
|
403
|
+
* `ISessionConnection` declared in `namespace Session` comes back as
|
|
404
|
+
* `['Session', 'ISessionConnection']`.
|
|
405
|
+
*/
|
|
406
|
+
function typeNamePathOf(node, context) {
|
|
407
|
+
const symbol = typeSymbolOf(node, context);
|
|
408
|
+
if (!symbol || !context.checker) {
|
|
409
|
+
return [];
|
|
410
|
+
}
|
|
411
|
+
let qualified;
|
|
412
|
+
try {
|
|
413
|
+
qualified = context.checker.getFullyQualifiedName(symbol);
|
|
414
|
+
}
|
|
415
|
+
catch {
|
|
416
|
+
return [symbol.getName()];
|
|
417
|
+
}
|
|
418
|
+
// A module-scoped symbol is qualified by its quoted specifier, which may
|
|
419
|
+
// itself contain dots (`"@jupyterlab/services"`, `"./foo.bar"`).
|
|
420
|
+
const withoutModule = qualified.replace(/^(["'])(?:(?!\1).)*\1\.?/, '');
|
|
421
|
+
const segments = (withoutModule || qualified).split('.').filter(Boolean);
|
|
422
|
+
return segments.length > 0 ? segments : [symbol.getName()];
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* The `longLivedTypes` entry matching this expression's static type, or null.
|
|
426
|
+
*
|
|
427
|
+
* An entry matches when it is a suffix of the type's namespace path, so
|
|
428
|
+
* `Session.ISessionConnection` and a bare `ISessionConnection` both match
|
|
429
|
+
* `Session.ISessionConnection` while `Session.ISessionConnection` does not
|
|
430
|
+
* match some unrelated top-level `ISessionConnection`. When several entries
|
|
431
|
+
* match, the longest wins: a list carrying both `IContext` and
|
|
432
|
+
* `DocumentRegistry.IContext` reports the qualified one regardless of the order
|
|
433
|
+
* they were configured in.
|
|
434
|
+
*/
|
|
435
|
+
function matchLongLivedType(node, context) {
|
|
436
|
+
const path = typeNamePathOf(node, context);
|
|
437
|
+
if (path.length === 0) {
|
|
438
|
+
return null;
|
|
439
|
+
}
|
|
440
|
+
let best = null;
|
|
441
|
+
let bestLength = 0;
|
|
442
|
+
for (const entry of context.longLivedTypes) {
|
|
443
|
+
const wanted = entry.split('.').filter(Boolean);
|
|
444
|
+
if (wanted.length <= bestLength || wanted.length > path.length) {
|
|
445
|
+
continue;
|
|
446
|
+
}
|
|
447
|
+
const offset = path.length - wanted.length;
|
|
448
|
+
if (wanted.every((segment, i) => segment === path[offset + i])) {
|
|
449
|
+
best = entry;
|
|
450
|
+
bestLength = wanted.length;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
return best;
|
|
454
|
+
}
|
|
394
455
|
function isWidgetTyped(node, context) {
|
|
395
456
|
const { checker, services } = context;
|
|
396
457
|
if (!checker || !services || !services.esTreeNodeToTSNodeMap) {
|
|
@@ -608,8 +669,8 @@ function isLongLivedService(chain, context) {
|
|
|
608
669
|
// configured entry) is not matched against itself.
|
|
609
670
|
const start = chain.root?.type === 'ThisExpression' ? 1 : 0;
|
|
610
671
|
for (let i = start; i < chain.prefixes.length; i++) {
|
|
611
|
-
const name =
|
|
612
|
-
if (!name
|
|
672
|
+
const name = matchLongLivedType(chain.prefixes[i], context);
|
|
673
|
+
if (!name) {
|
|
613
674
|
continue;
|
|
614
675
|
}
|
|
615
676
|
let blocked = false;
|
package/lib/utils/signals.d.ts
CHANGED
|
@@ -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 {};
|
package/lib/utils/signals.js
CHANGED
|
@@ -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 =
|
|
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
|
|
57
|
+
const ast_1 = require("./ast");
|
|
58
58
|
const ts = __importStar(require("typescript"));
|
|
59
|
-
|
|
60
|
-
|
|
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' ||
|
package/package.json
CHANGED