@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
package/lib/index.d.ts CHANGED
@@ -9,9 +9,17 @@ declare const plugin: {
9
9
  'command-described-by': import("@typescript-eslint/utils/ts-eslint").RuleModule<"missingDescribedBy", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
10
10
  name: string;
11
11
  };
12
+ 'command-id-convention': import("@typescript-eslint/utils/ts-eslint").RuleModule<"missingNamespace" | "emptySegment", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
13
+ name: string;
14
+ };
12
15
  'plugin-description': import("@typescript-eslint/utils/ts-eslint").RuleModule<"missingDescription" | "emptyDescription", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
13
16
  name: string;
14
17
  };
18
+ 'plugin-id-convention': import("@typescript-eslint/utils/ts-eslint").RuleModule<"mismatchedPrefix" | "idEqualsPackageName", [{
19
+ reportIdEqualToPackageName: boolean;
20
+ }], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
21
+ name: string;
22
+ };
15
23
  'no-translation-concatenation': import("@typescript-eslint/utils/ts-eslint").RuleModule<"noConcatenation", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
16
24
  name: string;
17
25
  };
@@ -21,8 +29,9 @@ declare const plugin: {
21
29
  'token-format': import("@typescript-eslint/utils/ts-eslint").RuleModule<"missingColon" | "invalidTokenSymbol", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
22
30
  name: string;
23
31
  };
24
- 'no-untranslated-string': import("@typescript-eslint/utils/ts-eslint").RuleModule<"untranslatedCommandProp" | "untranslatedSetAttribute" | "untranslatedPropertyAssign" | "untranslatedTitleProp" | "untranslatedDialogOption" | "untranslatedDialogButtonLabel" | "untranslatedJsxText", [{
32
+ 'no-untranslated-string': import("@typescript-eslint/utils/ts-eslint").RuleModule<"untranslatedCommandProp" | "untranslatedSetAttribute" | "untranslatedPropertyAssign" | "untranslatedDialogOption" | "untranslatedDialogButtonLabel" | "untranslatedJsxText" | "untranslatedJsxAttribute" | "untranslatedProperty", [{
25
33
  enforcePunctuation: boolean;
34
+ checkProperties: string[];
26
35
  }], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
27
36
  name: string;
28
37
  };
@@ -49,6 +58,9 @@ declare const plugin: {
49
58
  }], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
50
59
  name: string;
51
60
  };
61
+ 'galata-prefer-context-menu-helper': import("@typescript-eslint/utils/ts-eslint").RuleModule<"preferNotebookOpenNoKernel" | "preferFilebrowserOpenFactory" | "preferFilebrowserOpen", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
62
+ name: string;
63
+ };
52
64
  'galata-prefer-filebrowser-helper': import("@typescript-eslint/utils/ts-eslint").RuleModule<"preferNotebookOpenByPath" | "preferOpenHomeDirectory" | "preferOpenDirectory" | "preferFilebrowserHelper", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
53
65
  name: string;
54
66
  };
