Skip to content

Commit b635c51

Browse files
authored
feat(rule): より一般的なルールに変更・追加 (#6)
- "実行" -> "する" - "行う" -> "する" に対するルールの一般化を行った。 いくつかfalse positiveがあるため、オプションで無視できるようにする。
2 parents e80ec17 + 8c7f8c5 commit b635c51

File tree

4 files changed

+56
-34
lines changed

4 files changed

+56
-34
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
- 参考: <http://www.sekaihaasobiba.com/entry/2014/10/24/204024>
1515
- "であると考えている"は冗長な表現です。"である" または "と考えている"を省き簡潔な表現にすると文章が明瞭になります。
1616
- 参考: <http://www.atmarkit.co.jp/ait/articles/1001/19/news106_2.html>
17-
- "確認を行わなければ"は冗長な表現です。"確認しなければ"など簡潔な表現にすると文章が明瞭になります。
17+
- "を行う"は冗長な表現です。"$1する"など簡潔な表現にすると文章が明瞭になります。
18+
- 参考: <http://www.atmarkit.co.jp/ait/articles/1001/19/news106_2.html>
19+
- "を実行"は冗長な表現です。"$1する"など簡潔な表現にすると文章が明瞭になります。
1820
- 参考: <http://www.atmarkit.co.jp/ait/articles/1001/19/news106_2.html>
1921

2022
## Install

src/dictionary.js

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -253,20 +253,13 @@ module.exports = [
253253
},
254254
{
255255
// https://azu.github.io/morpheme-match/?text=動作の(確認を行わなければ)ならない
256-
message: `"確認を行わなければ"は冗長な表現です。"確認しなければ"など簡潔な表現にすると文章が明瞭になります。`,
256+
message: `"$1を行う"は冗長な表現です。"$1する"など簡潔な表現にすると文章が明瞭になります。`,
257257
url: "http://www.atmarkit.co.jp/ait/articles/1001/19/news106_2.html",
258258
tokens: [
259259
{
260-
"surface_form": "確認",
261260
"pos": "名詞",
262261
"pos_detail_1": "サ変接続",
263-
"pos_detail_2": "*",
264-
"pos_detail_3": "*",
265-
"conjugated_type": "*",
266-
"conjugated_form": "*",
267-
"basic_form": "確認",
268-
"reading": "カクニン",
269-
"pronunciation": "カクニン"
262+
"_capture": "$1"
270263
},
271264
{
272265
"surface_form": "を",
@@ -281,41 +274,49 @@ module.exports = [
281274
"pronunciation": "ヲ"
282275
},
283276
{
284-
"surface_form": "行わ",
285277
"pos": "動詞",
286278
"pos_detail_1": "自立",
287279
"pos_detail_2": "*",
288280
"pos_detail_3": "*",
289281
"conjugated_type": "五段・ワ行促音便",
290-
"conjugated_form": "未然形",
291282
"basic_form": "行う",
292-
"reading": "オコナワ",
293-
"pronunciation": "オコナワ"
283+
}
284+
]
285+
},
286+
{
287+
message: `"$1を実行"は冗長な表現です。"$1する"など簡潔な表現にすると文章が明瞭になります。`,
288+
url: "http://www.atmarkit.co.jp/ait/articles/1001/19/news106_2.html",
289+
tokens: [
290+
{
291+
"pos": "名詞",
292+
"pos_detail_1": "サ変接続",
293+
"_capture": "$1"
294294
},
295295
{
296-
"surface_form": "なけれ",
297-
"pos": "助動詞",
298-
"pos_detail_1": "*",
299-
"pos_detail_2": "*",
296+
"surface_form": "",
297+
"pos": "助詞",
298+
"pos_detail_1": "格助詞",
299+
"pos_detail_2": "一般",
300300
"pos_detail_3": "*",
301-
"conjugated_type": "特殊・ナイ",
302-
"conjugated_form": "仮定形",
303-
"basic_form": "ない",
304-
"reading": "ナケレ",
305-
"pronunciation": "ナケレ"
301+
"conjugated_type": "*",
302+
"conjugated_form": "*",
303+
"basic_form": "",
304+
"reading": "",
305+
"pronunciation": ""
306306
},
307307
{
308-
"surface_form": "",
309-
"pos": "助詞",
310-
"pos_detail_1": "接続助詞",
308+
"surface_form": "実行",
309+
"pos": "名詞",
310+
"pos_detail_1": "サ変接続",
311311
"pos_detail_2": "*",
312312
"pos_detail_3": "*",
313313
"conjugated_type": "*",
314314
"conjugated_form": "*",
315-
"basic_form": "",
316-
"reading": "",
317-
"pronunciation": ""
318-
}
315+
"basic_form": "実行",
316+
"reading": "ジッコウ",
317+
"pronunciation": "ジッコー"
318+
},
319319
]
320320
}
321+
321322
];

