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:
3535
3636``` js
3737...
38- " jsx-max-props-per-line" : [< enabled> , { " maximum" : < number> }]
38+ " jsx-max-props-per-line" : [< enabled> , { " maximum" : < number> , " when " : < string > }]
3939...
4040```
4141
@@ -60,6 +60,28 @@ The following patterns are not considered warnings:
6060/ > ;
6161```
6262
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+
6385## When not to use
6486
6587If 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 = {
2323 maximum : {
2424 type : 'integer' ,
2525 minimum : 1
26+ } ,
27+ when : {
28+ type : 'string' ,
29+ enum : [ 'always' , 'multiline' ]
2630 }
2731 }
2832 } ]
@@ -33,6 +37,7 @@ module.exports = {
3337 var sourceCode = context . getSourceCode ( ) ;
3438 var configuration = context . options [ 0 ] || { } ;
3539 var maximum = configuration . maximum || 1 ;
40+ var when = configuration . when || 'always' ;
3641
3742 function getPropName ( propNode ) {
3843 if ( propNode . type === 'JSXSpreadAttribute' ) {
@@ -47,6 +52,10 @@ module.exports = {
4752 return ;
4853 }
4954
55+ if ( when === 'multiline' && node . loc . start . line === node . loc . end . line ) {
56+ return ;
57+ }
58+
5059 var firstProp = node . attributes [ 0 ] ;
5160 var linePartitionedProps = [ [ firstProp ] ] ;
5261
Original file line number Diff line number Diff line change @@ -25,12 +25,23 @@ var parserOptions = {
2525var ruleTester = new RuleTester ( ) ;
2626ruleTester . run ( 'jsx-max-props-per-line' , rule , {
2727 valid : [ {
28+ code : '<App />' ,
29+ parserOptions : parserOptions
30+ } , {
2831 code : '<App foo />' ,
2932 parserOptions : parserOptions
3033 } , {
3134 code : '<App foo bar />' ,
3235 options : [ { maximum : 2 } ] ,
3336 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
3445 } , {
3546 code : '<App {...this.props} bar />' ,
3647 options : [ { maximum : 2 } ] ,
You can’t perform that action at this time.
0 commit comments