@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.
Files changed (53) hide show
  1. package/lib/index.d.ts +98 -1
  2. package/lib/index.js +61 -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/galata-prefer-menu-helper.d.ts +6 -0
  6. package/lib/rules/galata-prefer-menu-helper.js +478 -0
  7. package/lib/rules/galata-prefer-notebook-cell-helper.d.ts +6 -0
  8. package/lib/rules/galata-prefer-notebook-cell-helper.js +403 -0
  9. package/lib/rules/galata-prefer-sidebar-activity-helper.d.ts +6 -0
  10. package/lib/rules/galata-prefer-sidebar-activity-helper.js +332 -0
  11. package/lib/rules/incorrect-translator-usage.d.ts +4 -0
  12. package/lib/rules/incorrect-translator-usage.js +208 -0
  13. package/lib/rules/no-dynamic-translation.d.ts +4 -0
  14. package/lib/rules/no-dynamic-translation.js +92 -0
  15. package/lib/rules/no-pageconfig-base-url.d.ts +4 -0
  16. package/lib/rules/no-pageconfig-base-url.js +37 -0
  17. package/lib/rules/no-schema-enum.d.ts +1 -1
  18. package/lib/rules/no-schema-enum.js +54 -2
  19. package/lib/rules/no-translation-concatenation.js +46 -84
  20. package/lib/rules/no-untranslated-string.js +7 -4
  21. package/lib/rules/plugin-activation-args.js +1 -2
  22. package/lib/rules/prefer-lazy-imports.d.ts +6 -0
  23. package/lib/rules/prefer-lazy-imports.js +308 -0
  24. package/lib/rules/prefer-signal-this-arg.d.ts +7 -0
  25. package/lib/rules/prefer-signal-this-arg.js +196 -0
  26. package/lib/rules/require-disposable-ownership.d.ts +5 -0
  27. package/lib/rules/require-disposable-ownership.js +120 -0
  28. package/lib/rules/require-disposable-transfer.d.ts +5 -0
  29. package/lib/rules/require-disposable-transfer.js +223 -0
  30. package/lib/rules/require-signal-cleanup.d.ts +8 -0
  31. package/lib/rules/require-signal-cleanup.js +164 -0
  32. package/lib/rules/require-signal-this-arg.d.ts +5 -0
  33. package/lib/rules/require-signal-this-arg.js +74 -0
  34. package/lib/rules/token-format.js +1 -2
  35. package/lib/utils/disposables.d.ts +64 -0
  36. package/lib/utils/disposables.js +1723 -0
  37. package/lib/utils/lazy-imports.d.ts +70 -0
  38. package/lib/utils/lazy-imports.js +515 -0
  39. package/lib/utils/module-size.d.ts +12 -0
  40. package/lib/utils/module-size.js +240 -0
  41. package/lib/utils/playwright-selectors.d.ts +102 -0
  42. package/lib/utils/playwright-selectors.js +306 -0
  43. package/lib/utils/plugin-utils.d.ts +18 -0
  44. package/lib/utils/plugin-utils.js +127 -19
  45. package/lib/utils/shared-packages.d.ts +9 -0
  46. package/lib/utils/shared-packages.js +138 -0
  47. package/lib/utils/signal-lifetime.d.ts +158 -0
  48. package/lib/utils/signal-lifetime.js +816 -0
  49. package/lib/utils/signals.d.ts +143 -0
  50. package/lib/utils/signals.js +601 -0
  51. package/lib/utils/translation.d.ts +45 -0
  52. package/lib/utils/translation.js +122 -0
  53. package/package.json +9 -2
package/lib/index.d.ts CHANGED
@@ -15,6 +15,9 @@ declare const plugin: {
15
15
  'no-translation-concatenation': import("@typescript-eslint/utils/ts-eslint").RuleModule<"noConcatenation", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
16
16
  name: string;
17
17
  };
18
+ 'no-dynamic-translation': import("@typescript-eslint/utils/ts-eslint").RuleModule<"noInterpolation" | "noDynamicMessage", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
19
+ name: string;
20
+ };
18
21
  'token-format': import("@typescript-eslint/utils/ts-eslint").RuleModule<"missingColon" | "invalidTokenSymbol", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
