1
1
// LICENSE : MIT
2
2
"use strict" ;
3
- import { RuleHelper } from "textlint-rule-helper" ;
4
- import { matchPatterns } from "@textlint/regexp-string-matcher" ;
5
- import { matchCaptureGroupAll } from "match-index"
3
+ import { RuleHelper } from "textlint-rule-helper" ;
4
+ import { matchPatterns } from "@textlint/regexp-string-matcher" ;
5
+ import { matchCaptureGroupAll } from "match-index" ;
6
6
7
7
/**
8
8
* if actual is in the `matchPatternResults`, return true
@@ -11,24 +11,23 @@ import {matchCaptureGroupAll} from "match-index"
11
11
* @returns {boolean }
12
12
*/
13
13
const isIgnoredRange = ( matchPatternResults , actual ) => {
14
- return matchPatternResults . some ( result => {
14
+ return matchPatternResults . some ( ( result ) => {
15
15
return result . startIndex <= actual . index && actual . index <= result . endIndex ;
16
16
} ) ;
17
17
} ;
18
18
19
+ const DEFAULT_ALLOW_LIST = [ "Yahoo!" ] ;
19
20
const defaultOptions = {
20
21
// allow words
21
- "allow" : [
22
- "Yahoo!"
23
- ] ,
22
+ allow : [ ] ,
24
23
// allow to use !
25
- " allowHalfWidthExclamation" : false ,
24
+ allowHalfWidthExclamation : false ,
26
25
// allow to use !
27
- " allowFullWidthExclamation" : false ,
26
+ allowFullWidthExclamation : false ,
28
27
// allow to use ?
29
- " allowHalfWidthQuestion" : false ,
28
+ allowHalfWidthQuestion : false ,
30
29
// allow to use ?
31
- " allowFullWidthQuestion" : false
30
+ allowFullWidthQuestion : false
32
31
} ;
33
32
const Mark = {
34
33
HalfWidthExclamation : / ( ! ) / ,
@@ -38,16 +37,16 @@ const Mark = {
38
37
} ;
39
38
40
39
module . exports = function ( context , options = defaultOptions ) {
41
- const { Syntax, RuleError, report, getSource} = context ;
40
+ const { Syntax, RuleError, report, getSource } = context ;
42
41
const helper = new RuleHelper ( context ) ;
43
- const allow = options . allow || defaultOptions . allow ;
42
+ const allow = ( options . allow || defaultOptions . allow ) . concat ( DEFAULT_ALLOW_LIST ) ;
44
43
const allowHalfWidthExclamation = options . allowHalfWidthExclamation || defaultOptions . allowHalfWidthExclamation ;
45
44
const allowFullWidthExclamation = options . allowFullWidthExclamation || defaultOptions . allowFullWidthExclamation ;
46
45
const allowHalfWidthQuestion = options . allowHalfWidthQuestion || defaultOptions . allowHalfWidthQuestion ;
47
46
const allowFullWidthQuestion = options . allowFullWidthQuestion || defaultOptions . allowFullWidthQuestion ;
48
47
49
48
return {
50
- [ Syntax . Str ] ( node ) {
49
+ [ Syntax . Str ] ( node ) {
51
50
if ( helper . isChildNode ( node , [ Syntax . Link , Syntax . Image , Syntax . BlockQuote , Syntax . Emphasis ] ) ) {
52
51
return ;
53
52
}
@@ -60,16 +59,19 @@ module.exports = function (context, options = defaultOptions) {
60
59
const reportIfIncludeMark = ( text , markRegExp ) => {
61
60
const ignoreMatch = matchPatterns ( text , allow ) ;
62
61
matchCaptureGroupAll ( text , markRegExp ) . forEach ( ( actual ) => {
63
- const { text, index} = actual ;
62
+ const { text, index } = actual ;
64
63
65
64
// 無視する単語を含んでいるなら無視
66
65
if ( isIgnoredRange ( ignoreMatch , actual ) ) {
67
66
return ;
68
67
}
69
68
70
- report ( node , new RuleError ( `Disallow to use "${ text } ".` , {
71
- index
72
- } ) ) ;
69
+ report (
70
+ node ,
71
+ new RuleError ( `Disallow to use "${ text } ".` , {
72
+ index
73
+ } )
74
+ ) ;
73
75
} ) ;
74
76
} ;
75
77
// Check
@@ -86,5 +88,5 @@ module.exports = function (context, options = defaultOptions) {
86
88
reportIfIncludeMark ( text , Mark . FullWidthQuestion ) ;
87
89
}
88
90
}
89
- }
90
- } ;
91
+ } ;
92
+ } ;
0 commit comments