33import { RuleHelper } from "textlint-rule-helper" ;
44import { getTokenizer } from "kuromojin" ;
55import splitSentences , { Syntax as SentenceSyntax } from "sentence-splitter" ;
6+ import StringSource from "textlint-util-to-string" ;
67/**
78 * create a object that
89 * map ={
@@ -45,11 +46,12 @@ export default function (context, options = {}) {
4546 let isStrict = options . strict || defaultOptions . strict ;
4647 let { Syntax, report, getSource, RuleError} = context ;
4748 return {
48- [ Syntax . Str ] ( node ) {
49+ [ Syntax . Paragraph ] ( node ) {
4950 if ( helper . isChildNode ( node , [ Syntax . Link , Syntax . Image , Syntax . BlockQuote , Syntax . Emphasis ] ) ) {
5051 return ;
5152 }
52- let text = getSource ( node ) ;
53+ const source = new StringSource ( node ) ;
54+ let text = source . toString ( ) ;
5355 let sentences = splitSentences ( text ) . filter ( node => {
5456 return node . type === SentenceSyntax . Sentence ;
5557 } ) ;
@@ -73,7 +75,7 @@ export default function (context, options = {}) {
7375 let tokens = joshiTokenSurfaceKeyMap [ key ] ;
7476 // strict mode ではない時例外を除去する
7577 if ( ! isStrict ) {
76- if ( matchExceptionRule ( tokens ) ) {
78+ if ( matchExceptionRule ( tokens ) ) {
7779 return ;
7880 }
7981 }
@@ -87,11 +89,20 @@ export default function (context, options = {}) {
8789 // if difference
8890 let differenceIndex = otherPosition - startPosition ;
8991 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+ } ) ;
90101 report ( node , new RuleError ( `一文に二回以上利用されている助詞 "${ key } " がみつかりました。` , {
91- line : sentence . loc . start . line - 1 ,
102+ line : originalPosition . line - 1 ,
92103 // matchLastToken.word_position start with 1
93104 // this is padding column start with 0 (== -1)
94- column : sentence . loc . start . column + ( current . word_position - 1 )
105+ column : originalPosition . column
95106 } ) ) ;
96107 }
97108 return current ;
0 commit comments