@jupyter/eslint-plugin 1.2.0 → 1.3.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 +19 -1
- package/lib/index.js +14 -3
- package/lib/rules/galata-prefer-context-menu-helper.d.ts +6 -0
- package/lib/rules/galata-prefer-context-menu-helper.js +394 -0
- package/lib/rules/galata-prefer-menu-helper.js +18 -102
- package/lib/rules/no-untranslated-string.d.ts +2 -1
- package/lib/rules/no-untranslated-string.js +191 -113
- package/lib/rules/plugin-id-convention.d.ts +7 -0
- package/lib/rules/plugin-id-convention.js +296 -0
- package/lib/rules/prefer-lazy-imports.js +204 -36
- package/lib/rules/require-disposable-ownership.js +1 -16
- package/lib/rules/require-disposable-transfer.js +7 -2
- package/lib/utils/ast.d.ts +12 -0
- package/lib/utils/ast.js +49 -0
- package/lib/utils/disposables.d.ts +12 -0
- package/lib/utils/disposables.js +101 -10
- package/lib/utils/lazy-imports.d.ts +26 -3
- package/lib/utils/lazy-imports.js +121 -36
- package/lib/utils/module-size.d.ts +7 -1
- package/lib/utils/module-size.js +10 -1
- package/lib/utils/package-json.d.ts +8 -0
- package/lib/utils/package-json.js +76 -0
- package/lib/utils/playwright-selectors.d.ts +15 -0
- package/lib/utils/playwright-selectors.js +80 -0
- package/lib/utils/plugin-utils.d.ts +35 -5
- package/lib/utils/plugin-utils.js +119 -44
- package/lib/utils/shared-packages.js +6 -16
- package/lib/utils/signals.d.ts +2 -8
- package/lib/utils/signals.js +7 -42
- package/package.json +1 -1
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Copyright (c) Jupyter Development Team.
|
|
4
4
|
* Distributed under the terms of the Modified BSD License.
|
|
5
5
|
*/
|
|
6
|
+
const ast_1 = require("../utils/ast");
|
|
6
7
|
const create_rule_1 = require("../utils/create-rule");
|
|
7
8
|
const playwright_selectors_1 = require("../utils/playwright-selectors");
|
|
8
9
|
// JupyterLab's main menu bar
|
|
@@ -141,83 +142,19 @@ function menuOriginOf(node) {
|
|
|
141
142
|
? 'menubar'
|
|
142
143
|
: null;
|
|
143
144
|
}
|
|
144
|
-
function
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}
|
|
149
|
-
// Calls whose callback is stored and run later. Statements next to such a call
|
|
150
|
-
// say nothing about the state its body starts in.
|
|
151
|
-
const DEFERRED_CALLBACK_CALLEES = new Set([
|
|
152
|
-
'test',
|
|
153
|
-
'it',
|
|
154
|
-
'describe',
|
|
155
|
-
'suite',
|
|
156
|
-
'beforeAll',
|
|
157
|
-
'beforeEach',
|
|
158
|
-
'afterAll',
|
|
159
|
-
'afterEach'
|
|
160
|
-
]);
|
|
161
|
-
function rootCalleeName(node) {
|
|
162
|
-
let current = node;
|
|
163
|
-
while (current.type === 'MemberExpression') {
|
|
164
|
-
current = current.object;
|
|
165
|
-
}
|
|
166
|
-
return current.type === 'Identifier' ? current.name : null;
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Whether the lookback must stop before leaving `node`, and whether the scan of
|
|
170
|
-
* preceding statements must stop before entering it.
|
|
171
|
-
*
|
|
172
|
-
* A callback written inline runs where it stands, so the statements above it
|
|
173
|
-
* did run first and the walk continues through it: `perf.measure(async () => {
|
|
174
|
-
* … })` keeps the menu its caller opened. A named helper and a test callback do
|
|
175
|
-
* not. `async function openMenu(page) { … }` can be called from anywhere, and
|
|
176
|
-
* `test('b', …)` does not run after the body of `test('a', …)`, so a
|
|
177
|
-
* right-click in one test must not silence the next one.
|
|
178
|
-
*/
|
|
179
|
-
function isLookbackBoundary(node) {
|
|
180
|
-
if (node.type === 'FunctionDeclaration') {
|
|
181
|
-
return true;
|
|
182
|
-
}
|
|
183
|
-
if (node.type !== 'FunctionExpression' &&
|
|
184
|
-
node.type !== 'ArrowFunctionExpression') {
|
|
185
|
-
return false;
|
|
186
|
-
}
|
|
187
|
-
const parent = node.parent;
|
|
188
|
-
if (parent?.type === 'VariableDeclarator' || parent?.type === 'Property') {
|
|
189
|
-
return true;
|
|
190
|
-
}
|
|
191
|
-
return (parent?.type === 'CallExpression' &&
|
|
192
|
-
parent.arguments.includes(node) &&
|
|
193
|
-
DEFERRED_CALLBACK_CALLEES.has(rootCalleeName(parent.callee) ?? ''));
|
|
194
|
-
}
|
|
195
|
-
function collectMenuOrigins(node, found) {
|
|
196
|
-
if (isLookbackBoundary(node)) {
|
|
197
|
-
return;
|
|
198
|
-
}
|
|
199
|
-
if (node.type === 'CallExpression') {
|
|
200
|
-
const origin = menuOriginOf(node);
|
|
201
|
-
if (origin) {
|
|
202
|
-
found.push({ origin, start: node.range[0] });
|
|
145
|
+
function collectMenuOrigins(root, found) {
|
|
146
|
+
(0, ast_1.walkFrom)(root, node => {
|
|
147
|
+
if ((0, playwright_selectors_1.isTestScopeBoundary)(node)) {
|
|
148
|
+
return 'skip-children';
|
|
203
149
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
continue;
|
|
209
|
-
}
|
|
210
|
-
if (Array.isArray(value)) {
|
|
211
|
-
for (const item of value) {
|
|
212
|
-
if (isNode(item)) {
|
|
213
|
-
collectMenuOrigins(item, found);
|
|
214
|
-
}
|
|
150
|
+
if (node.type === 'CallExpression') {
|
|
151
|
+
const origin = menuOriginOf(node);
|
|
152
|
+
if (origin) {
|
|
153
|
+
found.push({ origin, start: node.range[0] });
|
|
215
154
|
}
|
|
216
155
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
}
|
|
220
|
-
}
|
|
156
|
+
return undefined;
|
|
157
|
+
});
|
|
221
158
|
}
|
|
222
159
|
/**
|
|
223
160
|
* The last menu-opening gesture among the first `index` statements of `block`.
|
|
@@ -257,7 +194,7 @@ function originBeforeStatement(block, body, index, cache) {
|
|
|
257
194
|
* preceding statements all come after an outer block's, so the innermost block
|
|
258
195
|
* with an answer holds the latest one and the walk can stop there. The walk
|
|
259
196
|
* also stops at the enclosing test callback or named helper, so one test's menu
|
|
260
|
-
* state never reaches the next (see `
|
|
197
|
+
* state never reaches the next (see `isTestScopeBoundary`).
|
|
261
198
|
*/
|
|
262
199
|
function findMenuOrigin(node, cache) {
|
|
263
200
|
let current = node;
|
|
@@ -277,7 +214,7 @@ function findMenuOrigin(node, cache) {
|
|
|
277
214
|
return origin;
|
|
278
215
|
}
|
|
279
216
|
}
|
|
280
|
-
if (
|
|
217
|
+
if ((0, playwright_selectors_1.isTestScopeBoundary)(parent)) {
|
|
281
218
|
return null;
|
|
282
219
|
}
|
|
283
220
|
current = parent;
|
|
@@ -305,10 +242,7 @@ const MENU_WORD_PATTERN = /menus?\b/i;
|
|
|
305
242
|
* or a file name says nothing.
|
|
306
243
|
*/
|
|
307
244
|
function testMentionsMenuMarkup(node) {
|
|
308
|
-
|
|
309
|
-
while (scope.parent && !isLookbackBoundary(scope)) {
|
|
310
|
-
scope = scope.parent;
|
|
311
|
-
}
|
|
245
|
+
const scope = (0, playwright_selectors_1.enclosingTestScope)(node);
|
|
312
246
|
// The title of a `test(…)` sits next to its callback rather than inside it.
|
|
313
247
|
// It is a sentence a person wrote about what the test does, so the bare word
|
|
314
248
|
// is enough there, where in a selector it would not be.
|
|
@@ -322,35 +256,17 @@ function testMentionsMenuMarkup(node) {
|
|
|
322
256
|
}
|
|
323
257
|
}
|
|
324
258
|
let found = false;
|
|
325
|
-
|
|
326
|
-
if (found) {
|
|
327
|
-
return;
|
|
328
|
-
}
|
|
259
|
+
(0, ast_1.walkFrom)(scope, current => {
|
|
329
260
|
if ((current.type === 'Literal' && typeof current.value === 'string'
|
|
330
261
|
? ANY_MENU_MARKUP_PATTERN.test(current.value)
|
|
331
262
|
: false) ||
|
|
332
263
|
(current.type === 'TemplateElement' &&
|
|
333
264
|
ANY_MENU_MARKUP_PATTERN.test(current.value.cooked ?? ''))) {
|
|
334
265
|
found = true;
|
|
335
|
-
return;
|
|
336
|
-
}
|
|
337
|
-
for (const [key, value] of Object.entries(current)) {
|
|
338
|
-
if (key === 'parent') {
|
|
339
|
-
continue;
|
|
340
|
-
}
|
|
341
|
-
if (Array.isArray(value)) {
|
|
342
|
-
for (const item of value) {
|
|
343
|
-
if (isNode(item)) {
|
|
344
|
-
visit(item);
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
else if (isNode(value)) {
|
|
349
|
-
visit(value);
|
|
350
|
-
}
|
|
266
|
+
return 'stop';
|
|
351
267
|
}
|
|
352
|
-
|
|
353
|
-
|
|
268
|
+
return undefined;
|
|
269
|
+
});
|
|
354
270
|
return found;
|
|
355
271
|
}
|
|
356
272
|
/**
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
declare const noUntranslatedString: import("@typescript-eslint/utils/ts-eslint").RuleModule<"untranslatedCommandProp" | "untranslatedSetAttribute" | "untranslatedPropertyAssign" | "
|
|
1
|
+
declare const noUntranslatedString: import("@typescript-eslint/utils/ts-eslint").RuleModule<"untranslatedCommandProp" | "untranslatedSetAttribute" | "untranslatedPropertyAssign" | "untranslatedDialogOption" | "untranslatedDialogButtonLabel" | "untranslatedJsxText" | "untranslatedJsxAttribute" | "untranslatedProperty", [{
|
|
2
2
|
enforcePunctuation: boolean;
|
|
3
|
+
checkProperties: string[];
|
|
3
4
|
}], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
|
|
4
5
|
name: string;
|
|
5
6
|
};
|
|
@@ -5,30 +5,64 @@
|
|
|
5
5
|
*/
|
|
6
6
|
const commands_1 = require("../utils/commands");
|
|
7
7
|
const plugin_utils_1 = require("../utils/plugin-utils");
|
|
8
|
+
const translation_1 = require("../utils/translation");
|
|
8
9
|
const create_rule_1 = require("../utils/create-rule");
|
|
9
10
|
function hasLetters(str) {
|
|
10
11
|
return /\p{L}/u.test(str);
|
|
11
12
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Returns every raw string a value expression can evaluate to, empty when it
|
|
15
|
+
* can evaluate to none.
|
|
16
|
+
*
|
|
17
|
+
* A conditional has more than one result, and each one reaches the user on its
|
|
18
|
+
* own: `visible ? 'Hide' : 'Show'` displays either branch, `label ?? 'Untitled'`
|
|
19
|
+
* displays either operand. Collecting them all means a half-translated
|
|
20
|
+
* conditional reports only the branch that is still raw.
|
|
21
|
+
*/
|
|
22
|
+
function getRawStrings(node) {
|
|
23
|
+
const inner = (0, translation_1.unwrapExpression)(node);
|
|
24
|
+
switch (inner.type) {
|
|
25
|
+
case 'Literal':
|
|
26
|
+
return typeof inner.value === 'string'
|
|
27
|
+
? [{ node: inner, value: inner.value }]
|
|
28
|
+
: [];
|
|
29
|
+
case 'TemplateLiteral':
|
|
30
|
+
return inner.expressions.length === 0
|
|
31
|
+
? [
|
|
32
|
+
{
|
|
33
|
+
node: inner,
|
|
34
|
+
value: inner.quasis.map(q => q.value.cooked ?? '').join('')
|
|
35
|
+
}
|
|
36
|
+
]
|
|
37
|
+
: [];
|
|
38
|
+
case 'ArrowFunctionExpression':
|
|
39
|
+
return inner.body.type === 'BlockStatement'
|
|
40
|
+
? []
|
|
41
|
+
: getRawStrings(inner.body);
|
|
42
|
+
case 'ConditionalExpression':
|
|
43
|
+
return [
|
|
44
|
+
...getRawStrings(inner.consequent),
|
|
45
|
+
...getRawStrings(inner.alternate)
|
|
46
|
+
];
|
|
47
|
+
case 'LogicalExpression':
|
|
48
|
+
// `a && 'text'` evaluates to the left operand only when that operand is
|
|
49
|
+
// falsy, and the only falsy string is blank, which this rule never
|
|
50
|
+
// reports. `a || 'text'` and `a ?? 'text'` evaluate to either operand.
|
|
51
|
+
return [
|
|
52
|
+
...(inner.operator === '&&' ? [] : getRawStrings(inner.left)),
|
|
53
|
+
...getRawStrings(inner.right)
|
|
54
|
+
];
|
|
55
|
+
default:
|
|
56
|
+
return [];
|
|
22
57
|
}
|
|
23
|
-
return null;
|
|
24
58
|
}
|
|
25
59
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
60
|
+
* Folds the hyphenated and camelCase spellings of a name together so that a
|
|
61
|
+
* single configured entry covers both, e.g. the `aria-label` attribute and the
|
|
62
|
+
* `ariaLabel` DOM property.
|
|
28
63
|
*/
|
|
29
|
-
function
|
|
30
|
-
|
|
31
|
-
return rawValue !== null && rawValue.trim().length > 0;
|
|
64
|
+
function normalizeName(name) {
|
|
65
|
+
return name.replace(/-/g, '').toLowerCase();
|
|
32
66
|
}
|
|
33
67
|
function isSetAttributeCall(node) {
|
|
34
68
|
return (node.callee.type === 'MemberExpression' &&
|
|
@@ -54,12 +88,43 @@ function isDialogButtonCall(node) {
|
|
|
54
88
|
node.callee.property.type === 'Identifier' &&
|
|
55
89
|
DIALOG_BUTTON_BUILDERS.includes(node.callee.property.name));
|
|
56
90
|
}
|
|
91
|
+
// Properties checked only on the call they belong to, because the name alone
|
|
92
|
+
// does not imply user-facing text anywhere else.
|
|
57
93
|
const MONITORED_COMMAND_PROPS = ['label', 'caption', 'usage'];
|
|
58
|
-
const MONITORED_A11Y_ATTRS = ['aria-label', 'aria-description', 'title'];
|
|
59
|
-
const MONITORED_SET_ATTRIBUTE_ATTRS = MONITORED_A11Y_ATTRS;
|
|
60
|
-
const MONITORED_ASSIGNMENT_PROPS = ['title', 'ariaLabel'];
|
|
61
94
|
const MONITORED_DIALOG_PROPS = ['title', 'body'];
|
|
62
|
-
|
|
95
|
+
/**
|
|
96
|
+
* Names checked in every generic position: object literal properties, JSX
|
|
97
|
+
* attributes, `setAttribute()` attribute names and assignment targets.
|
|
98
|
+
*/
|
|
99
|
+
const DEFAULT_CHECK_PROPERTIES = [
|
|
100
|
+
'alt',
|
|
101
|
+
'aria-description',
|
|
102
|
+
'aria-label',
|
|
103
|
+
'caption',
|
|
104
|
+
'category',
|
|
105
|
+
'label',
|
|
106
|
+
'placeholder',
|
|
107
|
+
'title',
|
|
108
|
+
'tooltip',
|
|
109
|
+
'textContent',
|
|
110
|
+
'innerText'
|
|
111
|
+
];
|
|
112
|
+
/**
|
|
113
|
+
* Returns the static name of a non-computed object property key, or null when
|
|
114
|
+
* the key is computed or not a plain identifier/string.
|
|
115
|
+
*/
|
|
116
|
+
function getPropertyKeyName(node) {
|
|
117
|
+
if (node.computed) {
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
if (node.key.type === 'Identifier') {
|
|
121
|
+
return node.key.name;
|
|
122
|
+
}
|
|
123
|
+
if (node.key.type === 'Literal' && typeof node.key.value === 'string') {
|
|
124
|
+
return node.key.value;
|
|
125
|
+
}
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
63
128
|
const noUntranslatedString = (0, create_rule_1.createRule)({
|
|
64
129
|
name: 'no-untranslated-string',
|
|
65
130
|
meta: {
|
|
@@ -72,25 +137,85 @@ const noUntranslatedString = (0, create_rule_1.createRule)({
|
|
|
72
137
|
untranslatedCommandProp: 'Command property "{{ prop }}" has an untranslated string literal. Wrap it with trans.__().',
|
|
73
138
|
untranslatedSetAttribute: 'setAttribute("{{ attr }}", ...) has an untranslated string literal. Wrap the value with trans.__().',
|
|
74
139
|
untranslatedPropertyAssign: 'Assignment to "{{ prop }}" has an untranslated string literal. Wrap it with trans.__().',
|
|
75
|
-
untranslatedTitleProp: 'Assignment to "title.{{ prop }}" has an untranslated string literal. Wrap it with trans.__().',
|
|
76
140
|
untranslatedDialogOption: 'Dialog/showDialog "{{ prop }}" option has an untranslated string literal. Wrap it with trans.__().',
|
|
77
141
|
untranslatedDialogButtonLabel: 'Dialog button "label" option has an untranslated string literal. Wrap it with trans.__().',
|
|
78
|
-
untranslatedJsxText: 'JSX text content has an untranslated string literal. Wrap it with {trans.__(...)}'
|
|
142
|
+
untranslatedJsxText: 'JSX text content has an untranslated string literal. Wrap it with {trans.__(...)}',
|
|
143
|
+
untranslatedJsxAttribute: 'JSX attribute "{{ prop }}" has an untranslated string literal. Wrap it with {trans.__(...)}',
|
|
144
|
+
untranslatedProperty: 'Property "{{ prop }}" has an untranslated string literal. Wrap it with trans.__().'
|
|
79
145
|
},
|
|
80
146
|
schema: [
|
|
81
147
|
{
|
|
82
148
|
type: 'object',
|
|
83
149
|
properties: {
|
|
84
|
-
enforcePunctuation: { type: 'boolean' }
|
|
150
|
+
enforcePunctuation: { type: 'boolean' },
|
|
151
|
+
checkProperties: {
|
|
152
|
+
type: 'array',
|
|
153
|
+
items: { type: 'string' },
|
|
154
|
+
uniqueItems: true
|
|
155
|
+
}
|
|
85
156
|
},
|
|
86
157
|
additionalProperties: false
|
|
87
158
|
}
|
|
88
159
|
]
|
|
89
160
|
},
|
|
90
|
-
defaultOptions: [
|
|
161
|
+
defaultOptions: [
|
|
162
|
+
{
|
|
163
|
+
enforcePunctuation: false,
|
|
164
|
+
checkProperties: DEFAULT_CHECK_PROPERTIES
|
|
165
|
+
}
|
|
166
|
+
],
|
|
91
167
|
create(context) {
|
|
92
|
-
const
|
|
93
|
-
|
|
168
|
+
const options = context.options[0];
|
|
169
|
+
const enforcePunctuation = options?.enforcePunctuation ?? false;
|
|
170
|
+
const checkProperties = new Set((options?.checkProperties ?? DEFAULT_CHECK_PROPERTIES).map(normalizeName));
|
|
171
|
+
function isMonitoredName(name) {
|
|
172
|
+
return checkProperties.has(normalizeName(name));
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Returns true if the text should be wrapped in a translation call.
|
|
176
|
+
*
|
|
177
|
+
* Blank strings are never reported. A string with no letters is read as a
|
|
178
|
+
* bare number when it has digits ('1970', '100%'), which this rule never
|
|
179
|
+
* reports, and as punctuation otherwise ('/', '-'), which it reports only
|
|
180
|
+
* when `enforcePunctuation` is on.
|
|
181
|
+
*/
|
|
182
|
+
function isReportableText(value) {
|
|
183
|
+
if (value.trim().length === 0) {
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
// No letters: a bare number is never reported, punctuation only on request.
|
|
187
|
+
return hasLetters(value) || (enforcePunctuation && !/\p{N}/u.test(value));
|
|
188
|
+
}
|
|
189
|
+
// Literals already reported by a more specific branch (e.g. addCommand or
|
|
190
|
+
// a Dialog button builder), so the generic checks do not duplicate them.
|
|
191
|
+
// Enclosing calls are visited before the properties they contain, so the
|
|
192
|
+
// specific branch always runs first.
|
|
193
|
+
const reportedNodes = new Set();
|
|
194
|
+
function report(node, messageId, data) {
|
|
195
|
+
reportedNodes.add(node);
|
|
196
|
+
context.report({ node, messageId, data });
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Reports every string literal behind `value` that has not been reported
|
|
200
|
+
* already.
|
|
201
|
+
*/
|
|
202
|
+
function reportRawString(value, messageId, data) {
|
|
203
|
+
for (const raw of getRawStrings(value)) {
|
|
204
|
+
if (reportedNodes.has(raw.node) || !isReportableText(raw.value)) {
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
report(raw.node, messageId, data);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Reports a monitored JSX attribute whose value is a raw string.
|
|
212
|
+
*/
|
|
213
|
+
function checkJsxAttributeValue(attrName, value) {
|
|
214
|
+
if (!attrName || !isMonitoredName(attrName)) {
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
reportRawString(value, 'untranslatedJsxAttribute', { prop: attrName });
|
|
218
|
+
}
|
|
94
219
|
return {
|
|
95
220
|
CallExpression(node) {
|
|
96
221
|
// Branch A: commands.addCommand(id, { label, caption, usage })
|
|
@@ -105,17 +230,15 @@ const noUntranslatedString = (0, create_rule_1.createRule)({
|
|
|
105
230
|
const properties = (0, plugin_utils_1.getObjectProperties)(optionsArg);
|
|
106
231
|
for (const propName of MONITORED_COMMAND_PROPS) {
|
|
107
232
|
const prop = properties.get(propName);
|
|
108
|
-
if (prop
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
messageId: 'untranslatedCommandProp',
|
|
112
|
-
data: { prop: propName }
|
|
233
|
+
if (prop) {
|
|
234
|
+
reportRawString(prop.value, 'untranslatedCommandProp', {
|
|
235
|
+
prop: propName
|
|
113
236
|
});
|
|
114
237
|
}
|
|
115
238
|
}
|
|
116
239
|
return;
|
|
117
240
|
}
|
|
118
|
-
// Branch B: element.setAttribute('aria-label'
|
|
241
|
+
// Branch B: element.setAttribute('aria-label', string)
|
|
119
242
|
if (isSetAttributeCall(node)) {
|
|
120
243
|
if (node.arguments.length < 2) {
|
|
121
244
|
return;
|
|
@@ -123,17 +246,12 @@ const noUntranslatedString = (0, create_rule_1.createRule)({
|
|
|
123
246
|
const attrNameArg = node.arguments[0];
|
|
124
247
|
if (attrNameArg.type !== 'Literal' ||
|
|
125
248
|
typeof attrNameArg.value !== 'string' ||
|
|
126
|
-
!
|
|
249
|
+
!isMonitoredName(attrNameArg.value)) {
|
|
127
250
|
return;
|
|
128
251
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
node: attrValueArg,
|
|
133
|
-
messageId: 'untranslatedSetAttribute',
|
|
134
|
-
data: { attr: attrNameArg.value }
|
|
135
|
-
});
|
|
136
|
-
}
|
|
252
|
+
reportRawString(node.arguments[1], 'untranslatedSetAttribute', {
|
|
253
|
+
attr: attrNameArg.value
|
|
254
|
+
});
|
|
137
255
|
return;
|
|
138
256
|
}
|
|
139
257
|
// Branch C: showDialog({ title, body })
|
|
@@ -148,11 +266,9 @@ const noUntranslatedString = (0, create_rule_1.createRule)({
|
|
|
148
266
|
const properties = (0, plugin_utils_1.getObjectProperties)(optionsArg);
|
|
149
267
|
for (const propName of MONITORED_DIALOG_PROPS) {
|
|
150
268
|
const prop = properties.get(propName);
|
|
151
|
-
if (prop
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
messageId: 'untranslatedDialogOption',
|
|
155
|
-
data: { prop: propName }
|
|
269
|
+
if (prop) {
|
|
270
|
+
reportRawString(prop.value, 'untranslatedDialogOption', {
|
|
271
|
+
prop: propName
|
|
156
272
|
});
|
|
157
273
|
}
|
|
158
274
|
}
|
|
@@ -169,11 +285,8 @@ const noUntranslatedString = (0, create_rule_1.createRule)({
|
|
|
169
285
|
}
|
|
170
286
|
const properties = (0, plugin_utils_1.getObjectProperties)(optionsArg);
|
|
171
287
|
const labelProp = properties.get('label');
|
|
172
|
-
if (labelProp
|
|
173
|
-
|
|
174
|
-
node: labelProp.value,
|
|
175
|
-
messageId: 'untranslatedDialogButtonLabel'
|
|
176
|
-
});
|
|
288
|
+
if (labelProp) {
|
|
289
|
+
reportRawString(labelProp.value, 'untranslatedDialogButtonLabel');
|
|
177
290
|
}
|
|
178
291
|
}
|
|
179
292
|
},
|
|
@@ -192,15 +305,16 @@ const noUntranslatedString = (0, create_rule_1.createRule)({
|
|
|
192
305
|
const properties = (0, plugin_utils_1.getObjectProperties)(optionsArg);
|
|
193
306
|
for (const propName of MONITORED_DIALOG_PROPS) {
|
|
194
307
|
const prop = properties.get(propName);
|
|
195
|
-
if (prop
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
messageId: 'untranslatedDialogOption',
|
|
199
|
-
data: { prop: propName }
|
|
308
|
+
if (prop) {
|
|
309
|
+
reportRawString(prop.value, 'untranslatedDialogOption', {
|
|
310
|
+
prop: propName
|
|
200
311
|
});
|
|
201
312
|
}
|
|
202
313
|
}
|
|
203
314
|
},
|
|
315
|
+
// Any monitored assignment target: element.title = STRING,
|
|
316
|
+
// widget.label = STRING, this.label = STRING, node.textContent = STRING,
|
|
317
|
+
// and Lumino widget titles such as this.title.label = STRING
|
|
204
318
|
AssignmentExpression(node) {
|
|
205
319
|
if (node.operator !== '=') {
|
|
206
320
|
return;
|
|
@@ -208,58 +322,39 @@ const noUntranslatedString = (0, create_rule_1.createRule)({
|
|
|
208
322
|
const left = node.left;
|
|
209
323
|
if (left.type !== 'MemberExpression' ||
|
|
210
324
|
left.computed ||
|
|
211
|
-
left.property.type !== 'Identifier'
|
|
325
|
+
left.property.type !== 'Identifier' ||
|
|
326
|
+
!isMonitoredName(left.property.name)) {
|
|
212
327
|
return;
|
|
213
328
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
329
|
+
reportRawString(node.right, 'untranslatedPropertyAssign', {
|
|
330
|
+
prop: left.property.name
|
|
331
|
+
});
|
|
332
|
+
},
|
|
333
|
+
// Any monitored object property: { label: 'raw string' }.
|
|
334
|
+
// Runs after the call-specific branches above, which mark the literals
|
|
335
|
+
// they already reported so a property is never reported twice.
|
|
336
|
+
Property(node) {
|
|
337
|
+
if (node.shorthand) {
|
|
222
338
|
return;
|
|
223
339
|
}
|
|
224
|
-
|
|
225
|
-
if (
|
|
226
|
-
|
|
227
|
-
left.object.type === 'MemberExpression' &&
|
|
228
|
-
!left.object.computed &&
|
|
229
|
-
left.object.property.type === 'Identifier' &&
|
|
230
|
-
left.object.property.name === 'title' &&
|
|
231
|
-
isRawStringNode(node.right)) {
|
|
232
|
-
context.report({
|
|
233
|
-
node: node.right,
|
|
234
|
-
messageId: 'untranslatedTitleProp',
|
|
235
|
-
data: { prop: left.property.name }
|
|
236
|
-
});
|
|
340
|
+
const keyName = getPropertyKeyName(node);
|
|
341
|
+
if (!keyName || !isMonitoredName(keyName)) {
|
|
342
|
+
return;
|
|
237
343
|
}
|
|
344
|
+
reportRawString(node.value, 'untranslatedProperty', { prop: keyName });
|
|
238
345
|
},
|
|
239
|
-
//
|
|
346
|
+
// Monitored attribute with a plain string: <span aria-label="text" />
|
|
240
347
|
JSXAttribute(node) {
|
|
241
348
|
if (!node.value || node.value.type === 'JSXExpressionContainer') {
|
|
242
349
|
return;
|
|
243
350
|
}
|
|
244
351
|
const attrName = node.name.type === 'JSXIdentifier' ? node.name.name : null;
|
|
245
|
-
|
|
246
|
-
return;
|
|
247
|
-
}
|
|
248
|
-
if (isRawStringNode(node.value)) {
|
|
249
|
-
context.report({
|
|
250
|
-
node: node.value,
|
|
251
|
-
messageId: 'untranslatedJsxText'
|
|
252
|
-
});
|
|
253
|
-
}
|
|
352
|
+
checkJsxAttributeValue(attrName, node.value);
|
|
254
353
|
},
|
|
255
354
|
// Raw text between JSX tags: <span>Untranslated text</span>
|
|
256
355
|
JSXText(node) {
|
|
257
|
-
if (node.value
|
|
258
|
-
(
|
|
259
|
-
context.report({
|
|
260
|
-
node,
|
|
261
|
-
messageId: 'untranslatedJsxText'
|
|
262
|
-
});
|
|
356
|
+
if (isReportableText(node.value)) {
|
|
357
|
+
report(node, 'untranslatedJsxText');
|
|
263
358
|
}
|
|
264
359
|
},
|
|
265
360
|
// String literal inside JSX expression: <span>{'raw string'}</span>
|
|
@@ -271,27 +366,10 @@ const noUntranslatedString = (0, create_rule_1.createRule)({
|
|
|
271
366
|
const attrName = node.parent.name.type === 'JSXIdentifier'
|
|
272
367
|
? node.parent.name.name
|
|
273
368
|
: null;
|
|
274
|
-
|
|
275
|
-
return;
|
|
276
|
-
}
|
|
277
|
-
if (isRawStringNode(node.expression)) {
|
|
278
|
-
context.report({
|
|
279
|
-
node: node.expression,
|
|
280
|
-
messageId: 'untranslatedJsxText'
|
|
281
|
-
});
|
|
282
|
-
}
|
|
369
|
+
checkJsxAttributeValue(attrName, node.expression);
|
|
283
370
|
return;
|
|
284
371
|
}
|
|
285
|
-
|
|
286
|
-
const value = getRawStringValue(node.expression);
|
|
287
|
-
if (value !== null &&
|
|
288
|
-
(enforcePunctuation ? value.trim().length > 0 : hasLetters(value))) {
|
|
289
|
-
context.report({
|
|
290
|
-
node: node.expression,
|
|
291
|
-
messageId: 'untranslatedJsxText'
|
|
292
|
-
});
|
|
293
|
-
}
|
|
294
|
-
}
|
|
372
|
+
reportRawString(node.expression, 'untranslatedJsxText');
|
|
295
373
|
}
|
|
296
374
|
};
|
|
297
375
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ESLintUtils } from '@typescript-eslint/utils';
|
|
2
|
+
declare const pluginIdConvention: ESLintUtils.RuleModule<"mismatchedPrefix" | "idEqualsPackageName", [{
|
|
3
|
+
reportIdEqualToPackageName: boolean;
|
|
4
|
+
}], unknown, ESLintUtils.RuleListener> & {
|
|
5
|
+
name: string;
|
|
6
|
+
};
|
|
7
|
+
export = pluginIdConvention;
|