diff --git a/src/textlint-rule-date-weekday-mismatch.js b/src/textlint-rule-date-weekday-mismatch.js index f46a49f..cf90704 100644 --- a/src/textlint-rule-date-weekday-mismatch.js +++ b/src/textlint-rule-date-weekday-mismatch.js @@ -22,6 +22,15 @@ const supportedLang = [ const textIncludesNumber = (chronoDate) => { return /[0-90-9]/.test(chronoDate.text); }; +const yearMonthDayShouldKnownValues = (chronoDate) => { + if (!chronoDate.start) { + return false; + } + // year-month-day should known value + // if have not anyone, not report as error + const kV = chronoDate.start.knownValues; + return kV.year !== undefined && kV.month !== undefined && kV.day !== undefined; +}; /** * detect lang and return language string * @param {string[]} tags @@ -56,10 +65,11 @@ function reporter(context, config = {}) { return { [Syntax.Str](node){ const text = getSource(node); - const chronoDate = chrono.parse(text); + const chronoDates = chrono.parse(text); // ignore "今日" text - - chronoDate.filter(textIncludesNumber).forEach(chronoDate => { + // ignore not valid data + const filteredChronoDates = chronoDates.filter(textIncludesNumber).filter(yearMonthDayShouldKnownValues); + filteredChronoDates.forEach(chronoDate => { const lang = detectLang(Object.keys(chronoDate.tags), preferLang); if (!lang) { // not found lang @@ -71,7 +81,7 @@ function reporter(context, config = {}) { try { $moment = moment(`${kV.year}-${kV.month}-${kV.day}`, "YYYY-MM-DD", lang); } catch (error) { - console.warn("Maybe textlint-rule-date-weekday-mismatch options was wrong language.", lang); + report(node, new RuleError(`Maybe textlint-rule-date-weekday-mismatch options was wrong language. lang: ${lang}`)); // parse error is ignore return; } diff --git a/test/textlint-rule-date-weekday-mismatch-test.js b/test/textlint-rule-date-weekday-mismatch-test.js index 42588a3..e90a2a0 100644 --- a/test/textlint-rule-date-weekday-mismatch-test.js +++ b/test/textlint-rule-date-weekday-mismatch-test.js @@ -9,6 +9,11 @@ tester.run("rule", rule, { "2016年12月29日(木曜日)", "2016-12-29(Thursday)", "2016-12-29(Tsu)", + // real example + `今回で192回目の更新ですが、このままのペースだと11月10日(月)に200回目となるので、 +それを記念して勉強会的なイベントをやろうかと思ってます。 + +詳細は(まだ詳細は決まってない)以下に書いてありますが、2014年11月09日(日)を予定しています。`, // invalid date should be ignored "11月 25日 (火曜日) ", // ignore relative word