File tree 3 files changed +112
-0
lines changed
3 files changed +112
-0
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
17
17
* [ ` prefer-exact-props ` ] improve performance for ` Identifier ` visitor ([ #3190 ] [ ] @meowtec )
18
18
* ` propTypes ` : Handle TSTypeReference in no-unused-prop-type ([ #3195 ] [ ] @niik )
19
19
* [ ` sort-prop-types ` ] : avoid repeated warnings of the same node/reason ([ #519 ] [ ] @ljharb )
20
+ * [ ` jsx-indent ` ] : Fix indent handling for closing parentheses ([ #620 ] [ ] @stefanbuck ] )
20
21
21
22
### Changed
22
23
* [ readme] change [ ` jsx-runtime ` ] link from branch to sha ([ #3160 ] [ ] @tatsushitoji )
@@ -40,6 +41,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
40
41
[ #3133 ] : https://github.com/yannickcr/eslint-plugin-react/pull/3133
41
42
[ #2921 ] : https://github.com/yannickcr/eslint-plugin-react/pull/2921
42
43
[ #2753 ] : https://github.com/yannickcr/eslint-plugin-react/pull/2753
44
+ [ #620 ] : https://github.com/yannickcr/eslint-plugin-react/pull/620
43
45
[ #519 ] : https://github.com/yannickcr/eslint-plugin-react/issues/519
44
46
45
47
## [ 7.28.0] - 2021.12.22
Original file line number Diff line number Diff line change @@ -114,6 +114,21 @@ module.exports = {
114
114
} ;
115
115
}
116
116
117
+ if ( node . type === 'ReturnStatement' ) {
118
+ const raw = context . getSourceCode ( ) . getText ( node ) ;
119
+ const lines = raw . split ( '\n' ) ;
120
+ if ( lines . length > 1 ) {
121
+ return function fix ( fixer ) {
122
+ const lastLineStart = raw . lastIndexOf ( '\n' ) ;
123
+ const lastLine = raw . slice ( lastLineStart ) . replace ( / ^ \n [ \t ] * ( \S ) / , ( match , p1 ) => `\n${ indent } ${ p1 } ` ) ;
124
+ return fixer . replaceTextRange (
125
+ [ node . range [ 0 ] + lastLineStart , node . range [ 1 ] ] ,
126
+ lastLine
127
+ ) ;
128
+ } ;
129
+ }
130
+ }
131
+
117
132
return function fix ( fixer ) {
118
133
return fixer . replaceTextRange (
119
134
[ node . range [ 0 ] - node . loc . start . column , node . range [ 0 ] ] ,
@@ -396,6 +411,19 @@ module.exports = {
396
411
} ,
397
412
Literal : handleLiteral ,
398
413
JSXText : handleLiteral ,
414
+
415
+ ReturnStatement ( node ) {
416
+ if ( ! node . parent ) {
417
+ return ;
418
+ }
419
+
420
+ const openingIndent = getNodeIndent ( node ) ;
421
+ const closingIndent = getNodeIndent ( node , true ) ;
422
+
423
+ if ( openingIndent !== closingIndent ) {
424
+ report ( node , openingIndent , closingIndent ) ;
425
+ }
426
+ } ,
399
427
} ;
400
428
} ,
401
429
} ;
Original file line number Diff line number Diff line change @@ -1094,6 +1094,28 @@ const Component = () => (
1094
1094
}
1095
1095
` ,
1096
1096
} ,
1097
+ {
1098
+ code : `
1099
+ function App() {
1100
+ return (
1101
+ <App />
1102
+ );
1103
+ }
1104
+ ` ,
1105
+ options : [ 2 ] ,
1106
+ parserOptions,
1107
+ } ,
1108
+ {
1109
+ code : `
1110
+ function App() {
1111
+ return <App>
1112
+ <Foo />
1113
+ </App>;
1114
+ }
1115
+ ` ,
1116
+ options : [ 2 ] ,
1117
+ parserOptions,
1118
+ } ,
1097
1119
] ) ,
1098
1120
1099
1121
invalid : parsers . all ( [
@@ -1291,6 +1313,17 @@ const Component = () => (
1291
1313
errors : [
1292
1314
{
1293
1315
messageId : 'wrongIndent' ,
1316
+ line : 3 ,
1317
+ data : {
1318
+ needed : 10 ,
1319
+ type : 'space' ,
1320
+ characters : 'characters' ,
1321
+ gotten : 17 ,
1322
+ } ,
1323
+ } ,
1324
+ {
1325
+ messageId : 'wrongIndent' ,
1326
+ line : 5 ,
1294
1327
data : {
1295
1328
needed : 10 ,
1296
1329
type : 'space' ,
@@ -1319,6 +1352,17 @@ const Component = () => (
1319
1352
errors : [
1320
1353
{
1321
1354
messageId : 'wrongIndent' ,
1355
+ line : 3 ,
1356
+ data : {
1357
+ needed : 10 ,
1358
+ type : 'space' ,
1359
+ characters : 'characters' ,
1360
+ gotten : 12 ,
1361
+ } ,
1362
+ } ,
1363
+ {
1364
+ messageId : 'wrongIndent' ,
1365
+ line : 5 ,
1322
1366
data : {
1323
1367
needed : 10 ,
1324
1368
type : 'space' ,
@@ -2771,5 +2815,43 @@ const Component = () => (
2771
2815
} ,
2772
2816
] ,
2773
2817
} ,
2818
+ {
2819
+ code : `
2820
+ function App() {
2821
+ return (
2822
+ <App />
2823
+ );
2824
+ }
2825
+ ` ,
2826
+ output : `
2827
+ function App() {
2828
+ return (
2829
+ <App />
2830
+ );
2831
+ }
2832
+ ` ,
2833
+ options : [ 2 ] ,
2834
+ parserOptions,
2835
+ errors : [ { message : 'Expected indentation of 10 space characters but found 12.' } ] ,
2836
+ } ,
2837
+ {
2838
+ code : `
2839
+ function App() {
2840
+ return (
2841
+ <App />
2842
+ );
2843
+ }
2844
+ ` ,
2845
+ output : `
2846
+ function App() {
2847
+ return (
2848
+ <App />
2849
+ );
2850
+ }
2851
+ ` ,
2852
+ options : [ 2 ] ,
2853
+ parserOptions,
2854
+ errors : [ { message : 'Expected indentation of 10 space characters but found 8.' } ] ,
2855
+ } ,
2774
2856
] ) ,
2775
2857
} ) ;
You can’t perform that action at this time.
0 commit comments