File tree Expand file tree Collapse file tree 3 files changed +23
-2
lines changed Expand file tree Collapse file tree 3 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ You can also specify some settings that will be shared across all the plugin rul
3737{
3838 " settings" : {
3939 " react" : {
40+ " createClass" : " createClass" , // Regex for Component Factory to use, default to "createClass"
4041 " pragma" : " React" , // Pragma to use, default to "React"
4142 " version" : " 15.0" // React version, default to the latest React stable release
4243 }
Original file line number Diff line number Diff line change @@ -136,6 +136,7 @@ Components.prototype.length = function() {
136136
137137function componentRule ( rule , context ) {
138138
139+ var createClass = pragmaUtil . getCreateClassFromContext ( context ) ;
139140 var pragma = pragmaUtil . getFromContext ( context ) ;
140141 var sourceCode = context . getSourceCode ( ) ;
141142 var components = new Components ( ) ;
@@ -153,7 +154,7 @@ function componentRule(rule, context) {
153154 if ( ! node . parent ) {
154155 return false ;
155156 }
156- return new RegExp ( '^(' + pragma + '\\.)?createClass$' ) . test ( sourceCode . getText ( node . parent . callee ) ) ;
157+ return new RegExp ( '^(' + pragma + '\\.)?' + createClass + ' $') . test ( sourceCode . getText ( node . parent . callee ) ) ;
157158 } ,
158159
159160 /**
Original file line number Diff line number Diff line change 55'use strict' ;
66
77var JSX_ANNOTATION_REGEX = / ^ \* \s * @ j s x \s + ( [ ^ \s ] + ) / ;
8+ // Does not check for reserved keywords or unicode characters
9+ var JS_IDENTIFIER_REGEX = / ^ [ _ $ a - z A - Z ] [ _ $ a - z A - Z 0 - 9 ] * $ / ;
10+
11+
12+ function getCreateClassFromContext ( context ) {
13+ var pragma = 'createClass' ;
14+ // .eslintrc shared settings (http://eslint.org/docs/user-guide/configuring#adding-shared-settings)
15+ if ( context . settings . react && context . settings . react . createClass ) {
16+ pragma = context . settings . react . createClass ;
17+ }
18+ if ( ! JS_IDENTIFIER_REGEX . test ( pragma ) ) {
19+ throw new Error ( 'createClass pragma ' + pragma + 'is not a valid function name' ) ;
20+ }
21+ return pragma ;
22+ }
823
924function getFromContext ( context ) {
1025 var pragma = 'React' ;
1126 // .eslintrc shared settings (http://eslint.org/docs/user-guide/configuring#adding-shared-settings)
1227 if ( context . settings . react && context . settings . react . pragma ) {
1328 pragma = context . settings . react . pragma ;
1429 }
15- return pragma . split ( '.' ) [ 0 ] ;
30+ if ( ! JS_IDENTIFIER_REGEX . test ( pragma ) ) {
31+ throw new Error ( 'React pragma ' + pragma + 'is not a valid identifier' ) ;
32+ }
33+ return pragma ;
1634}
1735
1836function getFromNode ( node ) {
@@ -24,6 +42,7 @@ function getFromNode(node) {
2442}
2543
2644module . exports = {
45+ getCreateClassFromContext : getCreateClassFromContext ,
2746 getFromContext : getFromContext ,
2847 getFromNode : getFromNode
2948} ;
You can’t perform that action at this time.
0 commit comments