eslint-plugin-formatjs 6.3.0 → 6.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.
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-formatjs",
|
|
3
3
|
"description": "ESLint plugin for formatjs",
|
|
4
|
-
"version": "6.
|
|
4
|
+
"version": "6.4.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Long Ho <holevietlong@gmail.com>",
|
|
7
7
|
"type": "module",
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
"magic-string": "^0.30.0",
|
|
13
13
|
"picomatch": "2 || 3 || 4",
|
|
14
14
|
"tslib": "^2.8.1",
|
|
15
|
-
"@formatjs/
|
|
16
|
-
"@formatjs/
|
|
15
|
+
"@formatjs/ts-transformer": "4.4.0",
|
|
16
|
+
"@formatjs/icu-messageformat-parser": "3.5.1"
|
|
17
17
|
},
|
|
18
18
|
"peerDependencies": {
|
|
19
19
|
"eslint": "9 || 10"
|
|
@@ -4,9 +4,27 @@ export let Option = /* @__PURE__ */ function(Option) {
|
|
|
4
4
|
Option["anything"] = "anything";
|
|
5
5
|
return Option;
|
|
6
6
|
}({});
|
|
7
|
+
function normalizeOptions(raw) {
|
|
8
|
+
if (typeof raw === "string") {
|
|
9
|
+
return {
|
|
10
|
+
mode: raw,
|
|
11
|
+
minLength: undefined
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
if (typeof raw === "object" && raw !== null) {
|
|
15
|
+
return {
|
|
16
|
+
mode: raw.mode,
|
|
17
|
+
minLength: raw.minLength
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
mode: undefined,
|
|
22
|
+
minLength: undefined
|
|
23
|
+
};
|
|
24
|
+
}
|
|
7
25
|
function checkNode(context, node) {
|
|
8
26
|
const msgs = extractMessages(node, getSettings(context));
|
|
9
|
-
const {
|
|
27
|
+
const { mode: type, minLength } = normalizeOptions(context.options[0]);
|
|
10
28
|
for (const [{ message: { description }, descriptionNode, messageDescriptorNode }] of msgs) {
|
|
11
29
|
if (!description) {
|
|
12
30
|
if (type === "literal" && descriptionNode) {
|
|
@@ -20,6 +38,15 @@ function checkNode(context, node) {
|
|
|
20
38
|
messageId: "enforceDescription"
|
|
21
39
|
});
|
|
22
40
|
}
|
|
41
|
+
} else if (typeof minLength === "number" && typeof description === "string" && description.length < minLength) {
|
|
42
|
+
context.report({
|
|
43
|
+
node: descriptionNode ?? messageDescriptorNode,
|
|
44
|
+
messageId: "enforceDescriptionMinLength",
|
|
45
|
+
data: {
|
|
46
|
+
minLength: String(minLength),
|
|
47
|
+
length: String(description.length)
|
|
48
|
+
}
|
|
49
|
+
});
|
|
23
50
|
}
|
|
24
51
|
}
|
|
25
52
|
}
|
|
@@ -32,13 +59,28 @@ export const rule = {
|
|
|
32
59
|
url: "https://formatjs.github.io/docs/tooling/linter#enforce-description"
|
|
33
60
|
},
|
|
34
61
|
fixable: "code",
|
|
35
|
-
schema: [{
|
|
62
|
+
schema: [{ oneOf: [{
|
|
36
63
|
type: "string",
|
|
37
64
|
enum: Object.keys(Option)
|
|
38
|
-
}
|
|
65
|
+
}, {
|
|
66
|
+
type: "object",
|
|
67
|
+
properties: {
|
|
68
|
+
mode: {
|
|
69
|
+
type: "string",
|
|
70
|
+
enum: Object.keys(Option)
|
|
71
|
+
},
|
|
72
|
+
minLength: {
|
|
73
|
+
type: "integer",
|
|
74
|
+
minimum: 1
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
additionalProperties: false,
|
|
78
|
+
minProperties: 1
|
|
79
|
+
}] }],
|
|
39
80
|
messages: {
|
|
40
81
|
enforceDescription: "`description` has to be specified in message descriptor",
|
|
41
|
-
enforceDescriptionLiteral: "`description` has to be a string literal (not function call or variable)"
|
|
82
|
+
enforceDescriptionLiteral: "`description` has to be a string literal (not function call or variable)",
|
|
83
|
+
enforceDescriptionMinLength: "`description` must be at least {{minLength}} characters long (currently {{length}})"
|
|
42
84
|
}
|
|
43
85
|
},
|
|
44
86
|
create(context) {
|