@@ -24,8 +24,6 @@ module.exports = {
2424 * @returns {Object } AST event handlers.
2525 */
2626 create ( context ) {
27- const sourceCode = context . getSourceCode ( )
28-
2927 function formatValue ( token ) {
3028 switch ( token . type ) {
3129 case 'HTMLSelfClosingTagClose' : return '/>'
@@ -53,33 +51,16 @@ module.exports = {
5351
5452 let prevToken = tokens . shift ( )
5553 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 ) {
6956 context . report ( {
7057 node : token ,
7158 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
8061 } ,
8162 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 ] ] , ' ') ,
8364 data : {
8465 displayValue : formatValue ( token )
8566 }
0 commit comments