2
2
"use strict" ;
3
3
import { RuleHelper } from "textlint-rule-helper" ;
4
4
import { getTokenizer } from "kuromojin" ;
5
- import splitSentences , { Syntax as SentenceSyntax } from "sentence-splitter" ;
5
+ import { split as splitSentences , Syntax as SentenceSyntax } from "sentence-splitter" ;
6
6
import StringSource from "textlint-util-to-string" ;
7
7
8
8
/*
@@ -27,6 +27,11 @@ export default function (context, options = {}) {
27
27
let sentences = splitSentences ( text , {
28
28
charRegExp : / [ 。 \? \! ? ! ] /
29
29
} ) . filter ( isSentenceNode ) ;
30
+ // if not have a sentence, early return
31
+ // It is for avoiding error of emptyArray.reduce().
32
+ if ( sentences . length === 0 ) {
33
+ return ;
34
+ }
30
35
return getTokenizer ( ) . then ( tokenizer => {
31
36
const selectConjenction = ( sentence ) => {
32
37
let tokens = tokenizer . tokenizeForSentence ( sentence . raw ) ;
@@ -43,16 +48,13 @@ export default function (context, options = {}) {
43
48
}
44
49
if ( current_tokens . length > 0 ) {
45
50
if ( token && current_tokens [ 0 ] . surface_form === token . surface_form ) {
46
- let originalPosition = source . originalPositionFor ( {
51
+ let originalIndex = source . originalIndexFromPosition ( {
47
52
line : sentence . loc . start . line ,
48
53
column : sentence . loc . start . column + ( current_tokens [ 0 ] . word_position - 1 )
49
54
} ) ;
50
55
// padding position
51
56
var padding = {
52
- line : originalPosition . line - 1 ,
53
- // matchLastToken.word_position start with 1
54
- // this is padding column start with 0 (== -1)
55
- column : originalPosition . column
57
+ index : originalIndex
56
58
} ;
57
59
report ( node , new RuleError ( `同じ接続詞が連続して使われています。` , padding ) ) ;
58
60
}
0 commit comments