Skip to content

Commit 9834912

Browse files
authored
fix(deps): update to kuromojin@3 (#35)
* fix(deps): update to kuromojin@3 * CI: Move to GitHub Actions * style: apply prettier
1 parent eaef736 commit 9834912

File tree

8 files changed

+1621
-1530
lines changed

8 files changed

+1621
-1530
lines changed

.github/workflows/test.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: test
2+
on: [push, pull_request]
3+
jobs:
4+
test:
5+
name: "Test on Node.js ${{ matrix.node-version }}"
6+
runs-on: ubuntu-latest
7+
strategy:
8+
matrix:
9+
node-version: [12, 14]
10+
steps:
11+
- name: checkout
12+
uses: actions/checkout@v2
13+
- name: setup Node.js ${{ matrix.node-version }}
14+
uses: actions/setup-node@v2
15+
with:
16+
node-version: ${{ matrix.node-version }}
17+
- name: Install
18+
run: yarn install
19+
- name: Test
20+
run: yarn test

.travis.yml

Lines changed: 0 additions & 3 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# textlint-rule-no-doubled-joshi [![Build Status](https://travis-ci.org/textlint-ja/textlint-rule-no-doubled-joshi.svg?branch=master)](https://travis-ci.org/textlint-ja/textlint-rule-no-doubled-joshi)
1+
# textlint-rule-no-doubled-joshi [![Actions Status: test](https://github.com/textlint-ja/textlint-rule-no-doubled-joshi/workflows/test/badge.svg)](https://github.com/textlint-ja/textlint-rule-no-doubled-joshi/actions?query=workflow%3A"test")
22

33
1つの文中に同じ助詞が連続して出てくるのをチェックする[textlint](https://github.com/textlint/textlint)ルールです。
44

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,18 @@
3434
"textlintrule"
3535
],
3636
"devDependencies": {
37-
"@textlint/types": "^1.2.3",
38-
"@types/node": "^12.12.14",
37+
"@textlint/types": "^1.5.4",
38+
"@types/node": "^14.14.41",
3939
"husky": "^3.1.0",
40-
"lint-staged": "^9.5.0",
41-
"prettier": "^1.19.1",
40+
"lint-staged": "^10.5.4",
41+
"prettier": "^2.2.1",
4242
"textlint-scripts": "^3.0.0",
43-
"ts-node": "^8.5.4",
44-
"typescript": "^3.7.3"
43+
"ts-node": "^9.1.1",
44+
"typescript": "^4.2.4"
4545
},
4646
"dependencies": {
47-
"kuromojin": "^2.0.0",
48-
"sentence-splitter": "^3.2.0",
47+
"kuromojin": "^3.0.0",
48+
"sentence-splitter": "^3.2.1",
4949
"textlint-rule-helper": "^2.1.1",
5050
"textlint-util-to-string": "^3.0.0"
5151
},

src/no-doubled-joshi.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import {
88
create読点Matcher,
99
concatJoishiTokens,
1010
createKeyFromKey,
11-
restoreToSurfaceFromKey, is括弧Token
11+
restoreToSurfaceFromKey,
12+
is括弧Token,
1213
} from "./token-utils";
1314
import { TxtNode } from "@textlint/ast-node-types";
1415
import { TextlintRuleModule } from "@textlint/types";
@@ -71,12 +72,12 @@ const defaultOptions = {
7172
"?", // question mark
7273
"!", // exclamation mark
7374
"?", // (ja) zenkaku question mark
74-
"!" // (ja) zenkaku exclamation mark
75+
"!", // (ja) zenkaku exclamation mark
7576
],
7677
commaCharacters: [
7778
"、",
78-
"," // 全角カンマ
79-
]
79+
",", // 全角カンマ
80+
],
8081
};
8182

