@@ -21,26 +21,59 @@ module.exports = {
21
21
} ,
22
22
23
23
schema : [ {
24
- type : 'object' ,
25
- properties : {
26
- eventHandlerPrefix : {
27
- type : 'string'
28
- } ,
29
- eventHandlerPropPrefix : {
30
- type : 'string'
24
+ oneOf : [
25
+ {
26
+ type : 'object' ,
27
+ properties : {
28
+ eventHandlerPrefix : { type : 'string' } ,
29
+ eventHandlerPropPrefix : { type : 'string' }
30
+ } ,
31
+ additionalProperties : false
32
+ } , {
33
+ type : 'object' ,
34
+ properties : {
35
+ eventHandlerPrefix : { type : 'string' } ,
36
+ eventHandlerPropPrefix : {
37
+ type : 'boolean' ,
38
+ enum : [ false ]
39
+ }
40
+ } ,
41
+ additionalProperties : false
42
+ } , {
43
+ type : 'object' ,
44
+ properties : {
45
+ eventHandlerPrefix : {
46
+ type : 'boolean' ,
47
+ enum : [ false ]
48
+ } ,
49
+ eventHandlerPropPrefix : { type : 'string' }
50
+ } ,
51
+ additionalProperties : false
31
52
}
32
- } ,
33
- additionalProperties : false
53
+ ]
34
54
} ]
35
55
} ,
36
56
37
57
create ( context ) {
58
+ function isPrefixDisabled ( prefix ) {
59
+ return prefix === false ;
60
+ }
61
+
38
62
const configuration = context . options [ 0 ] || { } ;
39
- const eventHandlerPrefix = configuration . eventHandlerPrefix || 'handle' ;
40
- const eventHandlerPropPrefix = configuration . eventHandlerPropPrefix || 'on' ;
41
63
42
- const EVENT_HANDLER_REGEX = new RegExp ( `^((props\\.${ eventHandlerPropPrefix } )|((.*\\.)?${ eventHandlerPrefix } ))[A-Z].*$` ) ;
43
- const PROP_EVENT_HANDLER_REGEX = new RegExp ( `^(${ eventHandlerPropPrefix } [A-Z].*|ref)$` ) ;
64
+ const eventHandlerPrefix = isPrefixDisabled ( configuration . eventHandlerPrefix ) ?
65
+ null :
66
+ configuration . eventHandlerPrefix || 'handle' ;
67
+ const eventHandlerPropPrefix = isPrefixDisabled ( configuration . eventHandlerPropPrefix ) ?
68
+ null :
69
+ configuration . eventHandlerPropPrefix || 'on' ;
70
+
71
+ const EVENT_HANDLER_REGEX = ! eventHandlerPrefix ?
72
+ null :
73
+ new RegExp ( `^((props\\.${ eventHandlerPropPrefix || '' } )|((.*\\.)?${ eventHandlerPrefix } ))[A-Z].*$` ) ;
74
+ const PROP_EVENT_HANDLER_REGEX = ! eventHandlerPropPrefix ?
75
+ null :
76
+ new RegExp ( `^(${ eventHandlerPropPrefix } [A-Z].*|ref)$` ) ;
44
77
45
78
return {
46
79
JSXAttribute ( node ) {
@@ -55,15 +88,23 @@ module.exports = {
55
88
return ;
56
89
}
57
90
58
- const propIsEventHandler = PROP_EVENT_HANDLER_REGEX . test ( propKey ) ;
59
- const propFnIsNamedCorrectly = EVENT_HANDLER_REGEX . test ( propValue ) ;
91
+ const propIsEventHandler = PROP_EVENT_HANDLER_REGEX && PROP_EVENT_HANDLER_REGEX . test ( propKey ) ;
92
+ const propFnIsNamedCorrectly = EVENT_HANDLER_REGEX && EVENT_HANDLER_REGEX . test ( propValue ) ;
60
93
61
- if ( propIsEventHandler && ! propFnIsNamedCorrectly ) {
94
+ if (
95
+ propIsEventHandler &&
96
+ propFnIsNamedCorrectly !== null &&
97
+ ! propFnIsNamedCorrectly
98
+ ) {
62
99
context . report ( {
63
100
node,
64
101
message : `Handler function for ${ propKey } prop key must begin with '${ eventHandlerPrefix } '`
65
102
} ) ;
66
- } else if ( propFnIsNamedCorrectly && ! propIsEventHandler ) {
103
+ } else if (
104
+ propFnIsNamedCorrectly &&
105
+ propIsEventHandler !== null &&
106
+ ! propIsEventHandler
107
+ ) {
67
108
context . report ( {
68
109
node,
69
110
message : `Prop key for ${ propValue } must begin with '${ eventHandlerPropPrefix } '`
0 commit comments