diff --git a/plugins/eslint-check-i18n-json.js b/plugins/eslint-check-i18n-json.js index af98d8a82..fccdbe1c0 100644 --- a/plugins/eslint-check-i18n-json.js +++ b/plugins/eslint-check-i18n-json.js @@ -71,7 +71,7 @@ export default { category: "Possible Errors", recommended: true, }, - fixable: null, + fixable: "code", // 将 fixable 设置为 "code" }, create(context) { return { @@ -109,6 +109,15 @@ export default { context.report({ node, message: `Key "${key}" is present in ${lang}.json but not in en.json for namespace "${namespace}"`, + fix(fixer) { + const newJson = Object.fromEntries( + Object.entries(currentJson).filter(([k]) => !extraKeys.includes(k)), + ) + + const newText = `${JSON.stringify(newJson, null, 2)}\n` + + return fixer.replaceText(node, newText) + }, }) } }, diff --git a/plugins/eslint-recursive-sort.js b/plugins/eslint-recursive-sort.js index 113a070a3..924cbff62 100644 --- a/plugins/eslint-recursive-sort.js +++ b/plugins/eslint-recursive-sort.js @@ -34,7 +34,7 @@ export default { try { const json = JSON.parse(text) const sortedJson = sortObjectKeys(json) - const sortedText = JSON.stringify(sortedJson, null, 2) + const sortedText = `${JSON.stringify(sortedJson, null, 2)}\n` if (text.trim() !== sortedText.trim()) { context.report({