@@ -22,45 +22,48 @@ module.exports = {
22
22
} ,
23
23
24
24
create : function ( context ) {
25
- return {
26
- JSXClosingElement : function ( node ) {
27
- if ( ! node . parent ) {
28
- return ;
29
- }
30
-
31
- const opening = node . parent . openingElement ;
32
- if ( opening . loc . start . line === node . loc . start . line ) {
33
- return ;
34
- }
25
+ function handleClosingElement ( node ) {
26
+ if ( ! node . parent ) {
27
+ return ;
28
+ }
35
29
36
- if ( opening . loc . start . column === node . loc . start . column ) {
37
- return ;
38
- }
30
+ const opening = node . parent . openingElement || node . parent . openingFragment ;
31
+ if ( opening . loc . start . line === node . loc . start . line ) {
32
+ return ;
33
+ }
39
34
40
- let message ;
41
- if ( ! astUtil . isNodeFirstInLine ( context , node ) ) {
42
- message = 'Closing tag of a multiline JSX expression must be on its own line.' ;
43
- } else {
44
- message = 'Expected closing tag to match indentation of opening.' ;
45
- }
35
+ if ( opening . loc . start . column === node . loc . start . column ) {
36
+ return ;
37
+ }
46
38
47
- context . report ( {
48
- node : node ,
49
- loc : node . loc ,
50
- message,
51
- fix : function ( fixer ) {
52
- const indent = Array ( opening . loc . start . column + 1 ) . join ( ' ' ) ;
53
- if ( astUtil . isNodeFirstInLine ( context , node ) ) {
54
- return fixer . replaceTextRange (
55
- [ node . range [ 0 ] - node . loc . start . column , node . range [ 0 ] ] ,
56
- indent
57
- ) ;
58
- }
39
+ let message ;
40
+ if ( ! astUtil . isNodeFirstInLine ( context , node ) ) {
41
+ message = 'Closing tag of a multiline JSX expression must be on its own line.' ;
42
+ } else {
43
+ message = 'Expected closing tag to match indentation of opening.' ;
44
+ }
59
45
60
- return fixer . insertTextBefore ( node , `\n${ indent } ` ) ;
46
+ context . report ( {
47
+ node : node ,
48
+ loc : node . loc ,
49
+ message,
50
+ fix : function ( fixer ) {
51
+ const indent = Array ( opening . loc . start . column + 1 ) . join ( ' ' ) ;
52
+ if ( astUtil . isNodeFirstInLine ( context , node ) ) {
53
+ return fixer . replaceTextRange (
54
+ [ node . range [ 0 ] - node . loc . start . column , node . range [ 0 ] ] ,
55
+ indent
56
+ ) ;
61
57
}
62
- } ) ;
63
- }
58
+
59
+ return fixer . insertTextBefore ( node , `\n${ indent } ` ) ;
60
+ }
61
+ } ) ;
62
+ }
63
+
64
+ return {
65
+ JSXClosingElement : handleClosingElement ,
66
+ JSXClosingFragment : handleClosingElement
64
67
} ;
65
68
}
66
69
} ;
0 commit comments