Skip to content

Commit 79f3b4e

Browse files
committed
feat(rule): add exception rule of "連体化"
1 parent 90caf4d commit 79f3b4e

File tree

3 files changed

+43
-6
lines changed

3 files changed

+43
-6
lines changed

README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
"rules": {
2525
"no-doubled-joshi": {
2626
// 助詞のtoken同士の距離が2以下ならエラー
27-
"min_interval" : 2
27+
"min_interval" : 2,
28+
// 例外を許可するかどうか
29+
"strict": true
2830
}
2931
}
3032
}
@@ -62,7 +64,7 @@ MIT
6264

6365
- [Doubled Joshi Validator · Issue #460 · redpen-cc/redpen](https://github.com/redpen-cc/redpen/issues/460 "Doubled Joshi Validator · Issue #460 · redpen-cc/redpen")
6466
- [事象の構造から見る二重デ格構文の発生 ](https://www.ninjal.ac.jp/event/specialists/project-meeting/files/JCLWorkshop_no6_papers/JCLWorkshop_No6_01.pdf "JCLWorkshop_No6_01.pdf")
65-
67+
- [第8回:読みやすさへの工夫 3(てにおは助詞) - たくみの匠](http://www.asca-co.com/takumi/2010/07/3.html "第8回:読みやすさへの工夫 3(てにおは助詞) - たくみの匠")
6668

6769
## 判定処理
6870

@@ -76,4 +78,12 @@ MIT
7678
7779
この場合 "を" が最低間隔値2で並んでいるためエラーとするべき。
7880

79-
- [kuromoji.js demo](http://takuyaa.github.io/kuromoji.js/demo/tokenize.html "kuromoji.js demo")
81+
- [kuromoji.js demo](http://takuyaa.github.io/kuromoji.js/demo/tokenize.html "kuromoji.js demo")
82+
83+
## 例外
84+
85+
例外は `{ strict: true }` ならばエラーとするが、デフォルトでは`{ strict: false }`としエラーとしない
86+
87+
助詞:連体化である"の"の重なりは例外として許可する。
88+
89+
- [第8回:読みやすさへの工夫 3(てにおは助詞) - たくみの匠](http://www.asca-co.com/takumi/2010/07/3.html "第8回:読みやすさへの工夫 3(てにおは助詞) - たくみの匠")

src/no-doubled-joshi.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,21 @@ function createSurfaceKeyMap(tokens) {
2222
return keyMap;
2323
}, {});
2424
}
25-
25+
function exceptionRule(token) {
26+
if (token.pos_detail_1 === "連体化") {
27+
return false;
28+
}
29+
return true;
30+
}
2631
const defaultOptions = {
27-
min_interval: 2
32+
min_interval: 2,
33+
strict: false
2834
};
2935
export default function (context, options = {}) {
3036
const helper = new RuleHelper(context);
3137
// 最低間隔値
3238
let minInterval = options.min_interval || defaultOptions.min_interval;
39+
let isStrict = options.strict || defaultOptions.strict;
3340
let {Syntax, report, getSource, RuleError} = context;
3441
return {
3542
[Syntax.Str](node){
@@ -46,6 +53,10 @@ export default function (context, options = {}) {
4653
let joshiTokens = tokens.filter(token => {
4754
return token.pos === "助詞";
4855
});
56+
// strict mode ではない時例外を除去する
57+
if (!isStrict) {
58+
joshiTokens = joshiTokens.filter(exceptionRule);
59+
}
4960
let joshiTokenSurfaceKeyMap = createSurfaceKeyMap(joshiTokens);
5061
/*
5162
# Data Structure

test/no-doubled-joshi-test.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import TextLintTester from "textlint-tester";
44
var tester = new TextLintTester();
55
tester.run("no-double-joshi", rule, {
66
valid: [
7-
"私は彼が好きだ"
7+
"私は彼が好きだ",
8+
{
9+
text: "既存のコードの利用"
10+
}
811
],
912
invalid: [
1013
{
@@ -82,6 +85,19 @@ tester.run("no-double-joshi", rule, {
8285
column: 13
8386
}
8487
]
88+
},
89+
{
90+
text: "既存のコードの利用",
91+
options:{
92+
strict :true
93+
},
94+
errors: [
95+
{
96+
message: `一文に二回以上利用されている助詞 "の" がみつかりました。`,
97+
line: 1,
98+
column: 7
99+
}
100+
]
85101
}
86102
]
87103
});

0 commit comments

Comments
 (0)