@@ -14,7 +14,8 @@ module.exports = function(context) {
1414 'after-props' : 'placed after the last prop' ,
1515 'after-tag' : 'placed after the opening tag' ,
1616 'props-aligned' : 'aligned with the last prop' ,
17- 'tag-aligned' : 'aligned with the opening tag'
17+ 'tag-aligned' : 'aligned with the opening tag' ,
18+ 'line-aligned' : 'aligned with the line containing the opening tag'
1819 } ;
1920 var DEFAULT_LOCATION = 'tag-aligned' ;
2021
@@ -80,15 +81,19 @@ module.exports = function(context) {
8081 return tokens . lastProp . column === tokens . closing . column ;
8182 case 'tag-aligned' :
8283 return tokens . opening . column === tokens . closing . column ;
84+ case 'line-aligned' :
85+ return tokens . openingStartOfLine . column === tokens . closing . column ;
8386 default :
8487 return true ;
8588 }
8689 }
8790
8891 /**
89- * Get the locations of the opening bracket, closing bracket and last prop
92+ * Get the locations of the opening bracket, closing bracket, last prop, and
93+ * start of opening line.
9094 * @param {ASTNode } node The node to check
91- * @return {Object } Locations of the opening bracket, closing bracket and last prop
95+ * @return {Object } Locations of the opening bracket, closing bracket, last
96+ * prop and start of opening line.
9297 */
9398 function getTokensLocations ( node ) {
9499 var opening = context . getFirstToken ( node ) . loc . start ;
@@ -102,12 +107,18 @@ module.exports = function(context) {
102107 line : context . getLastToken ( lastProp ) . loc . end . line
103108 } ;
104109 }
110+ var openingLine = context . getSourceCode ( ) . lines [ opening . line - 1 ] ;
111+ var openingStartOfLine = {
112+ column : / ^ \s * / . exec ( openingLine ) [ 0 ] . length ,
113+ line : opening . line
114+ } ;
105115 return {
106116 tag : tag ,
107117 opening : opening ,
108118 closing : closing ,
109119 lastProp : lastProp ,
110- selfClosing : node . selfClosing
120+ selfClosing : node . selfClosing ,
121+ openingStartOfLine : openingStartOfLine
111122 } ;
112123 }
113124
@@ -129,24 +140,24 @@ module.exports = function(context) {
129140module . exports . schema = [ {
130141 oneOf : [
131142 {
132- enum : [ 'after-props' , 'props-aligned' , 'tag-aligned' ]
143+ enum : [ 'after-props' , 'props-aligned' , 'tag-aligned' , 'line-aligned' ]
133144 } ,
134145 {
135146 type : 'object' ,
136147 properties : {
137148 location : {
138- enum : [ 'after-props' , 'props-aligned' , 'tag-aligned' ]
149+ enum : [ 'after-props' , 'props-aligned' , 'tag-aligned' , 'line-aligned' ]
139150 }
140151 } ,
141152 additionalProperties : false
142153 } , {
143154 type : 'object' ,
144155 properties : {
145156 nonEmpty : {
146- enum : [ 'after-props' , 'props-aligned' , 'tag-aligned' ]
157+ enum : [ 'after-props' , 'props-aligned' , 'tag-aligned' , 'line-aligned' ]
147158 } ,
148159 selfClosing : {
149- enum : [ 'after-props' , 'props-aligned' , 'tag-aligned' ]
160+ enum : [ 'after-props' , 'props-aligned' , 'tag-aligned' , 'line-aligned' ]
150161 }
151162 } ,
152163 additionalProperties : false
0 commit comments