@@ -14,7 +14,8 @@ module.exports = function(context) {
14
14
'after-props' : 'placed after the last prop' ,
15
15
'after-tag' : 'placed after the opening tag' ,
16
16
'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'
18
19
} ;
19
20
var DEFAULT_LOCATION = 'tag-aligned' ;
20
21
@@ -80,15 +81,19 @@ module.exports = function(context) {
80
81
return tokens . lastProp . column === tokens . closing . column ;
81
82
case 'tag-aligned' :
82
83
return tokens . opening . column === tokens . closing . column ;
84
+ case 'line-aligned' :
85
+ return tokens . openingStartOfLine . column === tokens . closing . column ;
83
86
default :
84
87
return true ;
85
88
}
86
89
}
87
90
88
91
/**
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.
90
94
* @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.
92
97
*/
93
98
function getTokensLocations ( node ) {
94
99
var opening = context . getFirstToken ( node ) . loc . start ;
@@ -102,12 +107,18 @@ module.exports = function(context) {
102
107
line : context . getLastToken ( lastProp ) . loc . end . line
103
108
} ;
104
109
}
110
+ var openingLine = context . getSourceCode ( ) . lines [ opening . line - 1 ] ;
111
+ var openingStartOfLine = {
112
+ column : / ^ \s * / . exec ( openingLine ) [ 0 ] . length ,
113
+ line : opening . line
114
+ } ;
105
115
return {
106
116
tag : tag ,
107
117
opening : opening ,
108
118
closing : closing ,
109
119
lastProp : lastProp ,
110
- selfClosing : node . selfClosing
120
+ selfClosing : node . selfClosing ,
121
+ openingStartOfLine : openingStartOfLine
111
122
} ;
112
123
}
113
124
@@ -129,24 +140,24 @@ module.exports = function(context) {
129
140
module . exports . schema = [ {
130
141
oneOf : [
131
142
{
132
- enum : [ 'after-props' , 'props-aligned' , 'tag-aligned' ]
143
+ enum : [ 'after-props' , 'props-aligned' , 'tag-aligned' , 'line-aligned' ]
133
144
} ,
134
145
{
135
146
type : 'object' ,
136
147
properties : {
137
148
location : {
138
- enum : [ 'after-props' , 'props-aligned' , 'tag-aligned' ]
149
+ enum : [ 'after-props' , 'props-aligned' , 'tag-aligned' , 'line-aligned' ]
139
150
}
140
151
} ,
141
152
additionalProperties : false
142
153
} , {
143
154
type : 'object' ,
144
155
properties : {
145
156
nonEmpty : {
146
- enum : [ 'after-props' , 'props-aligned' , 'tag-aligned' ]
157
+ enum : [ 'after-props' , 'props-aligned' , 'tag-aligned' , 'line-aligned' ]
147
158
} ,
148
159
selfClosing : {
149
- enum : [ 'after-props' , 'props-aligned' , 'tag-aligned' ]
160
+ enum : [ 'after-props' , 'props-aligned' , 'tag-aligned' , 'line-aligned' ]
150
161
}
151
162
} ,
152
163
additionalProperties : false
0 commit comments