55 かっこの外側、内側ともにスペースを入れません。
66 */
77import { RuleHelper } from "textlint-rule-helper" ;
8- import { matchCaptureGroupAll } from "match-index" ;
98
109const brackets = [ "\\[" , "\\]" , "(" , ")" , "[" , "]" , "「" , "」" , "『" , "』" ] ;
1110
@@ -26,29 +25,29 @@ function reporter(context) {
2625 const text = getSource ( node ) ;
2726 // 左にスペース
2827 leftBrackets . forEach ( ( pattern ) => {
29- matchCaptureGroupAll ( text , pattern ) . forEach ( ( match ) => {
30- const { index } = match ;
28+ for ( const match of text . matchAll ( pattern ) ) {
29+ const indexZeroBased = match . index ;
3130 report (
3231 node ,
3332 new RuleError ( "かっこの外側、内側ともにスペースを入れません。" , {
34- index : index ,
35- fix : fixer . replaceTextRange ( [ index , index + 1 ] , "" )
33+ index : indexZeroBased ,
34+ fix : fixer . replaceTextRange ( [ indexZeroBased , indexZeroBased + 1 ] , "" )
3635 } )
3736 ) ;
38- } ) ;
37+ }
3938 } ) ;
4039 // 右にスペース
4140 rightBrackets . forEach ( ( pattern ) => {
42- matchCaptureGroupAll ( text , pattern ) . forEach ( ( match ) => {
43- const { index , text } = match ;
41+ for ( const match of text . matchAll ( pattern ) ) {
42+ const indexOnebased = match . index + 1 ;
4443 report (
4544 node ,
4645 new RuleError ( "かっこの外側、内側ともにスペースを入れません。" , {
47- index : index ,
48- fix : fixer . replaceTextRange ( [ index , index + 1 ] , "" )
46+ index : indexOnebased ,
47+ fix : fixer . replaceTextRange ( [ indexOnebased , indexOnebased + 1 ] , "" )
4948 } )
5049 ) ;
51- } ) ;
50+ }
5251 } ) ;
5352 }
5453 } ;
0 commit comments