src/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ const replaceWithCaptureTokens = (text, tokens, actualTokens) => {
1111
return;
1212
}
1313
const actualToken = actualTokens[index];
14-
resultText = resultText.replace(token._capture, actualToken.surface_form);
14+
resultText = resultText.split(token._capture).join(actualToken.surface_form);
1515
});
1616
return resultText;
1717
};
1818
const reporter = (context) => {
1919
const {Syntax, RuleError, report, fixer, getSource} = context;
2020
const matchAll = createMatchAll(dictionaryList);
2121
return {
22-
[Syntax.Str](node){
22+
[Syntax.Str](node) {
2323
const text = getSource(node);
2424
return tokenize(text).then(currentTokens => {
2525
/**
@@ -33,7 +33,7 @@ const reporter = (context) => {
3333
const lastWorkIndex = Math.max(lastToken.word_position - 1, 0);
3434
// replace $1
3535
const message = replaceWithCaptureTokens(matchResult.dict.message, matchResult.dict.tokens, matchResult.tokens)
36-
+ (matchResult.dict.url ? `参考: ${matchResult.dict.url}` : "");
36+
+ (matchResult.dict.url ? `参考: ${matchResult.dict.url}` : "");
3737
const expected = matchResult.dict.expected
3838
? replaceWithCaptureTokens(matchResult.dict.expected, matchResult.dict.tokens, matchResult.tokens)
3939
: undefined;

test/index-test.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,25 @@ tester.run("textlint-rule-ja-no-redundant-expression", rule, {
4949
}
5050
]
5151
},
52+
{
53+
text: "実験を行えば分かります。",
54+
errors: [
55+
{
56+
message: `"実験を行う"は冗長な表現です。"実験する"など簡潔な表現にすると文章が明瞭になります。参考: http://www.atmarkit.co.jp/ait/articles/1001/19/news106_2.html`,
57+
index: 0
58+
}
59+
]
60+
},
61+
{
62+
text: "検査を実行すれば分かります。",
63+
errors: [
64+
{
65+
message: `"検査を実行"は冗長な表現です。"検査する"など簡潔な表現にすると文章が明瞭になります。参考: http://www.atmarkit.co.jp/ait/articles/1001/19/news106_2.html`,
66+
index: 0
67+
}
68+
]
69+
},
70+
5271
//http://www.atmarkit.co.jp/ait/articles/1001/19/news106_2.html
5372
{
5473
text: "このコマンドの後には任意の値を設定することができる。このため、設定した値ごとに、システムの動作の確認を行わなければならない。この作業には時間がかかるため、テスト要員の追加が必要であると考えている。",
@@ -59,7 +78,7 @@ tester.run("textlint-rule-ja-no-redundant-expression", rule, {
5978
column: 18
6079
},
6180
{
62-
message: `"確認を行わなければ"は冗長な表現です。"確認しなければ"など簡潔な表現にすると文章が明瞭になります。参考: http://www.atmarkit.co.jp/ait/articles/1001/19/news106_2.html`,
81+
message: `"確認を行う"は冗長な表現です。"確認する"など簡潔な表現にすると文章が明瞭になります。参考: http://www.atmarkit.co.jp/ait/articles/1001/19/news106_2.html`,
6382
line: 1,
6483
column: 49
6584
},

0 commit comments

Comments
 (0)