Skip to content

fix: update kuromojin@3 and fix max option #11

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

Merged
merged 1 commit into from
Apr 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"rules": {
"max-ten": {
// 1文に利用できる最大の、の数
// max: 3の場合は4つ以上の読点でエラーとなる
"max": 3,
// 例外ルールを適応するかどうか,
"strict": false,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"textlint-scripts": "^3.0.0"
},
"dependencies": {
"kuromojin": "^2.1.1",
"kuromojin": "^3.0.0",
"sentence-splitter": "^3.2.0",
"structured-source": "^3.0.2",
"textlint-rule-helper": "^2.0.0",
Expand Down
6 changes: 3 additions & 3 deletions src/max-ten.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,16 @@ module.exports = function (context, options = {}) {
currentTenCount++;
lastToken = token;
}
if (surface === "。") {
if (surface === kuten) {
// reset
currentTenCount = 0;
}
// report
if (currentTenCount >= maxLen) {
if (currentTenCount > maxLen) {
const positionInSentence = source.originalIndexFromIndex(lastToken.word_position - 1);
const index = sentence.range[0] + positionInSentence;
const ruleError = new context.RuleError(
`一つの文で"${touten}"を${maxLen}つ以上使用しています`,
`一つの文で"${touten}"を${maxLen + 1}つ以上使用しています`,
{
index
}
Expand Down
52 changes: 25 additions & 27 deletions test/max-ten-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ const tester = new TextLintTester();
tester.run("max-ten", rule, {
// default max:3
valid: [
"名詞、名詞、名詞、名詞の場合は例外",
"名詞、名詞、名詞、名詞、名詞の場合は例外",
"ビスケットの主な材料は(1)小麦粉、(2)牛乳、(3)ショートニング、(4)バター、(5)砂糖である。",
"これは、TaskA、TaskB、TaskC、TaskDが処理するものです。",
{
text: textIncludeTen(3 - 1)
text: textIncludeTen(3)
},
{
text: textIncludeTen(5 - 1),
text: textIncludeTen(5),
options: {
max: 5
}
Expand All @@ -33,7 +33,7 @@ tester.run("max-ten", rule, {
}
},
{
text: `これは,これは.これは,これは.`,
text: `これは,これは.これは,これは,これは.`,
options: {
touten: ",",
kuten: "."
Expand All @@ -42,22 +42,20 @@ tester.run("max-ten", rule, {
],
invalid: [
{
text: `これは、これは、これは
、d`,
text: `これは、これは、これは、これは、これはだめ。`,
errors: [
{
message: `一つの文で"、"を3つ以上使用しています`,
line: 2,
column: 1
message: `一つの文で"、"を4つ以上使用しています`,
index: 15
}
]
},
{
text: `これは,これは,これは,これは。`,
text: `これは,これは,これは,これは,これは。`,
errors: [
{
message: `一つの文で","を3つ以上使用しています`,
index: 11
message: `一つの文で","を4つ以上使用しています`,
index: 15
}
],
options: {
Expand All @@ -66,11 +64,11 @@ tester.run("max-ten", rule, {
}
},
{
text: `これは,これは,これは。これは,これは,これは,`,
text: `これは,これは,これは。これは,これは,これは,どうですか?`,
errors: [
{
message: `一つの文で","を3つ以上使用しています`,
index: 23
message: `一つの文で","を4つ以上使用しています`,
index: 19
}
],
options: {
Expand All @@ -79,20 +77,20 @@ tester.run("max-ten", rule, {
}
},
{
text: textIncludeTen(5),
text: textIncludeTen(6),
options: {
max: 5
},
errors: [
{
message: `一つの文で"、"を5つ以上使用しています`
message: `一つの文で"、"を6つ以上使用しています`
}
]
},
{
text: `これは、長文の例ですが、columnがちゃんと計算、されてるはずです。`,
options: {
max: 3
max: 2
},
errors: [
{
Expand All @@ -103,41 +101,41 @@ tester.run("max-ten", rule, {
]
},
{
text: "間に、Str以外の`code`Nodeが、あっても、OK",
text: "間に、Str以外の`code`Nodeが、あっても、OKと、聞いています。",
options: {
max: 3
},
errors: [
{
message: `一つの文で"、"を3つ以上使用しています`,
message: `一つの文で"、"を4つ以上使用しています`,
line: 1,
column: 26
column: 30
}
]
},
{
text: `複数のセンテンスがある場合。これでも、columnが、ちゃんと計算、されているはずです。`,
text: `複数のセンテンスがある場合。これでも、columnが、ちゃんと計算、されているはず、そのためのテキストです。`,
options: {
max: 3
},
errors: [
{
message: `一つの文で"、"を3つ以上使用しています`,
message: `一つの文で"、"を4つ以上使用しています`,
line: 1,
column: 34
column: 42
}
]
},
{
text: `複数のセンテンスがあって、改行されている場合でも\n大丈夫です。これでも、lineとcolumnが、ちゃんと計算、されているはずです。`,
text: `複数のセンテンスがあって、改行されている場合でも\n大丈夫です。これでも、lineとcolumnが、ちゃんと計算、されているはず、そのためのテキストです。`,
options: {
max: 3
},
errors: [
{
message: `一つの文で"、"を3つ以上使用しています`,
message: `一つの文で"、"を4つ以上使用しています`,
line: 2,
column: 31
column: 39
}
]
}
Expand Down
34 changes: 20 additions & 14 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2706,21 +2706,22 @@ kind-of@^6.0.0, kind-of@^6.0.2:
resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-6.0.3.tgz#07c05034a6c349fa06e24fa35aa76db4580ce4dd"
integrity sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw==

[email protected].1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/kuromoji/-/kuromoji-0.1.1.tgz#4aabf39bcced8b8ad92d007a04a26be6da8477c9"
integrity sha1-Sqvzm8zti4rZLQB6BKJr5tqEd8k=
[email protected].2:
version "0.1.2"
resolved "https://registry.yarnpkg.com/kuromoji/-/kuromoji-0.1.2.tgz#293f0d6706df006112137980588d5daac26d0790"
integrity sha512-V0dUf+C2LpcPEXhoHLMAop/bOht16Dyr+mDiIE39yX3vqau7p80De/koFqpiTcL1zzdZlc3xuHZ8u5gjYRfFaQ==
dependencies:
async "^2.0.1"
doublearray "0.0.2"
zlibjs "^0.2.0"
zlibjs "^0.3.1"

kuromojin@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/kuromojin/-/kuromojin-2.1.1.tgz#5de1dbec4ffcc7cce57a10e75e751cd1ca384e38"
integrity sha512-bd5dfE9CdRBoRPiquE5uhzBrDOn2K3WuFeOWqZgM7DNtQhvS7P9IALy5MtDxXcnw7DLBAZ1A7DByPO5BhXdgew==
kuromojin@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/kuromojin/-/kuromojin-3.0.0.tgz#54a1a6643110f49f741c4beb82fef400d1cd498b"
integrity sha512-3h3qnn/NVVhqoKFP4oc7e6apO2B01Atc056oiVlIY7Uoup4rhrnBe28g3y9lK1HTmLDQEejvXB+3I3qxAneF7A==
dependencies:
kuromoji "0.1.1"
kuromoji "0.1.2"
lru_map "^0.4.1"

levn@^0.4.1:
version "0.4.1"
Expand Down Expand Up @@ -2858,6 +2859,11 @@ loud-rejection@^1.0.0:
currently-unhandled "^0.4.1"
signal-exit "^3.0.0"

lru_map@^0.4.1:
version "0.4.1"
resolved "https://registry.yarnpkg.com/lru_map/-/lru_map-0.4.1.tgz#f7b4046283c79fb7370c36f8fca6aee4324b0a98"
integrity sha512-I+lBvqMMFfqaV8CJCISjI3wbjmwVu/VyOoU7+qtu9d7ioW5klMgsTTiUOUp+DJvfTTzKXoPbyC6YfgkNcyPSOg==

make-dir@^2.0.0, make-dir@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/make-dir/-/make-dir-2.1.0.tgz#5f0310e18b8be898cc07009295a30ae41e91e6f5"
Expand Down Expand Up @@ -4690,7 +4696,7 @@ [email protected], yargs@^13.3.0:
y18n "^4.0.0"
yargs-parser "^13.1.2"

zlibjs@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/zlibjs/-/zlibjs-0.2.0.tgz#ae20f06243293d85c255563189f9b12f5b3ba1a0"
integrity sha1-riDwYkMpPYXCVVYxifmxL1s7oaA=
zlibjs@^0.3.1:
version "0.3.1"
resolved "https://registry.yarnpkg.com/zlibjs/-/zlibjs-0.3.1.tgz#50197edb28a1c42ca659cc8b4e6a9ddd6d444554"
integrity sha1-UBl+2yihxCymWcyLTmqd3W1ERVQ=