@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,122 @@
|
|
|
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.STATIC_ARGUMENT_INDICES = exports.BUNDLE_VARIABLE_NAME = exports.BUNDLE_PROPERTY_NAMES = exports.BUNDLE_METHODS = void 0;
|
|
8
|
+
exports.unwrapExpression = unwrapExpression;
|
|
9
|
+
exports.isRecognizedBundleMember = isRecognizedBundleMember;
|
|
10
|
+
exports.isTransBundle = isTransBundle;
|
|
11
|
+
/**
|
|
12
|
+
* Methods of the TranslationBundle interface from `@jupyterlab/translation`.
|
|
13
|
+
*/
|
|
14
|
+
exports.BUNDLE_METHODS = new Set([
|
|
15
|
+
'__',
|
|
16
|
+
'_n',
|
|
17
|
+
'_p',
|
|
18
|
+
'_np',
|
|
19
|
+
'gettext',
|
|
20
|
+
'ngettext',
|
|
21
|
+
'pgettext',
|
|
22
|
+
'npgettext',
|
|
23
|
+
'dcnpgettext'
|
|
24
|
+
]);
|
|
25
|
+
/**
|
|
26
|
+
* Property names under which a translation bundle may be stored so that the
|
|
27
|
+
* string extractor recognizes its usages (this.trans, this._trans,
|
|
28
|
+
* this.props.trans, props.trans).
|
|
29
|
+
* See jupyterlab.readthedocs.io/en/stable/extension/internationalization.html#rules
|
|
30
|
+
*/
|
|
31
|
+
exports.BUNDLE_PROPERTY_NAMES = new Set(['trans', '_trans']);
|
|
32
|
+
/**
|
|
33
|
+
* The only accepted name for a local variable holding a translation bundle.
|
|
34
|
+
*/
|
|
35
|
+
exports.BUNDLE_VARIABLE_NAME = 'trans';
|
|
36
|
+
/**
|
|
37
|
+
* For each bundle method, the argument indices the string extractor reads
|
|
38
|
+
* straight from the source and must therefore be static text.
|
|
39
|
+
*
|
|
40
|
+
* The `domain` argument of `dcnpgettext` is deliberately left out: it selects a
|
|
41
|
+
* catalog at runtime, it is not extracted message text.
|
|
42
|
+
*/
|
|
43
|
+
exports.STATIC_ARGUMENT_INDICES = {
|
|
44
|
+
// (msgid, ...args)
|
|
45
|
+
__: [0],
|
|
46
|
+
gettext: [0],
|
|
47
|
+
// (msgid, msgid_plural, n, ...args)
|
|
48
|
+
_n: [0, 1],
|
|
49
|
+
ngettext: [0, 1],
|
|
50
|
+
// (msgctxt, msgid, ...args)
|
|
51
|
+
_p: [0, 1],
|
|
52
|
+
pgettext: [0, 1],
|
|
53
|
+
// (msgctxt, msgid, msgid_plural, n, ...args)
|
|
54
|
+
_np: [0, 1, 2],
|
|
55
|
+
npgettext: [0, 1, 2],
|
|
56
|
+
// (domain, msgctxt, msgid, msgid_plural, n, ...args)
|
|
57
|
+
dcnpgettext: [1, 2, 3]
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Skips TypeScript-only and optional-chaining wrapper nodes so the underlying
|
|
61
|
+
* expression can be inspected.
|
|
62
|
+
*/
|
|
63
|
+
function unwrapExpression(node) {
|
|
64
|
+
switch (node.type) {
|
|
65
|
+
case 'ChainExpression':
|
|
66
|
+
case 'TSNonNullExpression':
|
|
67
|
+
case 'TSAsExpression':
|
|
68
|
+
case 'TSSatisfiesExpression':
|
|
69
|
+
case 'TSTypeAssertion':
|
|
70
|
+
return unwrapExpression(node.expression);
|
|
71
|
+
default:
|
|
72
|
+
return node;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Returns true when a member expression names one of the exact targets the
|
|
77
|
+
* string extractor recognizes as a translation bundle:
|
|
78
|
+
* this.trans, this._trans, props.trans, this.props.trans.
|
|
79
|
+
* See jupyterlab.readthedocs.io/en/stable/extension/internationalization.html#rules
|
|
80
|
+
*/
|
|
81
|
+
function isRecognizedBundleMember(node) {
|
|
82
|
+
if (node.computed || node.property.type !== 'Identifier') {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
const propertyName = node.property.name;
|
|
86
|
+
const object = unwrapExpression(node.object);
|
|
87
|
+
// this.trans / this._trans
|
|
88
|
+
if (object.type === 'ThisExpression') {
|
|
89
|
+
return exports.BUNDLE_PROPERTY_NAMES.has(propertyName);
|
|
90
|
+
}
|
|
91
|
+
if (propertyName !== exports.BUNDLE_VARIABLE_NAME) {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
// props.trans
|
|
95
|
+
if (object.type === 'Identifier' && object.name === 'props') {
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
// this.props.trans
|
|
99
|
+
return (object.type === 'MemberExpression' &&
|
|
100
|
+
!object.computed &&
|
|
101
|
+
object.object.type === 'ThisExpression' &&
|
|
102
|
+
object.property.type === 'Identifier' &&
|
|
103
|
+
object.property.name === 'props');
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Returns true if the node is a recognized JupyterLab translation bundle:
|
|
107
|
+
* trans | this.trans | this._trans | props.trans | this.props.trans
|
|
108
|
+
*
|
|
109
|
+
* TypeScript-only wrappers are seen through, so `this.trans!` and
|
|
110
|
+
* `(trans as any)` are recognized too — they still name the same bundle.
|
|
111
|
+
* See jupyterlab.readthedocs.io/en/stable/extension/internationalization.html#rules
|
|
112
|
+
*/
|
|
113
|
+
function isTransBundle(node) {
|
|
114
|
+
const expression = unwrapExpression(node);
|
|
115
|
+
if (expression.type === 'Identifier') {
|
|
116
|
+
return expression.name === exports.BUNDLE_VARIABLE_NAME;
|
|
117
|
+
}
|
|
118
|
+
if (expression.type === 'MemberExpression') {
|
|
119
|
+
return isRecognizedBundleMember(expression);
|
|
120
|
+
}
|
|
121
|
+
return false;
|
|
122
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jupyter/eslint-plugin",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.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",
|
|
@@ -49,6 +49,8 @@
|
|
|
49
49
|
}
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
+
"@lumino/signaling": "^2.1.6",
|
|
53
|
+
"@lumino/widgets": "^2.9.0",
|
|
52
54
|
"@types/eslint": "^9.6.1",
|
|
53
55
|
"@types/estree": "^1.0.8",
|
|
54
56
|
"@types/jest": "^30.0.0",
|
|
@@ -66,6 +68,7 @@
|
|
|
66
68
|
},
|
|
67
69
|
"dependencies": {
|
|
68
70
|
"@typescript-eslint/utils": "^8.54.0",
|
|
71
|
+
"@typescript-eslint/visitor-keys": "^8.54.0",
|
|
69
72
|
"jsonc-eslint-parser": "^2.4.0"
|
|
70
73
|
},
|
|
71
74
|
"peerDependencies": {
|
|
@@ -73,5 +76,9 @@
|
|
|
73
76
|
},
|
|
74
77
|
"engines": {
|
|
75
78
|
"node": ">=16.0.0"
|
|
76
|
-
}
|
|
79
|
+
},
|
|
80
|
+
"pre-commit": [
|
|
81
|
+
"lint",
|
|
82
|
+
"test"
|
|
83
|
+
]
|
|
77
84
|
}
|