@@ -21,7 +21,13 @@ function createSurfaceKeyMap(tokens) {
21
21
return keyMap ;
22
22
} , { } ) ;
23
23
}
24
- export default function ( context ) {
24
+
25
+ const defaultOptions = {
26
+ min_interval : 2
27
+ } ;
28
+ export default function ( context , options = { } ) {
29
+ // 最低間隔値
30
+ let minInterval = options . min_interval || defaultOptions . min_interval ;
25
31
let { Syntax, report, getSource, RuleError} = context ;
26
32
return {
27
33
[ Syntax . Str ] ( node ) {
@@ -30,7 +36,7 @@ export default function (context) {
30
36
return node . type === SentenceSyntax . Sentence ;
31
37
} ) ;
32
38
return getTokenizer ( ) . then ( tokenizer => {
33
- sentences . forEach ( sentence => {
39
+ const checkSentence = ( sentence ) => {
34
40
let tokens = tokenizer . tokenizeForSentence ( sentence . raw ) ;
35
41
let joshiTokens = tokens . filter ( token => {
36
42
return token . pos === "助詞" ;
@@ -56,7 +62,7 @@ export default function (context) {
56
62
let otherPosition = joshiTokens . indexOf ( current ) ;
57
63
// if difference
58
64
let differenceIndex = otherPosition - startPosition ;
59
- if ( differenceIndex <= 2 ) {
65
+ if ( differenceIndex <= minInterval ) {
60
66
report ( node , new RuleError ( `一文に二回以上利用されている助詞 "${ key } " がみつかりました。` , {
61
67
line : sentence . loc . start . line - 1 ,
62
68
// matchLastToken.word_position start with 1
@@ -67,8 +73,9 @@ export default function (context) {
67
73
return current ;
68
74
} ) ;
69
75
} ) ;
70
- } ) ;
76
+ } ;
77
+ sentences . forEach ( checkSentence ) ;
71
78
} ) ;
72
79
}
73
80
}
74
- }
81
+ } ;
0 commit comments