19
22
  name: string;
20
23
  };
@@ -23,12 +26,53 @@ declare const plugin: {
23
26
  }], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
24
27
  name: string;
25
28
  };
26
- 'no-schema-enum': import("@typescript-eslint/utils/ts-eslint").RuleModule<"forbidEnum", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
29
+ 'no-schema-enum': import("@typescript-eslint/utils/ts-eslint").RuleModule<"forbidEnum" | "requireStringType", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
27
30
  name: string;
28
31
  };
29
32
  'require-soft-assertions-before-snapshots': import("@typescript-eslint/utils/ts-eslint").RuleModule<"requireSoftAssertion", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
30
33
  name: string;
31
34
  };
35
+ 'no-pageconfig-base-url': import("@typescript-eslint/utils/ts-eslint").RuleModule<"noPageconfigBaseUrl", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
36
+ name: string;
37
+ };
38
+ 'require-signal-cleanup': import("@typescript-eslint/utils/ts-eslint").RuleModule<"serviceOutlivesReceiver", [{
39
+ additionalCleanupMethods: string[];
40
+ longLivedTypes: string[] | undefined;
41
+ }], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
42
+ name: string;
43
+ };
44
+ 'require-signal-this-arg': import("@typescript-eslint/utils/ts-eslint").RuleModule<"missingThisArg" | "addThisArg", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
45
+ name: string;
46
+ };
47
+ 'prefer-signal-this-arg': import("@typescript-eslint/utils/ts-eslint").RuleModule<"addThisArg" | "preferThisArg" | "boundCallback" | "unbindAndAddThisArg", [{
48
+ longLivedTypes: string[] | undefined;
49
+ }], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
50
+ name: string;
51
+ };
52
+ 'galata-prefer-filebrowser-helper': import("@typescript-eslint/utils/ts-eslint").RuleModule<"preferNotebookOpenByPath" | "preferOpenHomeDirectory" | "preferOpenDirectory" | "preferFilebrowserHelper", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
53
+ name: string;
54
+ };
55
+ 'galata-prefer-menu-helper': import("@typescript-eslint/utils/ts-eslint").RuleModule<"preferMenuOpen" | "preferClickMenuItem" | "preferMenuHelper", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
56
+ name: string;
57
+ };
58
+ 'galata-prefer-notebook-cell-helper': import("@typescript-eslint/utils/ts-eslint").RuleModule<"preferSetCell" | "preferEnterCellEditingMode" | "preferSelectCells" | "preferRunCell", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
59
+ name: string;
60
+ };
61
+ 'galata-prefer-sidebar-activity-helper': import("@typescript-eslint/utils/ts-eslint").RuleModule<"preferSidebarHelper" | "preferActivityHelper", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
62
+ name: string;
63
+ };
64
+ 'require-disposable-ownership': import("@typescript-eslint/utils/ts-eslint").RuleModule<"unmanagedDisposable" | "unmanagedDisposableVariable", [{}], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
65
+ name: string;
66
+ };
67
+ 'require-disposable-transfer': import("@typescript-eslint/utils/ts-eslint").RuleModule<"unmanagedDisposableVariable" | "unhandledDisposable", [{}], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
68
+ name: string;
69
+ };
70
+ 'incorrect-translator-usage': import("@typescript-eslint/utils/ts-eslint").RuleModule<"chainedBundleMethod" | "invalidBundleName" | "destructuredBundle", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
71
+ name: string;
72
+ };
73
+ 'prefer-lazy-imports': import("@typescript-eslint/utils/ts-eslint").RuleModule<string, [import("./utils/lazy-imports").LazyImportOptions], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
74
+ name: string;
75
+ };
32
76
  };
