eslint-plugin-formatjs 8.1.4 → 8.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.
- package/index.d.ts +1 -2
- package/index.js +358 -128
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/util.d.ts +1 -2
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TYPE, isArgumentElement, isDateElement, isLiteralElement, isNumberElement, isPluralElement, isSelectElement, isTagElement, isTimeElement, parse } from "@formatjs/icu-messageformat-parser";
|
|
1
|
+
import { TYPE, isArgumentElement, isDateElement, isLiteralElement, isNumberElement, isNumberSkeleton, isPluralElement, isSelectElement, isTagElement, isTimeElement, parse } from "@formatjs/icu-messageformat-parser";
|
|
2
2
|
import { interpolateName } from "@formatjs/ts-transformer";
|
|
3
3
|
import emojiPresentationRegexCompiled from "@unicode/unicode-17.0.0/Binary_Property/Emoji_Presentation/regex.mjs";
|
|
4
4
|
import emojiPropertyRegexCompiled from "@unicode/unicode-17.0.0/Binary_Property/Emoji/regex.mjs";
|
|
@@ -6,14 +6,14 @@ import * as picomatchNs from "picomatch";
|
|
|
6
6
|
import MagicString from "magic-string";
|
|
7
7
|
// \0rolldown/runtime.js
|
|
8
8
|
var __defProp = Object.defineProperty;
|
|
9
|
-
var __exportAll = (all,
|
|
10
|
-
let target = {};
|
|
9
|
+
var __exportAll = (all, flags) => {
|
|
10
|
+
let target = Object.setPrototypeOf({}, null);
|
|
11
11
|
for (var name in all) __defProp(target, name, {
|
|
12
12
|
get: all[name],
|
|
13
13
|
enumerable: true
|
|
14
14
|
});
|
|
15
|
-
if (!
|
|
16
|
-
return target;
|
|
15
|
+
if (!(flags & 1)) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
16
|
+
return flags & 2 ? target : Object.preventExtensions(target);
|
|
17
17
|
};
|
|
18
18
|
// packages/eslint-plugin-formatjs/message-types.ts
|
|
19
19
|
function collectMessageArguments(ast) {
|
|
@@ -334,8 +334,8 @@ function checkPlaceholders(context, node) {
|
|
|
334
334
|
// packages/eslint-plugin-formatjs/messages.ts
|
|
335
335
|
const CORE_MESSAGES = { parseError: `Failed to parse message string {{error}}` };
|
|
336
336
|
// packages/eslint-plugin-formatjs/rules/enforce-placeholders.ts
|
|
337
|
-
const name$
|
|
338
|
-
const rule$
|
|
337
|
+
const name$25 = "enforce-placeholders";
|
|
338
|
+
const rule$23 = {
|
|
339
339
|
meta: {
|
|
340
340
|
type: "problem",
|
|
341
341
|
docs: {
|
|
@@ -367,7 +367,7 @@ const rule$21 = {
|
|
|
367
367
|
}
|
|
368
368
|
};
|
|
369
369
|
// packages/eslint-plugin-formatjs/rules/enforce-message-types.ts
|
|
370
|
-
const name$
|
|
370
|
+
const name$24 = "enforce-message-types";
|
|
371
371
|
const modules = /* @__PURE__ */ new Set([
|
|
372
372
|
"@formatjs/intl",
|
|
373
373
|
"react-intl",
|
|
@@ -788,7 +788,7 @@ function checkInlineMessage(context, node) {
|
|
|
788
788
|
});
|
|
789
789
|
return true;
|
|
790
790
|
}
|
|
791
|
-
const rule$
|
|
791
|
+
const rule$22 = {
|
|
792
792
|
meta: {
|
|
793
793
|
type: "problem",
|
|
794
794
|
docs: { description: "Check ICU placeholders and optionally generate TypeScript argument contracts" },
|
|
@@ -809,7 +809,7 @@ const rule$20 = {
|
|
|
809
809
|
additionalProperties: false
|
|
810
810
|
}],
|
|
811
811
|
messages: {
|
|
812
|
-
...rule$
|
|
812
|
+
...rule$23.meta.messages,
|
|
813
813
|
contract: "Generate or refresh the ICU argument contract.",
|
|
814
814
|
invalid: "Cannot generate message types: {{error}}.",
|
|
815
815
|
manual: "Unsupported number of generic arguments; update the call manually.",
|
|
@@ -1017,7 +1017,7 @@ const rule$20 = {
|
|
|
1017
1017
|
}
|
|
1018
1018
|
};
|
|
1019
1019
|
// packages/eslint-plugin-formatjs/rules/blocklist-elements.ts
|
|
1020
|
-
const name$
|
|
1020
|
+
const name$23 = "blocklist-elements";
|
|
1021
1021
|
function getMessage(type) {
|
|
1022
1022
|
return {
|
|
1023
1023
|
messageId: "blocklist",
|
|
@@ -1048,7 +1048,7 @@ function isBlocklisted(blocklist, type, element) {
|
|
|
1048
1048
|
return options.length !== allowedOptions.length || options.some((option) => !allowedOptions.includes(option));
|
|
1049
1049
|
});
|
|
1050
1050
|
}
|
|
1051
|
-
function verifyAst$
|
|
1051
|
+
function verifyAst$8(blocklist, ast) {
|
|
1052
1052
|
const errors = [];
|
|
1053
1053
|
for (const el of ast) {
|
|
1054
1054
|
if (isLiteralElement(el) && isBlocklisted(blocklist, "literal", el)) errors.push(getMessage("literal"));
|
|
@@ -1058,19 +1058,19 @@ function verifyAst$7(blocklist, ast) {
|
|
|
1058
1058
|
if (isTimeElement(el) && isBlocklisted(blocklist, "time", el)) errors.push(getMessage("time"));
|
|
1059
1059
|
if (isSelectElement(el) && isBlocklisted(blocklist, "select", el)) errors.push(getMessage("select"));
|
|
1060
1060
|
if (isTagElement(el) && isBlocklisted(blocklist, "tag", el)) errors.push(getMessage("tag"));
|
|
1061
|
-
if (isTagElement(el)) errors.push(...verifyAst$
|
|
1061
|
+
if (isTagElement(el)) errors.push(...verifyAst$8(blocklist, el.children));
|
|
1062
1062
|
if (isPluralElement(el)) {
|
|
1063
1063
|
if (isBlocklisted(blocklist, "plural", el)) errors.push(getMessage("argument"));
|
|
1064
1064
|
if (el.pluralType === "ordinal" && isBlocklisted(blocklist, "selectordinal", el)) errors.push(getMessage("selectordinal"));
|
|
1065
1065
|
}
|
|
1066
1066
|
if (isSelectElement(el) || isPluralElement(el)) {
|
|
1067
1067
|
const { options } = el;
|
|
1068
|
-
for (const selector of Object.keys(options)) errors.push(...verifyAst$
|
|
1068
|
+
for (const selector of Object.keys(options)) errors.push(...verifyAst$8(blocklist, options[selector].value));
|
|
1069
1069
|
}
|
|
1070
1070
|
}
|
|
1071
1071
|
return errors;
|
|
1072
1072
|
}
|
|
1073
|
-
function checkNode$
|
|
1073
|
+
function checkNode$18(context, node) {
|
|
1074
1074
|
const settings = getSettings(context);
|
|
1075
1075
|
const msgs = extractMessages(node, settings);
|
|
1076
1076
|
if (!msgs.length) return;
|
|
@@ -1089,14 +1089,14 @@ function checkNode$16(context, node) {
|
|
|
1089
1089
|
});
|
|
1090
1090
|
continue;
|
|
1091
1091
|
}
|
|
1092
|
-
const errors = verifyAst$
|
|
1092
|
+
const errors = verifyAst$8(blocklist, ast);
|
|
1093
1093
|
for (const error of errors) context.report({
|
|
1094
1094
|
node: messageNode,
|
|
1095
1095
|
...error
|
|
1096
1096
|
});
|
|
1097
1097
|
}
|
|
1098
1098
|
}
|
|
1099
|
-
const rule$
|
|
1099
|
+
const rule$21 = {
|
|
1100
1100
|
meta: {
|
|
1101
1101
|
type: "problem",
|
|
1102
1102
|
docs: {
|
|
@@ -1140,11 +1140,11 @@ const rule$19 = {
|
|
|
1140
1140
|
}
|
|
1141
1141
|
},
|
|
1142
1142
|
create(context) {
|
|
1143
|
-
const callExpressionVisitor = (node) => checkNode$
|
|
1143
|
+
const callExpressionVisitor = (node) => checkNode$18(context, node);
|
|
1144
1144
|
const parserServices = context.sourceCode.parserServices;
|
|
1145
1145
|
if (parserServices?.defineTemplateBodyVisitor) return parserServices.defineTemplateBodyVisitor({ CallExpression: callExpressionVisitor }, { CallExpression: callExpressionVisitor });
|
|
1146
1146
|
return {
|
|
1147
|
-
JSXOpeningElement: (node) => checkNode$
|
|
1147
|
+
JSXOpeningElement: (node) => checkNode$18(context, node),
|
|
1148
1148
|
CallExpression: callExpressionVisitor
|
|
1149
1149
|
};
|
|
1150
1150
|
}
|
|
@@ -1155,8 +1155,8 @@ let Option$1 = /* @__PURE__ */ function(Option) {
|
|
|
1155
1155
|
Option["anything"] = "anything";
|
|
1156
1156
|
return Option;
|
|
1157
1157
|
}({});
|
|
1158
|
-
const name$
|
|
1159
|
-
function checkNode$
|
|
1158
|
+
const name$22 = "enforce-default-message";
|
|
1159
|
+
function checkNode$17(context, node) {
|
|
1160
1160
|
const msgs = extractMessages(node, getSettings(context));
|
|
1161
1161
|
const { options: [type] } = context;
|
|
1162
1162
|
for (const [{ message: { defaultMessage }, messageNode, messageDescriptorNode }] of msgs) if (!defaultMessage) {
|
|
@@ -1170,7 +1170,7 @@ function checkNode$15(context, node) {
|
|
|
1170
1170
|
});
|
|
1171
1171
|
}
|
|
1172
1172
|
}
|
|
1173
|
-
const rule$
|
|
1173
|
+
const rule$20 = {
|
|
1174
1174
|
meta: {
|
|
1175
1175
|
type: "problem",
|
|
1176
1176
|
docs: {
|
|
@@ -1190,11 +1190,11 @@ const rule$18 = {
|
|
|
1190
1190
|
}
|
|
1191
1191
|
},
|
|
1192
1192
|
create(context) {
|
|
1193
|
-
const callExpressionVisitor = (node) => checkNode$
|
|
1193
|
+
const callExpressionVisitor = (node) => checkNode$17(context, node);
|
|
1194
1194
|
const parserServices = context.sourceCode.parserServices;
|
|
1195
1195
|
if (parserServices?.defineTemplateBodyVisitor) return parserServices.defineTemplateBodyVisitor({ CallExpression: callExpressionVisitor }, { CallExpression: callExpressionVisitor });
|
|
1196
1196
|
return {
|
|
1197
|
-
JSXOpeningElement: (node) => checkNode$
|
|
1197
|
+
JSXOpeningElement: (node) => checkNode$17(context, node),
|
|
1198
1198
|
CallExpression: callExpressionVisitor
|
|
1199
1199
|
};
|
|
1200
1200
|
}
|
|
@@ -1219,7 +1219,7 @@ function normalizeOptions(raw) {
|
|
|
1219
1219
|
minLength: void 0
|
|
1220
1220
|
};
|
|
1221
1221
|
}
|
|
1222
|
-
function checkNode$
|
|
1222
|
+
function checkNode$16(context, node) {
|
|
1223
1223
|
const msgs = extractMessages(node, getSettings(context));
|
|
1224
1224
|
const { mode: type, minLength } = normalizeOptions(context.options[0]);
|
|
1225
1225
|
for (const [{ message: { description }, descriptionNode, messageDescriptorNode }] of msgs) if (!description) {
|
|
@@ -1240,8 +1240,8 @@ function checkNode$14(context, node) {
|
|
|
1240
1240
|
}
|
|
1241
1241
|
});
|
|
1242
1242
|
}
|
|
1243
|
-
const name$
|
|
1244
|
-
const rule$
|
|
1243
|
+
const name$21 = "enforce-description";
|
|
1244
|
+
const rule$19 = {
|
|
1245
1245
|
meta: {
|
|
1246
1246
|
type: "problem",
|
|
1247
1247
|
docs: {
|
|
@@ -1274,17 +1274,17 @@ const rule$17 = {
|
|
|
1274
1274
|
}
|
|
1275
1275
|
},
|
|
1276
1276
|
create(context) {
|
|
1277
|
-
const callExpressionVisitor = (node) => checkNode$
|
|
1277
|
+
const callExpressionVisitor = (node) => checkNode$16(context, node);
|
|
1278
1278
|
const parserServices = context.sourceCode.parserServices;
|
|
1279
1279
|
if (parserServices?.defineTemplateBodyVisitor) return parserServices.defineTemplateBodyVisitor({ CallExpression: callExpressionVisitor }, { CallExpression: callExpressionVisitor });
|
|
1280
1280
|
return {
|
|
1281
|
-
JSXOpeningElement: (node) => checkNode$
|
|
1281
|
+
JSXOpeningElement: (node) => checkNode$16(context, node),
|
|
1282
1282
|
CallExpression: callExpressionVisitor
|
|
1283
1283
|
};
|
|
1284
1284
|
}
|
|
1285
1285
|
};
|
|
1286
1286
|
// packages/eslint-plugin-formatjs/rules/enforce-id.ts
|
|
1287
|
-
function checkNode$
|
|
1287
|
+
function checkNode$15(context, node, { idInterpolationPattern, idWhitelistRegexps, quoteStyle }) {
|
|
1288
1288
|
const msgs = extractMessages(node, getSettings(context));
|
|
1289
1289
|
for (const [{ message: { defaultMessage, description, id }, idPropNode, descriptionNode, messagePropNode, messageDescriptorNode }] of msgs) {
|
|
1290
1290
|
if (!idInterpolationPattern && !idPropNode) {
|
|
@@ -1342,8 +1342,8 @@ function checkNode$13(context, node, { idInterpolationPattern, idWhitelistRegexp
|
|
|
1342
1342
|
}
|
|
1343
1343
|
}
|
|
1344
1344
|
}
|
|
1345
|
-
const name$
|
|
1346
|
-
const rule$
|
|
1345
|
+
const name$20 = "enforce-id";
|
|
1346
|
+
const rule$18 = {
|
|
1347
1347
|
meta: {
|
|
1348
1348
|
type: "problem",
|
|
1349
1349
|
docs: {
|
|
@@ -1394,11 +1394,11 @@ Actual: {{actual}}`
|
|
|
1394
1394
|
const { idWhitelist } = tmp;
|
|
1395
1395
|
opts.idWhitelistRegexps = idWhitelist.map((str) => new RegExp(str, "i"));
|
|
1396
1396
|
}
|
|
1397
|
-
const callExpressionVisitor = (node) => checkNode$
|
|
1397
|
+
const callExpressionVisitor = (node) => checkNode$15(context, node, opts);
|
|
1398
1398
|
const parserServices = context.sourceCode.parserServices;
|
|
1399
1399
|
if (parserServices?.defineTemplateBodyVisitor) return parserServices.defineTemplateBodyVisitor({ CallExpression: callExpressionVisitor }, { CallExpression: callExpressionVisitor });
|
|
1400
1400
|
return {
|
|
1401
|
-
JSXOpeningElement: (node) => checkNode$
|
|
1401
|
+
JSXOpeningElement: (node) => checkNode$15(context, node, opts),
|
|
1402
1402
|
CallExpression: callExpressionVisitor
|
|
1403
1403
|
};
|
|
1404
1404
|
}
|
|
@@ -1413,7 +1413,7 @@ var LDML = /* @__PURE__ */ function(LDML) {
|
|
|
1413
1413
|
LDML["other"] = "other";
|
|
1414
1414
|
return LDML;
|
|
1415
1415
|
}(LDML || {});
|
|
1416
|
-
function verifyAst$
|
|
1416
|
+
function verifyAst$7(plConfig, ast) {
|
|
1417
1417
|
const errors = [];
|
|
1418
1418
|
for (const el of ast) if (isPluralElement(el)) {
|
|
1419
1419
|
const rules = Object.keys(plConfig);
|
|
@@ -1428,11 +1428,11 @@ function verifyAst$6(plConfig, ast) {
|
|
|
1428
1428
|
});
|
|
1429
1429
|
}
|
|
1430
1430
|
const { options } = el;
|
|
1431
|
-
for (const selector of Object.keys(options)) errors.push(...verifyAst$
|
|
1431
|
+
for (const selector of Object.keys(options)) errors.push(...verifyAst$7(plConfig, options[selector].value));
|
|
1432
1432
|
}
|
|
1433
1433
|
return errors;
|
|
1434
1434
|
}
|
|
1435
|
-
function checkNode$
|
|
1435
|
+
function checkNode$14(context, node) {
|
|
1436
1436
|
const settings = getSettings(context);
|
|
1437
1437
|
const msgs = extractMessages(node, settings);
|
|
1438
1438
|
if (!msgs.length) return;
|
|
@@ -1451,15 +1451,15 @@ function checkNode$12(context, node) {
|
|
|
1451
1451
|
});
|
|
1452
1452
|
continue;
|
|
1453
1453
|
}
|
|
1454
|
-
const errors = verifyAst$
|
|
1454
|
+
const errors = verifyAst$7(plConfig, ast);
|
|
1455
1455
|
for (const error of errors) context.report({
|
|
1456
1456
|
node: messageNode,
|
|
1457
1457
|
...error
|
|
1458
1458
|
});
|
|
1459
1459
|
}
|
|
1460
1460
|
}
|
|
1461
|
-
const name$
|
|
1462
|
-
const rule$
|
|
1461
|
+
const name$19 = "enforce-plural-rules";
|
|
1462
|
+
const rule$17 = {
|
|
1463
1463
|
meta: {
|
|
1464
1464
|
type: "problem",
|
|
1465
1465
|
docs: {
|
|
@@ -1482,19 +1482,19 @@ const rule$15 = {
|
|
|
1482
1482
|
}
|
|
1483
1483
|
},
|
|
1484
1484
|
create(context) {
|
|
1485
|
-
const callExpressionVisitor = (node) => checkNode$
|
|
1485
|
+
const callExpressionVisitor = (node) => checkNode$14(context, node);
|
|
1486
1486
|
const parserServices = context.sourceCode.parserServices;
|
|
1487
1487
|
if (parserServices?.defineTemplateBodyVisitor) return parserServices.defineTemplateBodyVisitor({ CallExpression: callExpressionVisitor }, { CallExpression: callExpressionVisitor });
|
|
1488
1488
|
return {
|
|
1489
|
-
JSXOpeningElement: (node) => checkNode$
|
|
1489
|
+
JSXOpeningElement: (node) => checkNode$14(context, node),
|
|
1490
1490
|
CallExpression: callExpressionVisitor
|
|
1491
1491
|
};
|
|
1492
1492
|
}
|
|
1493
1493
|
};
|
|
1494
1494
|
// packages/eslint-plugin-formatjs/rules/no-camel-case.ts
|
|
1495
|
-
const name$
|
|
1495
|
+
const name$18 = "no-camel-case";
|
|
1496
1496
|
const CAMEL_CASE_REGEX = /[A-Z]/;
|
|
1497
|
-
function verifyAst$
|
|
1497
|
+
function verifyAst$6(ast) {
|
|
1498
1498
|
const errors = [];
|
|
1499
1499
|
for (const el of ast) {
|
|
1500
1500
|
if (isArgumentElement(el)) {
|
|
@@ -1510,12 +1510,12 @@ function verifyAst$5(ast) {
|
|
|
1510
1510
|
data: {}
|
|
1511
1511
|
});
|
|
1512
1512
|
const { options } = el;
|
|
1513
|
-
for (const selector of Object.keys(options)) errors.push(...verifyAst$
|
|
1513
|
+
for (const selector of Object.keys(options)) errors.push(...verifyAst$6(options[selector].value));
|
|
1514
1514
|
}
|
|
1515
1515
|
}
|
|
1516
1516
|
return errors;
|
|
1517
1517
|
}
|
|
1518
|
-
function checkNode$
|
|
1518
|
+
function checkNode$13(context, node) {
|
|
1519
1519
|
const settings = getSettings(context);
|
|
1520
1520
|
const msgs = extractMessages(node, settings);
|
|
1521
1521
|
for (const [{ message: { defaultMessage }, messageNode }] of msgs) {
|
|
@@ -1531,14 +1531,14 @@ function checkNode$11(context, node) {
|
|
|
1531
1531
|
});
|
|
1532
1532
|
continue;
|
|
1533
1533
|
}
|
|
1534
|
-
const errors = verifyAst$
|
|
1534
|
+
const errors = verifyAst$6(ast);
|
|
1535
1535
|
for (const error of errors) context.report({
|
|
1536
1536
|
node: messageNode,
|
|
1537
1537
|
...error
|
|
1538
1538
|
});
|
|
1539
1539
|
}
|
|
1540
1540
|
}
|
|
1541
|
-
const rule$
|
|
1541
|
+
const rule$16 = {
|
|
1542
1542
|
meta: {
|
|
1543
1543
|
type: "problem",
|
|
1544
1544
|
docs: {
|
|
@@ -1553,11 +1553,11 @@ const rule$14 = {
|
|
|
1553
1553
|
}
|
|
1554
1554
|
},
|
|
1555
1555
|
create(context) {
|
|
1556
|
-
const callExpressionVisitor = (node) => checkNode$
|
|
1556
|
+
const callExpressionVisitor = (node) => checkNode$13(context, node);
|
|
1557
1557
|
const parserServices = context.sourceCode.parserServices;
|
|
1558
1558
|
if (parserServices?.defineTemplateBodyVisitor) return parserServices.defineTemplateBodyVisitor({ CallExpression: callExpressionVisitor }, { CallExpression: callExpressionVisitor });
|
|
1559
1559
|
return {
|
|
1560
|
-
JSXOpeningElement: (node) => checkNode$
|
|
1560
|
+
JSXOpeningElement: (node) => checkNode$13(context, node),
|
|
1561
1561
|
CallExpression: callExpressionVisitor
|
|
1562
1562
|
};
|
|
1563
1563
|
}
|
|
@@ -1589,7 +1589,7 @@ function calculateComplexity(ast) {
|
|
|
1589
1589
|
return complexity;
|
|
1590
1590
|
}
|
|
1591
1591
|
}
|
|
1592
|
-
function checkNode$
|
|
1592
|
+
function checkNode$12(context, node) {
|
|
1593
1593
|
const settings = getSettings(context);
|
|
1594
1594
|
const msgs = extractMessages(node, settings);
|
|
1595
1595
|
if (!msgs.length) return;
|
|
@@ -1621,8 +1621,8 @@ function checkNode$10(context, node) {
|
|
|
1621
1621
|
});
|
|
1622
1622
|
}
|
|
1623
1623
|
}
|
|
1624
|
-
const name$
|
|
1625
|
-
const rule$
|
|
1624
|
+
const name$17 = "no-complex-selectors";
|
|
1625
|
+
const rule$15 = {
|
|
1626
1626
|
meta: {
|
|
1627
1627
|
type: "problem",
|
|
1628
1628
|
docs: {
|
|
@@ -1649,11 +1649,11 @@ Default complexity limit is 20
|
|
|
1649
1649
|
}
|
|
1650
1650
|
},
|
|
1651
1651
|
create(context) {
|
|
1652
|
-
const callExpressionVisitor = (node) => checkNode$
|
|
1652
|
+
const callExpressionVisitor = (node) => checkNode$12(context, node);
|
|
1653
1653
|
const parserServices = context.sourceCode.parserServices;
|
|
1654
1654
|
if (parserServices?.defineTemplateBodyVisitor) return parserServices.defineTemplateBodyVisitor({ CallExpression: callExpressionVisitor }, { CallExpression: callExpressionVisitor });
|
|
1655
1655
|
return {
|
|
1656
|
-
JSXOpeningElement: (node) => checkNode$
|
|
1656
|
+
JSXOpeningElement: (node) => checkNode$12(context, node),
|
|
1657
1657
|
CallExpression: callExpressionVisitor
|
|
1658
1658
|
};
|
|
1659
1659
|
}
|
|
@@ -4280,8 +4280,8 @@ function parseVersion(version) {
|
|
|
4280
4280
|
return parseFloat(version);
|
|
4281
4281
|
}
|
|
4282
4282
|
// packages/eslint-plugin-formatjs/rules/no-emoji.ts
|
|
4283
|
-
const name$
|
|
4284
|
-
function checkNode$
|
|
4283
|
+
const name$16 = "no-emoji";
|
|
4284
|
+
function checkNode$11(context, node) {
|
|
4285
4285
|
const msgs = extractMessages(node, getSettings(context));
|
|
4286
4286
|
let versionAbove;
|
|
4287
4287
|
const [emojiConfig] = context.options;
|
|
@@ -4306,7 +4306,7 @@ function checkNode$9(context, node) {
|
|
|
4306
4306
|
}
|
|
4307
4307
|
}
|
|
4308
4308
|
}
|
|
4309
|
-
const rule$
|
|
4309
|
+
const rule$14 = {
|
|
4310
4310
|
meta: {
|
|
4311
4311
|
type: "problem",
|
|
4312
4312
|
docs: {
|
|
@@ -4343,11 +4343,11 @@ const rule$12 = {
|
|
|
4343
4343
|
}
|
|
4344
4344
|
},
|
|
4345
4345
|
create(context) {
|
|
4346
|
-
const callExpressionVisitor = (node) => checkNode$
|
|
4346
|
+
const callExpressionVisitor = (node) => checkNode$11(context, node);
|
|
4347
4347
|
const parserServices = context.sourceCode.parserServices;
|
|
4348
4348
|
if (parserServices?.defineTemplateBodyVisitor) return parserServices.defineTemplateBodyVisitor({ CallExpression: callExpressionVisitor }, { CallExpression: callExpressionVisitor });
|
|
4349
4349
|
return {
|
|
4350
|
-
JSXOpeningElement: (node) => checkNode$
|
|
4350
|
+
JSXOpeningElement: (node) => checkNode$11(context, node),
|
|
4351
4351
|
CallExpression: callExpressionVisitor
|
|
4352
4352
|
};
|
|
4353
4353
|
}
|
|
@@ -4356,8 +4356,8 @@ const rule$12 = {
|
|
|
4356
4356
|
function isComment(token) {
|
|
4357
4357
|
return !!token && (token.type === "Block" || token.type === "Line");
|
|
4358
4358
|
}
|
|
4359
|
-
const name$
|
|
4360
|
-
function checkNode$
|
|
4359
|
+
const name$15 = "no-id";
|
|
4360
|
+
function checkNode$10(context, node) {
|
|
4361
4361
|
const msgs = extractMessages(node, getSettings(context));
|
|
4362
4362
|
for (const [{ idPropNode }] of msgs) if (idPropNode) context.report({
|
|
4363
4363
|
node: idPropNode,
|
|
@@ -4370,7 +4370,7 @@ function checkNode$8(context, node) {
|
|
|
4370
4370
|
}
|
|
4371
4371
|
});
|
|
4372
4372
|
}
|
|
4373
|
-
const rule$
|
|
4373
|
+
const rule$13 = {
|
|
4374
4374
|
meta: {
|
|
4375
4375
|
type: "problem",
|
|
4376
4376
|
docs: {
|
|
@@ -4382,18 +4382,18 @@ const rule$11 = {
|
|
|
4382
4382
|
messages: { noId: "Manual `id` are not allowed in message descriptor" }
|
|
4383
4383
|
},
|
|
4384
4384
|
create(context) {
|
|
4385
|
-
const callExpressionVisitor = (node) => checkNode$
|
|
4385
|
+
const callExpressionVisitor = (node) => checkNode$10(context, node);
|
|
4386
4386
|
const parserServices = context.sourceCode.parserServices;
|
|
4387
4387
|
if (parserServices?.defineTemplateBodyVisitor) return parserServices.defineTemplateBodyVisitor({ CallExpression: callExpressionVisitor }, { CallExpression: callExpressionVisitor });
|
|
4388
4388
|
return {
|
|
4389
|
-
JSXOpeningElement: (node) => checkNode$
|
|
4389
|
+
JSXOpeningElement: (node) => checkNode$10(context, node),
|
|
4390
4390
|
CallExpression: callExpressionVisitor
|
|
4391
4391
|
};
|
|
4392
4392
|
}
|
|
4393
4393
|
};
|
|
4394
4394
|
// packages/eslint-plugin-formatjs/rules/no-invalid-icu.ts
|
|
4395
|
-
const name$
|
|
4396
|
-
function checkNode$
|
|
4395
|
+
const name$14 = "no-invalid-icu";
|
|
4396
|
+
function checkNode$9(context, node) {
|
|
4397
4397
|
const settings = getSettings(context);
|
|
4398
4398
|
let msgs;
|
|
4399
4399
|
try {
|
|
@@ -4420,7 +4420,7 @@ function checkNode$7(context, node) {
|
|
|
4420
4420
|
}
|
|
4421
4421
|
}
|
|
4422
4422
|
}
|
|
4423
|
-
const rule$
|
|
4423
|
+
const rule$12 = {
|
|
4424
4424
|
meta: {
|
|
4425
4425
|
type: "problem",
|
|
4426
4426
|
docs: { description: `Make sure ICU messages are formatted correctly with no bad select statements, plurals, etc.` },
|
|
@@ -4429,11 +4429,11 @@ const rule$10 = {
|
|
|
4429
4429
|
messages: CORE_MESSAGES
|
|
4430
4430
|
},
|
|
4431
4431
|
create(context) {
|
|
4432
|
-
const callExpressionVisitor = (node) => checkNode$
|
|
4432
|
+
const callExpressionVisitor = (node) => checkNode$9(context, node);
|
|
4433
4433
|
const parserServices = context.sourceCode.parserServices;
|
|
4434
4434
|
if (parserServices?.defineTemplateBodyVisitor) return parserServices.defineTemplateBodyVisitor({ CallExpression: callExpressionVisitor }, { CallExpression: callExpressionVisitor });
|
|
4435
4435
|
return {
|
|
4436
|
-
JSXOpeningElement: (node) => checkNode$
|
|
4436
|
+
JSXOpeningElement: (node) => checkNode$9(context, node),
|
|
4437
4437
|
CallExpression: callExpressionVisitor
|
|
4438
4438
|
};
|
|
4439
4439
|
}
|
|
@@ -4465,8 +4465,8 @@ function compilePropMatcher(propMatcher) {
|
|
|
4465
4465
|
return [picomatch.makeRe(tagNamePattern, { contains: false }), picomatch.makeRe(propNamePattern, { contains: false })];
|
|
4466
4466
|
});
|
|
4467
4467
|
}
|
|
4468
|
-
const name$
|
|
4469
|
-
const rule$
|
|
4468
|
+
const name$13 = "no-literal-string-in-jsx";
|
|
4469
|
+
const rule$11 = {
|
|
4470
4470
|
meta: {
|
|
4471
4471
|
type: "problem",
|
|
4472
4472
|
docs: {
|
|
@@ -4562,8 +4562,8 @@ const rule$9 = {
|
|
|
4562
4562
|
}
|
|
4563
4563
|
};
|
|
4564
4564
|
// packages/eslint-plugin-formatjs/rules/no-missing-icu-plural-one-placeholders.ts
|
|
4565
|
-
const name$
|
|
4566
|
-
function verifyAst$
|
|
4565
|
+
const name$12 = "no-missing-icu-plural-one-placeholders";
|
|
4566
|
+
function verifyAst$5(context, messageNode, ast) {
|
|
4567
4567
|
const patches = [];
|
|
4568
4568
|
_verifyAstAndReplace(ast);
|
|
4569
4569
|
if (patches.length > 0) {
|
|
@@ -4597,7 +4597,7 @@ function verifyAst$4(context, messageNode, ast) {
|
|
|
4597
4597
|
}
|
|
4598
4598
|
}
|
|
4599
4599
|
}
|
|
4600
|
-
function checkNode$
|
|
4600
|
+
function checkNode$8(context, node) {
|
|
4601
4601
|
const msgs = extractMessages(node);
|
|
4602
4602
|
for (const [{ message: { defaultMessage }, messageNode }] of msgs) {
|
|
4603
4603
|
if (!defaultMessage || !messageNode) continue;
|
|
@@ -4612,10 +4612,10 @@ function checkNode$6(context, node) {
|
|
|
4612
4612
|
});
|
|
4613
4613
|
continue;
|
|
4614
4614
|
}
|
|
4615
|
-
verifyAst$
|
|
4615
|
+
verifyAst$5(context, messageNode, ast);
|
|
4616
4616
|
}
|
|
4617
4617
|
}
|
|
4618
|
-
const rule$
|
|
4618
|
+
const rule$10 = {
|
|
4619
4619
|
meta: {
|
|
4620
4620
|
type: "problem",
|
|
4621
4621
|
docs: {
|
|
@@ -4630,17 +4630,17 @@ const rule$8 = {
|
|
|
4630
4630
|
schema: []
|
|
4631
4631
|
},
|
|
4632
4632
|
create(context) {
|
|
4633
|
-
const callExpressionVisitor = (node) => checkNode$
|
|
4633
|
+
const callExpressionVisitor = (node) => checkNode$8(context, node);
|
|
4634
4634
|
const parserServices = context.sourceCode.parserServices;
|
|
4635
4635
|
if (parserServices?.defineTemplateBodyVisitor) return parserServices.defineTemplateBodyVisitor({ CallExpression: callExpressionVisitor }, { CallExpression: callExpressionVisitor });
|
|
4636
4636
|
return {
|
|
4637
|
-
JSXOpeningElement: (node) => checkNode$
|
|
4637
|
+
JSXOpeningElement: (node) => checkNode$8(context, node),
|
|
4638
4638
|
CallExpression: callExpressionVisitor
|
|
4639
4639
|
};
|
|
4640
4640
|
}
|
|
4641
4641
|
};
|
|
4642
4642
|
// packages/eslint-plugin-formatjs/rules/no-multiple-plurals.ts
|
|
4643
|
-
function verifyAst$
|
|
4643
|
+
function verifyAst$4(ast, pluralCount = { count: 0 }) {
|
|
4644
4644
|
const errors = [];
|
|
4645
4645
|
for (const el of ast) if (isPluralElement(el)) {
|
|
4646
4646
|
pluralCount.count++;
|
|
@@ -4649,11 +4649,11 @@ function verifyAst$3(ast, pluralCount = { count: 0 }) {
|
|
|
4649
4649
|
data: {}
|
|
4650
4650
|
});
|
|
4651
4651
|
const { options } = el;
|
|
4652
|
-
for (const selector of Object.keys(options)) errors.push(...verifyAst$
|
|
4652
|
+
for (const selector of Object.keys(options)) errors.push(...verifyAst$4(options[selector].value, pluralCount));
|
|
4653
4653
|
}
|
|
4654
4654
|
return errors;
|
|
4655
4655
|
}
|
|
4656
|
-
function checkNode$
|
|
4656
|
+
function checkNode$7(context, node) {
|
|
4657
4657
|
const settings = getSettings(context);
|
|
4658
4658
|
const msgs = extractMessages(node, settings);
|
|
4659
4659
|
for (const [{ message: { defaultMessage }, messageNode }] of msgs) {
|
|
@@ -4669,15 +4669,15 @@ function checkNode$5(context, node) {
|
|
|
4669
4669
|
});
|
|
4670
4670
|
continue;
|
|
4671
4671
|
}
|
|
4672
|
-
const errors = verifyAst$
|
|
4672
|
+
const errors = verifyAst$4(ast);
|
|
4673
4673
|
for (const error of errors) context.report({
|
|
4674
4674
|
node,
|
|
4675
4675
|
...error
|
|
4676
4676
|
});
|
|
4677
4677
|
}
|
|
4678
4678
|
}
|
|
4679
|
-
const name$
|
|
4680
|
-
const rule$
|
|
4679
|
+
const name$11 = "no-multiple-plurals";
|
|
4680
|
+
const rule$9 = {
|
|
4681
4681
|
meta: {
|
|
4682
4682
|
type: "problem",
|
|
4683
4683
|
docs: {
|
|
@@ -4692,11 +4692,11 @@ const rule$7 = {
|
|
|
4692
4692
|
}
|
|
4693
4693
|
},
|
|
4694
4694
|
create(context) {
|
|
4695
|
-
const callExpressionVisitor = (node) => checkNode$
|
|
4695
|
+
const callExpressionVisitor = (node) => checkNode$7(context, node);
|
|
4696
4696
|
const parserServices = context.sourceCode.parserServices;
|
|
4697
4697
|
if (parserServices?.defineTemplateBodyVisitor) return parserServices.defineTemplateBodyVisitor({ CallExpression: callExpressionVisitor }, { CallExpression: callExpressionVisitor });
|
|
4698
4698
|
return {
|
|
4699
|
-
JSXOpeningElement: (node) => checkNode$
|
|
4699
|
+
JSXOpeningElement: (node) => checkNode$7(context, node),
|
|
4700
4700
|
CallExpression: callExpressionVisitor
|
|
4701
4701
|
};
|
|
4702
4702
|
}
|
|
@@ -4753,7 +4753,7 @@ function trimMultiWhitespaces(message, ast) {
|
|
|
4753
4753
|
trimmedFragments.push(message.slice(currentOffset));
|
|
4754
4754
|
return trimmedFragments.join("");
|
|
4755
4755
|
}
|
|
4756
|
-
function checkNode$
|
|
4756
|
+
function checkNode$6(context, node) {
|
|
4757
4757
|
const msgs = extractMessages(node, getSettings(context));
|
|
4758
4758
|
for (const [{ message: { defaultMessage }, messageNode }] of msgs) {
|
|
4759
4759
|
if (!defaultMessage || !messageNode) continue;
|
|
@@ -4778,8 +4778,8 @@ function checkNode$4(context, node) {
|
|
|
4778
4778
|
}
|
|
4779
4779
|
}
|
|
4780
4780
|
}
|
|
4781
|
-
const name$
|
|
4782
|
-
const rule$
|
|
4781
|
+
const name$10 = "no-multiple-whitespaces";
|
|
4782
|
+
const rule$8 = {
|
|
4783
4783
|
meta: {
|
|
4784
4784
|
type: "problem",
|
|
4785
4785
|
docs: {
|
|
@@ -4794,17 +4794,17 @@ const rule$6 = {
|
|
|
4794
4794
|
schema: []
|
|
4795
4795
|
},
|
|
4796
4796
|
create(context) {
|
|
4797
|
-
const callExpressionVisitor = (node) => checkNode$
|
|
4797
|
+
const callExpressionVisitor = (node) => checkNode$6(context, node);
|
|
4798
4798
|
const parserServices = context.sourceCode.parserServices;
|
|
4799
4799
|
if (parserServices?.defineTemplateBodyVisitor) return parserServices.defineTemplateBodyVisitor({ CallExpression: callExpressionVisitor }, { CallExpression: callExpressionVisitor });
|
|
4800
4800
|
return {
|
|
4801
|
-
JSXOpeningElement: (node) => checkNode$
|
|
4801
|
+
JSXOpeningElement: (node) => checkNode$6(context, node),
|
|
4802
4802
|
CallExpression: callExpressionVisitor
|
|
4803
4803
|
};
|
|
4804
4804
|
}
|
|
4805
4805
|
};
|
|
4806
4806
|
// packages/eslint-plugin-formatjs/rules/no-offset.ts
|
|
4807
|
-
function verifyAst$
|
|
4807
|
+
function verifyAst$3(ast) {
|
|
4808
4808
|
const errors = [];
|
|
4809
4809
|
for (const el of ast) if (isPluralElement(el)) {
|
|
4810
4810
|
if (el.offset) errors.push({
|
|
@@ -4812,11 +4812,11 @@ function verifyAst$2(ast) {
|
|
|
4812
4812
|
data: {}
|
|
4813
4813
|
});
|
|
4814
4814
|
const { options } = el;
|
|
4815
|
-
for (const selector of Object.keys(options)) errors.push(...verifyAst$
|
|
4815
|
+
for (const selector of Object.keys(options)) errors.push(...verifyAst$3(options[selector].value));
|
|
4816
4816
|
}
|
|
4817
4817
|
return errors;
|
|
4818
4818
|
}
|
|
4819
|
-
function checkNode$
|
|
4819
|
+
function checkNode$5(context, node) {
|
|
4820
4820
|
const settings = getSettings(context);
|
|
4821
4821
|
const msgs = extractMessages(node, settings);
|
|
4822
4822
|
for (const [{ message: { defaultMessage }, messageNode }] of msgs) {
|
|
@@ -4832,15 +4832,15 @@ function checkNode$3(context, node) {
|
|
|
4832
4832
|
});
|
|
4833
4833
|
continue;
|
|
4834
4834
|
}
|
|
4835
|
-
const errors = verifyAst$
|
|
4835
|
+
const errors = verifyAst$3(ast);
|
|
4836
4836
|
for (const error of errors) context.report({
|
|
4837
4837
|
node: messageNode,
|
|
4838
4838
|
...error
|
|
4839
4839
|
});
|
|
4840
4840
|
}
|
|
4841
4841
|
}
|
|
4842
|
-
const name$
|
|
4843
|
-
const rule$
|
|
4842
|
+
const name$9 = "no-offset";
|
|
4843
|
+
const rule$7 = {
|
|
4844
4844
|
meta: {
|
|
4845
4845
|
type: "problem",
|
|
4846
4846
|
docs: {
|
|
@@ -4855,17 +4855,17 @@ const rule$5 = {
|
|
|
4855
4855
|
schema: []
|
|
4856
4856
|
},
|
|
4857
4857
|
create(context) {
|
|
4858
|
-
const callExpressionVisitor = (node) => checkNode$
|
|
4858
|
+
const callExpressionVisitor = (node) => checkNode$5(context, node);
|
|
4859
4859
|
const parserServices = context.sourceCode.parserServices;
|
|
4860
4860
|
if (parserServices?.defineTemplateBodyVisitor) return parserServices.defineTemplateBodyVisitor({ CallExpression: callExpressionVisitor }, { CallExpression: callExpressionVisitor });
|
|
4861
4861
|
return {
|
|
4862
|
-
JSXOpeningElement: (node) => checkNode$
|
|
4862
|
+
JSXOpeningElement: (node) => checkNode$5(context, node),
|
|
4863
4863
|
CallExpression: callExpressionVisitor
|
|
4864
4864
|
};
|
|
4865
4865
|
}
|
|
4866
4866
|
};
|
|
4867
4867
|
// packages/eslint-plugin-formatjs/rules/no-useless-message.ts
|
|
4868
|
-
function verifyAst$
|
|
4868
|
+
function verifyAst$2(ast) {
|
|
4869
4869
|
if (ast.length !== 1) return;
|
|
4870
4870
|
switch (ast[0].type) {
|
|
4871
4871
|
case TYPE.argument: return "unnecessaryFormat";
|
|
@@ -4874,7 +4874,7 @@ function verifyAst$1(ast) {
|
|
|
4874
4874
|
case TYPE.time: return "unnecessaryFormatTime";
|
|
4875
4875
|
}
|
|
4876
4876
|
}
|
|
4877
|
-
function checkNode$
|
|
4877
|
+
function checkNode$4(context, node) {
|
|
4878
4878
|
const settings = getSettings(context);
|
|
4879
4879
|
const msgs = extractMessages(node, settings);
|
|
4880
4880
|
for (const [{ message: { defaultMessage }, messageNode }] of msgs) {
|
|
@@ -4890,15 +4890,15 @@ function checkNode$2(context, node) {
|
|
|
4890
4890
|
});
|
|
4891
4891
|
continue;
|
|
4892
4892
|
}
|
|
4893
|
-
const messageId = verifyAst$
|
|
4893
|
+
const messageId = verifyAst$2(ast);
|
|
4894
4894
|
if (messageId) context.report({
|
|
4895
4895
|
node: messageNode,
|
|
4896
4896
|
messageId
|
|
4897
4897
|
});
|
|
4898
4898
|
}
|
|
4899
4899
|
}
|
|
4900
|
-
const name$
|
|
4901
|
-
const rule$
|
|
4900
|
+
const name$8 = "no-useless-message";
|
|
4901
|
+
const rule$6 = {
|
|
4902
4902
|
meta: {
|
|
4903
4903
|
type: "problem",
|
|
4904
4904
|
docs: {
|
|
@@ -4916,17 +4916,17 @@ const rule$4 = {
|
|
|
4916
4916
|
}
|
|
4917
4917
|
},
|
|
4918
4918
|
create(context) {
|
|
4919
|
-
const callExpressionVisitor = (node) => checkNode$
|
|
4919
|
+
const callExpressionVisitor = (node) => checkNode$4(context, node);
|
|
4920
4920
|
const parserServices = context.sourceCode.parserServices;
|
|
4921
4921
|
if (parserServices?.defineTemplateBodyVisitor) return parserServices.defineTemplateBodyVisitor({ CallExpression: callExpressionVisitor }, { CallExpression: callExpressionVisitor });
|
|
4922
4922
|
return {
|
|
4923
|
-
JSXOpeningElement: (node) => checkNode$
|
|
4923
|
+
JSXOpeningElement: (node) => checkNode$4(context, node),
|
|
4924
4924
|
CallExpression: callExpressionVisitor
|
|
4925
4925
|
};
|
|
4926
4926
|
}
|
|
4927
4927
|
};
|
|
4928
4928
|
// packages/eslint-plugin-formatjs/rules/prefer-formatted-message.ts
|
|
4929
|
-
const name$
|
|
4929
|
+
const name$7 = "prefer-formatted-message";
|
|
4930
4930
|
function binding(context, node, name) {
|
|
4931
4931
|
let scope = context.sourceCode.getScope(node);
|
|
4932
4932
|
while (scope) {
|
|
@@ -4977,7 +4977,7 @@ function component(context, node) {
|
|
|
4977
4977
|
insert: (fixer) => fixer.insertTextBefore(anchor, specifier + ", ")
|
|
4978
4978
|
};
|
|
4979
4979
|
}
|
|
4980
|
-
const rule$
|
|
4980
|
+
const rule$5 = {
|
|
4981
4981
|
meta: {
|
|
4982
4982
|
type: "suggestion",
|
|
4983
4983
|
fixable: "code",
|
|
@@ -5031,7 +5031,7 @@ const rule$3 = {
|
|
|
5031
5031
|
}
|
|
5032
5032
|
};
|
|
5033
5033
|
// packages/eslint-plugin-formatjs/rules/prefer-pound-in-plural.ts
|
|
5034
|
-
function verifyAst(context, messageNode, ast) {
|
|
5034
|
+
function verifyAst$1(context, messageNode, ast) {
|
|
5035
5035
|
const patches = [];
|
|
5036
5036
|
_verifyAst(ast);
|
|
5037
5037
|
if (patches.length > 0) {
|
|
@@ -5105,7 +5105,7 @@ function verifyAst(context, messageNode, ast) {
|
|
|
5105
5105
|
});
|
|
5106
5106
|
}
|
|
5107
5107
|
}
|
|
5108
|
-
function checkNode$
|
|
5108
|
+
function checkNode$3(context, node) {
|
|
5109
5109
|
const msgs = extractMessages(node, getSettings(context));
|
|
5110
5110
|
for (const [{ message: { defaultMessage }, messageNode }] of msgs) {
|
|
5111
5111
|
if (!defaultMessage || !messageNode) continue;
|
|
@@ -5120,11 +5120,11 @@ function checkNode$1(context, node) {
|
|
|
5120
5120
|
});
|
|
5121
5121
|
return;
|
|
5122
5122
|
}
|
|
5123
|
-
verifyAst(context, messageNode, ast);
|
|
5123
|
+
verifyAst$1(context, messageNode, ast);
|
|
5124
5124
|
}
|
|
5125
5125
|
}
|
|
5126
|
-
const name$
|
|
5127
|
-
const rule$
|
|
5126
|
+
const name$6 = "prefer-pound-in-plural";
|
|
5127
|
+
const rule$4 = {
|
|
5128
5128
|
meta: {
|
|
5129
5129
|
type: "suggestion",
|
|
5130
5130
|
docs: {
|
|
@@ -5139,18 +5139,18 @@ const rule$2 = {
|
|
|
5139
5139
|
schema: []
|
|
5140
5140
|
},
|
|
5141
5141
|
create(context) {
|
|
5142
|
-
const callExpressionVisitor = (node) => checkNode$
|
|
5142
|
+
const callExpressionVisitor = (node) => checkNode$3(context, node);
|
|
5143
5143
|
const parserServices = context.sourceCode.parserServices;
|
|
5144
5144
|
if (parserServices?.defineTemplateBodyVisitor) return parserServices.defineTemplateBodyVisitor({ CallExpression: callExpressionVisitor }, { CallExpression: callExpressionVisitor });
|
|
5145
5145
|
return {
|
|
5146
|
-
JSXOpeningElement: (node) => checkNode$
|
|
5146
|
+
JSXOpeningElement: (node) => checkNode$3(context, node),
|
|
5147
5147
|
CallExpression: callExpressionVisitor
|
|
5148
5148
|
};
|
|
5149
5149
|
}
|
|
5150
5150
|
};
|
|
5151
5151
|
// packages/eslint-plugin-formatjs/rules/no-literal-string-in-object.ts
|
|
5152
|
-
const name$
|
|
5153
|
-
const rule$
|
|
5152
|
+
const name$5 = "no-literal-string-in-object";
|
|
5153
|
+
const rule$3 = {
|
|
5154
5154
|
meta: {
|
|
5155
5155
|
type: "problem",
|
|
5156
5156
|
docs: {
|
|
@@ -5247,7 +5247,7 @@ function findMessageIssues(ast) {
|
|
|
5247
5247
|
}
|
|
5248
5248
|
return issues;
|
|
5249
5249
|
}
|
|
5250
|
-
function checkNode(context, node) {
|
|
5250
|
+
function checkNode$2(context, node) {
|
|
5251
5251
|
const msgs = extractMessages(node, getSettings(context));
|
|
5252
5252
|
for (const [{ message: { defaultMessage }, messageNode }] of msgs) {
|
|
5253
5253
|
if (!defaultMessage || !messageNode) continue;
|
|
@@ -5274,8 +5274,8 @@ function checkNode(context, node) {
|
|
|
5274
5274
|
}
|
|
5275
5275
|
}
|
|
5276
5276
|
}
|
|
5277
|
-
const name$
|
|
5278
|
-
const rule = {
|
|
5277
|
+
const name$4 = "prefer-full-sentence";
|
|
5278
|
+
const rule$2 = {
|
|
5279
5279
|
meta: {
|
|
5280
5280
|
type: "suggestion",
|
|
5281
5281
|
docs: {
|
|
@@ -5291,11 +5291,237 @@ const rule = {
|
|
|
5291
5291
|
schema: []
|
|
5292
5292
|
},
|
|
5293
5293
|
create(context) {
|
|
5294
|
-
const callExpressionVisitor = (node) => checkNode(context, node);
|
|
5294
|
+
const callExpressionVisitor = (node) => checkNode$2(context, node);
|
|
5295
5295
|
const parserServices = context.sourceCode.parserServices;
|
|
5296
5296
|
if (parserServices?.defineTemplateBodyVisitor) return parserServices.defineTemplateBodyVisitor({ CallExpression: callExpressionVisitor }, { CallExpression: callExpressionVisitor });
|
|
5297
5297
|
return {
|
|
5298
|
-
JSXOpeningElement: (node) => checkNode(context, node),
|
|
5298
|
+
JSXOpeningElement: (node) => checkNode$2(context, node),
|
|
5299
|
+
CallExpression: callExpressionVisitor
|
|
5300
|
+
};
|
|
5301
|
+
}
|
|
5302
|
+
};
|
|
5303
|
+
// packages/eslint-plugin-formatjs/rules/no-literal-number-symbol.ts
|
|
5304
|
+
const MESSAGE_IDS = {
|
|
5305
|
+
percent: "literalPercent",
|
|
5306
|
+
permille: "literalPermille",
|
|
5307
|
+
sign: "literalSign",
|
|
5308
|
+
currency: "literalCurrency",
|
|
5309
|
+
degree: "literalDegree"
|
|
5310
|
+
};
|
|
5311
|
+
const SATISFYING_STEMS = {
|
|
5312
|
+
percent: /* @__PURE__ */ new Set(["percent", "%"]),
|
|
5313
|
+
permille: /* @__PURE__ */ new Set(["permille"]),
|
|
5314
|
+
sign: /* @__PURE__ */ new Set([
|
|
5315
|
+
"sign-always",
|
|
5316
|
+
"sign-except-zero",
|
|
5317
|
+
"sign-accounting-always",
|
|
5318
|
+
"sign-accounting-except-zero",
|
|
5319
|
+
"+!",
|
|
5320
|
+
"+?",
|
|
5321
|
+
"()!",
|
|
5322
|
+
"()?"
|
|
5323
|
+
]),
|
|
5324
|
+
currency: /* @__PURE__ */ new Set(["currency"]),
|
|
5325
|
+
degree: /* @__PURE__ */ new Set(["unit", "measure-unit"])
|
|
5326
|
+
};
|
|
5327
|
+
const SIMPLE_STYLES = {
|
|
5328
|
+
percent: "percent",
|
|
5329
|
+
currency: "currency"
|
|
5330
|
+
};
|
|
5331
|
+
const GAP = "[ \\u00a0\\u202f]?";
|
|
5332
|
+
const SUFFIXES = [
|
|
5333
|
+
["percent", new RegExp(`^${GAP}[%٪﹪%]`, "u")],
|
|
5334
|
+
["permille", new RegExp(`^${GAP}[‰؉]`, "u")],
|
|
5335
|
+
["degree", new RegExp(`^${GAP}(?:°|℃|℉)`, "u")],
|
|
5336
|
+
["currency", new RegExp(`^${GAP}\\p{Sc}`, "u")]
|
|
5337
|
+
];
|
|
5338
|
+
const PREFIXES = [
|
|
5339
|
+
["percent", new RegExp(`[%٪﹪%]${GAP}$`, "u")],
|
|
5340
|
+
["permille", new RegExp(`[‰؉]${GAP}$`, "u")],
|
|
5341
|
+
["currency", new RegExp(`\\p{Sc}${GAP}$`, "u")]
|
|
5342
|
+
];
|
|
5343
|
+
const SIGN_PREFIX = /(^|[\s([])[+\-−+-﹢﹣]$/u;
|
|
5344
|
+
function satisfies(element, kind) {
|
|
5345
|
+
const { style } = element;
|
|
5346
|
+
if (!style) return false;
|
|
5347
|
+
if (typeof style === "string") return SIMPLE_STYLES[kind] === style;
|
|
5348
|
+
return isNumberSkeleton(style) && style.tokens.some(({ stem }) => SATISFYING_STEMS[kind].has(stem));
|
|
5349
|
+
}
|
|
5350
|
+
function literalAt$1(ast, index) {
|
|
5351
|
+
const element = ast[index];
|
|
5352
|
+
return element?.type === TYPE.literal ? element.value : null;
|
|
5353
|
+
}
|
|
5354
|
+
function symbolsNextTo(ast, index) {
|
|
5355
|
+
const kinds = /* @__PURE__ */ new Set();
|
|
5356
|
+
const after = literalAt$1(ast, index + 1);
|
|
5357
|
+
const before = literalAt$1(ast, index - 1);
|
|
5358
|
+
if (after !== null) {
|
|
5359
|
+
for (const [kind, pattern] of SUFFIXES) if (pattern.test(after)) kinds.add(kind);
|
|
5360
|
+
}
|
|
5361
|
+
if (before !== null) {
|
|
5362
|
+
for (const [kind, pattern] of PREFIXES) if (pattern.test(before)) kinds.add(kind);
|
|
5363
|
+
const sign = SIGN_PREFIX.exec(before);
|
|
5364
|
+
if (sign && (sign[1] !== "" || index - 1 === 0)) kinds.add("sign");
|
|
5365
|
+
}
|
|
5366
|
+
return kinds;
|
|
5367
|
+
}
|
|
5368
|
+
function verifyAst(ast, errors) {
|
|
5369
|
+
for (const [index, element] of ast.entries()) switch (element.type) {
|
|
5370
|
+
case TYPE.argument:
|
|
5371
|
+
case TYPE.number:
|
|
5372
|
+
for (const kind of symbolsNextTo(ast, index)) {
|
|
5373
|
+
if (element.type === TYPE.number && satisfies(element, kind)) continue;
|
|
5374
|
+
errors.push({
|
|
5375
|
+
messageId: MESSAGE_IDS[kind],
|
|
5376
|
+
data: { argument: element.value }
|
|
5377
|
+
});
|
|
5378
|
+
}
|
|
5379
|
+
break;
|
|
5380
|
+
case TYPE.plural:
|
|
5381
|
+
case TYPE.select:
|
|
5382
|
+
for (const option of Object.values(element.options)) verifyAst(option.value, errors);
|
|
5383
|
+
break;
|
|
5384
|
+
case TYPE.tag: verifyAst(element.children, errors);
|
|
5385
|
+
}
|
|
5386
|
+
}
|
|
5387
|
+
function checkNode$1(context, node) {
|
|
5388
|
+
const settings = getSettings(context);
|
|
5389
|
+
for (const [{ message, messageNode }] of extractMessages(node, settings)) {
|
|
5390
|
+
if (!message.defaultMessage || !messageNode) continue;
|
|
5391
|
+
let ast;
|
|
5392
|
+
try {
|
|
5393
|
+
ast = parse(message.defaultMessage, { ignoreTag: settings.ignoreTag });
|
|
5394
|
+
} catch (e) {
|
|
5395
|
+
context.report({
|
|
5396
|
+
node: messageNode,
|
|
5397
|
+
messageId: "parseError",
|
|
5398
|
+
data: { error: e.message }
|
|
5399
|
+
});
|
|
5400
|
+
continue;
|
|
5401
|
+
}
|
|
5402
|
+
const errors = [];
|
|
5403
|
+
verifyAst(ast, errors);
|
|
5404
|
+
for (const error of errors) context.report({
|
|
5405
|
+
node: messageNode,
|
|
5406
|
+
...error
|
|
5407
|
+
});
|
|
5408
|
+
}
|
|
5409
|
+
}
|
|
5410
|
+
const name$3 = "no-literal-number-symbol";
|
|
5411
|
+
const rule$1 = {
|
|
5412
|
+
meta: {
|
|
5413
|
+
type: "problem",
|
|
5414
|
+
docs: {
|
|
5415
|
+
description: "Disallow literal percent, per mille, sign, currency and degree symbols next to a number argument",
|
|
5416
|
+
url: "https://formatjs.github.io/docs/tooling/linter#no-literal-number-symbol"
|
|
5417
|
+
},
|
|
5418
|
+
messages: {
|
|
5419
|
+
...CORE_MESSAGES,
|
|
5420
|
+
literalPercent: "Format `{{argument}}` with `::percent` and pass a ratio instead of writing a literal percent sign. Locales control the symbol, spacing and position.",
|
|
5421
|
+
literalPermille: "Format `{{argument}}` with `::permille` and pass a ratio instead of writing a literal per mille sign.",
|
|
5422
|
+
literalSign: "Format `{{argument}}` with `::sign-always` (or `sign-except-zero`) instead of writing a literal plus or minus sign. Locales control the sign glyph and position.",
|
|
5423
|
+
literalCurrency: "Format `{{argument}}` with `::currency/XXX` instead of writing a literal currency symbol. Locales control the symbol, spacing and position.",
|
|
5424
|
+
literalDegree: "Format `{{argument}}` with `::unit/celsius`, `::unit/fahrenheit` or `::unit/degree` instead of writing a literal degree sign."
|
|
5425
|
+
},
|
|
5426
|
+
schema: []
|
|
5427
|
+
},
|
|
5428
|
+
create(context) {
|
|
5429
|
+
const callExpressionVisitor = (node) => checkNode$1(context, node);
|
|
5430
|
+
const parserServices = context.sourceCode.parserServices;
|
|
5431
|
+
if (parserServices?.defineTemplateBodyVisitor) return parserServices.defineTemplateBodyVisitor({ CallExpression: callExpressionVisitor }, { CallExpression: callExpressionVisitor });
|
|
5432
|
+
return {
|
|
5433
|
+
JSXOpeningElement: (node) => checkNode$1(context, node),
|
|
5434
|
+
CallExpression: callExpressionVisitor
|
|
5435
|
+
};
|
|
5436
|
+
}
|
|
5437
|
+
};
|
|
5438
|
+
// packages/eslint-plugin-formatjs/rules/no-count-without-plural.ts
|
|
5439
|
+
const DEFAULT_COUNT_PATTERN = "^(?:count|n|num|total|quantity|qty|\\w+Count|\\w+Total)$";
|
|
5440
|
+
const PLURAL_NOUN = /^\s+(\p{L}*\p{Ll}s)\b/u;
|
|
5441
|
+
const NOT_NOUNS = /* @__PURE__ */ new Set([
|
|
5442
|
+
"as",
|
|
5443
|
+
"has",
|
|
5444
|
+
"his",
|
|
5445
|
+
"is",
|
|
5446
|
+
"its",
|
|
5447
|
+
"plus",
|
|
5448
|
+
"this",
|
|
5449
|
+
"us",
|
|
5450
|
+
"was",
|
|
5451
|
+
"yes"
|
|
5452
|
+
]);
|
|
5453
|
+
function literalAt(ast, index) {
|
|
5454
|
+
const element = ast[index];
|
|
5455
|
+
return element?.type === TYPE.literal ? element.value : "";
|
|
5456
|
+
}
|
|
5457
|
+
function isCountedNoun(ast, index) {
|
|
5458
|
+
const next = literalAt(ast, index + 1);
|
|
5459
|
+
const noun = PLURAL_NOUN.exec(next)?.[1];
|
|
5460
|
+
if (noun !== void 0) return !NOT_NOUNS.has(noun.toLowerCase());
|
|
5461
|
+
return next === " " && ast[index + 2]?.type === TYPE.argument;
|
|
5462
|
+
}
|
|
5463
|
+
function findCount(ast, countPattern) {
|
|
5464
|
+
for (const [index, element] of ast.entries()) {
|
|
5465
|
+
if ((element.type === TYPE.argument || element.type === TYPE.number) && countPattern.test(element.value) && isCountedNoun(ast, index)) return element.value;
|
|
5466
|
+
if (element.type === TYPE.select) for (const option of Object.values(element.options)) {
|
|
5467
|
+
const found = findCount(option.value, countPattern);
|
|
5468
|
+
if (found !== void 0) return found;
|
|
5469
|
+
}
|
|
5470
|
+
if (element.type === TYPE.tag) {
|
|
5471
|
+
const found = findCount(element.children, countPattern);
|
|
5472
|
+
if (found !== void 0) return found;
|
|
5473
|
+
}
|
|
5474
|
+
}
|
|
5475
|
+
}
|
|
5476
|
+
function checkNode(context, node, countPattern) {
|
|
5477
|
+
const settings = getSettings(context);
|
|
5478
|
+
for (const [{ message, messageNode }] of extractMessages(node, settings)) {
|
|
5479
|
+
if (!message.defaultMessage || !messageNode) continue;
|
|
5480
|
+
let ast;
|
|
5481
|
+
try {
|
|
5482
|
+
ast = parse(message.defaultMessage, { ignoreTag: settings.ignoreTag });
|
|
5483
|
+
} catch (e) {
|
|
5484
|
+
context.report({
|
|
5485
|
+
node: messageNode,
|
|
5486
|
+
messageId: "parseError",
|
|
5487
|
+
data: { error: e.message }
|
|
5488
|
+
});
|
|
5489
|
+
continue;
|
|
5490
|
+
}
|
|
5491
|
+
const argument = findCount(ast, countPattern);
|
|
5492
|
+
if (argument !== void 0) context.report({
|
|
5493
|
+
node: messageNode,
|
|
5494
|
+
messageId: "countWithoutPlural",
|
|
5495
|
+
data: { argument }
|
|
5496
|
+
});
|
|
5497
|
+
}
|
|
5498
|
+
}
|
|
5499
|
+
const name$2 = "no-count-without-plural";
|
|
5500
|
+
const rule = {
|
|
5501
|
+
meta: {
|
|
5502
|
+
type: "problem",
|
|
5503
|
+
docs: {
|
|
5504
|
+
description: "Require an ICU plural when a count argument is followed by a noun",
|
|
5505
|
+
url: "https://formatjs.github.io/docs/tooling/linter#no-count-without-plural"
|
|
5506
|
+
},
|
|
5507
|
+
messages: {
|
|
5508
|
+
...CORE_MESSAGES,
|
|
5509
|
+
countWithoutPlural: "Put the noun after `{{argument}}` inside `{{{argument}}, plural, one {# …} other {# …}}`. Other locales inflect the noun for up to 6 plural categories; `{{{argument}}, number}` alone only localizes the digits."
|
|
5510
|
+
},
|
|
5511
|
+
schema: [{
|
|
5512
|
+
type: "object",
|
|
5513
|
+
properties: { countPattern: { type: "string" } },
|
|
5514
|
+
additionalProperties: false
|
|
5515
|
+
}]
|
|
5516
|
+
},
|
|
5517
|
+
create(context) {
|
|
5518
|
+
const options = context.options[0] ?? {};
|
|
5519
|
+
const countPattern = new RegExp(options.countPattern ?? DEFAULT_COUNT_PATTERN, "u");
|
|
5520
|
+
const callExpressionVisitor = (node) => checkNode(context, node, countPattern);
|
|
5521
|
+
const parserServices = context.sourceCode.parserServices;
|
|
5522
|
+
if (parserServices?.defineTemplateBodyVisitor) return parserServices.defineTemplateBodyVisitor({ CallExpression: callExpressionVisitor }, { CallExpression: callExpressionVisitor });
|
|
5523
|
+
return {
|
|
5524
|
+
JSXOpeningElement: (node) => checkNode(context, node, countPattern),
|
|
5299
5525
|
CallExpression: callExpressionVisitor
|
|
5300
5526
|
};
|
|
5301
5527
|
}
|
|
@@ -5320,7 +5546,7 @@ var package_exports = /* @__PURE__ */ __exportAll({
|
|
|
5320
5546
|
version: () => version$1
|
|
5321
5547
|
});
|
|
5322
5548
|
var name$1 = "eslint-plugin-formatjs";
|
|
5323
|
-
var version$1 = "8.
|
|
5549
|
+
var version$1 = "8.2.0";
|
|
5324
5550
|
var description = "ESLint plugin for formatjs";
|
|
5325
5551
|
var keywords = [
|
|
5326
5552
|
"eslint",
|
|
@@ -5375,26 +5601,28 @@ const plugin = {
|
|
|
5375
5601
|
version
|
|
5376
5602
|
},
|
|
5377
5603
|
rules: {
|
|
5604
|
+
[name$24]: rule$22,
|
|
5605
|
+
[name$23]: rule$21,
|
|
5378
5606
|
[name$22]: rule$20,
|
|
5379
5607
|
[name$21]: rule$19,
|
|
5380
5608
|
[name$20]: rule$18,
|
|
5609
|
+
[name$25]: rule$23,
|
|
5381
5610
|
[name$19]: rule$17,
|
|
5382
5611
|
[name$18]: rule$16,
|
|
5383
|
-
[name$23]: rule$21,
|
|
5384
5612
|
[name$17]: rule$15,
|
|
5385
5613
|
[name$16]: rule$14,
|
|
5386
5614
|
[name$15]: rule$13,
|
|
5387
5615
|
[name$14]: rule$12,
|
|
5388
5616
|
[name$13]: rule$11,
|
|
5389
|
-
[name$12]: rule$10,
|
|
5390
5617
|
[name$11]: rule$9,
|
|
5618
|
+
[name$10]: rule$8,
|
|
5391
5619
|
[name$9]: rule$7,
|
|
5392
5620
|
[name$8]: rule$6,
|
|
5393
5621
|
[name$7]: rule$5,
|
|
5394
5622
|
[name$6]: rule$4,
|
|
5623
|
+
[name$12]: rule$10,
|
|
5395
5624
|
[name$5]: rule$3,
|
|
5396
5625
|
[name$4]: rule$2,
|
|
5397
|
-
[name$10]: rule$8,
|
|
5398
5626
|
[name$3]: rule$1,
|
|
5399
5627
|
[name$2]: rule
|
|
5400
5628
|
},
|
|
@@ -5433,7 +5661,9 @@ plugin.configs = {
|
|
|
5433
5661
|
]
|
|
5434
5662
|
}
|
|
5435
5663
|
}]],
|
|
5436
|
-
"formatjs/prefer-full-sentence": "error"
|
|
5664
|
+
"formatjs/prefer-full-sentence": "error",
|
|
5665
|
+
"formatjs/no-literal-number-symbol": "error",
|
|
5666
|
+
"formatjs/no-count-without-plural": "error"
|
|
5437
5667
|
}
|
|
5438
5668
|
},
|
|
5439
5669
|
recommended: {
|