File tree Expand file tree Collapse file tree 3 files changed +43
-1
lines changed Expand file tree Collapse file tree 3 files changed +43
-1
lines changed Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ The following patterns are not considered warnings:
35
35
36
36
``` js
37
37
...
38
- " jsx-max-props-per-line" : [< enabled> , { " maximum" : < number> }]
38
+ " jsx-max-props-per-line" : [< enabled> , { " maximum" : < number> , " when " : < string > }]
39
39
...
40
40
```
41
41
@@ -60,6 +60,28 @@ The following patterns are not considered warnings:
60
60
/ > ;
61
61
```
62
62
63
+ ### ` when `
64
+
65
+ Possible values:
66
+ - ` always ` (default) - Always check for max props per line.
67
+ - ` multiline ` - Only check for max props per line when jsx tag spans multiple lines.
68
+
69
+ The following patterns are considered warnings:
70
+ ``` jsx
71
+ // [1, {when: always}]
72
+ < Hello firstName= " John" lastName= " Smith" / >
73
+ ```
74
+
75
+ The following patterns are not considered warnings:
76
+ ``` jsx
77
+ // [1, {when: multiline}]
78
+ < Hello firstName= " John" lastName= " Smith" / >
79
+ < Hello
80
+ firstName= " John"
81
+ lastName= " Smith"
82
+ / >
83
+ ```
84
+
63
85
## When not to use
64
86
65
87
If you are not using JSX then you can disable this rule.
Original file line number Diff line number Diff line change @@ -23,6 +23,10 @@ module.exports = {
23
23
maximum : {
24
24
type : 'integer' ,
25
25
minimum : 1
26
+ } ,
27
+ when : {
28
+ type : 'string' ,
29
+ enum : [ 'always' , 'multiline' ]
26
30
}
27
31
}
28
32
} ]
@@ -33,6 +37,7 @@ module.exports = {
33
37
var sourceCode = context . getSourceCode ( ) ;
34
38
var configuration = context . options [ 0 ] || { } ;
35
39
var maximum = configuration . maximum || 1 ;
40
+ var when = configuration . when || 'always' ;
36
41
37
42
function getPropName ( propNode ) {
38
43
if ( propNode . type === 'JSXSpreadAttribute' ) {
@@ -47,6 +52,10 @@ module.exports = {
47
52
return ;
48
53
}
49
54
55
+ if ( when === 'multiline' && node . loc . start . line === node . loc . end . line ) {
56
+ return ;
57
+ }
58
+
50
59
var firstProp = node . attributes [ 0 ] ;
51
60
var linePartitionedProps = [ [ firstProp ] ] ;
52
61
Original file line number Diff line number Diff line change @@ -25,12 +25,23 @@ var parserOptions = {
25
25
var ruleTester = new RuleTester ( ) ;
26
26
ruleTester . run ( 'jsx-max-props-per-line' , rule , {
27
27
valid : [ {
28
+ code : '<App />' ,
29
+ parserOptions : parserOptions
30
+ } , {
28
31
code : '<App foo />' ,
29
32
parserOptions : parserOptions
30
33
} , {
31
34
code : '<App foo bar />' ,
32
35
options : [ { maximum : 2 } ] ,
33
36
parserOptions : parserOptions
37
+ } , {
38
+ code : '<App foo bar />' ,
39
+ options : [ { when : 'multiline' } ] ,
40
+ parserOptions : parserOptions
41
+ } , {
42
+ code : '<App foo bar baz />' ,
43
+ options : [ { maximum : 2 , when : 'multiline' } ] ,
44
+ parserOptions : parserOptions
34
45
} , {
35
46
code : '<App {...this.props} bar />' ,
36
47
options : [ { maximum : 2 } ] ,
You can’t perform that action at this time.
0 commit comments