3
3
import { RuleHelper } from "textlint-rule-helper" ;
4
4
import { getTokenizer } from "kuromojin" ;
5
5
import splitSentences , { Syntax as SentenceSyntax } from "sentence-splitter" ;
6
+ import StringSource from "textlint-util-to-string" ;
6
7
/**
7
8
* create a object that
8
9
* map ={
@@ -45,11 +46,12 @@ export default function (context, options = {}) {
45
46
let isStrict = options . strict || defaultOptions . strict ;
46
47
let { Syntax, report, getSource, RuleError} = context ;
47
48
return {
48
- [ Syntax . Str ] ( node ) {
49
+ [ Syntax . Paragraph ] ( node ) {
49
50
if ( helper . isChildNode ( node , [ Syntax . Link , Syntax . Image , Syntax . BlockQuote , Syntax . Emphasis ] ) ) {
50
51
return ;
51
52
}
52
- let text = getSource ( node ) ;
53
+ const source = new StringSource ( node ) ;
54
+ let text = source . toString ( ) ;
53
55
let sentences = splitSentences ( text ) . filter ( node => {
54
56
return node . type === SentenceSyntax . Sentence ;
55
57
} ) ;
@@ -73,7 +75,7 @@ export default function (context, options = {}) {
73
75
let tokens = joshiTokenSurfaceKeyMap [ key ] ;
74
76
// strict mode ではない時例外を除去する
75
77
if ( ! isStrict ) {
76
- if ( matchExceptionRule ( tokens ) ) {
78
+ if ( matchExceptionRule ( tokens ) ) {
77
79
return ;
78
80
}
79
81
}
@@ -87,11 +89,20 @@ export default function (context, options = {}) {
87
89
// if difference
88
90
let differenceIndex = otherPosition - startPosition ;
89
91
if ( differenceIndex <= minInterval ) {
92
+ console . log ( node ) ;
93
+ console . log ( text ) ;
94
+ console . log ( sentences ) ;
95
+ console . log ( sentence . loc ) ;
96
+ console . log ( current . word_position ) ;
97
+ let originalPosition = source . originalPositionFor ( {
98
+ line : sentence . loc . start . line ,
99
+ column : sentence . loc . start . column + ( current . word_position - 1 )
100
+ } ) ;
90
101
report ( node , new RuleError ( `一文に二回以上利用されている助詞 "${ key } " がみつかりました。` , {
91
- line : sentence . loc . start . line - 1 ,
102
+ line : originalPosition . line - 1 ,
92
103
// matchLastToken.word_position start with 1
93
104
// this is padding column start with 0 (== -1)
94
- column : sentence . loc . start . column + ( current . word_position - 1 )
105
+ column : originalPosition . column
95
106
} ) ) ;
96
107
}
97
108
return current ;
0 commit comments