1
1
// LICENSE : MIT
2
2
"use strict" ;
3
- import { RuleHelper } from "textlint-rule-helper" ;
3
+ import { RuleHelper } from "textlint-rule-helper" ;
4
4
import kuromojin from "kuromojin" ;
5
5
6
6
function isTargetVerb ( token ) {
7
- return token . pos == '動詞' &&
8
- token . pos_detail_1 == '自立' &&
9
- token . conjugated_type == '一段' &&
10
- token . conjugated_form == '未然形' ;
7
+ return (
8
+ token . pos == "動詞" &&
9
+ token . pos_detail_1 == "自立" &&
10
+ token . conjugated_type == "一段" &&
11
+ token . conjugated_form == "未然形"
12
+ ) ;
11
13
}
12
14
13
15
function isRaWord ( token ) {
14
- return token . pos == '動詞' &&
15
- token . pos_detail_1 == '接尾' &&
16
- token . basic_form == 'れる'
16
+ return token . pos == "動詞" && token . pos_detail_1 == "接尾" && token . basic_form == "れる" ;
17
17
}
18
18
19
19
function isKoreru ( token ) {
20
- return token . pos == '動詞' &&
21
- token . basic_form == '来れる'
20
+ return token . pos == "動詞" && token . basic_form == "来れる" ;
22
21
}
23
22
24
23
module . exports = function ( context ) {
25
24
const helper = new RuleHelper ( context ) ;
26
- const { Syntax, report, getSource, RuleError} = context ;
25
+ const { Syntax, report, getSource, RuleError } = context ;
27
26
return {
28
- [ Syntax . Str ] ( node ) {
27
+ [ Syntax . Str ] ( node ) {
29
28
if ( helper . isChildNode ( node , [ Syntax . Link , Syntax . Image , Syntax . BlockQuote , Syntax . Emphasis ] ) ) {
30
29
return ;
31
30
}
32
31
const text = getSource ( node ) ;
33
32
return kuromojin ( text ) . then ( tokens => {
34
- tokens . forEach ( ( token ) => {
33
+ tokens . forEach ( token => {
35
34
if ( isKoreru ( token ) ) {
36
- report ( node , new RuleError ( "ら抜き言葉を使用しています。" , {
37
- index : ( token . word_position )
38
- } ) ) ;
35
+ report (
36
+ node ,
37
+ new RuleError ( "ら抜き言葉を使用しています。" , {
38
+ index : token . word_position
39
+ } )
40
+ ) ;
39
41
}
40
42
} ) ;
41
43
// tokenのペアがない場合は無視する
@@ -44,13 +46,16 @@ module.exports = function(context) {
44
46
}
45
47
tokens . reduce ( ( prev , current ) => {
46
48
if ( isTargetVerb ( prev ) && isRaWord ( current ) ) {
47
- report ( node , new RuleError ( "ら抜き言葉を使用しています。" , {
48
- index : ( current . word_position - 1 )
49
- } ) ) ;
49
+ report (
50
+ node ,
51
+ new RuleError ( "ら抜き言葉を使用しています。" , {
52
+ index : current . word_position - 1
53
+ } )
54
+ ) ;
50
55
}
51
56
return current ;
52
57
} ) ;
53
58
} ) ;
54
59
}
55
- }
60
+ } ;
56
61
} ;
0 commit comments