@@ -80,7 +92,9 @@ declare const plugin: {
80
92
  rules: {
81
93
  'jupyter/plugin-activation-args': string;
82
94
  'jupyter/command-described-by': string;
95
+ 'jupyter/command-id-convention': string;
83
96
  'jupyter/plugin-description': string;
97
+ 'jupyter/plugin-id-convention': string;
84
98
  'jupyter/no-translation-concatenation': string;
85
99
  'jupyter/no-dynamic-translation': string;
86
100
  'jupyter/token-format': string;
@@ -95,6 +109,7 @@ declare const plugin: {
95
109
  'jupyter/prefer-lazy-imports': string;
96
110
  'jupyter/no-schema-enum'?: undefined;
97
111
  'jupyter/require-soft-assertions-before-snapshots'?: undefined;
112
+ 'jupyter/galata-prefer-context-menu-helper'?: undefined;
98
113
  'jupyter/galata-prefer-filebrowser-helper'?: undefined;
99
114
  'jupyter/galata-prefer-menu-helper'?: undefined;
100
115
  'jupyter/galata-prefer-notebook-cell-helper'?: undefined;
@@ -110,7 +125,9 @@ declare const plugin: {
110
125
  'jupyter/no-schema-enum': string;
111
126
  'jupyter/plugin-activation-args'?: undefined;
112
127
  'jupyter/command-described-by'?: undefined;
128
+ 'jupyter/command-id-convention'?: undefined;
113
129
  'jupyter/plugin-description'?: undefined;
130
+ 'jupyter/plugin-id-convention'?: undefined;
114
131
  'jupyter/no-translation-concatenation'?: undefined;
115
132
  'jupyter/no-dynamic-translation'?: undefined;
116
133
  'jupyter/token-format'?: undefined;
@@ -124,6 +141,7 @@ declare const plugin: {
124
141
  'jupyter/incorrect-translator-usage'?: undefined;
125
142
  'jupyter/prefer-lazy-imports'?: undefined;
126
143
  'jupyter/require-soft-assertions-before-snapshots'?: undefined;
144
+ 'jupyter/galata-prefer-context-menu-helper'?: undefined;
127
145
  'jupyter/galata-prefer-filebrowser-helper'?: undefined;
128
146
  'jupyter/galata-prefer-menu-helper'?: undefined;
129
147
  'jupyter/galata-prefer-notebook-cell-helper'?: undefined;
@@ -133,11 +151,14 @@ declare const plugin: {
133
151
  files: string[];
134
152
  rules: {
135
153
  'jupyter/require-soft-assertions-before-snapshots': string;
154
+ 'jupyter/galata-prefer-context-menu-helper': string;
136
155
  'jupyter/galata-prefer-filebrowser-helper': string;
137
156
  'jupyter/galata-prefer-menu-helper': string;
138
157
  'jupyter/galata-prefer-notebook-cell-helper': string;
139
158
  'jupyter/galata-prefer-sidebar-activity-helper': string;
140
159
  'jupyter/prefer-lazy-imports': string;
160
+ 'jupyter/plugin-id-convention': string;
161
+ 'jupyter/command-id-convention': string;
141
162
  'jupyter/plugin-activation-args'?: undefined;
142
163
  'jupyter/command-described-by'?: undefined;
143
164
  'jupyter/plugin-description'?: undefined;
@@ -160,7 +181,9 @@ declare const plugin: {
160
181
  rules: {
161
182
  'jupyter/plugin-activation-args': string;
162
183
  'jupyter/command-described-by': string;
184
+ 'jupyter/command-id-convention': string;
163
185
  'jupyter/plugin-description': string;
186
+ 'jupyter/plugin-id-convention': string;
164
187
  'jupyter/no-translation-concatenation': string;
165
188
  'jupyter/no-dynamic-translation': string;
166
189
  'jupyter/token-format': string;
@@ -179,11 +202,14 @@ declare const plugin: {
179
202
  files: string[];
180
203
  rules: {
181
204
  'jupyter/require-soft-assertions-before-snapshots': string;
205
+ 'jupyter/galata-prefer-context-menu-helper': string;
182
206
  'jupyter/galata-prefer-filebrowser-helper': string;
183
207
  'jupyter/galata-prefer-menu-helper': string;
184
208
  'jupyter/galata-prefer-notebook-cell-helper': string;
185
209
  'jupyter/galata-prefer-sidebar-activity-helper': string;
186
210
  'jupyter/prefer-lazy-imports': string;
211
+ 'jupyter/plugin-id-convention': string;
212
+ 'jupyter/command-id-convention': string;
187
213
  };
188
214
  }[];
189
215
  };
package/lib/index.js CHANGED
@@ -42,7 +42,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
42
42
  const jsoncParser = __importStar(require("jsonc-eslint-parser"));
43
43
  const plugin_activation_args_1 = __importDefault(require("./rules/plugin-activation-args"));
44
44
  const command_described_by_1 = __importDefault(require("./rules/command-described-by"));
45
+ const command_id_convention_1 = __importDefault(require("./rules/command-id-convention"));
45
46
  const plugin_description_1 = __importDefault(require("./rules/plugin-description"));
47
+ const plugin_id_convention_1 = __importDefault(require("./rules/plugin-id-convention"));
46
48
  const no_translation_concatenation_1 = __importDefault(require("./rules/no-translation-concatenation"));
47
49
  const no_dynamic_translation_1 = __importDefault(require("./rules/no-dynamic-translation"));
48
50
  const token_format_1 = __importDefault(require("./rules/token-format"));
@@ -53,6 +55,7 @@ const no_pageconfig_base_url_1 = __importDefault(require("./rules/no-pageconfig-
53
55
  const require_signal_cleanup_1 = __importDefault(require("./rules/require-signal-cleanup"));
54
56
  const require_signal_this_arg_1 = __importDefault(require("./rules/require-signal-this-arg"));
55
57
  const prefer_signal_this_arg_1 = __importDefault(require("./rules/prefer-signal-this-arg"));
58
+ const galata_prefer_context_menu_helper_1 = __importDefault(require("./rules/galata-prefer-context-menu-helper"));
56
59
  const galata_prefer_filebrowser_helper_1 = __importDefault(require("./rules/galata-prefer-filebrowser-helper"));
57
60
  const galata_prefer_menu_helper_1 = __importDefault(require("./rules/galata-prefer-menu-helper"));
58
61
  const galata_prefer_notebook_cell_helper_1 = __importDefault(require("./rules/galata-prefer-notebook-cell-helper"));
@@ -65,7 +68,9 @@ const plugin = {
65
68
  rules: {
66
69
  'plugin-activation-args': plugin_activation_args_1.default,
67
70
  'command-described-by': command_described_by_1.default,
71
+ 'command-id-convention': command_id_convention_1.default,
68
72
  'plugin-description': plugin_description_1.default,
73
+ 'plugin-id-convention': plugin_id_convention_1.default,
69
74
  'no-translation-concatenation': no_translation_concatenation_1.default,
70
75
  'no-dynamic-translation': no_dynamic_translation_1.default,
71
76
  'token-format': token_format_1.default,
@@ -76,6 +81,7 @@ const plugin = {
76
81
  'require-signal-cleanup': require_signal_cleanup_1.default,
77
82
  'require-signal-this-arg': require_signal_this_arg_1.default,
78
83
  'prefer-signal-this-arg': prefer_signal_this_arg_1.default,
84
+ 'galata-prefer-context-menu-helper': galata_prefer_context_menu_helper_1.default,
79
85
  'galata-prefer-filebrowser-helper': galata_prefer_filebrowser_helper_1.default,
80
86
  'galata-prefer-menu-helper': galata_prefer_menu_helper_1.default,
81
87
  'galata-prefer-notebook-cell-helper': galata_prefer_notebook_cell_helper_1.default,
@@ -92,7 +98,9 @@ const plugin = {
92
98
  rules: {
93
99
  'jupyter/plugin-activation-args': 'error',
94
100
  'jupyter/command-described-by': 'warn',
101
+ 'jupyter/command-id-convention': 'warn',
95
102
  'jupyter/plugin-description': 'warn',
103
+ 'jupyter/plugin-id-convention': 'warn',
96
104
  'jupyter/no-translation-concatenation': 'error',
97
105
  'jupyter/no-dynamic-translation': 'warn',
98
106
  'jupyter/token-format': 'error',
@@ -118,12 +126,17 @@ const plugin = {
118
126
  files: ['**/*.spec.ts', '**/*.spec.js', '**/*.test.ts', '**/*.test.js'],
119
127
  rules: {
120
128
  'jupyter/require-soft-assertions-before-snapshots': 'warn',
129
+ 'jupyter/galata-prefer-context-menu-helper': 'warn',
121
130
  'jupyter/galata-prefer-filebrowser-helper': 'warn',
122
131
  'jupyter/galata-prefer-menu-helper': 'warn',
123
132
  'jupyter/galata-prefer-notebook-cell-helper': 'warn',
124
133
  'jupyter/galata-prefer-sidebar-activity-helper': 'warn',
125
- // Test files declare mock plugins; deferring their imports is pointless.
126
- 'jupyter/prefer-lazy-imports': 'off'
134
+ // Test files declare mock plugins and commands; deferring their
135
+ // imports is pointless and their IDs are never used to disable an
136
+ // extension or to query commands.
137
+ 'jupyter/prefer-lazy-imports': 'off',
138
+ 'jupyter/plugin-id-convention': 'off',
139
+ 'jupyter/command-id-convention': 'off'
127
140
  }
128
141
  }
129
142
  ],
@@ -131,7 +144,9 @@ const plugin = {
131
144
  rules: {
132
145
  'jupyter/plugin-activation-args': 'error',
133
146
  'jupyter/command-described-by': 'warn',
147
+ 'jupyter/command-id-convention': 'warn',
134
148
  'jupyter/plugin-description': 'warn',
149
+ 'jupyter/plugin-id-convention': 'warn',
135
150
  'jupyter/no-translation-concatenation': 'error',
136
151
  'jupyter/no-dynamic-translation': 'warn',
137
152
  'jupyter/token-format': 'error',
@@ -156,11 +171,14 @@ const plugin = {
156
171
  ],
157
172
  rules: {
158
173
  'jupyter/require-soft-assertions-before-snapshots': 'warn',
174
+ 'jupyter/galata-prefer-context-menu-helper': 'warn',
159
175
  'jupyter/galata-prefer-filebrowser-helper': 'warn',
160
176
  'jupyter/galata-prefer-menu-helper': 'warn',
161
177
  'jupyter/galata-prefer-notebook-cell-helper': 'warn',
162
178
  'jupyter/galata-prefer-sidebar-activity-helper': 'warn',
163
- 'jupyter/prefer-lazy-imports': 'off'
179
+ 'jupyter/prefer-lazy-imports': 'off',
180
+ 'jupyter/plugin-id-convention': 'off',
181
+ 'jupyter/command-id-convention': 'off'
164
182
  }
165
183
  }
166
184
  ]
@@ -0,0 +1,5 @@
1
+ import { ESLintUtils } from '@typescript-eslint/utils';
2
+ declare const commandIdConvention: ESLintUtils.RuleModule<"missingNamespace" | "emptySegment", [], unknown, ESLintUtils.RuleListener> & {
3
+ name: string;
4
+ };
5
+ export = commandIdConvention;
@@ -0,0 +1,87 @@
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 commands_1 = require("../utils/commands");
8
+ const create_rule_1 = require("../utils/create-rule");
9
+ const commandIdConvention = (0, create_rule_1.createRule)({
10
+ name: 'command-id-convention',
11
+ meta: {
12
+ type: 'suggestion',
13
+ docs: {
14
+ description: 'Ensure JupyterLab command IDs follow the "namespace:name" convention',
15
+ url: 'https://eslint-plugin.readthedocs.io/en/latest/rules/command-id-convention/'
16
+ },
17
+ messages: {
18
+ missingNamespace: 'Command ID "{{ commandId }}" has no namespace; use the "namespace:name" form, e.g. "my-extension:{{ commandId }}".',
19
+ emptySegment: 'Command ID "{{ commandId }}" has an empty {{ segment }}; use the "namespace:name" form.'
20
+ },
21
+ schema: []
22
+ },
23
+ defaultOptions: [],
24
+ create(context) {
25
+ let services = null;
26
+ let checker = null;
27
+ try {
28
+ services = utils_1.ESLintUtils.getParserServices(context, true);
29
+ checker = services.program ? services.program.getTypeChecker() : null;
30
+ }
31
+ catch {
32
+ services = null;
33
+ }
34
+ const getTSNode = services
35
+ ? (node) => services?.esTreeNodeToTSNodeMap.get(node)
36
+ : null;
37
+ return {
38
+ CallExpression(node) {
39
+ // `addCommand(id, options)`: the arity filters out unrelated methods
40
+ // that happen to share the name.
41
+ if (!(0, commands_1.isAddCommandCall)(node) || node.arguments.length < 2) {
42
+ return;
43
+ }
44
+ const idArg = node.arguments[0];
45
+ if (idArg.type === 'SpreadElement') {
46
+ return;
47
+ }
48
+ // A registry created on the spot, such as one backing a context
49
+ // menu, is never listed or queried alongside the application's.
50
+ const callee = node.callee;
51
+ if (callee.object.type !== 'Super' &&
52
+ (0, commands_1.isPrivateCommandRegistry)(callee.object, context.sourceCode.getScope(node))) {
53
+ return;
54
+ }
55
+ const commandId = (0, commands_1.resolveCommandId)(idArg, context.sourceCode, checker, getTSNode);
56
+ if (commandId === null) {
57
+ return;
58
+ }
59
+ // The namespace is everything before the first `:`, as in the
60
+ // `namespace:name` form used by JupyterLab's own commands; the name
61
+ // itself may contain further colons.
62
+ const separator = commandId.indexOf(':');
63
+ if (separator === -1) {
64
+ context.report({
65
+ node: idArg,
66
+ messageId: 'missingNamespace',
67
+ data: { commandId }
68
+ });
69
+ return;
70
+ }
71
+ const segment = separator === 0
72
+ ? 'namespace'
73
+ : separator === commandId.length - 1
74
+ ? 'name'
75
+ : null;
76
+ if (segment) {
77
+ context.report({
78
+ node: idArg,
79
+ messageId: 'emptySegment',
80
+ data: { commandId, segment }
81
+ });
82
+ }
83
+ }
84
+ };
85
+ }
86
+ });
87
+ module.exports = commandIdConvention;
@@ -0,0 +1,6 @@
1
+ import { TSESLint } from '@typescript-eslint/utils';
2
+ type MessageIds = 'preferNotebookOpenNoKernel' | 'preferFilebrowserOpenFactory' | 'preferFilebrowserOpen';
3
+ declare const galataPreferContextMenuHelper: TSESLint.RuleModule<MessageIds, [], unknown, TSESLint.RuleListener> & {
4
+ name: string;
5
+ };
6
+ export = galataPreferContextMenuHelper;