From d783dc2c9381d74a0c0eaf9e57b7c93bc739d963 Mon Sep 17 00:00:00 2001 From: watackeech Date: Fri, 20 Jun 2025 13:19:40 +0900 Subject: [PATCH] fix: support for Japanese slash date without year --- src/textlint-rule-date-weekday-mismatch.js | 8 ++++---- .../textlint-rule-date-weekday-mismatch-test.js | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/textlint-rule-date-weekday-mismatch.js b/src/textlint-rule-date-weekday-mismatch.js index 314f0d7..936d2e8 100644 --- a/src/textlint-rule-date-weekday-mismatch.js +++ b/src/textlint-rule-date-weekday-mismatch.js @@ -58,10 +58,6 @@ const detectLang = (tags, preferLang) => { * @returns {string} */ const addYearToDateText = (dateText, year, lang) => { - // Japanese: 4月23日(月) → 2024年4月23日(月) - if (lang === "ja") { - return `${year}年${dateText}`; - } // Slash: 4/23(月) → 2024/4/23(月) if (/^[0-9]{1,2}\/[0-9]{1,2}/.test(dateText)) { return `${year}/${dateText}`; @@ -70,6 +66,10 @@ const addYearToDateText = (dateText, year, lang) => { if (/^[0-9]{1,2}-[0-9]{1,2}/.test(dateText)) { return `${year}-${dateText}`; } + // Japanese: 4月23日(月) → 2024年4月23日(月) + if (lang === "ja") { + return `${year}年${dateText}`; + } // Default: prepend year and a space return `${year} ${dateText}`; } diff --git a/test/textlint-rule-date-weekday-mismatch-test.js b/test/textlint-rule-date-weekday-mismatch-test.js index d96bb4e..74491f2 100644 --- a/test/textlint-rule-date-weekday-mismatch-test.js +++ b/test/textlint-rule-date-weekday-mismatch-test.js @@ -31,6 +31,11 @@ tester.run("rule", rule, { options: { useCurrentYearIfMissing: true, currentYear: 2025, lang: "en" }, // 2025-04-23 is Wednesday }, + { + text: "6/20(金)", + options: { useCurrentYearIfMissing: true, currentYear: 2025, lang: "ja" }, + // 2025/06/20は金曜日 + }, ], invalid: [ // single match @@ -159,5 +164,17 @@ tester.run("rule", rule, { } ] }, + { + text: "6/20(木)", + output: "6/20(金)", + options: { useCurrentYearIfMissing: true, currentYear: 2025, lang: "ja" }, + errors: [ + { + message: "6/20(木) mismatch weekday.\n6/20(木) => 6/20(金)", + line: 1, + column: 6 + } + ] + }, ] });