33
77
  configs: {
34
78
  recommended: ({
@@ -38,10 +82,23 @@ declare const plugin: {
38
82
  'jupyter/command-described-by': string;
39
83
  'jupyter/plugin-description': string;
40
84
  'jupyter/no-translation-concatenation': string;
85
+ 'jupyter/no-dynamic-translation': string;
41
86
  'jupyter/token-format': string;
42
87
  'jupyter/no-untranslated-string': string;
88
+ 'jupyter/no-pageconfig-base-url': string;
89
+ 'jupyter/require-signal-cleanup': string;
90
+ 'jupyter/require-signal-this-arg': string;
91
+ 'jupyter/prefer-signal-this-arg': string;
92
+ 'jupyter/require-disposable-ownership': string;
93
+ 'jupyter/require-disposable-transfer': string;
94
+ 'jupyter/incorrect-translator-usage': string;
95
+ 'jupyter/prefer-lazy-imports': string;
43
96
  'jupyter/no-schema-enum'?: undefined;
44
97
  'jupyter/require-soft-assertions-before-snapshots'?: undefined;
98
+ 'jupyter/galata-prefer-filebrowser-helper'?: undefined;
99
+ 'jupyter/galata-prefer-menu-helper'?: undefined;
100
+ 'jupyter/galata-prefer-notebook-cell-helper'?: undefined;
101
+ 'jupyter/galata-prefer-sidebar-activity-helper'?: undefined;
45
102
  };
46
103
  languageOptions?: undefined;
47
104
  } | {
@@ -55,20 +112,46 @@ declare const plugin: {
55
112
  'jupyter/command-described-by'?: undefined;
56
113
  'jupyter/plugin-description'?: undefined;
57
114
  'jupyter/no-translation-concatenation'?: undefined;
115
+ 'jupyter/no-dynamic-translation'?: undefined;
58
116
  'jupyter/token-format'?: undefined;
59
117
  'jupyter/no-untranslated-string'?: undefined;
118
+ 'jupyter/no-pageconfig-base-url'?: undefined;
119
+ 'jupyter/require-signal-cleanup'?: undefined;
120
+ 'jupyter/require-signal-this-arg'?: undefined;
121
+ 'jupyter/prefer-signal-this-arg'?: undefined;
122
+ 'jupyter/require-disposable-ownership'?: undefined;
123
+ 'jupyter/require-disposable-transfer'?: undefined;
124
+ 'jupyter/incorrect-translator-usage'?: undefined;
125
+ 'jupyter/prefer-lazy-imports'?: undefined;
60
126
  'jupyter/require-soft-assertions-before-snapshots'?: undefined;
127
+ 'jupyter/galata-prefer-filebrowser-helper'?: undefined;
128
+ 'jupyter/galata-prefer-menu-helper'?: undefined;
129
+ 'jupyter/galata-prefer-notebook-cell-helper'?: undefined;
130
+ 'jupyter/galata-prefer-sidebar-activity-helper'?: undefined;
61
131
  };
62
132
  } | {
63
133
  files: string[];
64
134
  rules: {
65
135
  'jupyter/require-soft-assertions-before-snapshots': string;
136
+ 'jupyter/galata-prefer-filebrowser-helper': string;
137
+ 'jupyter/galata-prefer-menu-helper': string;
138
+ 'jupyter/galata-prefer-notebook-cell-helper': string;
139
+ 'jupyter/galata-prefer-sidebar-activity-helper': string;
140
+ 'jupyter/prefer-lazy-imports': string;
66
141
  'jupyter/plugin-activation-args'?: undefined;
67
142
  'jupyter/command-described-by'?: undefined;
68
143
  'jupyter/plugin-description'?: undefined;
69
144
  'jupyter/no-translation-concatenation'?: undefined;
145
+ 'jupyter/no-dynamic-translation'?: undefined;
70
146
  'jupyter/token-format'?: undefined;
71
147
  'jupyter/no-untranslated-string'?: undefined;
148
+ 'jupyter/no-pageconfig-base-url'?: undefined;
149
+ 'jupyter/require-signal-cleanup'?: undefined;
150
+ 'jupyter/require-signal-this-arg'?: undefined;
151
+ 'jupyter/prefer-signal-this-arg'?: undefined;
152
+ 'jupyter/require-disposable-ownership'?: undefined;
153
+ 'jupyter/require-disposable-transfer'?: undefined;
154
+ 'jupyter/incorrect-translator-usage'?: undefined;
72
155
  'jupyter/no-schema-enum'?: undefined;
73
156
  };
74
157
  languageOptions?: undefined;
@@ -79,14 +162,28 @@ declare const plugin: {
79
162
  'jupyter/command-described-by': string;
80
163
  'jupyter/plugin-description': string;
81
164
  'jupyter/no-translation-concatenation': string;
165
+ 'jupyter/no-dynamic-translation': string;
82
166
  'jupyter/token-format': string;
83
167
  'jupyter/no-untranslated-string': string;
84
168
  'jupyter/no-schema-enum': string;
169
+ 'jupyter/no-pageconfig-base-url': string;
170
+ 'jupyter/require-signal-cleanup': string;
171
+ 'jupyter/require-signal-this-arg': string;
172
+ 'jupyter/prefer-signal-this-arg': string;
173
+ 'jupyter/require-disposable-ownership': string;
174
+ 'jupyter/require-disposable-transfer': string;
175
+ 'jupyter/incorrect-translator-usage': string;
176
+ 'jupyter/prefer-lazy-imports': string;
85
177
  };
86
178
  overrides: {
87
179
  files: string[];
88
180
  rules: {
89
181
  'jupyter/require-soft-assertions-before-snapshots': string;
182
+ 'jupyter/galata-prefer-filebrowser-helper': string;
183
+ 'jupyter/galata-prefer-menu-helper': string;
184
+ 'jupyter/galata-prefer-notebook-cell-helper': string;
185
+ 'jupyter/galata-prefer-sidebar-activity-helper': string;
186
+ 'jupyter/prefer-lazy-imports': string;
90
187
  };
91
188
  }[];
92
189
  };
package/lib/index.js CHANGED
@@ -44,20 +44,46 @@ const plugin_activation_args_1 = __importDefault(require("./rules/plugin-activat
44
44
  const command_described_by_1 = __importDefault(require("./rules/command-described-by"));
45
45
  const plugin_description_1 = __importDefault(require("./rules/plugin-description"));
46
46
  const no_translation_concatenation_1 = __importDefault(require("./rules/no-translation-concatenation"));
47
+ const no_dynamic_translation_1 = __importDefault(require("./rules/no-dynamic-translation"));
47
48
  const token_format_1 = __importDefault(require("./rules/token-format"));
48
49
  const no_untranslated_string_1 = __importDefault(require("./rules/no-untranslated-string"));
49
50
  const no_schema_enum_1 = __importDefault(require("./rules/no-schema-enum"));
50
51
  const require_soft_assertions_before_snapshots_1 = __importDefault(require("./rules/require-soft-assertions-before-snapshots"));
52
+ const no_pageconfig_base_url_1 = __importDefault(require("./rules/no-pageconfig-base-url"));
53
+ const require_signal_cleanup_1 = __importDefault(require("./rules/require-signal-cleanup"));
54
+ const require_signal_this_arg_1 = __importDefault(require("./rules/require-signal-this-arg"));
55
+ const prefer_signal_this_arg_1 = __importDefault(require("./rules/prefer-signal-this-arg"));
56
+ const galata_prefer_filebrowser_helper_1 = __importDefault(require("./rules/galata-prefer-filebrowser-helper"));
57
+ const galata_prefer_menu_helper_1 = __importDefault(require("./rules/galata-prefer-menu-helper"));
58
+ const galata_prefer_notebook_cell_helper_1 = __importDefault(require("./rules/galata-prefer-notebook-cell-helper"));
59
+ const galata_prefer_sidebar_activity_helper_1 = __importDefault(require("./rules/galata-prefer-sidebar-activity-helper"));
60
+ const require_disposable_ownership_1 = __importDefault(require("./rules/require-disposable-ownership"));
61
+ const require_disposable_transfer_1 = __importDefault(require("./rules/require-disposable-transfer"));
62
+ const incorrect_translator_usage_1 = __importDefault(require("./rules/incorrect-translator-usage"));
63
+ const prefer_lazy_imports_1 = __importDefault(require("./rules/prefer-lazy-imports"));
51
64
  const plugin = {
52
65
  rules: {
53
66
  'plugin-activation-args': plugin_activation_args_1.default,
54
67
  'command-described-by': command_described_by_1.default,
55
68
  'plugin-description': plugin_description_1.default,
56
69
  'no-translation-concatenation': no_translation_concatenation_1.default,
70
+ 'no-dynamic-translation': no_dynamic_translation_1.default,
57
71
  'token-format': token_format_1.default,
58
72
  'no-untranslated-string': no_untranslated_string_1.default,
59
73
  'no-schema-enum': no_schema_enum_1.default,
60
- 'require-soft-assertions-before-snapshots': require_soft_assertions_before_snapshots_1.default
74
+ 'require-soft-assertions-before-snapshots': require_soft_assertions_before_snapshots_1.default,
75
+ 'no-pageconfig-base-url': no_pageconfig_base_url_1.default,
76
+ 'require-signal-cleanup': require_signal_cleanup_1.default,
77
+ 'require-signal-this-arg': require_signal_this_arg_1.default,
78
+ 'prefer-signal-this-arg': prefer_signal_this_arg_1.default,
79
+ 'galata-prefer-filebrowser-helper': galata_prefer_filebrowser_helper_1.default,
80
+ 'galata-prefer-menu-helper': galata_prefer_menu_helper_1.default,
81
+ 'galata-prefer-notebook-cell-helper': galata_prefer_notebook_cell_helper_1.default,
82
+ 'galata-prefer-sidebar-activity-helper': galata_prefer_sidebar_activity_helper_1.default,
83
+ 'require-disposable-ownership': require_disposable_ownership_1.default,
84
+ 'require-disposable-transfer': require_disposable_transfer_1.default,
85
+ 'incorrect-translator-usage': incorrect_translator_usage_1.default,
86
+ 'prefer-lazy-imports': prefer_lazy_imports_1.default
61
87
  },
62
88
  configs: {
63
89
  recommended: [
@@ -68,8 +94,17 @@ const plugin = {
68
94
  'jupyter/command-described-by': 'warn',
69
95
  'jupyter/plugin-description': 'warn',
70
96
  'jupyter/no-translation-concatenation': 'error',
97
+ 'jupyter/no-dynamic-translation': 'warn',
71
98
  'jupyter/token-format': 'error',
72
- 'jupyter/no-untranslated-string': 'warn'
99
+ 'jupyter/no-untranslated-string': 'warn',
100
+ 'jupyter/no-pageconfig-base-url': 'warn',
101
+ 'jupyter/require-signal-cleanup': 'warn',
102
+ 'jupyter/require-signal-this-arg': 'error',
103
+ 'jupyter/prefer-signal-this-arg': 'warn',
104
+ 'jupyter/require-disposable-ownership': 'warn',
105
+ 'jupyter/require-disposable-transfer': 'warn',
106
+ 'jupyter/incorrect-translator-usage': 'warn',
107
+ 'jupyter/prefer-lazy-imports': 'warn'
73
108
  }
74
109
  },
75
110
  {
@@ -80,14 +115,15 @@ const plugin = {
80
115
  }
81
116
  },
82
117
  {
83
- files: [
84
- '**/*.spec.ts',
85
- '**/*.spec.js',
86
- '**/*.test.ts',
87
- '**/*.test.js'
88
- ],
118
+ files: ['**/*.spec.ts', '**/*.spec.js', '**/*.test.ts', '**/*.test.js'],
89
119
  rules: {
90
- 'jupyter/require-soft-assertions-before-snapshots': 'warn'
120
+ 'jupyter/require-soft-assertions-before-snapshots': 'warn',
121
+ 'jupyter/galata-prefer-filebrowser-helper': 'warn',
122
+ 'jupyter/galata-prefer-menu-helper': 'warn',
123
+ 'jupyter/galata-prefer-notebook-cell-helper': 'warn',
124
+ 'jupyter/galata-prefer-sidebar-activity-helper': 'warn',
125
+ // Test files declare mock plugins; deferring their imports is pointless.
126
+ 'jupyter/prefer-lazy-imports': 'off'
91
127
  }
92
128
  }
93
129
  ],
@@ -97,9 +133,18 @@ const plugin = {
97
133
  'jupyter/command-described-by': 'warn',
98
134
  'jupyter/plugin-description': 'warn',
99
135
  'jupyter/no-translation-concatenation': 'error',
136
+ 'jupyter/no-dynamic-translation': 'warn',
100
137
  'jupyter/token-format': 'error',
101
138
  'jupyter/no-untranslated-string': 'warn',
102
- 'jupyter/no-schema-enum': 'warn'
139
+ 'jupyter/no-schema-enum': 'warn',
140
+ 'jupyter/no-pageconfig-base-url': 'warn',
141
+ 'jupyter/require-signal-cleanup': 'warn',
142
+ 'jupyter/require-signal-this-arg': 'error',
143
+ 'jupyter/prefer-signal-this-arg': 'warn',
144
+ 'jupyter/require-disposable-ownership': 'warn',
145
+ 'jupyter/require-disposable-transfer': 'warn',
146
+ 'jupyter/incorrect-translator-usage': 'warn',
147
+ 'jupyter/prefer-lazy-imports': 'warn'
103
148
  },
104
149
  overrides: [
105
150
  {
@@ -110,7 +155,12 @@ const plugin = {
110
155
  '**/*.test.js'
111
156
  ],
112
157
  rules: {
113
- 'jupyter/require-soft-assertions-before-snapshots': 'warn'
158
+ 'jupyter/require-soft-assertions-before-snapshots': 'warn',
159
+ 'jupyter/galata-prefer-filebrowser-helper': 'warn',
160
+ 'jupyter/galata-prefer-menu-helper': 'warn',
161
+ 'jupyter/galata-prefer-notebook-cell-helper': 'warn',
162
+ 'jupyter/galata-prefer-sidebar-activity-helper': 'warn',
163
+ 'jupyter/prefer-lazy-imports': 'off'
114
164
  }
115
165
  }
116
166
  ]
@@ -0,0 +1,5 @@
1
+ type MessageIds = 'preferNotebookOpenByPath' | 'preferOpenHomeDirectory' | 'preferOpenDirectory' | 'preferFilebrowserHelper';
2
+ declare const galataPreferFilebrowserHelper: import("@typescript-eslint/utils/ts-eslint").RuleModule<MessageIds, [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
3
+ name: string;
4
+ };
5
+ export = galataPreferFilebrowserHelper;
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) Jupyter Development Team.
4
+ * Distributed under the terms of the Modified BSD License.
5
+ */
6
+ const create_rule_1 = require("../utils/create-rule");
7
+ const playwright_selectors_1 = require("../utils/playwright-selectors");
8
+ const NOTEBOOK_FILE_PATTERN = /\.ipynb\b/;
9
+ const BREADCRUMBS_PATTERN = /jp-BreadCrumbs-home/;
10
+ // Selectors scoped to the file browser region
11
+ const FILEBROWSER_CONTEXT_PATTERN = /File Browser Section|jp-DirListing-item|#filebrowser\b/;
12
+ // The file selector dialog reuses the directory listing markup, but the
13
+ // `page.filebrowser` helpers only drive the sidebar widget, so a selector
14
+ // scoped to a dialog has no helper to recommend.
15
+ const DIALOG_CONTEXT_PATTERN = /jp-Dialog\b/;
16
+ // A dotted file name inside a text match: `text=lorenz.py`,
17
+ // `:has-text("bar.vl.json")`. The dot must sit between word
18
+ // characters and only inside the text portion (which ends at `>>`), so CSS
19
+ // selectors like `span.lm-Menu-itemLabel` or `text=Close >> button.jp-Button`
20
+ // are not mistaken for file names.
21
+ const FILE_TEXT_PATTERN = /(?:text=|has-text\()["']?[^>"')]*\w\.\w/;
22
+ // The name a text match looks for: `text=notebooks`, `:has-text("mydir")`.
23
+ // Requires at least one word character, so the leftover static text of a
24
+ // fully interpolated name (`` `text=${dirName}` ``) does not count as a name.
25
+ const TEXT_MATCH_NAME_PATTERN = /(?:text=|has-text\()["']?([^>"')]*\w[^>"')]*)/;
26
+ const galataPreferFilebrowserHelper = (0, create_rule_1.createRule)({
27
+ name: 'galata-prefer-filebrowser-helper',
28
+ meta: {
29
+ type: 'suggestion',
30
+ docs: {
31
+ description: 'Prefer Galata filebrowser and notebook helpers over raw Playwright selectors for JupyterLab file browser interactions'
32
+ },
33
+ messages: {
34
+ preferNotebookOpenByPath: 'Prefer `page.notebook.openByPath(path)` (or `page.notebook.open(name)`) over raw selectors to open a notebook.',
35
+ preferOpenHomeDirectory: 'Prefer `page.filebrowser.openHomeDirectory()` over clicking the home breadcrumb (`.jp-BreadCrumbs-home`) directly.',
36
+ preferOpenDirectory: 'Prefer `page.filebrowser.openDirectory(path)` over double-clicking a directory. Note that `page.filebrowser.open(filePath)` and `page.notebook.openByPath(filePath)` already open the intermediate directories of the file they are given.',
37
+ preferFilebrowserHelper: 'Prefer the Galata `page.filebrowser` helper (e.g. `page.filebrowser.open(path)` for a file, `page.filebrowser.openDirectory(path)` for a directory) over raw file browser selectors.'
38
+ },
39
+ schema: []
40
+ },
41
+ defaultOptions: [],
42
+ create(context) {
43
+ return {
44
+ CallExpression(node) {
45
+ const match = (0, playwright_selectors_1.matchSelectorInteraction)(node);
46
+ if (!match) {
47
+ return;
48
+ }
49
+ // Right-clicks open the context menu
50
+ if (match.isRightClick) {
51
+ return;
52
+ }
53
+ const selectorText = (0, playwright_selectors_1.combineStaticSelectorText)(match);
54
+ if (selectorText === null) {
55
+ return;
56
+ }
57
+ // The dialog is not the file browser widget the helpers drive.
58
+ if (DIALOG_CONTEXT_PATTERN.test(selectorText)) {
59
+ return;
60
+ }
61
+ // Double-clicking is the open gesture.
62
+ const opensTarget = match.interactionMethod === 'dblclick';
63
+ if (opensTarget && NOTEBOOK_FILE_PATTERN.test(selectorText)) {
64
+ context.report({
65
+ node: match.callNode,
66
+ messageId: 'preferNotebookOpenByPath'
67
+ });
68
+ return;
69
+ }
70
+ if (BREADCRUMBS_PATTERN.test(selectorText)) {
71
+ context.report({
72
+ node: match.callNode,
73
+ messageId: 'preferOpenHomeDirectory'
74
+ });
75
+ return;
76
+ }
77
+ // Double-clicked file browser items and file names are opens; a
78
+ // waitForSelector on the file browser has helper waits instead.
79
+ if (opensTarget &&
80
+ (FILEBROWSER_CONTEXT_PATTERN.test(selectorText) ||
81
+ FILE_TEXT_PATTERN.test(selectorText))) {
82
+ // A name without a dot is a directory, which `open()` cannot handle:
83
+ // it waits for a document tab that a directory never opens.
84
+ const matchedName = TEXT_MATCH_NAME_PATTERN.exec(selectorText)?.[1];
85
+ const opensDirectory = matchedName !== undefined && !matchedName.includes('.');
86
+ context.report({
87
+ node: match.callNode,
88
+ messageId: opensDirectory
89
+ ? 'preferOpenDirectory'
90
+ : 'preferFilebrowserHelper'
91
+ });
92
+ return;
93
+ }
94
+ if (match.interactionMethod === 'waitForSelector' &&
95
+ FILEBROWSER_CONTEXT_PATTERN.test(selectorText)) {
96
+ context.report({
97
+ node: match.callNode,
98
+ messageId: 'preferFilebrowserHelper'
99
+ });
100
+ }
101
+ }
102
+ };
103
+ }
104
+ });
105
+ module.exports = galataPreferFilebrowserHelper;
@@ -0,0 +1,6 @@
1
+ import { TSESLint } from '@typescript-eslint/utils';
2
+ type MessageIds = 'preferMenuOpen' | 'preferClickMenuItem' | 'preferMenuHelper';
3
+ declare const galataPreferMenuHelper: TSESLint.RuleModule<MessageIds, [], unknown, TSESLint.RuleListener> & {
4
+ name: string;
5
+ };
6
+ export = galataPreferMenuHelper;