@jupyter/eslint-plugin 1.0.0 → 1.1.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 (35) hide show
  1. package/lib/index.d.ts +68 -0
  2. package/lib/index.js +42 -11
  3. package/lib/rules/galata-prefer-filebrowser-helper.d.ts +5 -0
  4. package/lib/rules/galata-prefer-filebrowser-helper.js +105 -0
  5. package/lib/rules/incorrect-translator-usage.d.ts +4 -0
  6. package/lib/rules/incorrect-translator-usage.js +208 -0
  7. package/lib/rules/no-dynamic-translation.d.ts +4 -0
  8. package/lib/rules/no-dynamic-translation.js +92 -0
  9. package/lib/rules/no-pageconfig-base-url.d.ts +4 -0
  10. package/lib/rules/no-pageconfig-base-url.js +37 -0
  11. package/lib/rules/no-translation-concatenation.js +46 -84
  12. package/lib/rules/no-untranslated-string.js +7 -4
  13. package/lib/rules/plugin-activation-args.js +6 -2
  14. package/lib/rules/prefer-signal-this-arg.d.ts +7 -0
  15. package/lib/rules/prefer-signal-this-arg.js +196 -0
  16. package/lib/rules/require-disposable-ownership.d.ts +5 -0
  17. package/lib/rules/require-disposable-ownership.js +120 -0
  18. package/lib/rules/require-disposable-transfer.d.ts +5 -0
  19. package/lib/rules/require-disposable-transfer.js +223 -0
  20. package/lib/rules/require-signal-cleanup.d.ts +8 -0
  21. package/lib/rules/require-signal-cleanup.js +164 -0
  22. package/lib/rules/require-signal-this-arg.d.ts +5 -0
  23. package/lib/rules/require-signal-this-arg.js +74 -0
  24. package/lib/rules/token-format.js +1 -2
  25. package/lib/utils/disposables.d.ts +64 -0
  26. package/lib/utils/disposables.js +1723 -0
  27. package/lib/utils/playwright-selectors.d.ts +66 -0
  28. package/lib/utils/playwright-selectors.js +193 -0
  29. package/lib/utils/signal-lifetime.d.ts +158 -0
  30. package/lib/utils/signal-lifetime.js +755 -0
  31. package/lib/utils/signals.d.ts +143 -0
  32. package/lib/utils/signals.js +601 -0
  33. package/lib/utils/translation.d.ts +45 -0
  34. package/lib/utils/translation.js +122 -0
  35. package/package.json +11 -4
@@ -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.0",
3
+ "version": "1.1.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",
@@ -59,19 +61,24 @@
59
61
  "eslint": "^9.39.2",
60
62
  "eslint-plugin": "^1.0.1",
61
63
  "jest": "^30.2.0",
62
- "jsonc-eslint-parser": "^2.4.2",
63
64
  "pre-commit": "^1.2.2",
64
65
  "prettier": "^3.8.1",
65
66
  "ts-jest": "^29.4.6",
66
67
  "typescript": "^5.9.3"
67
68
  },
68
69
  "dependencies": {
69
- "@typescript-eslint/utils": "^8.54.0"
70
+ "@typescript-eslint/utils": "^8.54.0",
71
+ "@typescript-eslint/visitor-keys": "^8.54.0",
72
+ "jsonc-eslint-parser": "^2.4.0"
70
73
  },
71
74
  "peerDependencies": {
72
75
  "eslint": ">=9.0.0"
73
76
  },
74
77
  "engines": {
75
78
  "node": ">=16.0.0"
76
- }
79
+ },
80
+ "pre-commit": [
81
+ "lint",
82
+ "test"
83
+ ]
77
84
  }