@jupyter/eslint-plugin 0.0.2 → 0.0.4
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/README.md +1 -1
- package/lib/index.d.ts +26 -3
- package/lib/index.js +15 -3
- package/lib/rules/command-described-by.d.ts +3 -2
- package/lib/rules/command-described-by.js +12 -12
- package/lib/rules/no-translation-concatenation.d.ts +4 -0
- package/lib/rules/no-translation-concatenation.js +132 -0
- package/lib/rules/no-untranslated-string.d.ts +4 -0
- package/lib/rules/no-untranslated-string.js +250 -0
- package/lib/rules/plugin-activation-args.d.ts +6 -2
- package/lib/rules/plugin-activation-args.js +233 -94
- package/lib/rules/plugin-description.d.ts +3 -2
- package/lib/rules/plugin-description.js +27 -18
- package/lib/rules/token-format.d.ts +4 -0
- package/lib/rules/token-format.js +63 -0
- package/lib/utils/commands.d.ts +2 -2
- package/lib/utils/create-rule.d.ts +4 -0
- package/lib/utils/create-rule.js +9 -0
- package/lib/utils/plugin-utils.d.ts +11 -7
- package/lib/utils/plugin-utils.js +35 -48
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ npm install --save-dev @jupyter/eslint-plugin
|
|
|
10
10
|
|
|
11
11
|
## Usage
|
|
12
12
|
|
|
13
|
-
Add `@jupyter/eslint-plugin` to the plugins section of your ESLint configuration. For detailed usage instructions and available rules, see the
|
|
13
|
+
Add `@jupyter/eslint-plugin` to the plugins section of your ESLint configuration. For detailed usage instructions and available rules, see the [documentation](https://eslint-plugin.readthedocs.io/en/latest/).
|
|
14
14
|
|
|
15
15
|
## License
|
|
16
16
|
|
package/lib/index.d.ts
CHANGED
|
@@ -1,8 +1,25 @@
|
|
|
1
1
|
declare const plugin: {
|
|
2
2
|
rules: {
|
|
3
|
-
'plugin-activation-args': import("eslint").
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
'plugin-activation-args': import("@typescript-eslint/utils/dist/ts-eslint").RuleModule<"mismatchedOrder" | "incorrectType" | "missingArgument" | "extraArgument" | "appNotFirst" | "serviceManagerFirstArgNotNull" | "invalidAppType" | "wrongArgumentCount" | "unresolvableTokenType", [{
|
|
4
|
+
allowedFirstArgumentNames: string[];
|
|
5
|
+
}], unknown, import("@typescript-eslint/utils/dist/ts-eslint").RuleListener> & {
|
|
6
|
+
name: string;
|
|
7
|
+
};
|
|
8
|
+
'command-described-by': import("@typescript-eslint/utils/dist/ts-eslint").RuleModule<"missingDescribedBy", [], unknown, import("@typescript-eslint/utils/dist/ts-eslint").RuleListener> & {
|
|
9
|
+
name: string;
|
|
10
|
+
};
|
|
11
|
+
'plugin-description': import("@typescript-eslint/utils/dist/ts-eslint").RuleModule<"missingDescription" | "emptyDescription", [], unknown, import("@typescript-eslint/utils/dist/ts-eslint").RuleListener> & {
|
|
12
|
+
name: string;
|
|
13
|
+
};
|
|
14
|
+
'no-translation-concatenation': import("@typescript-eslint/utils/dist/ts-eslint").RuleModule<"noConcatenation", [], unknown, import("@typescript-eslint/utils/dist/ts-eslint").RuleListener> & {
|
|
15
|
+
name: string;
|
|
16
|
+
};
|
|
17
|
+
'token-format': import("@typescript-eslint/utils/dist/ts-eslint").RuleModule<"missingColon" | "invalidTokenSymbol", [], unknown, import("@typescript-eslint/utils/dist/ts-eslint").RuleListener> & {
|
|
18
|
+
name: string;
|
|
19
|
+
};
|
|
20
|
+
'no-untranslated-string': import("@typescript-eslint/utils/dist/ts-eslint").RuleModule<"untranslatedCommandProp" | "untranslatedSetAttribute" | "untranslatedPropertyAssign" | "untranslatedTitleProp" | "untranslatedDialogOption" | "untranslatedDialogButtonLabel" | "untranslatedJsxText", [], unknown, import("@typescript-eslint/utils/dist/ts-eslint").RuleListener> & {
|
|
21
|
+
name: string;
|
|
22
|
+
};
|
|
6
23
|
};
|
|
7
24
|
configs: {
|
|
8
25
|
recommended: {
|
|
@@ -11,6 +28,9 @@ declare const plugin: {
|
|
|
11
28
|
'jupyter/plugin-activation-args': string;
|
|
12
29
|
'jupyter/command-described-by': string;
|
|
13
30
|
'jupyter/plugin-description': string;
|
|
31
|
+
'jupyter/no-translation-concatenation': string;
|
|
32
|
+
'jupyter/token-format': string;
|
|
33
|
+
'jupyter/no-untranslated-string': string;
|
|
14
34
|
};
|
|
15
35
|
};
|
|
16
36
|
'recommended-legacy': {
|
|
@@ -18,6 +38,9 @@ declare const plugin: {
|
|
|
18
38
|
'jupyter/plugin-activation-args': string;
|
|
19
39
|
'jupyter/command-described-by': string;
|
|
20
40
|
'jupyter/plugin-description': string;
|
|
41
|
+
'jupyter/no-translation-concatenation': string;
|
|
42
|
+
'jupyter/token-format': string;
|
|
43
|
+
'jupyter/no-untranslated-string': string;
|
|
21
44
|
};
|
|
22
45
|
};
|
|
23
46
|
};
|
package/lib/index.js
CHANGED
|
@@ -9,11 +9,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
9
9
|
const plugin_activation_args_1 = __importDefault(require("./rules/plugin-activation-args"));
|
|
10
10
|
const command_described_by_1 = __importDefault(require("./rules/command-described-by"));
|
|
11
11
|
const plugin_description_1 = __importDefault(require("./rules/plugin-description"));
|
|
12
|
+
const no_translation_concatenation_1 = __importDefault(require("./rules/no-translation-concatenation"));
|
|
13
|
+
const token_format_1 = __importDefault(require("./rules/token-format"));
|
|
14
|
+
const no_untranslated_string_1 = __importDefault(require("./rules/no-untranslated-string"));
|
|
12
15
|
const plugin = {
|
|
13
16
|
rules: {
|
|
14
17
|
'plugin-activation-args': plugin_activation_args_1.default,
|
|
15
18
|
'command-described-by': command_described_by_1.default,
|
|
16
|
-
'plugin-description': plugin_description_1.default
|
|
19
|
+
'plugin-description': plugin_description_1.default,
|
|
20
|
+
'no-translation-concatenation': no_translation_concatenation_1.default,
|
|
21
|
+
'token-format': token_format_1.default,
|
|
22
|
+
'no-untranslated-string': no_untranslated_string_1.default
|
|
17
23
|
},
|
|
18
24
|
configs: {
|
|
19
25
|
recommended: {
|
|
@@ -21,14 +27,20 @@ const plugin = {
|
|
|
21
27
|
rules: {
|
|
22
28
|
'jupyter/plugin-activation-args': 'error',
|
|
23
29
|
'jupyter/command-described-by': 'warn',
|
|
24
|
-
'jupyter/plugin-description': 'warn'
|
|
30
|
+
'jupyter/plugin-description': 'warn',
|
|
31
|
+
'jupyter/no-translation-concatenation': 'error',
|
|
32
|
+
'jupyter/token-format': 'error',
|
|
33
|
+
'jupyter/no-untranslated-string': 'warn'
|
|
25
34
|
}
|
|
26
35
|
},
|
|
27
36
|
'recommended-legacy': {
|
|
28
37
|
rules: {
|
|
29
38
|
'jupyter/plugin-activation-args': 'error',
|
|
30
39
|
'jupyter/command-described-by': 'warn',
|
|
31
|
-
'jupyter/plugin-description': 'warn'
|
|
40
|
+
'jupyter/plugin-description': 'warn',
|
|
41
|
+
'jupyter/no-translation-concatenation': 'error',
|
|
42
|
+
'jupyter/token-format': 'error',
|
|
43
|
+
'jupyter/no-untranslated-string': 'warn'
|
|
32
44
|
}
|
|
33
45
|
}
|
|
34
46
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
declare const jupyterCommandDescribedBy: import("@typescript-eslint/utils/dist/ts-eslint").RuleModule<"missingDescribedBy", [], unknown, import("@typescript-eslint/utils/dist/ts-eslint").RuleListener> & {
|
|
2
|
+
name: string;
|
|
3
|
+
};
|
|
3
4
|
export = jupyterCommandDescribedBy;
|
|
@@ -5,33 +5,34 @@
|
|
|
5
5
|
*/
|
|
6
6
|
const plugin_utils_1 = require("../utils/plugin-utils");
|
|
7
7
|
const commands_1 = require("../utils/commands");
|
|
8
|
-
const
|
|
8
|
+
const create_rule_1 = require("../utils/create-rule");
|
|
9
|
+
const jupyterCommandDescribedBy = (0, create_rule_1.createRule)({
|
|
10
|
+
name: 'command-described-by',
|
|
9
11
|
meta: {
|
|
10
12
|
type: 'problem',
|
|
11
13
|
docs: {
|
|
12
14
|
description: 'Ensure JupyterLab commands include describedBy property',
|
|
13
|
-
|
|
14
|
-
url: 'https://github.com/jupyterlab/eslint-plugin'
|
|
15
|
+
url: 'https://eslint-plugin.readthedocs.io/en/latest/rules/command-described-by/'
|
|
15
16
|
},
|
|
16
17
|
messages: {
|
|
17
18
|
missingDescribedBy: 'Command "{{ commandId }}" is missing the "describedBy" property.'
|
|
18
19
|
},
|
|
19
20
|
schema: []
|
|
20
21
|
},
|
|
22
|
+
defaultOptions: [],
|
|
21
23
|
create(context) {
|
|
22
24
|
return {
|
|
23
25
|
CallExpression(node) {
|
|
24
|
-
const callExpr = node;
|
|
25
26
|
// Check if this is <something>.addCommand()
|
|
26
|
-
if (!(0, commands_1.isAddCommandCall)(
|
|
27
|
+
if (!(0, commands_1.isAddCommandCall)(node)) {
|
|
27
28
|
return;
|
|
28
29
|
}
|
|
29
30
|
// Get the command ID and options
|
|
30
|
-
if (
|
|
31
|
+
if (node.arguments.length < 2) {
|
|
31
32
|
return;
|
|
32
33
|
}
|
|
33
|
-
const commandIdArg =
|
|
34
|
-
const optionsArg =
|
|
34
|
+
const commandIdArg = node.arguments[0];
|
|
35
|
+
const optionsArg = node.arguments[1];
|
|
35
36
|
// Extract command ID for error message
|
|
36
37
|
let commandId = 'unknown';
|
|
37
38
|
if (commandIdArg.type === 'Literal' &&
|
|
@@ -51,8 +52,7 @@ const jupyterCommandDescribedBy = {
|
|
|
51
52
|
if (optionsArg.type !== 'ObjectExpression') {
|
|
52
53
|
return;
|
|
53
54
|
}
|
|
54
|
-
const
|
|
55
|
-
const properties = (0, plugin_utils_1.getObjectProperties)(options);
|
|
55
|
+
const properties = (0, plugin_utils_1.getObjectProperties)(optionsArg);
|
|
56
56
|
// Check if execute function exists and has parameters
|
|
57
57
|
const executeProp = properties.get('execute');
|
|
58
58
|
if (!executeProp || executeProp.value.type === 'Literal') {
|
|
@@ -61,7 +61,7 @@ const jupyterCommandDescribedBy = {
|
|
|
61
61
|
const describedByProp = properties.get('describedBy');
|
|
62
62
|
if (!describedByProp) {
|
|
63
63
|
context.report({
|
|
64
|
-
node
|
|
64
|
+
node,
|
|
65
65
|
messageId: 'missingDescribedBy',
|
|
66
66
|
data: { commandId }
|
|
67
67
|
});
|
|
@@ -73,5 +73,5 @@ const jupyterCommandDescribedBy = {
|
|
|
73
73
|
}
|
|
74
74
|
};
|
|
75
75
|
}
|
|
76
|
-
};
|
|
76
|
+
});
|
|
77
77
|
module.exports = jupyterCommandDescribedBy;
|
|
@@ -0,0 +1,132 @@
|
|
|
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 TRANS_METHOD = '__';
|
|
8
|
+
/**
|
|
9
|
+
* Returns true when every leaf of a `+` expression tree is a string literal.
|
|
10
|
+
* Such concatenation is static and translation tools can handle it.
|
|
11
|
+
*/
|
|
12
|
+
function isAllStringLiterals(node) {
|
|
13
|
+
if (node.type === 'Literal') {
|
|
14
|
+
return typeof node.value === 'string';
|
|
15
|
+
}
|
|
16
|
+
if (node.type === 'BinaryExpression' && node.operator === '+') {
|
|
17
|
+
return isAllStringLiterals(node.left) && isAllStringLiterals(node.right);
|
|
18
|
+
}
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Returns the first `+` BinaryExpression found anywhere in the subtree that
|
|
23
|
+
* involves a non-literal operand, or null if none exists.
|
|
24
|
+
*/
|
|
25
|
+
function findConcatenation(node) {
|
|
26
|
+
if (node.type === 'BinaryExpression' && node.operator === '+') {
|
|
27
|
+
return isAllStringLiterals(node) ? null : node;
|
|
28
|
+
}
|
|
29
|
+
const record = node;
|
|
30
|
+
for (const key of Object.keys(record)) {
|
|
31
|
+
if (key === 'type' || key === 'loc' || key === 'range' || key === 'parent') {
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
const child = record[key];
|
|
35
|
+
if (child && typeof child === 'object') {
|
|
36
|
+
if (Array.isArray(child)) {
|
|
37
|
+
for (const item of child) {
|
|
38
|
+
if (item && typeof item.type === 'string') {
|
|
39
|
+
const found = findConcatenation(item);
|
|
40
|
+
if (found)
|
|
41
|
+
return found;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
else if (typeof child.type === 'string') {
|
|
46
|
+
const found = findConcatenation(child);
|
|
47
|
+
if (found)
|
|
48
|
+
return found;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Returns true if the node is a recognized JupyterLab translation bundle:
|
|
56
|
+
* trans | this.trans | this._trans | props.trans | this.props.trans
|
|
57
|
+
* See jupyterlab.readthedocs.io/en/stable/extension/internationalization.html#rules
|
|
58
|
+
*/
|
|
59
|
+
function isTransBundle(node) {
|
|
60
|
+
if (node.type === 'Identifier') {
|
|
61
|
+
return node.name === 'trans';
|
|
62
|
+
}
|
|
63
|
+
if (node.type === 'MemberExpression' && !node.computed) {
|
|
64
|
+
const prop = node.property;
|
|
65
|
+
if (prop.type !== 'Identifier') {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
// this.trans / this._trans
|
|
69
|
+
if (node.object.type === 'ThisExpression') {
|
|
70
|
+
return prop.name === 'trans' || prop.name === '_trans';
|
|
71
|
+
}
|
|
72
|
+
// props.trans
|
|
73
|
+
if (prop.name === 'trans' &&
|
|
74
|
+
node.object.type === 'Identifier' &&
|
|
75
|
+
node.object.name === 'props') {
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
// this.props.trans
|
|
79
|
+
if (prop.name === 'trans' &&
|
|
80
|
+
node.object.type === 'MemberExpression' &&
|
|
81
|
+
!node.object.computed &&
|
|
82
|
+
node.object.object.type === 'ThisExpression' &&
|
|
83
|
+
node.object.property.type === 'Identifier' &&
|
|
84
|
+
node.object.property.name === 'props') {
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
const noTranslationConcatenation = (0, create_rule_1.createRule)({
|
|
91
|
+
name: 'no-translation-concatenation',
|
|
92
|
+
meta: {
|
|
93
|
+
type: 'problem',
|
|
94
|
+
docs: {
|
|
95
|
+
description: 'Forbid string concatenation inside translation wrapper calls',
|
|
96
|
+
url: 'https://eslint-plugin.readthedocs.io/en/latest/rules/no-translation-concatenation/'
|
|
97
|
+
},
|
|
98
|
+
messages: {
|
|
99
|
+
noConcatenation: 'Do not use string concatenation inside translation wrappers. Use a placeholder instead, e.g. trans.__("Hello %1", name).'
|
|
100
|
+
},
|
|
101
|
+
schema: []
|
|
102
|
+
},
|
|
103
|
+
defaultOptions: [],
|
|
104
|
+
create(context) {
|
|
105
|
+
return {
|
|
106
|
+
CallExpression(node) {
|
|
107
|
+
if (node.callee.type !== 'MemberExpression') {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const callee = node.callee;
|
|
111
|
+
if (callee.computed || callee.property.type !== 'Identifier') {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
if (callee.property.name !== TRANS_METHOD) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
if (!isTransBundle(callee.object)) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const message = node.arguments[0];
|
|
121
|
+
if (!message) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
const concat = findConcatenation(message);
|
|
125
|
+
if (concat) {
|
|
126
|
+
context.report({ node: concat, messageId: 'noConcatenation' });
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
module.exports = noTranslationConcatenation;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
declare const noUntranslatedString: import("@typescript-eslint/utils/dist/ts-eslint").RuleModule<"untranslatedCommandProp" | "untranslatedSetAttribute" | "untranslatedPropertyAssign" | "untranslatedTitleProp" | "untranslatedDialogOption" | "untranslatedDialogButtonLabel" | "untranslatedJsxText", [], unknown, import("@typescript-eslint/utils/dist/ts-eslint").RuleListener> & {
|
|
2
|
+
name: string;
|
|
3
|
+
};
|
|
4
|
+
export = noUntranslatedString;
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) Jupyter Development Team.
|
|
4
|
+
* Distributed under the terms of the Modified BSD License.
|
|
5
|
+
*/
|
|
6
|
+
const commands_1 = require("../utils/commands");
|
|
7
|
+
const plugin_utils_1 = require("../utils/plugin-utils");
|
|
8
|
+
const create_rule_1 = require("../utils/create-rule");
|
|
9
|
+
/**
|
|
10
|
+
* Returns true if the node is a non-empty raw string literal that should be
|
|
11
|
+
* wrapped in a translation call. Handles:
|
|
12
|
+
* - String Literal: 'string' or "string"
|
|
13
|
+
* - TemplateLiteral with no expressions: `string`
|
|
14
|
+
* - Concise ArrowFunctionExpression whose body is one of the above
|
|
15
|
+
*/
|
|
16
|
+
function isRawStringNode(node) {
|
|
17
|
+
if (node.type === 'Literal') {
|
|
18
|
+
return typeof node.value === 'string' && node.value.length > 0;
|
|
19
|
+
}
|
|
20
|
+
if (node.type === 'TemplateLiteral') {
|
|
21
|
+
if (node.expressions.length > 0) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
const cooked = node.quasis.map(q => q.value.cooked ?? '').join('');
|
|
25
|
+
return cooked.length > 0;
|
|
26
|
+
}
|
|
27
|
+
if (node.type === 'ArrowFunctionExpression' &&
|
|
28
|
+
node.body.type !== 'BlockStatement') {
|
|
29
|
+
return isRawStringNode(node.body);
|
|
30
|
+
}
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
function isSetAttributeCall(node) {
|
|
34
|
+
return (node.callee.type === 'MemberExpression' &&
|
|
35
|
+
!node.callee.computed &&
|
|
36
|
+
node.callee.property.type === 'Identifier' &&
|
|
37
|
+
node.callee.property.name === 'setAttribute');
|
|
38
|
+
}
|
|
39
|
+
function isShowDialogCall(node) {
|
|
40
|
+
return (node.callee.type === 'Identifier' && node.callee.name === 'showDialog');
|
|
41
|
+
}
|
|
42
|
+
function isDialogConstructor(node) {
|
|
43
|
+
return node.callee.type === 'Identifier' && node.callee.name === 'Dialog';
|
|
44
|
+
}
|
|
45
|
+
const DIALOG_BUTTON_BUILDERS = [
|
|
46
|
+
'okButton',
|
|
47
|
+
'cancelButton',
|
|
48
|
+
'warnButton',
|
|
49
|
+
'errorButton'
|
|
50
|
+
];
|
|
51
|
+
function isDialogButtonCall(node) {
|
|
52
|
+
return (node.callee.type === 'MemberExpression' &&
|
|
53
|
+
!node.callee.computed &&
|
|
54
|
+
node.callee.property.type === 'Identifier' &&
|
|
55
|
+
DIALOG_BUTTON_BUILDERS.includes(node.callee.property.name));
|
|
56
|
+
}
|
|
57
|
+
const MONITORED_COMMAND_PROPS = ['label', 'caption', 'usage'];
|
|
58
|
+
const MONITORED_SET_ATTRIBUTE_ATTRS = ['aria-label', 'aria-description', 'title'];
|
|
59
|
+
const MONITORED_ASSIGNMENT_PROPS = ['title', 'ariaLabel'];
|
|
60
|
+
const MONITORED_DIALOG_PROPS = ['title', 'body'];
|
|
61
|
+
const noUntranslatedString = (0, create_rule_1.createRule)({
|
|
62
|
+
name: 'no-untranslated-string',
|
|
63
|
+
meta: {
|
|
64
|
+
type: 'suggestion',
|
|
65
|
+
docs: {
|
|
66
|
+
description: 'Require user-facing string literals to be wrapped in a translation call such as trans.__()',
|
|
67
|
+
url: 'https://eslint-plugin.readthedocs.io/en/latest/rules/no-untranslated-string/'
|
|
68
|
+
},
|
|
69
|
+
messages: {
|
|
70
|
+
untranslatedCommandProp: 'Command property "{{ prop }}" has an untranslated string literal. Wrap it with trans.__().',
|
|
71
|
+
untranslatedSetAttribute: 'setAttribute("{{ attr }}", ...) has an untranslated string literal. Wrap the value with trans.__().',
|
|
72
|
+
untranslatedPropertyAssign: 'Assignment to "{{ prop }}" has an untranslated string literal. Wrap it with trans.__().',
|
|
73
|
+
untranslatedTitleProp: 'Assignment to "title.{{ prop }}" has an untranslated string literal. Wrap it with trans.__().',
|
|
74
|
+
untranslatedDialogOption: 'Dialog/showDialog "{{ prop }}" option has an untranslated string literal. Wrap it with trans.__().',
|
|
75
|
+
untranslatedDialogButtonLabel: 'Dialog button "label" option has an untranslated string literal. Wrap it with trans.__().',
|
|
76
|
+
untranslatedJsxText: 'JSX text content has an untranslated string literal. Wrap it with {trans.__(...)}'
|
|
77
|
+
},
|
|
78
|
+
schema: []
|
|
79
|
+
},
|
|
80
|
+
defaultOptions: [],
|
|
81
|
+
create(context) {
|
|
82
|
+
return {
|
|
83
|
+
CallExpression(node) {
|
|
84
|
+
// Branch A: commands.addCommand(id, { label, caption, usage })
|
|
85
|
+
if ((0, commands_1.isAddCommandCall)(node)) {
|
|
86
|
+
if (node.arguments.length < 2) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
const optionsArg = node.arguments[1];
|
|
90
|
+
if (optionsArg.type !== 'ObjectExpression') {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const properties = (0, plugin_utils_1.getObjectProperties)(optionsArg);
|
|
94
|
+
for (const propName of MONITORED_COMMAND_PROPS) {
|
|
95
|
+
const prop = properties.get(propName);
|
|
96
|
+
if (prop && isRawStringNode(prop.value)) {
|
|
97
|
+
context.report({
|
|
98
|
+
node: prop.value,
|
|
99
|
+
messageId: 'untranslatedCommandProp',
|
|
100
|
+
data: { prop: propName }
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
// Branch B: element.setAttribute('aria-label'/'aria-description'/'title', string)
|
|
107
|
+
if (isSetAttributeCall(node)) {
|
|
108
|
+
if (node.arguments.length < 2) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const attrNameArg = node.arguments[0];
|
|
112
|
+
if (attrNameArg.type !== 'Literal' ||
|
|
113
|
+
typeof attrNameArg.value !== 'string' ||
|
|
114
|
+
!MONITORED_SET_ATTRIBUTE_ATTRS.includes(attrNameArg.value)) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const attrValueArg = node.arguments[1];
|
|
118
|
+
if (isRawStringNode(attrValueArg)) {
|
|
119
|
+
context.report({
|
|
120
|
+
node: attrValueArg,
|
|
121
|
+
messageId: 'untranslatedSetAttribute',
|
|
122
|
+
data: { attr: attrNameArg.value }
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
// Branch C: showDialog({ title, body })
|
|
128
|
+
if (isShowDialogCall(node)) {
|
|
129
|
+
if (node.arguments.length < 1) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
const optionsArg = node.arguments[0];
|
|
133
|
+
if (optionsArg.type !== 'ObjectExpression') {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
const properties = (0, plugin_utils_1.getObjectProperties)(optionsArg);
|
|
137
|
+
for (const propName of MONITORED_DIALOG_PROPS) {
|
|
138
|
+
const prop = properties.get(propName);
|
|
139
|
+
if (prop && isRawStringNode(prop.value)) {
|
|
140
|
+
context.report({
|
|
141
|
+
node: prop.value,
|
|
142
|
+
messageId: 'untranslatedDialogOption',
|
|
143
|
+
data: { prop: propName }
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
// Branch D: Dialog.okButton/cancelButton/warnButton/errorButton({ label })
|
|
150
|
+
if (isDialogButtonCall(node)) {
|
|
151
|
+
if (node.arguments.length < 1) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
const optionsArg = node.arguments[0];
|
|
155
|
+
if (optionsArg.type !== 'ObjectExpression') {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
const properties = (0, plugin_utils_1.getObjectProperties)(optionsArg);
|
|
159
|
+
const labelProp = properties.get('label');
|
|
160
|
+
if (labelProp && isRawStringNode(labelProp.value)) {
|
|
161
|
+
context.report({
|
|
162
|
+
node: labelProp.value,
|
|
163
|
+
messageId: 'untranslatedDialogButtonLabel'
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
// new Dialog({ title, body })
|
|
169
|
+
NewExpression(node) {
|
|
170
|
+
if (!isDialogConstructor(node)) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
if (node.arguments.length < 1) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
const optionsArg = node.arguments[0];
|
|
177
|
+
if (optionsArg.type !== 'ObjectExpression') {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
const properties = (0, plugin_utils_1.getObjectProperties)(optionsArg);
|
|
181
|
+
for (const propName of MONITORED_DIALOG_PROPS) {
|
|
182
|
+
const prop = properties.get(propName);
|
|
183
|
+
if (prop && isRawStringNode(prop.value)) {
|
|
184
|
+
context.report({
|
|
185
|
+
node: prop.value,
|
|
186
|
+
messageId: 'untranslatedDialogOption',
|
|
187
|
+
data: { prop: propName }
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
AssignmentExpression(node) {
|
|
193
|
+
if (node.operator !== '=') {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
const left = node.left;
|
|
197
|
+
if (left.type !== 'MemberExpression' ||
|
|
198
|
+
left.computed ||
|
|
199
|
+
left.property.type !== 'Identifier') {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
// element.title = STRING or element.ariaLabel = STRING
|
|
203
|
+
if (MONITORED_ASSIGNMENT_PROPS.includes(left.property.name) &&
|
|
204
|
+
isRawStringNode(node.right)) {
|
|
205
|
+
context.report({
|
|
206
|
+
node: node.right,
|
|
207
|
+
messageId: 'untranslatedPropertyAssign',
|
|
208
|
+
data: { prop: left.property.name }
|
|
209
|
+
});
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
// *.title.label = STRING or *.title.caption = STRING
|
|
213
|
+
if ((left.property.name === 'label' || left.property.name === 'caption') &&
|
|
214
|
+
left.object.type === 'MemberExpression' &&
|
|
215
|
+
!left.object.computed &&
|
|
216
|
+
left.object.property.type === 'Identifier' &&
|
|
217
|
+
left.object.property.name === 'title' &&
|
|
218
|
+
isRawStringNode(node.right)) {
|
|
219
|
+
context.report({
|
|
220
|
+
node: node.right,
|
|
221
|
+
messageId: 'untranslatedTitleProp',
|
|
222
|
+
data: { prop: left.property.name }
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
},
|
|
226
|
+
// Raw text between JSX tags: <span>Untranslated text</span>
|
|
227
|
+
JSXText(node) {
|
|
228
|
+
if (node.value.trim().length > 0) {
|
|
229
|
+
context.report({
|
|
230
|
+
node,
|
|
231
|
+
messageId: 'untranslatedJsxText'
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
},
|
|
235
|
+
// String literal inside JSX expression: <span>{'raw string'}</span>
|
|
236
|
+
JSXExpressionContainer(node) {
|
|
237
|
+
if (node.expression.type === 'JSXEmptyExpression') {
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
if (isRawStringNode(node.expression)) {
|
|
241
|
+
context.report({
|
|
242
|
+
node: node.expression,
|
|
243
|
+
messageId: 'untranslatedJsxText'
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
module.exports = noUntranslatedString;
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
declare const jupyterPluginActivationArgs:
|
|
1
|
+
import { ESLintUtils } from '@typescript-eslint/utils';
|
|
2
|
+
declare const jupyterPluginActivationArgs: ESLintUtils.RuleModule<"mismatchedOrder" | "incorrectType" | "missingArgument" | "extraArgument" | "appNotFirst" | "serviceManagerFirstArgNotNull" | "invalidAppType" | "wrongArgumentCount" | "unresolvableTokenType", [{
|
|
3
|
+
allowedFirstArgumentNames: string[];
|
|
4
|
+
}], unknown, ESLintUtils.RuleListener> & {
|
|
5
|
+
name: string;
|
|
6
|
+
};
|
|
3
7
|
export = jupyterPluginActivationArgs;
|