eslint-plugin-formatjs 8.0.1 → 8.0.2
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 +10 -8
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -639,7 +639,7 @@ function obsoleteTypes(context, replaced, replacement, fixer) {
|
|
|
639
639
|
}
|
|
640
640
|
return edits;
|
|
641
641
|
}
|
|
642
|
-
function
|
|
642
|
+
function messageAnnotation(context, node, catalog) {
|
|
643
643
|
const parent = node.parent;
|
|
644
644
|
if (parent?.type !== "VariableDeclarator" || parent.init !== node) return;
|
|
645
645
|
const annotation = parent.id.typeAnnotation?.typeAnnotation;
|
|
@@ -663,7 +663,8 @@ function catalogAnnotation(context, node) {
|
|
|
663
663
|
function broad(type, seen = /* @__PURE__ */ new Set()) {
|
|
664
664
|
if (seen.has(type)) return false;
|
|
665
665
|
seen.add(type);
|
|
666
|
-
if (
|
|
666
|
+
if (!catalog && imported(type, "MessageDescriptor")) return true;
|
|
667
|
+
if (type.type === "TSTypeLiteral") return catalog && !!type.members?.every((member) => member.type === "TSPropertySignature" && !!member.typeAnnotation && descriptorType(member.typeAnnotation.typeAnnotation));
|
|
667
668
|
let scope = context.sourceCode.getScope(type);
|
|
668
669
|
while (scope) {
|
|
669
670
|
const binding = scope.set.get(type.typeName?.name ?? "");
|
|
@@ -675,14 +676,15 @@ function catalogAnnotation(context, node) {
|
|
|
675
676
|
}
|
|
676
677
|
const parameters = (type.typeArguments ?? type.typeParameters)?.params;
|
|
677
678
|
if (type.typeName?.name === "Readonly" && parameters?.length === 1) return broad(parameters[0], seen);
|
|
678
|
-
return type.typeName?.name === "Record" && parameters?.length === 2 && descriptorType(parameters[1]);
|
|
679
|
+
return catalog && type.typeName?.name === "Record" && parameters?.length === 2 && descriptorType(parameters[1]);
|
|
679
680
|
}
|
|
680
681
|
function typedMap(type) {
|
|
682
|
+
if (!catalog) return imported(type, "TypedMessageDescriptor");
|
|
681
683
|
return type.type === "TSTypeLiteral" && !!type.members?.every((member) => member.type === "TSPropertySignature" && !!member.typeAnnotation && imported(member.typeAnnotation.typeAnnotation, "TypedMessageDescriptor"));
|
|
682
684
|
}
|
|
683
685
|
let base = annotation;
|
|
684
686
|
let generated = typedMap(annotation) ? annotation : void 0;
|
|
685
|
-
if (annotation.type === "TSIntersectionType" && annotation.types?.length === 2) {
|
|
687
|
+
if (catalog && annotation.type === "TSIntersectionType" && annotation.types?.length === 2) {
|
|
686
688
|
const [left, right] = annotation.types;
|
|
687
689
|
if (right.type === "TSTypeLiteral" && right.members?.every((member) => member.type === "TSPropertySignature" && !!member.typeAnnotation && imported(member.typeAnnotation.typeAnnotation, "TypedMessageDescriptor"))) {
|
|
688
690
|
base = left;
|
|
@@ -816,7 +818,7 @@ const rule$20 = {
|
|
|
816
818
|
contract: "Generate or refresh the ICU argument contract.",
|
|
817
819
|
invalid: "Cannot generate message types: {{error}}.",
|
|
818
820
|
manual: "Unsupported number of generic arguments; update the call manually.",
|
|
819
|
-
annotation: "
|
|
821
|
+
annotation: "Message annotation may erase ICU contracts; use TypedMessageDescriptor types.",
|
|
820
822
|
dynamic: "Typed messages require static message strings and parser options for contract verification."
|
|
821
823
|
}
|
|
822
824
|
},
|
|
@@ -962,7 +964,7 @@ const rule$20 = {
|
|
|
962
964
|
});
|
|
963
965
|
return;
|
|
964
966
|
}
|
|
965
|
-
const annotation = imported.helper === "defineMessages" ?
|
|
967
|
+
const annotation = imported.helper === "defineMessages" || imported.helper === "defineMessage" ? messageAnnotation(context, node, catalog) : void 0;
|
|
966
968
|
if (annotation && !annotation.supported) {
|
|
967
969
|
context.report({
|
|
968
970
|
node: annotation.annotation,
|
|
@@ -973,7 +975,7 @@ const rule$20 = {
|
|
|
973
975
|
let contract;
|
|
974
976
|
let catalogType;
|
|
975
977
|
try {
|
|
976
|
-
if (annotation) catalogType = entries.length ? "{ " + entries.map((entry, index) => "readonly " + entry.key + ": import(" + JSON.stringify(imported.module) + ").TypedMessageDescriptor<" + types[index] + ">").join("; ") + " }" : "{}";
|
|
978
|
+
if (annotation) catalogType = !catalog ? "import(" + JSON.stringify(imported.module) + ").TypedMessageDescriptor<" + types[0] + ">" : entries.length ? "{ " + entries.map((entry, index) => "readonly " + entry.key + ": import(" + JSON.stringify(imported.module) + ").TypedMessageDescriptor<" + types[index] + ">").join("; ") + " }" : "{}";
|
|
977
979
|
contract = !catalog ? types[0] : entries.length ? "{ " + entries.map((entry, index) => "readonly " + entry.key + ": " + types[index]).join("; ") + " }" : "{}";
|
|
978
980
|
} catch (error) {
|
|
979
981
|
context.report({
|
|
@@ -5263,7 +5265,7 @@ var package_exports = /* @__PURE__ */ __exportAll({
|
|
|
5263
5265
|
version: () => version$1
|
|
5264
5266
|
});
|
|
5265
5267
|
var name$1 = "eslint-plugin-formatjs";
|
|
5266
|
-
var version$1 = "8.0.
|
|
5268
|
+
var version$1 = "8.0.2";
|
|
5267
5269
|
var description = "ESLint plugin for formatjs";
|
|
5268
5270
|
var keywords = [
|
|
5269
5271
|
"eslint",
|