-
Notifications
You must be signed in to change notification settings - Fork 6
feat: add useCurrentYearIfMissing option to support dates without year #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
0a407bb
64959db
7402db3
da86588
4ed6d4f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,19 @@ | ||
| import TextLintTester from "textlint-tester"; | ||
| import sinon from "sinon"; | ||
|
|
||
| const tester = new TextLintTester(); | ||
| // rule | ||
| const rule = require("../src/textlint-rule-date-weekday-mismatch"); | ||
|
|
||
| // Mock: fix current date to 2025-04-23 to test `useCurrentYearIfMissing` option | ||
| let clock; | ||
| before(() => { | ||
| clock = sinon.useFakeTimers(new Date(2025, 4, 23).getTime()); | ||
| }); | ||
| after(() => { | ||
| clock.restore(); | ||
| }); | ||
|
|
||
|
||
| // ruleName, rule, { valid, invalid } | ||
| tester.run("rule", rule, { | ||
| valid: [ | ||
|
|
@@ -18,7 +29,18 @@ tester.run("rule", rule, { | |
| // invalid date should be ignored | ||
| "11月 25日 (火曜日) ", | ||
| // ignore relative word | ||
| "今日(火曜日)はどうしよう" | ||
| "今日(火曜日)はどうしよう", | ||
| // useCurrentYearIfMissing option: valid | ||
| { | ||
| text: "4月23日(水)", | ||
| options: { useCurrentYearIfMissing: true, lang: "ja" }, | ||
| // 2025年4月23日は水曜日 | ||
| }, | ||
| { | ||
| text: "4/23(Wed)", | ||
| options: { useCurrentYearIfMissing: true, lang: "en" }, | ||
| // 2025-04-23 is Wednesday | ||
| }, | ||
| ], | ||
| invalid: [ | ||
| // single match | ||
|
|
@@ -122,6 +144,30 @@ tester.run("rule", rule, { | |
| } | ||
| ] | ||
| }, | ||
|
|
||
| // useCurrentYearIfMissing option: invalid | ||
| { | ||
| text: "4月23日(金)", | ||
| output: "4月23日(水)", | ||
| options: { useCurrentYearIfMissing: true, lang: "ja" }, | ||
| errors: [ | ||
| { | ||
| message: "4月23日(金) mismatch weekday.\n4月23日(金) => 4月23日(水)", | ||
| line: 1, | ||
| column: 7 | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| text: "4/23(Fri)", | ||
| output: "4/23(Wed)", | ||
| options: { useCurrentYearIfMissing: true, lang: "en" }, | ||
| errors: [ | ||
| { | ||
| message: "4/23(Fri) mismatch weekday.\n4/23(Fri) => 4/23(Wed)", | ||
| line: 1, | ||
| column: 6 | ||
| } | ||
| ] | ||
| }, | ||
| ] | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -993,6 +993,29 @@ | |
| readdirp "^2.2.1" | ||
| upath "^1.1.1" | ||
|
|
||
| "@sinonjs/commons@^3.0.1": | ||
| version "3.0.1" | ||
| resolved "https://registry.yarnpkg.com/@sinonjs/commons/-/commons-3.0.1.tgz#1029357e44ca901a615585f6d27738dbc89084cd" | ||
| integrity sha512-K3mCHKQ9sVh8o1C9cxkwxaOmXoAMlDxC1mYyHrjqOWEcBjYr76t96zL2zlj5dUGZ3HSw240X1qgH3Mjf1yJWpQ== | ||
| dependencies: | ||
| type-detect "4.0.8" | ||
|
|
||
| "@sinonjs/fake-timers@^13.0.5": | ||
| version "13.0.5" | ||
| resolved "https://registry.yarnpkg.com/@sinonjs/fake-timers/-/fake-timers-13.0.5.tgz#36b9dbc21ad5546486ea9173d6bea063eb1717d5" | ||
| integrity sha512-36/hTbH2uaWuGVERyC6da9YwGWnzUZXuPro/F2LfsdOsLnCojz/iSH8MxUt/FD2S5XBSVPhmArFUXcpCQ2Hkiw== | ||
| dependencies: | ||
| "@sinonjs/commons" "^3.0.1" | ||
|
|
||
| "@sinonjs/samsam@^8.0.1": | ||
| version "8.0.2" | ||
| resolved "https://registry.yarnpkg.com/@sinonjs/samsam/-/samsam-8.0.2.tgz#e4386bf668ff36c95949e55a38dc5f5892fc2689" | ||
| integrity sha512-v46t/fwnhejRSFTGqbpn9u+LQ9xJDse10gNnPgAcxgdoCDMXj/G2asWAC/8Qs+BAZDicX+MNZouXT1A7c83kVw== | ||
| dependencies: | ||
| "@sinonjs/commons" "^3.0.1" | ||
| lodash.get "^4.4.2" | ||
| type-detect "^4.1.0" | ||
|
|
||
| "@textlint/ast-node-types@^12.0.0": | ||
| version "12.0.0" | ||
| resolved "https://registry.yarnpkg.com/@textlint/ast-node-types/-/ast-node-types-12.0.0.tgz#23bd683f9fc04209ae28bff72954c8aa67c6b1ca" | ||
|
|
@@ -1785,6 +1808,11 @@ diff@^4.0.2: | |
| resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d" | ||
| integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A== | ||
|
|
||
| diff@^7.0.0: | ||
| version "7.0.0" | ||
| resolved "https://registry.yarnpkg.com/diff/-/diff-7.0.0.tgz#3fb34d387cd76d803f6eebea67b921dab0182a9a" | ||
| integrity sha512-PJWHUb1RFevKCwaFA9RlG5tCd+FO5iRh9A8HEtkmBH2Li03iJriB6m6JIN4rGz3K3JLawI7/veA1xzRKP6ISBw== | ||
|
|
||
| ejs@^2.4.1: | ||
| version "2.7.1" | ||
| resolved "https://registry.yarnpkg.com/ejs/-/ejs-2.7.1.tgz#5b5ab57f718b79d4aca9254457afecd36fa80228" | ||
|
|
@@ -2565,6 +2593,11 @@ lodash.debounce@^4.0.8: | |
| resolved "https://registry.yarnpkg.com/lodash.debounce/-/lodash.debounce-4.0.8.tgz#82d79bff30a67c4005ffd5e2515300ad9ca4d7af" | ||
| integrity sha1-gteb/zCmfEAF/9XiUVMArZyk168= | ||
|
|
||
| lodash.get@^4.4.2: | ||
| version "4.4.2" | ||
| resolved "https://registry.yarnpkg.com/lodash.get/-/lodash.get-4.4.2.tgz#2d177f652fa31e939b4438d5341499dfa3825e99" | ||
| integrity sha512-z+Uw/vLuy6gQe8cfaFWD7p0wVv8fJl3mbzXh33RS+0oW2wvUqiRXiQ69gLWSLpgB5/6sU+r6BlQR0MBILadqTQ== | ||
|
|
||
| lodash.truncate@^4.4.2: | ||
| version "4.4.2" | ||
| resolved "https://registry.yarnpkg.com/lodash.truncate/-/lodash.truncate-4.4.2.tgz#5a350da0b1113b837ecfffd5812cbe58d6eae193" | ||
|
|
@@ -3614,6 +3647,17 @@ signal-exit@^3.0.0: | |
| resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d" | ||
| integrity sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0= | ||
|
|
||
| sinon@^20.0.0: | ||
| version "20.0.0" | ||
| resolved "https://registry.yarnpkg.com/sinon/-/sinon-20.0.0.tgz#4b653468735f7152ba694d05498c2b5d024ab006" | ||
| integrity sha512-+FXOAbdnj94AQIxH0w1v8gzNxkawVvNqE3jUzRLptR71Oykeu2RrQXXl/VQjKay+Qnh73fDt/oDfMo6xMeDQbQ== | ||
| dependencies: | ||
| "@sinonjs/commons" "^3.0.1" | ||
| "@sinonjs/fake-timers" "^13.0.5" | ||
| "@sinonjs/samsam" "^8.0.1" | ||
| diff "^7.0.0" | ||
| supports-color "^7.2.0" | ||
|
|
||
| slash@^2.0.0: | ||
| version "2.0.0" | ||
| resolved "https://registry.yarnpkg.com/slash/-/slash-2.0.0.tgz#de552851a1759df3a8f206535442f5ec4ddeab44" | ||
|
|
@@ -3842,7 +3886,7 @@ supports-color@^5.3.0: | |
| dependencies: | ||
| has-flag "^3.0.0" | ||
|
|
||
| supports-color@^7.1.0: | ||
| supports-color@^7.1.0, supports-color@^7.2.0: | ||
| version "7.2.0" | ||
| resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-7.2.0.tgz#1b7dcdcb32b8138801b3e478ba6a51caa89648da" | ||
| integrity sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw== | ||
|
|
@@ -3990,6 +4034,16 @@ type-check@^0.4.0, type-check@~0.4.0: | |
| dependencies: | ||
| prelude-ls "^1.2.1" | ||
|
|
||
| [email protected]: | ||
| version "4.0.8" | ||
| resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.0.8.tgz#7646fb5f18871cfbb7749e69bd39a6388eb7450c" | ||
| integrity sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g== | ||
|
|
||
| type-detect@^4.1.0: | ||
| version "4.1.0" | ||
| resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.1.0.tgz#deb2453e8f08dcae7ae98c626b13dddb0155906c" | ||
| integrity sha512-Acylog8/luQ8L7il+geoSxhEkazvkslg7PSNKOX59mbB9cOveP5aq9h74Y7YU8yDpJwetzQQrfIwtf4Wp4LKcw== | ||
|
|
||
| unicode-canonical-property-names-ecmascript@^1.0.4: | ||
| version "1.0.4" | ||
| resolved "https://registry.yarnpkg.com/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-1.0.4.tgz#2619800c4c825800efdd8343af7dd9933cbe2818" | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want to avoid to use
letand re-assign.I think the scope of the let can be reduced by cutting it out to a function like createChronoDates.