Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/textlint-rule-date-weekday-mismatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
Expand All @@ -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}`;
}
Expand Down
17 changes: 17 additions & 0 deletions test/textlint-rule-date-weekday-mismatch-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
]
},
]
});