File tree Expand file tree Collapse file tree 3 files changed +100
-0
lines changed Expand file tree Collapse file tree 3 files changed +100
-0
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,7 @@ var allRules = {
41
41
'jsx-indent-props' : require ( './lib/rules/jsx-indent-props' ) ,
42
42
'jsx-indent' : require ( './lib/rules/jsx-indent' ) ,
43
43
'jsx-closing-bracket-location' : require ( './lib/rules/jsx-closing-bracket-location' ) ,
44
+ 'jsx-closing-tag-location' : require ( './lib/rules/jsx-closing-tag-location' ) ,
44
45
'jsx-space-before-closing' : require ( './lib/rules/jsx-space-before-closing' ) ,
45
46
'no-direct-mutation-state' : require ( './lib/rules/no-direct-mutation-state' ) ,
46
47
'forbid-component-props' : require ( './lib/rules/forbid-component-props' ) ,
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @fileoverview Validate closing tag location in JSX
3
+ * @author Ross Solomon
4
+ */
5
+ 'use strict' ;
6
+
7
+ // ------------------------------------------------------------------------------
8
+ // Rule Definition
9
+ // ------------------------------------------------------------------------------
10
+ module . exports = {
11
+ meta : {
12
+ docs : {
13
+ description : 'Validate closing tag location in JSX' ,
14
+ category : 'Stylistic Issues' ,
15
+ recommended : false
16
+ }
17
+ } ,
18
+
19
+ create : function ( context ) {
20
+ return {
21
+ JSXClosingElement : function ( node ) {
22
+ if ( ! node . parent ) {
23
+ return ;
24
+ }
25
+
26
+ const opening = node . parent . openingElement ;
27
+ if ( opening . loc . start . line === node . loc . start . line ) {
28
+ return ;
29
+ }
30
+
31
+ if ( opening . loc . start . column === node . loc . start . column ) {
32
+ return ;
33
+ }
34
+
35
+ context . report ( {
36
+ node : node ,
37
+ loc : node . loc ,
38
+ message : 'Expected closing tag to match indentation of opening.'
39
+ } ) ;
40
+ }
41
+ } ;
42
+ }
43
+ } ;
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @fileoverview Validate closing tag location in JSX
3
+ * @author Ross Solomon
4
+ */
5
+ 'use strict' ;
6
+
7
+ // ------------------------------------------------------------------------------
8
+ // Requirements
9
+ // ------------------------------------------------------------------------------
10
+
11
+ const rule = require ( '../../../lib/rules/jsx-closing-tag-location' ) ;
12
+ const { RuleTester} = require ( 'eslint' ) ;
13
+ const parserOptions = {
14
+ ecmaVersion : 8 ,
15
+ sourceType : 'module' ,
16
+ ecmaFeatures : {
17
+ experimentalObjectRestSpread : true ,
18
+ jsx : true
19
+ }
20
+ } ;
21
+
22
+ const MESSAGE_MATCH_INDENTATION = [ { message : 'Expected closing tag to match indentation of opening.' } ] ;
23
+
24
+ // ------------------------------------------------------------------------------
25
+ // Tests
26
+ // ------------------------------------------------------------------------------
27
+
28
+ const ruleTester = new RuleTester ( { parserOptions} ) ;
29
+ ruleTester . run ( 'jsx-closing-tag-location' , rule , {
30
+ valid : [ {
31
+ code : [
32
+ '<App>' ,
33
+ ' foo' ,
34
+ '</App>'
35
+ ] . join ( '\n' )
36
+ } , {
37
+ code : [
38
+ '<App>foo</App>'
39
+ ] . join ( '\n' )
40
+ } ] ,
41
+
42
+ invalid : [ {
43
+ code : [
44
+ '<App>' ,
45
+ ' foo' ,
46
+ ' </App>'
47
+ ] . join ( '\n' ) ,
48
+ errors : MESSAGE_MATCH_INDENTATION
49
+ } , {
50
+ code : [
51
+ '<App>' ,
52
+ ' foo</App>'
53
+ ] . join ( '\n' ) ,
54
+ errors : MESSAGE_MATCH_INDENTATION
55
+ } ]
56
+ } ) ;
You can’t perform that action at this time.
0 commit comments