@@ -24,8 +24,6 @@ module.exports = {
24
24
* @returns {Object } AST event handlers.
25
25
*/
26
26
create ( context ) {
27
- const sourceCode = context . getSourceCode ( )
28
-
29
27
function formatValue ( token ) {
30
28
switch ( token . type ) {
31
29
case 'HTMLSelfClosingTagClose' : return '/>'
@@ -53,33 +51,16 @@ module.exports = {
53
51
54
52
let prevToken = tokens . shift ( )
55
53
for ( const token of tokens ) {
56
- const length = token . range [ 0 ] - prevToken . range [ 1 ] + 1
57
- const text = sourceCode . getText ( token , length , 0 ) . substring ( 0 , length )
58
-
59
- const match = text . match ( / ( [ ^ \r \n \t \s ] ) ( [ \t ] + ) ( [ > ] ? ) ( [ \n \r ] ? ) / )
60
- if ( ! match ) {
61
- prevToken = token
62
- continue // there is no errors
63
- }
64
-
65
- const spaces = match [ 2 ] . length
66
- const requiredSpaces = match [ 3 ] === '>' || match [ 4 ] !== '' ? 0 : 1
67
-
68
- if ( spaces > requiredSpaces ) {
54
+ const spaces = token . range [ 0 ] - prevToken . range [ 1 ]
55
+ if ( spaces > 1 && token . loc . start . line === prevToken . loc . start . line ) {
69
56
context . report ( {
70
57
node : token ,
71
58
loc : {
72
- start : {
73
- line : prevToken . loc . end . line ,
74
- column : prevToken . loc . end . column
75
- } ,
76
- end : {
77
- line : prevToken . loc . end . line ,
78
- column : prevToken . loc . end . column + spaces
79
- }
59
+ start : prevToken . loc . end ,
60
+ end : token . loc . start
80
61
} ,
81
62
message : "Multiple spaces found before '{{displayValue}}'." ,
82
- fix : ( fixer ) => fixer . replaceTextRange ( [ prevToken . range [ 1 ] , prevToken . range [ 1 ] + spaces ] , requiredSpaces ? ' ' : ' ') ,
63
+ fix : ( fixer ) => fixer . replaceTextRange ( [ prevToken . range [ 1 ] , token . range [ 0 ] ] , ' ') ,
83
64
data : {
84
65
displayValue : formatValue ( token )
85
66
}
0 commit comments