diff --git a/src/textlint-rule-date-weekday-mismatch.js b/src/textlint-rule-date-weekday-mismatch.js index 9e2cd68..7c1e522 100644 --- a/src/textlint-rule-date-weekday-mismatch.js +++ b/src/textlint-rule-date-weekday-mismatch.js @@ -13,7 +13,14 @@ const supportedLang = [ [/^FR/i, "fr"], [/^ZH/i, "zh"] ]; - +/** + * text should be includes number + * @param {Object} chronoDate + * @returns {boolean} + */ +const textIncludesNumber = (chronoDate) => { + return /[0-90-9]/.test(chronoDate.text); +}; /** * detect lang and return language string * @param {string[]} tags @@ -44,11 +51,13 @@ function reporter(context, config = {}) { if (typeof Intl === "undefined") { throw new Error("Not support your Node.js/browser. should be use latest version."); } + return { [Syntax.Str](node){ const text = getSource(node); const chronoDate = chrono.parse(text); - chronoDate.forEach(chronoDate => { + // ignore "今日" text + chronoDate.filter(textIncludesNumber).forEach(chronoDate => { const lang = detectLang(Object.keys(chronoDate.tags), preferLang); if (!lang) { // not found lang @@ -56,7 +65,13 @@ function reporter(context, config = {}) { } // get weekday from actual date string const kV = chronoDate.start.knownValues; - const $moment = moment(`${kV.year}-${kV.month}-${kV.day}`, "YYYY-MM-DD", lang); + let $moment; + try { + $moment = moment(`${kV.year}-${kV.month}-${kV.day}`, "YYYY-MM-DD", lang); + } catch (error) { + // parse error is ignore + return; + } if (!$moment.isValid()) { return; } diff --git a/test/textlint-rule-date-weekday-mismatch-test.js b/test/textlint-rule-date-weekday-mismatch-test.js index 9e441e7..aa5d04a 100644 --- a/test/textlint-rule-date-weekday-mismatch-test.js +++ b/test/textlint-rule-date-weekday-mismatch-test.js @@ -10,7 +10,9 @@ tester.run("rule", rule, { "2016-12-29(Thursday)", "2016-12-29(Tsu)", // invalid date should be ignored - "11月 25日 (火曜日) " + "11月 25日 (火曜日) ", + // ignore relative word + "今日は日曜 (火曜日) " ], invalid: [ // single match