@@ -21,26 +21,59 @@ module.exports = {
2121 } ,
2222
2323 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
3152 }
32- } ,
33- additionalProperties : false
53+ ]
3454 } ]
3555 } ,
3656
3757 create ( context ) {
58+ function isPrefixDisabled ( prefix ) {
59+ return prefix === false ;
60+ }
61+
3862 const configuration = context . options [ 0 ] || { } ;
39- const eventHandlerPrefix = configuration . eventHandlerPrefix || 'handle' ;
40- const eventHandlerPropPrefix = configuration . eventHandlerPropPrefix || 'on' ;
4163
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)$` ) ;
4477
4578 return {
4679 JSXAttribute ( node ) {
@@ -55,15 +88,23 @@ module.exports = {
5588 return ;
5689 }
5790
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 ) ;
6093
61- if ( propIsEventHandler && ! propFnIsNamedCorrectly ) {
94+ if (
95+ propIsEventHandler &&
96+ propFnIsNamedCorrectly !== null &&
97+ ! propFnIsNamedCorrectly
98+ ) {
6299 context . report ( {
63100 node,
64101 message : `Handler function for ${ propKey } prop key must begin with '${ eventHandlerPrefix } '`
65102 } ) ;
66- } else if ( propFnIsNamedCorrectly && ! propIsEventHandler ) {
103+ } else if (
104+ propFnIsNamedCorrectly &&
105+ propIsEventHandler !== null &&
106+ ! propIsEventHandler
107+ ) {
67108 context . report ( {
68109 node,
69110 message : `Prop key for ${ propValue } must begin with '${ eventHandlerPropPrefix } '`
0 commit comments