8283
export interface Options {
@@ -124,7 +125,7 @@ const report: TextlintRuleModule<Options> = function (context, options = {}) {
124125
const allow = options.allow || defaultOptions.allow;
125126
const separatorCharacters = options.separatorCharacters || defaultOptions.separatorCharacters;
126127
const commaCharacters = options.commaCharacters || defaultOptions.commaCharacters;
127-
const {Syntax, report, RuleError} = context;
128+
const { Syntax, report, RuleError } = context;
128129
const is読点Token = create読点Matcher(commaCharacters);
129130
return {
130131
[Syntax.Paragraph](node) {
@@ -136,8 +137,8 @@ const report: TextlintRuleModule<Options> = function (context, options = {}) {
136137
};
137138
const txtParentNode = splitSentences(node, {
138139
SeparatorParser: {
139-
separatorCharacters
140-
}
140+
separatorCharacters,
141+
},
141142
});
142143
const sentences = txtParentNode.children.filter(isSentenceNode);
143144
return getTokenizer().then((tokenizer: any) => {
@@ -150,7 +151,7 @@ const report: TextlintRuleModule<Options> = function (context, options = {}) {
150151
// 連語(助詞)の対応
151152
// http://www.weblio.jp/parts-of-speech/%E9%80%A3%E8%AA%9E(%E5%8A%A9%E8%A9%9E)_1
152153
const concatTokens = concatJoishiTokens(tokens);
153-
const countableTokens = concatTokens.filter(token => {
154+
const countableTokens = concatTokens.filter((token) => {
154155
if (isStrict) {
155156
return is助詞Token(token);
156157
}
@@ -178,7 +179,7 @@ const report: TextlintRuleModule<Options> = function (context, options = {}) {
178179
"で:助詞.係助詞": [tokenB, tokenD, tokenF]
179180
}
180181
*/
181-
Object.keys(joshiTokenSurfaceKeyMap).forEach(key => {
182+
Object.keys(joshiTokenSurfaceKeyMap).forEach((key) => {
182183
const tokens: KuromojiToken[] = joshiTokenSurfaceKeyMap[key];
183184
const joshiName = restoreToSurfaceFromKey(key);
184185
// check allow
@@ -209,7 +210,7 @@ const report: TextlintRuleModule<Options> = function (context, options = {}) {
209210
new RuleError(
210211
`一文に二回以上利用されている助詞 "${joshiName}" がみつかりました。`,
211212
{
212-
index: originalIndex
213+
index: originalIndex,
213214
}
214215
)
215216
);
@@ -218,9 +219,9 @@ const report: TextlintRuleModule<Options> = function (context, options = {}) {
218219
});
219220
});
220221
};
221-
sentences.forEach(node => checkSentence(node));
222+
sentences.forEach((node) => checkSentence(node));
222223
});
223-
}
224+
},
224225
};
225226
};
226227
export default report;

src/token-utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ export const is助詞Token = (token: KuromojiToken) => {
1010
};
1111

1212
export const is括弧Token = (token: KuromojiToken) => {
13-
return token && token.pos === "記号" && (token.pos_detail_1 === "括弧開" || token.pos_detail_1 === "括弧閉")
14-
}
13+
return token && token.pos === "記号" && (token.pos_detail_1 === "括弧開" || token.pos_detail_1 === "括弧閉");
14+
};
1515

1616
/**
1717
* 読点を判定する関数を返す
@@ -48,7 +48,7 @@ const concatToken = (aToken: KuromojiToken, bToken: KuromojiToken) => {
4848
*/
4949
export const concatJoishiTokens = (tokens: KuromojiToken[]) => {
5050
const newTokens: KuromojiToken[] = [];
51-
tokens.forEach(token => {
51+
tokens.forEach((token) => {
5252
const prevToken = newTokens[newTokens.length - 1];
5353
if (is助詞Token(token) && is助詞Token(prevToken)) {
5454
newTokens[newTokens.length - 1] = concatToken(prevToken, token);

test/no-doubled-joshi-test.ts

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,18 @@ tester.run("no-double-joshi", rule, {
4040
// "プロパティを削除しようとするとエラーが発生します。",
4141
{
4242
text: "太字も強調も同じように無視されます。",
43-
options: {allow: ["も"]}
43+
options: { allow: ["も"] },
4444
},
4545
// 区切り文字をカスタムする
4646
// ♪を区切り文字としたので、次の文は2つのセンテンスになる
4747
{
4848
text: "これはペンです♪これは鉛筆です♪",
49-
options: {separatorCharacters: ["♪"]}
49+
options: { separatorCharacters: ["♪"] },
5050
},
5151
// ,を読点とみなす
5252
{
5353
text: "これがiPhone,これがAndroidです。",
54-
options: {commaCharacters: [","]}
54+
options: { commaCharacters: [","] },
5555
},
5656
],
5757
invalid: [
@@ -63,116 +63,116 @@ tester.run("no-double-joshi", rule, {
6363
message: `一文に二回以上利用されている助詞 "は" がみつかりました。`,
6464
// last match
6565
line: 1,
66-
column: 4
67-
}
68-
]
66+
column: 4,
67+
},
68+
],
6969
},
7070
{
7171
text: "材料不足で代替素材で製品を作った。",
7272
errors: [
7373
{
7474
message: `一文に二回以上利用されている助詞 "で" がみつかりました。`,
7575
line: 1,
76-
column: 10
77-
}
78-
]
76+
column: 10,
77+
},
78+
],
7979
},
8080
{
8181
text: "クォートで囲むことで文字列を作成できる点は、他の文字列リテラルと同じです。",
8282
errors: [
8383
{
8484
message: `一文に二回以上利用されている助詞 "で" がみつかりました。`,
85-
index: 9
86-
}
87-
]
85+
index: 9,
86+
},
87+
],
8888
},
8989
{
9090
text: "列車事故でバスで振り替え輸送を行った。 ",
9191
errors: [
9292
{
9393
message: `一文に二回以上利用されている助詞 "で" がみつかりました。`,
9494
line: 1,
95-
column: 8
96-
}
97-
]
95+
column: 8,
96+
},
97+
],
9898
},
9999
{
100100
text: "洋服をドラム式洗濯機でお湯と洗剤で洗い、乾燥機で素早く乾燥させる。",
101101
options: {
102-
min_interval: 2
102+
min_interval: 2,
103103
},
104104
errors: [
105105
{
106106
message: `一文に二回以上利用されている助詞 "で" がみつかりました。`,
107107
line: 1,
108-
column: 17
108+
column: 17,
109109
},
110110
{
111111
message: `一文に二回以上利用されている助詞 "で" がみつかりました。`,
112112
line: 1,
113-
column: 24
114-
}
115-
]
113+
column: 24,
114+
},
115+
],
116116
},
117117
{
118118
text: "法律案は十三日の衆議院本会議で賛成多数で可決され、参議院に送付されます",
119119
errors: [
120120
{
121121
message: `一文に二回以上利用されている助詞 "で" がみつかりました。`,
122122
line: 1,
123-
column: 20
124-
}
125-
]
123+
column: 20,
124+
},
125+
],
126126
},
127127
{
128128
// 、 で間隔値が+1されるが、strictでは+されない
129129
text: "彼女は困り切った表情で、小声で尋ねた。",
130130
options: {
131-
strict: true
131+
strict: true,
132132
},
133133
errors: [
134134
{
135135
message: `一文に二回以上利用されている助詞 "で" がみつかりました。`,
136136
line: 1,
137-
column: 15
138-
}
139-
]
137+
column: 15,
138+
},
139+
],
140140
},
141141
{
142142
text: "白装束で重力のない足どりでやってくる",
143143
options: {
144-
min_interval: 2
144+
min_interval: 2,
145145
},
146146
errors: [
147147
{
148148
message: `一文に二回以上利用されている助詞 "で" がみつかりました。`,
149149
line: 1,
150-
column: 13
151-
}
152-
]
150+
column: 13,
151+
},
152+
],
153153
},
154154
{
155155
text: "既存のコードの利用",
156156
options: {
157-
strict: true
157+
strict: true,
158158
},
159159
errors: [
160160
{
161161
message: `一文に二回以上利用されている助詞 "の" がみつかりました。`,
162162
line: 1,
163-
column: 7
164-
}
165-
]
163+
column: 7,
164+
},
165+
],
166166
},
167167
{
168168
text: "これは`obj.method`は何をしているかを示します。",
169169
errors: [
170170
{
171171
message: `一文に二回以上利用されている助詞 "は" がみつかりました。`,
172172
line: 1,
173-
column: 16
174-
}
175-
]
173+
column: 16,
174+
},
175+
],
176176
},
177177
{
178178
// に + は と に + は
@@ -182,9 +182,9 @@ tester.run("no-double-joshi", rule, {
182182
{
183183
message: `一文に二回以上利用されている助詞 "には" がみつかりました。`,
184184
line: 1,
185-
column: 8
186-
}
187-
]
185+
column: 8,
186+
},
187+
],
188188
},
189189
//
190190
{
@@ -197,32 +197,32 @@ tester.run("no-double-joshi", rule, {
197197
errors: [
198198
{
199199
message: `一文に二回以上利用されている助詞 "は" がみつかりました。`,
200-
index: 19
201-
}
202-
]
200+
index: 19,
201+
},
202+
],
203203
},
204204
// オプションで、全角ピリオドを読点として認識させなくする
205205
// 次のtextは1つのセンテンスとして認識されるので、"は"が重複する
206206
{
207207
text: "これはペンです.これは鉛筆です.",
208-
options: {separatorCharacters: ["。"]},
208+
options: { separatorCharacters: ["。"] },
209209
errors: [
210210
{
211211
message: `一文に二回以上利用されている助詞 "は" がみつかりました。`,
212-
index: 10
213-
}
214-
]
212+
index: 10,
213+
},
214+
],
215215
},
216216
// 、を読点と認識させなくする
217217
{
218218
text: "これがiPhone、これがAndroidです。",
219-
options: {commaCharacters: []},
219+
options: { commaCharacters: [] },
220220
errors: [
221221
{
222222
message: `一文に二回以上利用されている助詞 "が" がみつかりました。`,
223-
index: 12
224-
}
225-
]
226-
}
227-
]
223+
index: 12,
224+
},
225+
],
226+
},
227+
],
228228
});

0 commit comments

Comments
 (0)