@jupyter/eslint-plugin 1.0.1 → 1.2.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 +98 -1
- package/lib/index.js +61 -11
- package/lib/rules/galata-prefer-filebrowser-helper.d.ts +5 -0
- package/lib/rules/galata-prefer-filebrowser-helper.js +105 -0
- package/lib/rules/galata-prefer-menu-helper.d.ts +6 -0
- package/lib/rules/galata-prefer-menu-helper.js +478 -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/incorrect-translator-usage.d.ts +4 -0
- package/lib/rules/incorrect-translator-usage.js +208 -0
- package/lib/rules/no-dynamic-translation.d.ts +4 -0
- package/lib/rules/no-dynamic-translation.js +92 -0
- package/lib/rules/no-pageconfig-base-url.d.ts +4 -0
- package/lib/rules/no-pageconfig-base-url.js +37 -0
- package/lib/rules/no-schema-enum.d.ts +1 -1
- package/lib/rules/no-schema-enum.js +54 -2
- package/lib/rules/no-translation-concatenation.js +46 -84
- package/lib/rules/no-untranslated-string.js +7 -4
- package/lib/rules/plugin-activation-args.js +1 -2
- package/lib/rules/prefer-lazy-imports.d.ts +6 -0
- package/lib/rules/prefer-lazy-imports.js +308 -0
- package/lib/rules/prefer-signal-this-arg.d.ts +7 -0
- package/lib/rules/prefer-signal-this-arg.js +196 -0
- package/lib/rules/require-disposable-ownership.d.ts +5 -0
- package/lib/rules/require-disposable-ownership.js +120 -0
- package/lib/rules/require-disposable-transfer.d.ts +5 -0
- package/lib/rules/require-disposable-transfer.js +223 -0
- package/lib/rules/require-signal-cleanup.d.ts +8 -0
- package/lib/rules/require-signal-cleanup.js +164 -0
- package/lib/rules/require-signal-this-arg.d.ts +5 -0
- package/lib/rules/require-signal-this-arg.js +74 -0
- package/lib/rules/token-format.js +1 -2
- package/lib/utils/disposables.d.ts +64 -0
- package/lib/utils/disposables.js +1723 -0
- package/lib/utils/lazy-imports.d.ts +70 -0
- package/lib/utils/lazy-imports.js +515 -0
- package/lib/utils/module-size.d.ts +12 -0
- package/lib/utils/module-size.js +240 -0
- package/lib/utils/playwright-selectors.d.ts +102 -0
- package/lib/utils/playwright-selectors.js +306 -0
- package/lib/utils/plugin-utils.d.ts +18 -0
- package/lib/utils/plugin-utils.js +127 -19
- package/lib/utils/shared-packages.d.ts +9 -0
- package/lib/utils/shared-packages.js +138 -0
- package/lib/utils/signal-lifetime.d.ts +158 -0
- package/lib/utils/signal-lifetime.js +816 -0
- package/lib/utils/signals.d.ts +143 -0
- package/lib/utils/signals.js +601 -0
- package/lib/utils/translation.d.ts +45 -0
- package/lib/utils/translation.js +122 -0
- package/package.json +9 -2
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) Jupyter Development Team.
|
|
4
|
+
* Distributed under the terms of the Modified BSD License.
|
|
5
|
+
*/
|
|
6
|
+
const utils_1 = require("@typescript-eslint/utils");
|
|
7
|
+
const create_rule_1 = require("../utils/create-rule");
|
|
8
|
+
const signals_1 = require("../utils/signals");
|
|
9
|
+
const signal_lifetime_1 = require("../utils/signal-lifetime");
|
|
10
|
+
const requireSignalCleanup = (0, create_rule_1.createRule)({
|
|
11
|
+
name: 'require-signal-cleanup',
|
|
12
|
+
meta: {
|
|
13
|
+
type: 'problem',
|
|
14
|
+
docs: {
|
|
15
|
+
description: 'Require a cleanup path for Lumino signal connections whose sender outlives the connecting class',
|
|
16
|
+
url: 'https://eslint-plugin.readthedocs.io/en/latest/rules/require-signal-cleanup/'
|
|
17
|
+
},
|
|
18
|
+
messages: {
|
|
19
|
+
serviceOutlivesReceiver: 'This connection to "{{ sender }}" is never removed, and "{{ typeName }}" is an application-lifetime service, so it will outlive this class and keep every instance alive. Disconnect it during teardown, or call Signal.clearData(this).'
|
|
20
|
+
},
|
|
21
|
+
schema: [
|
|
22
|
+
{
|
|
23
|
+
type: 'object',
|
|
24
|
+
properties: {
|
|
25
|
+
additionalCleanupMethods: {
|
|
26
|
+
type: 'array',
|
|
27
|
+
items: {
|
|
28
|
+
type: 'string'
|
|
29
|
+
},
|
|
30
|
+
default: [],
|
|
31
|
+
description: 'Additional method names (besides "disconnect") that count as cleanup evidence when called anywhere in the class'
|
|
32
|
+
},
|
|
33
|
+
longLivedTypes: {
|
|
34
|
+
type: 'array',
|
|
35
|
+
items: {
|
|
36
|
+
type: 'string'
|
|
37
|
+
},
|
|
38
|
+
description: 'Type names treated as application-lifetime services. Replaces the built-in list when provided.'
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
additionalProperties: false
|
|
42
|
+
}
|
|
43
|
+
]
|
|
44
|
+
},
|
|
45
|
+
defaultOptions: [
|
|
46
|
+
{
|
|
47
|
+
additionalCleanupMethods: [],
|
|
48
|
+
longLivedTypes: undefined
|
|
49
|
+
}
|
|
50
|
+
],
|
|
51
|
+
create(context, [options]) {
|
|
52
|
+
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
|
+
}
|
|
63
|
+
const sourceCode = context.sourceCode;
|
|
64
|
+
let program = null;
|
|
65
|
+
let signalLocalNames = new Set(['Signal']);
|
|
66
|
+
const cleanupEvidenceCache = new Map();
|
|
67
|
+
const ownershipCache = new Map();
|
|
68
|
+
return {
|
|
69
|
+
Program(node) {
|
|
70
|
+
program = node;
|
|
71
|
+
signalLocalNames = (0, signals_1.collectSignalNamespaceLocalNames)(node);
|
|
72
|
+
cleanupEvidenceCache.clear();
|
|
73
|
+
ownershipCache.clear();
|
|
74
|
+
},
|
|
75
|
+
CallExpression(node) {
|
|
76
|
+
if (!(0, signals_1.isConnectCall)(node) || !program) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (node.arguments.length < 2) {
|
|
80
|
+
// No thisArg — see require-signal-this-arg / prefer-signal-this-arg.
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (node.arguments[1].type !== 'ThisExpression') {
|
|
84
|
+
// Receiver is some other object; its lifetime is not traceable here.
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if ((0, signals_1.getThisBinding)(node) !== 'instance') {
|
|
88
|
+
// In a `static` member `this` is the class object, and in a nested
|
|
89
|
+
// regular function it is whatever the caller binds. Neither is an
|
|
90
|
+
// instance whose lifetime this rule reasons about, and neither is
|
|
91
|
+
// removed by a `Signal.clearData(this)` in `dispose()`.
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const enclosingClass = (0, signals_1.getEnclosingClass)(node);
|
|
95
|
+
if (!enclosingClass) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (enclosingClass.superClass) {
|
|
99
|
+
// The base class may clean up in an inherited dispose() that is
|
|
100
|
+
// invisible from here — Lumino's Widget.dispose() calls
|
|
101
|
+
// Signal.clearData(this), which removes exactly this connection.
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if (!(0, signal_lifetime_1.classHasDisposalProtocol)(enclosingClass)) {
|
|
105
|
+
// No dispose(), no isDisposed, no `implements IDisposable`: almost
|
|
106
|
+
// always a plugin-scope singleton whose lifetime matches the
|
|
107
|
+
// services it connects to, and with nowhere to put a disconnect.
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const chain = (0, signal_lifetime_1.buildSenderChain)(node.callee.object);
|
|
111
|
+
if ((0, signal_lifetime_1.isSelfTerminatingSignal)(chain)) {
|
|
112
|
+
// `x.disposed.connect(cb, this)` fires as its sender is torn down
|
|
113
|
+
// and is cleaned up sender-side. It is the pattern this rule
|
|
114
|
+
// recommends, so it must never be flagged.
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
let hasEvidence = cleanupEvidenceCache.get(enclosingClass);
|
|
118
|
+
if (hasEvidence === undefined) {
|
|
119
|
+
hasEvidence = (0, signals_1.classHasCleanupEvidence)(enclosingClass, signalLocalNames, additionalCleanupMethods);
|
|
120
|
+
cleanupEvidenceCache.set(enclosingClass, hasEvidence);
|
|
121
|
+
}
|
|
122
|
+
if (hasEvidence) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const classification = (0, signals_1.classifySignalReceiver)(node.callee.object, checker, services);
|
|
126
|
+
if (classification === 'not-signal') {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
let facts = ownershipCache.get(enclosingClass);
|
|
130
|
+
if (!facts) {
|
|
131
|
+
facts = (0, signal_lifetime_1.collectClassOwnershipFacts)(enclosingClass, sourceCode, signalLocalNames);
|
|
132
|
+
ownershipCache.set(enclosingClass, facts);
|
|
133
|
+
}
|
|
134
|
+
const analysis = (0, signal_lifetime_1.analyzeSender)(node.callee.object, {
|
|
135
|
+
classNode: enclosingClass,
|
|
136
|
+
facts,
|
|
137
|
+
sourceCode,
|
|
138
|
+
scope: sourceCode.getScope(node),
|
|
139
|
+
checker,
|
|
140
|
+
services,
|
|
141
|
+
longLivedTypes
|
|
142
|
+
});
|
|
143
|
+
// Only positively proven long-lived senders are reported. `self`,
|
|
144
|
+
// `owned` and `unknown` all stay silent: absence of cleanup is not
|
|
145
|
+
// evidence of a leak when the sender dies with the receiver.
|
|
146
|
+
//
|
|
147
|
+
// `long-lived-model` cannot occur here: it is gated on the receiver
|
|
148
|
+
// extending Lumino's Widget, and every such class is already skipped
|
|
149
|
+
// above by the `superClass` check.
|
|
150
|
+
if (analysis.lifetime === 'long-lived-service') {
|
|
151
|
+
context.report({
|
|
152
|
+
node,
|
|
153
|
+
messageId: 'serviceOutlivesReceiver',
|
|
154
|
+
data: {
|
|
155
|
+
sender: analysis.senderText,
|
|
156
|
+
typeName: analysis.typeName ?? 'service'
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
module.exports = requireSignalCleanup;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) Jupyter Development Team.
|
|
4
|
+
* Distributed under the terms of the Modified BSD License.
|
|
5
|
+
*/
|
|
6
|
+
const utils_1 = require("@typescript-eslint/utils");
|
|
7
|
+
const create_rule_1 = require("../utils/create-rule");
|
|
8
|
+
const signals_1 = require("../utils/signals");
|
|
9
|
+
const requireSignalThisArg = (0, create_rule_1.createRule)({
|
|
10
|
+
name: 'require-signal-this-arg',
|
|
11
|
+
meta: {
|
|
12
|
+
type: 'suggestion',
|
|
13
|
+
hasSuggestions: true,
|
|
14
|
+
docs: {
|
|
15
|
+
description: 'Require a thisArg when connecting a class method that references `this` to a Lumino signal',
|
|
16
|
+
url: 'https://eslint-plugin.readthedocs.io/en/latest/rules/require-signal-this-arg/'
|
|
17
|
+
},
|
|
18
|
+
messages: {
|
|
19
|
+
missingThisArg: 'Callback "{{ name }}" references "this" but is connected without a thisArg, so "this" will not be bound to this instance when the signal fires. Pass "this" as the second argument to connect().',
|
|
20
|
+
addThisArg: 'Add "this" as the second argument'
|
|
21
|
+
},
|
|
22
|
+
schema: []
|
|
23
|
+
},
|
|
24
|
+
defaultOptions: [],
|
|
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
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
CallExpression(node) {
|
|
37
|
+
if (!(0, signals_1.isConnectCall)(node) || node.arguments.length !== 1) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const unbound = (0, signals_1.resolveUnboundThisMethodConnect)(node);
|
|
41
|
+
if (!unbound) {
|
|
42
|
+
// Any other callback shape has no runtime `this` bug; the
|
|
43
|
+
// warning-level prefer-signal-this-arg rule covers those.
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const classification = (0, signals_1.classifySignalReceiver)(node.callee.object, checker, services);
|
|
47
|
+
if (classification === 'not-signal') {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (classification === 'unknown' &&
|
|
51
|
+
!(0, signals_1.looksLikeSignalByName)(node.callee.object)) {
|
|
52
|
+
// Single-argument `.connect(callback)` is a weak signature shared
|
|
53
|
+
// by many non-Lumino APIs — without type information, require a
|
|
54
|
+
// conventional signal name before flagging.
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
context.report({
|
|
58
|
+
node: unbound.arg,
|
|
59
|
+
messageId: 'missingThisArg',
|
|
60
|
+
data: {
|
|
61
|
+
name: unbound.isPrivate ? `#${unbound.name}` : unbound.name
|
|
62
|
+
},
|
|
63
|
+
suggest: [
|
|
64
|
+
{
|
|
65
|
+
messageId: 'addThisArg',
|
|
66
|
+
fix: fixer => fixer.insertTextAfter(unbound.arg, ', this')
|
|
67
|
+
}
|
|
68
|
+
]
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
module.exports = requireSignalThisArg;
|
|
@@ -27,8 +27,7 @@ const tokenFormat = (0, create_rule_1.createRule)({
|
|
|
27
27
|
create(context) {
|
|
28
28
|
return {
|
|
29
29
|
NewExpression(node) {
|
|
30
|
-
if (node.callee.type !== 'Identifier' ||
|
|
31
|
-
node.callee.name !== 'Token') {
|
|
30
|
+
if (node.callee.type !== 'Identifier' || node.callee.name !== 'Token') {
|
|
32
31
|
return;
|
|
33
32
|
}
|
|
34
33
|
if (node.arguments.length === 0) {
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { TSESTree } from '@typescript-eslint/types';
|
|
2
|
+
import { ParserServices, TSESLint } from '@typescript-eslint/utils';
|
|
3
|
+
import * as ts from 'typescript';
|
|
4
|
+
/**
|
|
5
|
+
* Resolves a configurable name list option.
|
|
6
|
+
*
|
|
7
|
+
* A user-supplied list is *added* to the built-in defaults, so a project only
|
|
8
|
+
* has to name its own helpers rather than restate this plugin's list. Passing
|
|
9
|
+
* the matching `extendDefault...` option as `false` drops the defaults, whether
|
|
10
|
+
* or not a replacement list is given, which is also how to ask for the
|
|
11
|
+
* strictest possible checking.
|
|
12
|
+
*/
|
|
13
|
+
export declare function resolveNameListOption(provided: readonly string[] | undefined, defaults: readonly string[], extendDefaults: boolean): Set<string>;
|
|
14
|
+
export declare const DEFAULT_OWNERSHIP_FUNCTION_NAMES: string[];
|
|
15
|
+
interface PendingDisposable {
|
|
16
|
+
node: TSESTree.Node;
|
|
17
|
+
}
|
|
18
|
+
export interface DisposableOwnershipContext {
|
|
19
|
+
sourceCode: TSESLint.SourceCode;
|
|
20
|
+
checker: ts.TypeChecker | null;
|
|
21
|
+
services: ParserServices | null;
|
|
22
|
+
ownershipFunctionNames: Set<string>;
|
|
23
|
+
}
|
|
24
|
+
export type PendingDisposableMap = Map<TSESLint.Scope.Variable, PendingDisposable[]>;
|
|
25
|
+
export declare function getCalleeName(node: TSESTree.Node): string | null;
|
|
26
|
+
export declare function isDisposableConstructor(node: TSESTree.NewExpression): boolean;
|
|
27
|
+
export declare function isDisposableSetFactoryCall(node: TSESTree.Node): boolean;
|
|
28
|
+
export declare function addPendingDisposable(pending: PendingDisposableMap, variable: TSESLint.Scope.Variable, node: TSESTree.Node): void;
|
|
29
|
+
export declare function getAssignedVariable(node: TSESTree.Node, sourceCode: TSESLint.SourceCode): TSESLint.Scope.Variable | null;
|
|
30
|
+
export declare function isOuterFunctionScopeVariable(node: TSESTree.Node, variable: TSESLint.Scope.Variable, sourceCode: TSESLint.SourceCode): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Checks whether a variable is an exported binding, in any of the forms the
|
|
33
|
+
* `export` keyword can take.
|
|
34
|
+
*
|
|
35
|
+
* Ownership of an exported singleton passes to the importers of the module, so
|
|
36
|
+
* this file cannot see - and is not responsible for - its disposal. Such
|
|
37
|
+
* declarations are also created exactly once and live for the lifetime of the
|
|
38
|
+
* program, so there is nothing to leak.
|
|
39
|
+
*/
|
|
40
|
+
export declare function isExportedVariable(variable: TSESLint.Scope.Variable): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Checks whether a variable's lifetime is taken over by a nested function, in
|
|
43
|
+
* any of three ways:
|
|
44
|
+
*
|
|
45
|
+
* - it is captured by a closure the declaring function returns, so the closure
|
|
46
|
+
* owns it (`createToolbarFactory`);
|
|
47
|
+
* - an escaping callback unconditionally disposes it
|
|
48
|
+
* (`requestAnimationFrame(() => splash.dispose())`, promise chains);
|
|
49
|
+
* - an escaping callback unconditionally hands its ownership to something else.
|
|
50
|
+
*
|
|
51
|
+
* The last two generalise the existing `disposed.connect(...)` special case to
|
|
52
|
+
* any callback. Cleanup that is itself conditional inside the callback does not
|
|
53
|
+
* count, so "cleanup only on some paths" stays reportable, and every branch
|
|
54
|
+
* resolves identifiers to this variable rather than comparing names, so a
|
|
55
|
+
* shadowing binding inside the callback cannot silence the outer one.
|
|
56
|
+
*/
|
|
57
|
+
export declare function isDisposedByNestedFunction(variable: TSESLint.Scope.Variable, ownership: DisposableOwnershipContext): boolean;
|
|
58
|
+
export declare function isInJupyterPluginActivate(node: TSESTree.Node, ownership: DisposableOwnershipContext): boolean;
|
|
59
|
+
export declare function isClassFieldCollectionMutationCall(node: TSESTree.CallExpression, names: readonly string[]): boolean;
|
|
60
|
+
export declare function isDisposableExpressionManaged(node: TSESTree.Node, ownership: DisposableOwnershipContext): boolean;
|
|
61
|
+
export declare function markManagedDisposableUse(pending: PendingDisposableMap, node: TSESTree.Node, ownership: DisposableOwnershipContext): void;
|
|
62
|
+
export declare function isDisposableType(type: ts.Type, checker: ts.TypeChecker, seen?: Set<ts.Type>): boolean;
|
|
63
|
+
export declare function shouldCheckReturnedDisposable(node: TSESTree.CallExpression): boolean;
|
|
64
|
+
export {};
|