From e3de7e018d545a9a6c65a9d1fc9263ed9d0475ca Mon Sep 17 00:00:00 2001 From: azu Date: Sat, 11 Feb 2023 21:39:36 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=E3=80=8C...=E3=80=8D=E3=81=AE=E4=B8=AD?= =?UTF-8?q?=E3=81=A7=E3=81=AE=E5=8C=BA=E5=88=87=E3=82=8A=E6=96=87=E5=AD=97?= =?UTF-8?q?=E3=81=AE=E5=88=A4=E5=AE=9A=E3=81=AB=E5=8F=A5=E7=82=B9=E3=81=AE?= =?UTF-8?q?=E3=81=BF=E3=81=8C=E4=BD=BF=E3=82=8F=E3=82=8C=E3=81=84=E3=81=9F?= =?UTF-8?q?=E5=95=8F=E9=A1=8C=E3=82=92=E4=BF=AE=E6=AD=A3=20(#24)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit センテンス分解に使うと区切り文字も「...」の中の区切り文字として扱うように追加した。 - "?", // question mark - "!", // exclamation mark - "?", // (ja) zenkaku question mark - "!" // (ja) zenkaku exclamation mark --- package.json | 5 ++- src/max-ten.js | 24 +++++++++----- test/max-ten-test.js | 7 ++-- yarn.lock | 76 +++++++++++++++++++++++++++++++------------- 4 files changed, 77 insertions(+), 35 deletions(-) diff --git a/package.json b/package.json index 5da6cb9..1c6e64e 100644 --- a/package.json +++ b/package.json @@ -42,9 +42,8 @@ "dependencies": { "kuromojin": "^3.0.0", "sentence-splitter": "^3.2.0", - "structured-source": "^3.0.2", - "textlint-rule-helper": "^2.0.0", - "textlint-util-to-string": "^3.1.1" + "textlint-rule-helper": "^2.3.0", + "textlint-util-to-string": "^3.3.0" }, "prettier": { "singleQuote": false, diff --git a/src/max-ten.js b/src/max-ten.js index 8a2a2c1..b351f1d 100644 --- a/src/max-ten.js +++ b/src/max-ten.js @@ -39,6 +39,7 @@ function is括弧(token) { } return false; } + /** * 括弧などの記号的なTokenはスキップとして隣接するTokenを探す * @see https://github.com/textlint-ja/textlint-rule-max-ten/issues/12 @@ -75,6 +76,12 @@ module.exports = function (context, options = {}) { const kuten = options.kuten ?? defaultOptions.kuten; const helper = new RuleHelper(context); const { Syntax, RuleError, report, getSource } = context; + const separatorCharacters = [ + "?", // question mark + "!", // exclamation mark + "?", // (ja) zenkaku question mark + "!" // (ja) zenkaku exclamation mark + ].concat(kuten); return { [Syntax.Paragraph](node) { if (helper.isChildNode(node, [Syntax.BlockQuote])) { @@ -82,12 +89,7 @@ module.exports = function (context, options = {}) { } const resultNode = splitAST(node, { SeparatorParser: { - separatorCharacters: [ - "?", // question mark - "!", // exclamation mark - "?", // (ja) zenkaku question mark - "!" // (ja) zenkaku exclamation mark - ].concat(kuten) + separatorCharacters: separatorCharacters } }); const sentences = resultNode.children.filter((childNode) => childNode.type === SentenceSyntax.Sentence); @@ -104,7 +106,13 @@ module.exports = function (context, options = {}) { 3. check tokens */ const checkSentence = async (sentence) => { - const source = new StringSource(sentence); + const source = new StringSource(sentence, { + replacer({ node, maskValue }) { + if (node.type === Syntax.Code) { + return maskValue("_"); + } + } + }); const text = source.toString(); const tokens = await tokenize(text); let currentTenCount = 0; @@ -133,7 +141,7 @@ module.exports = function (context, options = {}) { currentTenCount++; lastToken = token; } - if (surface === kuten) { + if (separatorCharacters.includes(surface)) { // reset currentTenCount = 0; } diff --git a/test/max-ten-test.js b/test/max-ten-test.js index 464d34f..74dfb6e 100644 --- a/test/max-ten-test.js +++ b/test/max-ten-test.js @@ -42,7 +42,10 @@ tester.run("max-ten", rule, { touten: ",", kuten: "." } - } + }, + // https://github.com/textlint-ja/textlint-rule-max-ten/issues/17 + "紅ちゃんは、たたえなくなっていいって、思う? もっと大事なものがあったら、スパイになれなくてもいいって、思う?", + "「紅ちゃんは、たたえなくなっていいって、思う? もっと大事なものがあったら、スパイになれなくてもいいって、思う?」" ], invalid: [ { @@ -148,7 +151,7 @@ tester.run("max-ten", rule, { { // 3行目が、の問題 text: `このパラグラフはOKです。 - + 変数の名前は、名前のルールが決まっていて、そのルールは複雑で、たくさんのルールがあるので、箇条書きしましょう。 3つめのパラグラフはもOKです。 diff --git a/yarn.lock b/yarn.lock index 45de5a4..c884eee 100644 --- a/yarn.lock +++ b/yarn.lock @@ -913,7 +913,12 @@ readdirp "^2.2.1" upath "^1.1.1" -"@textlint/ast-node-types@^4.2.1", "@textlint/ast-node-types@^4.2.4", "@textlint/ast-node-types@^4.4.2": +"@textlint/ast-node-types@^13.0.2", "@textlint/ast-node-types@^13.0.5": + version "13.2.0" + resolved "https://registry.yarnpkg.com/@textlint/ast-node-types/-/ast-node-types-13.2.0.tgz#9210439c88bc61664f8534a19cb7794dcc2061ed" + integrity sha512-P76rGK9SoN/f40yVW2Dep3QkXQOkAYTzEZjV0yBf/W9N0c81HUDJPS//aRbS3ml0Yb7TNgkXYm/ChTsL79RcAg== + +"@textlint/ast-node-types@^4.4.2": version "4.4.2" resolved "https://registry.yarnpkg.com/@textlint/ast-node-types/-/ast-node-types-4.4.2.tgz#d3fda5c9086baba04bc75440039ccf18415c8446" integrity sha512-m5brKbI7UY/Q8sbIZ7z1KB8ls04nRILshz5fPQ4EZ04jL19qrrUHJR8A6nK3vJ/GelkDWl4I0VDYSAjLEFQV8g== @@ -1042,7 +1047,7 @@ dependencies: "@textlint/text-to-ast" "^3.3.4" -"@textlint/types@^1.1.2", "@textlint/types@^1.5.4": +"@textlint/types@^1.5.4": version "1.5.4" resolved "https://registry.yarnpkg.com/@textlint/types/-/types-1.5.4.tgz#4ebd6b052bb329810949516412ad2b285b04dc02" integrity sha512-bhSrOjW8AFSa/xf6lYZ2akE0j+4O/WEAA2S/R8RrjNMkA5Az2j57mxPNpqMhEeyHDkpzN/coIlqUwgYvcJHv1A== @@ -1059,11 +1064,6 @@ resolved "https://registry.yarnpkg.com/@types/parse-json/-/parse-json-4.0.0.tgz#2f8bb441434d163b35fb8ffdccd7138927ffb8c0" integrity sha512-//oorEZjL6sbPcKUaCdIGlIUeH26mgzimjBB77G6XRgnDl/L5wOnpyBGRe/Mmf5CVW3PwEBE1NjiMZ/ssFh4wA== -"@types/structured-source@^3.0.0": - version "3.0.0" - resolved "https://registry.yarnpkg.com/@types/structured-source/-/structured-source-3.0.0.tgz#e95d76037d400c1957f3b709f023b308e92f3829" - integrity sha512-8u+Wo5+GEXe4jZyQ8TplLp+1A7g32ZcVoE7VZu8VcxnlaEm5I/+T579R7q3qKN76jmK0lRshpo4hl4bj/kEPKA== - "@types/unist@^2.0.0", "@types/unist@^2.0.2": version "2.0.3" resolved "https://registry.yarnpkg.com/@types/unist/-/unist-2.0.3.tgz#9c088679876f374eb5983f150d4787aa6fb32d7e" @@ -1301,6 +1301,11 @@ boundary@^1.0.1: resolved "https://registry.yarnpkg.com/boundary/-/boundary-1.0.1.tgz#4d67dc2602c0cc16dd9bce7ebf87e948290f5812" integrity sha1-TWfcJgLAzBbdm85+v4fpSCkPWBI= +boundary@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/boundary/-/boundary-2.0.0.tgz#169c8b1f0d44cf2c25938967a328f37e0a4e5efc" + integrity sha512-rJKn5ooC9u8q13IMCrW0RSp31pxBCHE3y9V/tp3TdWSLf8Em3p6Di4NBpfzbJge9YjjFEsD0RtFEjtvHL5VyEA== + brace-expansion@^1.1.7: version "1.1.11" resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd" @@ -4138,6 +4143,13 @@ structured-source@^3.0.2: dependencies: boundary "^1.0.1" +structured-source@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/structured-source/-/structured-source-4.0.0.tgz#0c9e59ee43dedd8fc60a63731f60e358102a4948" + integrity sha512-qGzRFNJDjFieQkl/sVOI2dUjHKRyL9dAJi2gCPGJLbJHBIkyOHxjuocpIEfbLioX+qSJpvbYdT49/YCdMznKxA== + dependencies: + boundary "^2.0.0" + supports-color@6.0.0: version "6.0.0" resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-6.0.0.tgz#76cfe742cf1f41bb9b1c29ad03068c05b4c0e40a" @@ -4181,15 +4193,14 @@ text-table@^0.2.0: resolved "https://registry.yarnpkg.com/text-table/-/text-table-0.2.0.tgz#7f5ee823ae805207c00af2df4a84ec3fcfa570b4" integrity sha1-f17oI66AUgfACvLfSoTsP8+lcLQ= -textlint-rule-helper@^2.0.0: - version "2.1.1" - resolved "https://registry.yarnpkg.com/textlint-rule-helper/-/textlint-rule-helper-2.1.1.tgz#d572588685359134bc779939b217e61f087dab0f" - integrity sha512-6fxgHzoJVkjl3LaC1b2Egi+5wbhG4i0pU0knJmQujVhxIJ3D3AcQQZPs457xKAi5xKz1WayYeTeJ5jrD/hnO7g== +textlint-rule-helper@^2.3.0: + version "2.3.0" + resolved "https://registry.yarnpkg.com/textlint-rule-helper/-/textlint-rule-helper-2.3.0.tgz#5ab84db686d42fd2e39a63b40310501bb336520d" + integrity sha512-Ug78Saahb/qVImttL0NSFyT5/JJ5wXvOPepR2pYAjNi54BsQAAz/hAyyEgKuYeR0+yjFb0KPhby4f880X5vqHA== dependencies: - "@textlint/ast-node-types" "^4.2.1" - "@textlint/types" "^1.1.2" - structured-source "^3.0.2" - unist-util-visit "^1.1.0" + "@textlint/ast-node-types" "^13.0.2" + structured-source "^4.0.0" + unist-util-visit "^2.0.3" textlint-scripts@^3.0.0: version "3.0.0" @@ -4217,15 +4228,14 @@ textlint-tester@^5.1.10: "@textlint/kernel" "^3.4.4" textlint "^11.9.0" -textlint-util-to-string@^3.1.1: - version "3.1.1" - resolved "https://registry.yarnpkg.com/textlint-util-to-string/-/textlint-util-to-string-3.1.1.tgz#666c8b0f2e00a92b29c8b168b453a9b8aeb48381" - integrity sha512-mHE7/pDw/Hk+Q6YdSMNRrZPl5bCuWnFLbF+bxW+MsWQ64dw+Ia9irkammYbH5I0hVMMcfwb0MQc5nbsjqgWeyQ== +textlint-util-to-string@^3.3.0: + version "3.3.0" + resolved "https://registry.yarnpkg.com/textlint-util-to-string/-/textlint-util-to-string-3.3.0.tgz#712fac187edff54e0650ef1a7469db8d5b7c9186" + integrity sha512-HGPpecnYkVkNB5k1NxhzA8nV1T9/ksUj6XK/81U2kb5d1PhPYiGFyikNPI9SxAF7AkrhlQ9mrBgJqy1Q0y4bhA== dependencies: - "@textlint/ast-node-types" "^4.2.4" - "@types/structured-source" "^3.0.0" + "@textlint/ast-node-types" "^13.0.5" rehype-parse "^6.0.1" - structured-source "^3.0.2" + structured-source "^4.0.0" unified "^8.4.0" textlint@^11.9.0: @@ -4441,6 +4451,11 @@ unist-util-is@^3.0.0: resolved "https://registry.yarnpkg.com/unist-util-is/-/unist-util-is-3.0.0.tgz#d9e84381c2468e82629e4a5be9d7d05a2dd324cd" integrity sha512-sVZZX3+kspVNmLWBPAB6r+7D9ZgAFPNWm66f7YNb420RlQSbn+n8rG8dGZSkrER7ZIXGQYNm5pqC3v3HopH24A== +unist-util-is@^4.0.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/unist-util-is/-/unist-util-is-4.1.0.tgz#976e5f462a7a5de73d94b706bac1b90671b57797" + integrity sha512-ZOQSsnce92GrxSqlnEEseX0gi7GH9zTJZ0p9dtu87WRb/37mMPO2Ilx1s/t9vBHrFhbgweUwb+t7cIn5dxPhZg== + unist-util-remove-position@^1.0.0: version "1.1.4" resolved "https://registry.yarnpkg.com/unist-util-remove-position/-/unist-util-remove-position-1.1.4.tgz#ec037348b6102c897703eee6d0294ca4755a2020" @@ -4467,6 +4482,14 @@ unist-util-visit-parents@^2.0.0: dependencies: unist-util-is "^3.0.0" +unist-util-visit-parents@^3.0.0: + version "3.1.1" + resolved "https://registry.yarnpkg.com/unist-util-visit-parents/-/unist-util-visit-parents-3.1.1.tgz#65a6ce698f78a6b0f56aa0e88f13801886cdaef6" + integrity sha512-1KROIZWo6bcMrZEwiH2UrXDyalAa0uqzWCxCJj6lPOvTve2WkfgCytoDTPaMnodXh1WrXOq0haVYHj99ynJlsg== + dependencies: + "@types/unist" "^2.0.0" + unist-util-is "^4.0.0" + unist-util-visit@^1.1.0: version "1.4.1" resolved "https://registry.yarnpkg.com/unist-util-visit/-/unist-util-visit-1.4.1.tgz#4724aaa8486e6ee6e26d7ff3c8685960d560b1e3" @@ -4474,6 +4497,15 @@ unist-util-visit@^1.1.0: dependencies: unist-util-visit-parents "^2.0.0" +unist-util-visit@^2.0.3: + version "2.0.3" + resolved "https://registry.yarnpkg.com/unist-util-visit/-/unist-util-visit-2.0.3.tgz#c3703893146df47203bb8a9795af47d7b971208c" + integrity sha512-iJ4/RczbJMkD0712mGktuGpm/U4By4FfDonL7N/9tATGIF4imikjOuagyMY53tnZq3NP6BcmlrHhEKAfGWjh7Q== + dependencies: + "@types/unist" "^2.0.0" + unist-util-is "^4.0.0" + unist-util-visit-parents "^3.0.0" + unset-value@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/unset-value/-/unset-value-1.0.0.tgz#8376873f7d2335179ffb1e6fc3a8ed0dfc8ab559"