eslint-plugin-formatjs 8.0.3 → 8.0.4
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
|
@@ -63,7 +63,7 @@ function messageTypes(ast, module, ignoreList = []) {
|
|
|
63
63
|
else type = `import(${JSON.stringify(module)}).MessageTag`;
|
|
64
64
|
return `readonly ${JSON.stringify(name)}${ignored.has(name) ? "?" : ""}: ${type}`;
|
|
65
65
|
});
|
|
66
|
-
return fields.length ? `{ ${fields.join("; ")} }` :
|
|
66
|
+
return fields.length ? `{ ${fields.join("; ")} }` : `import(${JSON.stringify(module)}).NoMessageValues`;
|
|
67
67
|
}
|
|
68
68
|
//#endregion
|
|
69
69
|
//#region packages/eslint-plugin-formatjs/util.ts
|
|
@@ -538,7 +538,7 @@ function hoistTypes(context, node, contract) {
|
|
|
538
538
|
const occupied = new Set(source.scopeManager?.scopes.flatMap((scope) => scope.variables.map((variable) => variable.name)));
|
|
539
539
|
const resolved = /* @__PURE__ */ new Map();
|
|
540
540
|
return {
|
|
541
|
-
text: contract.replace(/import\(("(?:[^"\\]|\\.)*")\)\.(MessageTag|MessageValuesOf|MessageValue|TypedMessageDescriptor)/g, (reference, quotedModule, imported) => {
|
|
541
|
+
text: contract.replace(/import\(("(?:[^"\\]|\\.)*")\)\.(MessageTag|MessageValuesOf|MessageValue|NoMessageValues|TypedMessageDescriptor)/g, (reference, quotedModule, imported) => {
|
|
542
542
|
if (resolved.has(reference)) return resolved.get(reference);
|
|
543
543
|
const module = JSON.parse(quotedModule);
|
|
544
544
|
for (const declaration of source.ast.body) {
|
|
@@ -762,10 +762,11 @@ function checkInlineMessage(context, node) {
|
|
|
762
762
|
});
|
|
763
763
|
return true;
|
|
764
764
|
}
|
|
765
|
+
const emptyContract = contract === `import(${JSON.stringify(module)}).NoMessageValues`;
|
|
765
766
|
const imports = hoistTypes(context, node, contract);
|
|
766
767
|
contract = imports.text;
|
|
767
768
|
const parameters = generic?.params;
|
|
768
|
-
if (
|
|
769
|
+
if (emptyContract && node.arguments.length === 1) {
|
|
769
770
|
if (!generic) return true;
|
|
770
771
|
if (parameters?.length === 1) {
|
|
771
772
|
context.report({
|
|
@@ -974,8 +975,9 @@ const rule$20 = {
|
|
|
974
975
|
}
|
|
975
976
|
let contract;
|
|
976
977
|
let catalogType;
|
|
978
|
+
const emptyContract = `import(${JSON.stringify(imported.module)}).NoMessageValues`;
|
|
977
979
|
try {
|
|
978
|
-
if (annotation) catalogType = !catalog ? "import(" + JSON.stringify(imported.module) + ").TypedMessageDescriptor" + (types[0] ===
|
|
980
|
+
if (annotation) catalogType = !catalog ? "import(" + JSON.stringify(imported.module) + ").TypedMessageDescriptor" + (types[0] === emptyContract ? "" : "<" + types[0] + ">") : entries.length ? "{ " + entries.map((entry, index) => "readonly " + entry.key + ": import(" + JSON.stringify(imported.module) + ").TypedMessageDescriptor" + (types[index] === emptyContract ? "" : "<" + types[index] + ">")).join("; ") + " }" : "{}";
|
|
979
981
|
contract = !catalog ? types[0] : entries.length ? "{ " + entries.map((entry, index) => "readonly " + entry.key + ": " + types[index]).join("; ") + " }" : "{}";
|
|
980
982
|
} catch (error) {
|
|
981
983
|
context.report({
|
|
@@ -985,11 +987,11 @@ const rule$20 = {
|
|
|
985
987
|
});
|
|
986
988
|
return;
|
|
987
989
|
}
|
|
988
|
-
const
|
|
990
|
+
const parameters = generic?.params;
|
|
991
|
+
const omitContract = (imported.helper === "defineMessage" || catalog) && types.every((type) => type === emptyContract) && (!parameters || parameters.length === 1);
|
|
992
|
+
const imports = hoistTypes(context, node, (omitContract ? "" : contract) + (catalogType ? "\n" + catalogType : ""));
|
|
989
993
|
[contract, catalogType] = imports.text.split("\n");
|
|
990
994
|
const annotationMatches = !annotation || annotation.annotation === annotation.generated && renderType(annotation.generated) === catalogType;
|
|
991
|
-
const parameters = generic?.params;
|
|
992
|
-
const omitContract = (imported.helper === "defineMessage" || catalog) && types.every((type) => type === "{}") && (!parameters || parameters.length === 1);
|
|
993
995
|
const expected = omitContract ? "" : `<${contract}>`;
|
|
994
996
|
if (omitContract && !generic && annotationMatches) return;
|
|
995
997
|
if (!omitContract && parameters && parameters.length >= 1 && parameters.length <= 2 && renderType(parameters[0]) === contract && !generated && annotationMatches) return;
|
|
@@ -5267,7 +5269,7 @@ var package_exports = /* @__PURE__ */ __exportAll({
|
|
|
5267
5269
|
version: () => version$1
|
|
5268
5270
|
});
|
|
5269
5271
|
var name$1 = "eslint-plugin-formatjs";
|
|
5270
|
-
var version$1 = "8.0.
|
|
5272
|
+
var version$1 = "8.0.4";
|
|
5271
5273
|
var description = "ESLint plugin for formatjs";
|
|
5272
5274
|
var keywords = [
|
|
5273
5275
|
"eslint",
|