1
1
// LICENSE : MIT
2
2
"use strict" ;
3
- import { matchCaptureGroupAll } from "match-index"
4
- import { RuleHelper } from "textlint-rule-helper" ;
5
- import { TextlintRuleReporter } from "@textlint/types" ;
6
-
7
- const unorm = require ( "unorm" ) ;
3
+ import { matchCaptureGroupAll } from "match-index"
4
+ import { RuleHelper } from "textlint-rule-helper" ;
5
+ import { TextlintRuleReporter } from "@textlint/types" ;
6
+ import unorm from "unorm" ;
8
7
9
8
const reporter : TextlintRuleReporter = function ( context ) {
10
- const { Syntax, RuleError, report, fixer, getSource} = context ;
9
+ const { Syntax, RuleError, report, fixer, getSource, locator } = context ;
11
10
const helper = new RuleHelper ( context ) ;
12
11
return {
13
12
[ Syntax . Str ] ( node ) {
14
13
if ( helper . isChildNode ( node , [ Syntax . Link , Syntax . Image , Syntax . BlockQuote , Syntax . Emphasis ] ) ) {
15
14
return ;
16
15
}
17
16
const text = getSource ( node ) ;
18
- matchCaptureGroupAll ( text , / ( [ \u309b \u309c \u309a \u3099 ] ) / g) . forEach ( ( { index} ) => {
17
+ matchCaptureGroupAll ( text , / ( [ \u309b \u309c \u309a \u3099 ] ) / g) . forEach ( ( { index } ) => {
19
18
if ( index === 0 ) {
20
19
return ;
21
20
}
@@ -24,16 +23,15 @@ const reporter: TextlintRuleReporter = function (context) {
24
23
const nfdlized = dakutenChars . replace ( "\u309B" , "\u3099" ) . replace ( "\u309C" , "\u309A" ) ;
25
24
const expectedText = unorm . nfc ( nfdlized ) ;
26
25
const ruleError = new RuleError ( `Disallow to use NFD(well-known as UTF8-MAC 濁点): "${ dakutenChars } " => "${ expectedText } "` , {
27
- index,
26
+ padding : locator . at ( index ) ,
28
27
fix : fixer . replaceTextRange ( [ index - 1 , index + 1 ] , expectedText )
29
28
} ) ;
30
29
report ( node , ruleError ) ;
31
30
} ) ;
32
31
}
33
32
}
34
33
} ;
35
-
36
- module . exports = {
34
+ export default {
37
35
linter : reporter ,
38
36
fixer : reporter
39
37
} ;
0 commit comments