Skip to content

Commit e3de7e0

Browse files
authored
fix: 「...」の中での区切り文字の判定に句点のみが使われいた問題を修正 (#24)
センテンス分解に使うと区切り文字も「...」の中の区切り文字として扱うように追加した。 - "?", // question mark - "!", // exclamation mark - "?", // (ja) zenkaku question mark - "!" // (ja) zenkaku exclamation mark
1 parent 08992d7 commit e3de7e0

File tree

4 files changed

+77
-35
lines changed

4 files changed

+77
-35
lines changed

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,8 @@
4242
"dependencies": {
4343
"kuromojin": "^3.0.0",
4444
"sentence-splitter": "^3.2.0",
45-
"structured-source": "^3.0.2",
46-
"textlint-rule-helper": "^2.0.0",
47-
"textlint-util-to-string": "^3.1.1"
45+
"textlint-rule-helper": "^2.3.0",
46+
"textlint-util-to-string": "^3.3.0"
4847
},
4948
"prettier": {
5049
"singleQuote": false,

src/max-ten.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ function is括弧(token) {
3939
}
4040
return false;
4141
}
42+
4243
/**
4344
* 括弧などの記号的なTokenはスキップとして隣接するTokenを探す
4445
* @see https://github.com/textlint-ja/textlint-rule-max-ten/issues/12
@@ -75,19 +76,20 @@ module.exports = function (context, options = {}) {
7576
const kuten = options.kuten ?? defaultOptions.kuten;
7677
const helper = new RuleHelper(context);
7778
const { Syntax, RuleError, report, getSource } = context;
79+
const separatorCharacters = [
80+
"?", // question mark
81+
"!", // exclamation mark
82+
"?", // (ja) zenkaku question mark
83+
"!" // (ja) zenkaku exclamation mark
84+
].concat(kuten);
7885
return {
7986
[Syntax.Paragraph](node) {
8087
if (helper.isChildNode(node, [Syntax.BlockQuote])) {
8188
return;
8289
}
8390
const resultNode = splitAST(node, {
8491
SeparatorParser: {
85-
separatorCharacters: [
86-
"?", // question mark
87-
"!", // exclamation mark
88-
"?", // (ja) zenkaku question mark
89-
"!" // (ja) zenkaku exclamation mark
90-
].concat(kuten)
92+
separatorCharacters: separatorCharacters
9193
}
9294
});
9395
const sentences = resultNode.children.filter((childNode) => childNode.type === SentenceSyntax.Sentence);
@@ -104,7 +106,13 @@ module.exports = function (context, options = {}) {
104106
3. check tokens
105107
*/
106108
const checkSentence = async (sentence) => {
107-
const source = new StringSource(sentence);
109+
const source = new StringSource(sentence, {
110+
replacer({ node, maskValue }) {
111+
if (node.type === Syntax.Code) {
112+
return maskValue("_");
113+
}
114+
}
115+
});
108116
const text = source.toString();
109117
const tokens = await tokenize(text);
110118
let currentTenCount = 0;
@@ -133,7 +141,7 @@ module.exports = function (context, options = {}) {
133141
currentTenCount++;
134142
lastToken = token;
135143
}
136-
if (surface === kuten) {
144+
if (separatorCharacters.includes(surface)) {
137145
// reset
138146
currentTenCount = 0;
139147
}

test/max-ten-test.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ tester.run("max-ten", rule, {
4242
touten: ",",
4343
kuten: "."
4444
}
45-
}
45+
},
46+
// https://github.com/textlint-ja/textlint-rule-max-ten/issues/17
47+
"紅ちゃんは、たたえなくなっていいって、思う? もっと大事なものがあったら、スパイになれなくてもいいって、思う?",
48+
"「紅ちゃんは、たたえなくなっていいって、思う? もっと大事なものがあったら、スパイになれなくてもいいって、思う?」"
4649
],
4750
invalid: [
4851
{
@@ -148,7 +151,7 @@ tester.run("max-ten", rule, {
148151
{
149152
// 3行目が、の問題
150153
text: `このパラグラフはOKです。
151-
154+
152155
変数の名前は、名前のルールが決まっていて、そのルールは複雑で、たくさんのルールがあるので、箇条書きしましょう。
153156
154157
3つめのパラグラフはもOKです。

yarn.lock

Lines changed: 54 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,12 @@
913913
readdirp "^2.2.1"
914914
upath "^1.1.1"
915915

916-
"@textlint/ast-node-types@^4.2.1", "@textlint/ast-node-types@^4.2.4", "@textlint/ast-node-types@^4.4.2":
916+
"@textlint/ast-node-types@^13.0.2", "@textlint/ast-node-types@^13.0.5":
917+
version "13.2.0"
918+
resolved "https://registry.yarnpkg.com/@textlint/ast-node-types/-/ast-node-types-13.2.0.tgz#9210439c88bc61664f8534a19cb7794dcc2061ed"
919+
integrity sha512-P76rGK9SoN/f40yVW2Dep3QkXQOkAYTzEZjV0yBf/W9N0c81HUDJPS//aRbS3ml0Yb7TNgkXYm/ChTsL79RcAg==
920+
921+
"@textlint/ast-node-types@^4.4.2":
917922
version "4.4.2"
918923
resolved "https://registry.yarnpkg.com/@textlint/ast-node-types/-/ast-node-types-4.4.2.tgz#d3fda5c9086baba04bc75440039ccf18415c8446"
919924
integrity sha512-m5brKbI7UY/Q8sbIZ7z1KB8ls04nRILshz5fPQ4EZ04jL19qrrUHJR8A6nK3vJ/GelkDWl4I0VDYSAjLEFQV8g==
@@ -1042,7 +1047,7 @@
10421047
dependencies:
10431048
"@textlint/text-to-ast" "^3.3.4"
10441049

1045-
"@textlint/types@^1.1.2", "@textlint/types@^1.5.4":
1050+
"@textlint/types@^1.5.4":
10461051
version "1.5.4"
10471052
resolved "https://registry.yarnpkg.com/@textlint/types/-/types-1.5.4.tgz#4ebd6b052bb329810949516412ad2b285b04dc02"
10481053
integrity sha512-bhSrOjW8AFSa/xf6lYZ2akE0j+4O/WEAA2S/R8RrjNMkA5Az2j57mxPNpqMhEeyHDkpzN/coIlqUwgYvcJHv1A==
@@ -1059,11 +1064,6 @@
10591064
resolved "https://registry.yarnpkg.com/@types/parse-json/-/parse-json-4.0.0.tgz#2f8bb441434d163b35fb8ffdccd7138927ffb8c0"
10601065
integrity sha512-//oorEZjL6sbPcKUaCdIGlIUeH26mgzimjBB77G6XRgnDl/L5wOnpyBGRe/Mmf5CVW3PwEBE1NjiMZ/ssFh4wA==
10611066

1062-
"@types/structured-source@^3.0.0":
1063-
version "3.0.0"
1064-
resolved "https://registry.yarnpkg.com/@types/structured-source/-/structured-source-3.0.0.tgz#e95d76037d400c1957f3b709f023b308e92f3829"
1065-
integrity sha512-8u+Wo5+GEXe4jZyQ8TplLp+1A7g32ZcVoE7VZu8VcxnlaEm5I/+T579R7q3qKN76jmK0lRshpo4hl4bj/kEPKA==
1066-
10671067
"@types/unist@^2.0.0", "@types/unist@^2.0.2":
10681068
version "2.0.3"
10691069
resolved "https://registry.yarnpkg.com/@types/unist/-/unist-2.0.3.tgz#9c088679876f374eb5983f150d4787aa6fb32d7e"
@@ -1301,6 +1301,11 @@ boundary@^1.0.1:
13011301
resolved "https://registry.yarnpkg.com/boundary/-/boundary-1.0.1.tgz#4d67dc2602c0cc16dd9bce7ebf87e948290f5812"
13021302
integrity sha1-TWfcJgLAzBbdm85+v4fpSCkPWBI=
13031303

1304+
boundary@^2.0.0:
1305+
version "2.0.0"
1306+
resolved "https://registry.yarnpkg.com/boundary/-/boundary-2.0.0.tgz#169c8b1f0d44cf2c25938967a328f37e0a4e5efc"
1307+
integrity sha512-rJKn5ooC9u8q13IMCrW0RSp31pxBCHE3y9V/tp3TdWSLf8Em3p6Di4NBpfzbJge9YjjFEsD0RtFEjtvHL5VyEA==
1308+
13041309
brace-expansion@^1.1.7:
13051310
version "1.1.11"
13061311
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd"
@@ -4138,6 +4143,13 @@ structured-source@^3.0.2:
41384143
dependencies:
41394144
boundary "^1.0.1"
41404145

4146+
structured-source@^4.0.0:
4147+
version "4.0.0"
4148+
resolved "https://registry.yarnpkg.com/structured-source/-/structured-source-4.0.0.tgz#0c9e59ee43dedd8fc60a63731f60e358102a4948"
4149+
integrity sha512-qGzRFNJDjFieQkl/sVOI2dUjHKRyL9dAJi2gCPGJLbJHBIkyOHxjuocpIEfbLioX+qSJpvbYdT49/YCdMznKxA==
4150+
dependencies:
4151+
boundary "^2.0.0"
4152+
41414153
41424154
version "6.0.0"
41434155
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-6.0.0.tgz#76cfe742cf1f41bb9b1c29ad03068c05b4c0e40a"
@@ -4181,15 +4193,14 @@ text-table@^0.2.0:
41814193
resolved "https://registry.yarnpkg.com/text-table/-/text-table-0.2.0.tgz#7f5ee823ae805207c00af2df4a84ec3fcfa570b4"
41824194
integrity sha1-f17oI66AUgfACvLfSoTsP8+lcLQ=
41834195

4184-
textlint-rule-helper@^2.0.0:
4185-
version "2.1.1"
4186-
resolved "https://registry.yarnpkg.com/textlint-rule-helper/-/textlint-rule-helper-2.1.1.tgz#d572588685359134bc779939b217e61f087dab0f"
4187-
integrity sha512-6fxgHzoJVkjl3LaC1b2Egi+5wbhG4i0pU0knJmQujVhxIJ3D3AcQQZPs457xKAi5xKz1WayYeTeJ5jrD/hnO7g==
4196+
textlint-rule-helper@^2.3.0:
4197+
version "2.3.0"
4198+
resolved "https://registry.yarnpkg.com/textlint-rule-helper/-/textlint-rule-helper-2.3.0.tgz#5ab84db686d42fd2e39a63b40310501bb336520d"
4199+
integrity sha512-Ug78Saahb/qVImttL0NSFyT5/JJ5wXvOPepR2pYAjNi54BsQAAz/hAyyEgKuYeR0+yjFb0KPhby4f880X5vqHA==
41884200
dependencies:
4189-
"@textlint/ast-node-types" "^4.2.1"
4190-
"@textlint/types" "^1.1.2"
4191-
structured-source "^3.0.2"
4192-
unist-util-visit "^1.1.0"
4201+
"@textlint/ast-node-types" "^13.0.2"
4202+
structured-source "^4.0.0"
4203+
unist-util-visit "^2.0.3"
41934204

41944205
textlint-scripts@^3.0.0:
41954206
version "3.0.0"
@@ -4217,15 +4228,14 @@ textlint-tester@^5.1.10:
42174228
"@textlint/kernel" "^3.4.4"
42184229
textlint "^11.9.0"
42194230

4220-
textlint-util-to-string@^3.1.1:
4221-
version "3.1.1"
4222-
resolved "https://registry.yarnpkg.com/textlint-util-to-string/-/textlint-util-to-string-3.1.1.tgz#666c8b0f2e00a92b29c8b168b453a9b8aeb48381"
4223-
integrity sha512-mHE7/pDw/Hk+Q6YdSMNRrZPl5bCuWnFLbF+bxW+MsWQ64dw+Ia9irkammYbH5I0hVMMcfwb0MQc5nbsjqgWeyQ==
4231+
textlint-util-to-string@^3.3.0:
4232+
version "3.3.0"
4233+
resolved "https://registry.yarnpkg.com/textlint-util-to-string/-/textlint-util-to-string-3.3.0.tgz#712fac187edff54e0650ef1a7469db8d5b7c9186"
4234+
integrity sha512-HGPpecnYkVkNB5k1NxhzA8nV1T9/ksUj6XK/81U2kb5d1PhPYiGFyikNPI9SxAF7AkrhlQ9mrBgJqy1Q0y4bhA==
42244235
dependencies:
4225-
"@textlint/ast-node-types" "^4.2.4"
4226-
"@types/structured-source" "^3.0.0"
4236+
"@textlint/ast-node-types" "^13.0.5"
42274237
rehype-parse "^6.0.1"
4228-
structured-source "^3.0.2"
4238+
structured-source "^4.0.0"
42294239
unified "^8.4.0"
42304240

42314241
textlint@^11.9.0:
@@ -4441,6 +4451,11 @@ unist-util-is@^3.0.0:
44414451
resolved "https://registry.yarnpkg.com/unist-util-is/-/unist-util-is-3.0.0.tgz#d9e84381c2468e82629e4a5be9d7d05a2dd324cd"
44424452
integrity sha512-sVZZX3+kspVNmLWBPAB6r+7D9ZgAFPNWm66f7YNb420RlQSbn+n8rG8dGZSkrER7ZIXGQYNm5pqC3v3HopH24A==
44434453

4454+
unist-util-is@^4.0.0:
4455+
version "4.1.0"
4456+
resolved "https://registry.yarnpkg.com/unist-util-is/-/unist-util-is-4.1.0.tgz#976e5f462a7a5de73d94b706bac1b90671b57797"
4457+
integrity sha512-ZOQSsnce92GrxSqlnEEseX0gi7GH9zTJZ0p9dtu87WRb/37mMPO2Ilx1s/t9vBHrFhbgweUwb+t7cIn5dxPhZg==
4458+
44444459
unist-util-remove-position@^1.0.0:
44454460
version "1.1.4"
44464461
resolved "https://registry.yarnpkg.com/unist-util-remove-position/-/unist-util-remove-position-1.1.4.tgz#ec037348b6102c897703eee6d0294ca4755a2020"
@@ -4467,13 +4482,30 @@ unist-util-visit-parents@^2.0.0:
44674482
dependencies:
44684483
unist-util-is "^3.0.0"
44694484

4485+
unist-util-visit-parents@^3.0.0:
4486+
version "3.1.1"
4487+
resolved "https://registry.yarnpkg.com/unist-util-visit-parents/-/unist-util-visit-parents-3.1.1.tgz#65a6ce698f78a6b0f56aa0e88f13801886cdaef6"
4488+
integrity sha512-1KROIZWo6bcMrZEwiH2UrXDyalAa0uqzWCxCJj6lPOvTve2WkfgCytoDTPaMnodXh1WrXOq0haVYHj99ynJlsg==
4489+
dependencies:
4490+
"@types/unist" "^2.0.0"
4491+
unist-util-is "^4.0.0"
4492+
44704493
unist-util-visit@^1.1.0:
44714494
version "1.4.1"
44724495
resolved "https://registry.yarnpkg.com/unist-util-visit/-/unist-util-visit-1.4.1.tgz#4724aaa8486e6ee6e26d7ff3c8685960d560b1e3"
44734496
integrity sha512-AvGNk7Bb//EmJZyhtRUnNMEpId/AZ5Ph/KUpTI09WHQuDZHKovQ1oEv3mfmKpWKtoMzyMC4GLBm1Zy5k12fjIw==
44744497
dependencies:
44754498
unist-util-visit-parents "^2.0.0"
44764499

4500+
unist-util-visit@^2.0.3:
4501+
version "2.0.3"
4502+
resolved "https://registry.yarnpkg.com/unist-util-visit/-/unist-util-visit-2.0.3.tgz#c3703893146df47203bb8a9795af47d7b971208c"
4503+
integrity sha512-iJ4/RczbJMkD0712mGktuGpm/U4By4FfDonL7N/9tATGIF4imikjOuagyMY53tnZq3NP6BcmlrHhEKAfGWjh7Q==
4504+
dependencies:
4505+
"@types/unist" "^2.0.0"
4506+
unist-util-is "^4.0.0"
4507+
unist-util-visit-parents "^3.0.0"
4508+
44774509
unset-value@^1.0.0:
44784510
version "1.0.0"
44794511
resolved "https://registry.yarnpkg.com/unset-value/-/unset-value-1.0.0.tgz#8376873f7d2335179ffb1e6fc3a8ed0dfc8ab559"

0 commit comments

Comments
 (0)