Skip to content

Commit ff12cf4

Browse files
committed
Remove special handling for > and do not touch Trailing spaces, withc are covered by other rules
1 parent d5a288d commit ff12cf4

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

lib/rules/no-multi-spaces.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,15 @@ module.exports = {
5656
const length = token.range[0] - prevToken.range[1] + 1
5757
const text = sourceCode.getText(token, length, 0).substring(0, length)
5858

59-
const match = text.match(/([^\r\n\t\s])([ \t]+)([>]?)([\n\r]?)/)
60-
if (!match) {
59+
const match = text.match(/([ \t]{2,})/)
60+
if (!match || /[\n\r]/g.test(text)) {
6161
prevToken = token
6262
continue // there is no errors
6363
}
6464

65-
const spaces = match[2].length
66-
const requiredSpaces = match[3] === '>' || match[4] !== '' ? 0 : 1
65+
const spaces = match[1].length
6766

68-
if (spaces > requiredSpaces) {
67+
if (spaces > 1) {
6968
context.report({
7069
node: token,
7170
loc: {
@@ -79,7 +78,7 @@ module.exports = {
7978
}
8079
},
8180
message: "Multiple spaces found before '{{displayValue}}'.",
82-
fix: (fixer) => fixer.replaceTextRange([prevToken.range[1], prevToken.range[1] + spaces], requiredSpaces ? ' ' : ''),
81+
fix: (fixer) => fixer.replaceTextRange([prevToken.range[1], token.range[0]], ' '),
8382
data: {
8483
displayValue: formatValue(token)
8584
}

tests/lib/rules/no-multi-spaces.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ ruleTester.run('no-multi-spaces', rule, {
3939
'<template><div>{{test}} <!-- fooo --></div></template>',
4040
'<template><div v-for="i in b">{{ i }}</div></template>',
4141
'<template><div v-for=" i in b ">{{ i }}</div></template>',
42-
'<template><div :test="` `"> {{ a }} </div></template>'
42+
'<template><div :test="` `"> {{ a }} </div></template>',
43+
'<template><div :test="` `"> \n {{ a }} </div></template>'
4344
],
4445
invalid: [
4546
{
@@ -118,12 +119,8 @@ ruleTester.run('no-multi-spaces', rule, {
118119
},
119120
{
120121
code: '<template><foo v-foo="" \n class="foo" /></template>',
121-
output: '<template><foo v-foo=""\n class="foo" /></template>',
122+
output: '<template><foo v-foo="" \n class="foo" /></template>',
122123
errors: [
123-
{
124-
message: "Multiple spaces found before 'class'.",
125-
type: 'HTMLIdentifier'
126-
},
127124
{
128125
message: "Multiple spaces found before '/>'.",
129126
type: 'HTMLSelfClosingTagClose'

0 commit comments

Comments
 (0)