Skip to content

Commit

Permalink
feat(rule): より一般的なルールに変更・追加 (#6)
Browse files Browse the repository at this point in the history
- "実行" -> "する"
- "行う" -> "する"

に対するルールの一般化を行った。
いくつかfalse positiveがあるため、オプションで無視できるようにする。
  • Loading branch information
azu authored Dec 26, 2018
2 parents e80ec17 + 8c7f8c5 commit b635c51
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 34 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
- 参考: <http://www.sekaihaasobiba.com/entry/2014/10/24/204024>
- "であると考えている"は冗長な表現です。"である" または "と考えている"を省き簡潔な表現にすると文章が明瞭になります。
- 参考: <http://www.atmarkit.co.jp/ait/articles/1001/19/news106_2.html>
- "確認を行わなければ"は冗長な表現です。"確認しなければ"など簡潔な表現にすると文章が明瞭になります。
- "を行う"は冗長な表現です。"$1する"など簡潔な表現にすると文章が明瞭になります。
- 参考: <http://www.atmarkit.co.jp/ait/articles/1001/19/news106_2.html>
- "を実行"は冗長な表現です。"$1する"など簡潔な表現にすると文章が明瞭になります。
- 参考: <http://www.atmarkit.co.jp/ait/articles/1001/19/news106_2.html>

## Install
Expand Down
59 changes: 30 additions & 29 deletions src/dictionary.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,20 +253,13 @@ module.exports = [
},
{
// https://azu.github.io/morpheme-match/?text=動作の(確認を行わなければ)ならない
message: `"確認を行わなければ"は冗長な表現です。"確認しなければ"など簡潔な表現にすると文章が明瞭になります。`,
message: `"$1を行う"は冗長な表現です。"$1する"など簡潔な表現にすると文章が明瞭になります。`,
url: "http://www.atmarkit.co.jp/ait/articles/1001/19/news106_2.html",
tokens: [
{
"surface_form": "確認",
"pos": "名詞",
"pos_detail_1": "サ変接続",
"pos_detail_2": "*",
"pos_detail_3": "*",
"conjugated_type": "*",
"conjugated_form": "*",
"basic_form": "確認",
"reading": "カクニン",
"pronunciation": "カクニン"
"_capture": "$1"
},
{
"surface_form": "を",
Expand All @@ -281,41 +274,49 @@ module.exports = [
"pronunciation": "ヲ"
},
{
"surface_form": "行わ",
"pos": "動詞",
"pos_detail_1": "自立",
"pos_detail_2": "*",
"pos_detail_3": "*",
"conjugated_type": "五段・ワ行促音便",
"conjugated_form": "未然形",
"basic_form": "行う",
"reading": "オコナワ",
"pronunciation": "オコナワ"
}
]
},
{
message: `"$1を実行"は冗長な表現です。"$1する"など簡潔な表現にすると文章が明瞭になります。`,
url: "http://www.atmarkit.co.jp/ait/articles/1001/19/news106_2.html",
tokens: [
{
"pos": "名詞",
"pos_detail_1": "サ変接続",
"_capture": "$1"
},
{
"surface_form": "なけれ",
"pos": "助動詞",
"pos_detail_1": "*",
"pos_detail_2": "*",
"surface_form": "",
"pos": "助詞",
"pos_detail_1": "格助詞",
"pos_detail_2": "一般",
"pos_detail_3": "*",
"conjugated_type": "特殊・ナイ",
"conjugated_form": "仮定形",
"basic_form": "ない",
"reading": "ナケレ",
"pronunciation": "ナケレ"
"conjugated_type": "*",
"conjugated_form": "*",
"basic_form": "",
"reading": "",
"pronunciation": ""
},
{
"surface_form": "",
"pos": "助詞",
"pos_detail_1": "接続助詞",
"surface_form": "実行",
"pos": "名詞",
"pos_detail_1": "サ変接続",
"pos_detail_2": "*",
"pos_detail_3": "*",
"conjugated_type": "*",
"conjugated_form": "*",
"basic_form": "",
"reading": "",
"pronunciation": ""
}
"basic_form": "実行",
"reading": "ジッコウ",
"pronunciation": "ジッコー"
},
]
}

];
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ const replaceWithCaptureTokens = (text, tokens, actualTokens) => {
return;
}
const actualToken = actualTokens[index];
resultText = resultText.replace(token._capture, actualToken.surface_form);
resultText = resultText.split(token._capture).join(actualToken.surface_form);
});
return resultText;
};
const reporter = (context) => {
const {Syntax, RuleError, report, fixer, getSource} = context;
const matchAll = createMatchAll(dictionaryList);
return {
[Syntax.Str](node){
[Syntax.Str](node) {
const text = getSource(node);
return tokenize(text).then(currentTokens => {
/**
Expand All @@ -33,7 +33,7 @@ const reporter = (context) => {
const lastWorkIndex = Math.max(lastToken.word_position - 1, 0);
// replace $1
const message = replaceWithCaptureTokens(matchResult.dict.message, matchResult.dict.tokens, matchResult.tokens)
+ (matchResult.dict.url ? `参考: ${matchResult.dict.url}` : "");
+ (matchResult.dict.url ? `参考: ${matchResult.dict.url}` : "");
const expected = matchResult.dict.expected
? replaceWithCaptureTokens(matchResult.dict.expected, matchResult.dict.tokens, matchResult.tokens)
: undefined;
Expand Down
21 changes: 20 additions & 1 deletion test/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,25 @@ tester.run("textlint-rule-ja-no-redundant-expression", rule, {
}
]
},
{
text: "実験を行えば分かります。",
errors: [
{
message: `"実験を行う"は冗長な表現です。"実験する"など簡潔な表現にすると文章が明瞭になります。参考: http://www.atmarkit.co.jp/ait/articles/1001/19/news106_2.html`,
index: 0
}
]
},
{
text: "検査を実行すれば分かります。",
errors: [
{
message: `"検査を実行"は冗長な表現です。"検査する"など簡潔な表現にすると文章が明瞭になります。参考: http://www.atmarkit.co.jp/ait/articles/1001/19/news106_2.html`,
index: 0
}
]
},

//http://www.atmarkit.co.jp/ait/articles/1001/19/news106_2.html
{
text: "このコマンドの後には任意の値を設定することができる。このため、設定した値ごとに、システムの動作の確認を行わなければならない。この作業には時間がかかるため、テスト要員の追加が必要であると考えている。",
Expand All @@ -59,7 +78,7 @@ tester.run("textlint-rule-ja-no-redundant-expression", rule, {
column: 18
},
{
message: `"確認を行わなければ"は冗長な表現です。"確認しなければ"など簡潔な表現にすると文章が明瞭になります。参考: http://www.atmarkit.co.jp/ait/articles/1001/19/news106_2.html`,
message: `"確認を行う"は冗長な表現です。"確認する"など簡潔な表現にすると文章が明瞭になります。参考: http://www.atmarkit.co.jp/ait/articles/1001/19/news106_2.html`,
line: 1,
column: 49
},
Expand Down

0 comments on commit b635c51

Please sign in to comment.