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
37
37
{
38
38
" settings" : {
39
39
" react" : {
40
+ " createClass" : " createClass" , // Regex for Component Factory to use, default to "createClass"
40
41
" pragma" : " React" , // Pragma to use, default to "React"
41
42
" version" : " 15.0" // React version, default to the latest React stable release
42
43
}
Original file line number Diff line number Diff line change @@ -136,6 +136,7 @@ Components.prototype.length = function() {
136
136
137
137
function componentRule ( rule , context ) {
138
138
139
+ var createClass = pragmaUtil . getCreateClassFromContext ( context ) ;
139
140
var pragma = pragmaUtil . getFromContext ( context ) ;
140
141
var sourceCode = context . getSourceCode ( ) ;
141
142
var components = new Components ( ) ;
@@ -153,7 +154,7 @@ function componentRule(rule, context) {
153
154
if ( ! node . parent ) {
154
155
return false ;
155
156
}
156
- return new RegExp ( '^(' + pragma + '\\.)?createClass$' ) . test ( sourceCode . getText ( node . parent . callee ) ) ;
157
+ return new RegExp ( '^(' + pragma + '\\.)?' + createClass + ' $') . test ( sourceCode . getText ( node . parent . callee ) ) ;
157
158
} ,
158
159
159
160
/**
Original file line number Diff line number Diff line change 5
5
'use strict' ;
6
6
7
7
var 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
+ }
8
23
9
24
function getFromContext ( context ) {
10
25
var pragma = 'React' ;
11
26
// .eslintrc shared settings (http://eslint.org/docs/user-guide/configuring#adding-shared-settings)
12
27
if ( context . settings . react && context . settings . react . pragma ) {
13
28
pragma = context . settings . react . pragma ;
14
29
}
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 ;
16
34
}
17
35
18
36
function getFromNode ( node ) {
@@ -24,6 +42,7 @@ function getFromNode(node) {
24
42
}
25
43
26
44
module . exports = {
45
+ getCreateClassFromContext : getCreateClassFromContext ,
27
46
getFromContext : getFromContext ,
28
47
getFromNode : getFromNode
29
48
} ;
You can’t perform that action at this time.
0 commit comments