5
5
かっこの外側、内側ともにスペースを入れません。
6
6
*/
7
7
import { RuleHelper } from "textlint-rule-helper" ;
8
- import { matchCaptureGroupAll } from "match-index" ;
9
8
10
9
const brackets = [ "\\[" , "\\]" , "(" , ")" , "[" , "]" , "「" , "」" , "『" , "』" ] ;
11
10
@@ -26,29 +25,29 @@ function reporter(context) {
26
25
const text = getSource ( node ) ;
27
26
// 左にスペース
28
27
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 ;
31
30
report (
32
31
node ,
33
32
new RuleError ( "かっこの外側、内側ともにスペースを入れません。" , {
34
- index : index ,
35
- fix : fixer . replaceTextRange ( [ index , index + 1 ] , "" )
33
+ index : indexZeroBased ,
34
+ fix : fixer . replaceTextRange ( [ indexZeroBased , indexZeroBased + 1 ] , "" )
36
35
} )
37
36
) ;
38
- } ) ;
37
+ }
39
38
} ) ;
40
39
// 右にスペース
41
40
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 ;
44
43
report (
45
44
node ,
46
45
new RuleError ( "かっこの外側、内側ともにスペースを入れません。" , {
47
- index : index ,
48
- fix : fixer . replaceTextRange ( [ index , index + 1 ] , "" )
46
+ index : indexOnebased ,
47
+ fix : fixer . replaceTextRange ( [ indexOnebased , indexOnebased + 1 ] , "" )
49
48
} )
50
49
) ;
51
- } ) ;
50
+ }
52
51
} ) ;
53
52
}
54
53
} ;
0 commit comments