eslint-plugin-formatjs 8.0.2 → 8.0.3
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 +7 -5
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -975,7 +975,7 @@ const rule$20 = {
|
|
|
975
975
|
let contract;
|
|
976
976
|
let catalogType;
|
|
977
977
|
try {
|
|
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("; ") + " }" : "{}";
|
|
978
|
+
if (annotation) catalogType = !catalog ? "import(" + JSON.stringify(imported.module) + ").TypedMessageDescriptor" + (types[0] === "{}" ? "" : "<" + types[0] + ">") : entries.length ? "{ " + entries.map((entry, index) => "readonly " + entry.key + ": import(" + JSON.stringify(imported.module) + ").TypedMessageDescriptor" + (types[index] === "{}" ? "" : "<" + types[index] + ">")).join("; ") + " }" : "{}";
|
|
979
979
|
contract = !catalog ? types[0] : entries.length ? "{ " + entries.map((entry, index) => "readonly " + entry.key + ": " + types[index]).join("; ") + " }" : "{}";
|
|
980
980
|
} catch (error) {
|
|
981
981
|
context.report({
|
|
@@ -988,9 +988,11 @@ const rule$20 = {
|
|
|
988
988
|
const imports = hoistTypes(context, node, contract + (catalogType ? "\n" + catalogType : ""));
|
|
989
989
|
[contract, catalogType] = imports.text.split("\n");
|
|
990
990
|
const annotationMatches = !annotation || annotation.annotation === annotation.generated && renderType(annotation.generated) === catalogType;
|
|
991
|
-
const expected = `<${contract}>`;
|
|
992
991
|
const parameters = generic?.params;
|
|
993
|
-
|
|
992
|
+
const omitContract = (imported.helper === "defineMessage" || catalog) && types.every((type) => type === "{}") && (!parameters || parameters.length === 1);
|
|
993
|
+
const expected = omitContract ? "" : `<${contract}>`;
|
|
994
|
+
if (omitContract && !generic && annotationMatches) return;
|
|
995
|
+
if (!omitContract && parameters && parameters.length >= 1 && parameters.length <= 2 && renderType(parameters[0]) === contract && !generated && annotationMatches) return;
|
|
994
996
|
if (generic && (!parameters || parameters.length < 1 || parameters.length > 2)) {
|
|
995
997
|
context.report({
|
|
996
998
|
node: generic,
|
|
@@ -1005,7 +1007,7 @@ const rule$20 = {
|
|
|
1005
1007
|
const edits = [
|
|
1006
1008
|
...imports.fix(fixer),
|
|
1007
1009
|
...obsoleteTypes(context, [...parameters?.[0] ? [parameters[0]] : [], ...annotation && !annotationMatches ? [annotation.annotation] : []], contract + (catalogType ?? ""), fixer),
|
|
1008
|
-
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)
|
|
1010
|
+
omitContract && generic ? fixer.remove(generic) : 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)
|
|
1009
1011
|
];
|
|
1010
1012
|
if (annotation && !annotationMatches) edits.push(fixer.replaceText(annotation.annotation, catalogType));
|
|
1011
1013
|
return edits;
|
|
@@ -5265,7 +5267,7 @@ var package_exports = /* @__PURE__ */ __exportAll({
|
|
|
5265
5267
|
version: () => version$1
|
|
5266
5268
|
});
|
|
5267
5269
|
var name$1 = "eslint-plugin-formatjs";
|
|
5268
|
-
var version$1 = "8.0.
|
|
5270
|
+
var version$1 = "8.0.3";
|
|
5269
5271
|
var description = "ESLint plugin for formatjs";
|
|
5270
5272
|
var keywords = [
|
|
5271
5273
|
"eslint",
|