eslint-plugin-formatjs 7.0.0-rc.0 → 8.0.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.js +24 -26
- package/index.js.map +1 -1
- package/package.json +3 -3
package/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { TYPE, isArgumentElement, isDateElement, isLiteralElement, isNumberElement, isPluralElement, isSelectElement, isTagElement, isTimeElement, parse } from "@formatjs/icu-messageformat-parser";
|
|
2
2
|
import { interpolateName } from "@formatjs/ts-transformer";
|
|
3
|
-
import
|
|
4
|
-
import
|
|
3
|
+
import emojiPresentationRegexCompiled from "@unicode/unicode-17.0.0/Binary_Property/Emoji_Presentation/regex.mjs";
|
|
4
|
+
import emojiPropertyRegexCompiled from "@unicode/unicode-17.0.0/Binary_Property/Emoji/regex.mjs";
|
|
5
5
|
import * as picomatchNs from "picomatch";
|
|
6
6
|
import MagicString from "magic-string";
|
|
7
7
|
//#region \0rolldown/runtime.js
|
|
@@ -378,6 +378,8 @@ const modules = /* @__PURE__ */ new Set([
|
|
|
378
378
|
"@formatjs/intl",
|
|
379
379
|
"react-intl",
|
|
380
380
|
"react-intl/server",
|
|
381
|
+
"@formatjs/svelte-intl",
|
|
382
|
+
"vue-intl",
|
|
381
383
|
"intl-messageformat"
|
|
382
384
|
]);
|
|
383
385
|
function staticObject(node) {
|
|
@@ -576,7 +578,9 @@ function catalogAnnotation(context, node) {
|
|
|
576
578
|
const descriptorModules = /* @__PURE__ */ new Set([
|
|
577
579
|
"@formatjs/intl",
|
|
578
580
|
"react-intl",
|
|
579
|
-
"react-intl/server"
|
|
581
|
+
"react-intl/server",
|
|
582
|
+
"@formatjs/svelte-intl",
|
|
583
|
+
"vue-intl"
|
|
580
584
|
]);
|
|
581
585
|
function checkInlineMessage(context, node) {
|
|
582
586
|
if (node.type !== "CallExpression") return;
|
|
@@ -635,6 +639,17 @@ function checkInlineMessage(context, node) {
|
|
|
635
639
|
const imports = hoistTypes(context, node, contract);
|
|
636
640
|
contract = imports.text;
|
|
637
641
|
const parameters = generic?.params;
|
|
642
|
+
if (contract === "{}" && node.arguments.length === 1) {
|
|
643
|
+
if (!generic) return true;
|
|
644
|
+
if (parameters?.length === 1) {
|
|
645
|
+
context.report({
|
|
646
|
+
node: generic,
|
|
647
|
+
messageId: "contract",
|
|
648
|
+
fix: (fixer) => fixer.remove(generic)
|
|
649
|
+
});
|
|
650
|
+
return true;
|
|
651
|
+
}
|
|
652
|
+
}
|
|
638
653
|
if (parameters && parameters.length >= 1 && parameters.length <= 2 && renderType(parameters[0]) === contract && !generated) return true;
|
|
639
654
|
if (generic && (!parameters || parameters.length > 2)) {
|
|
640
655
|
context.report({
|
|
@@ -765,19 +780,18 @@ const rule$20 = {
|
|
|
765
780
|
const generated = !!generic && /^<\s*\/\* @formatjs-generated \*\//.test(source.getText(generic));
|
|
766
781
|
const options = node.arguments[1];
|
|
767
782
|
const typed = staticObject(options) && options.properties.length === 1 && options.properties.some((p) => p.type === "Property" && (p.key.type === "Identifier" ? p.key.name : p.key.type === "Literal" ? p.key.value : void 0) === "typed" && p.value.type === "Literal" && p.value.value === true);
|
|
768
|
-
if (!
|
|
769
|
-
if (!typed && generic && !generated && !context.options[0]?.generateTypes) return;
|
|
783
|
+
if (!generic && !typed && !context.options[0]?.generateTypes) return;
|
|
770
784
|
if (node.arguments.length > 2 || options && !typed) return;
|
|
771
785
|
const descriptor = node.arguments[0];
|
|
772
786
|
if (!staticObject(descriptor)) {
|
|
773
|
-
if (
|
|
787
|
+
if (generic || typed) context.report({
|
|
774
788
|
node,
|
|
775
789
|
messageId: "dynamic"
|
|
776
790
|
});
|
|
777
791
|
return;
|
|
778
792
|
}
|
|
779
793
|
if (imported.helper === "defineMessages" && !descriptor.properties.every((p) => p.type === "Property" && staticObject(p.value))) {
|
|
780
|
-
if (
|
|
794
|
+
if (generic || typed) context.report({
|
|
781
795
|
node,
|
|
782
796
|
messageId: "dynamic"
|
|
783
797
|
});
|
|
@@ -791,7 +805,7 @@ const rule$20 = {
|
|
|
791
805
|
}
|
|
792
806
|
}, getSettings(context));
|
|
793
807
|
if (messages.some(([message]) => typeof message.message.defaultMessage !== "string" || !staticMessage(message.messageNode ?? void 0)) || messages.length !== (imported.helper === "defineMessage" ? 1 : descriptor.properties.length)) {
|
|
794
|
-
if (
|
|
808
|
+
if (generic || typed) context.report({
|
|
795
809
|
node,
|
|
796
810
|
messageId: "dynamic"
|
|
797
811
|
});
|
|
@@ -837,7 +851,7 @@ const rule$20 = {
|
|
|
837
851
|
const annotationMatches = !annotation || annotation.annotation === annotation.generated && renderType(annotation.generated) === catalogType;
|
|
838
852
|
const expected = `<${contract}>`;
|
|
839
853
|
const parameters = generic?.params;
|
|
840
|
-
if (parameters && parameters.length >= 1 && parameters.length <= 2 && renderType(parameters[0]) === contract &&
|
|
854
|
+
if (parameters && parameters.length >= 1 && parameters.length <= 2 && renderType(parameters[0]) === contract && !generated && annotationMatches) return;
|
|
841
855
|
if (generic && (!parameters || parameters.length < 1 || parameters.length > 2)) {
|
|
842
856
|
context.report({
|
|
843
857
|
node: generic,
|
|
@@ -851,11 +865,6 @@ const rule$20 = {
|
|
|
851
865
|
fix(fixer) {
|
|
852
866
|
const edits = [...imports.fix(fixer), generic && parameters?.[0] ? fixer.replaceTextRange([generic.range[0] + 1, parameters[0].range[1]], contract) : fixer.insertTextAfter(node.optional ? source.getTokenAfter(node.callee) : node.callee, expected)];
|
|
853
867
|
if (annotation && !annotationMatches) edits.push(fixer.replaceText(annotation.annotation, catalogType));
|
|
854
|
-
if (!typed) {
|
|
855
|
-
const close = source.getLastToken(node);
|
|
856
|
-
const previous = source.getTokenBefore(close);
|
|
857
|
-
edits.push(fixer.insertTextBefore(close, `${previous.value === "," ? "" : ","} {typed: true}`));
|
|
858
|
-
}
|
|
859
868
|
return edits;
|
|
860
869
|
}
|
|
861
870
|
});
|
|
@@ -4062,17 +4071,6 @@ const EMOJI_RANGES = [
|
|
|
4062
4071
|
*/
|
|
4063
4072
|
const graphemeSegmenter = new Intl.Segmenter("en", { granularity: "grapheme" });
|
|
4064
4073
|
/**
|
|
4065
|
-
* Regex for detecting emoji using Unicode 17.0.0 Emoji_Presentation data
|
|
4066
|
-
* Generated from @unicode/unicode-17.0.0/Binary_Property/Emoji_Presentation
|
|
4067
|
-
* This avoids false positives from #, *, digits, and text symbols like ©
|
|
4068
|
-
*/
|
|
4069
|
-
const emojiPresentationRegexCompiled = emojiPresentationRegex.default ?? emojiPresentationRegex;
|
|
4070
|
-
/**
|
|
4071
|
-
* Regex for detecting emoji-capable characters using Unicode 17.0.0 Emoji property
|
|
4072
|
-
* This includes characters that can have emoji presentation (like ❤, ☀)
|
|
4073
|
-
*/
|
|
4074
|
-
const emojiPropertyRegexCompiled = emojiPropertyRegex.default ?? emojiPropertyRegex;
|
|
4075
|
-
/**
|
|
4076
4074
|
* Check if a string contains any emoji
|
|
4077
4075
|
* Uses Unicode 17.0.0 Emoji_Presentation data and variation selector (U+FE0F)
|
|
4078
4076
|
* to properly detect emoji while avoiding false positives from characters like
|
|
@@ -5124,7 +5122,7 @@ var package_exports = /* @__PURE__ */ __exportAll({
|
|
|
5124
5122
|
version: () => version$1
|
|
5125
5123
|
});
|
|
5126
5124
|
var name$1 = "eslint-plugin-formatjs";
|
|
5127
|
-
var version$1 = "
|
|
5125
|
+
var version$1 = "8.0.0";
|
|
5128
5126
|
var description = "ESLint plugin for formatjs";
|
|
5129
5127
|
var keywords = [
|
|
5130
5128
|
"eslint",
|