Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: no-multi-spaces false positive with irregular indent whitespace #8412

Merged
merged 1 commit into from Apr 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/rules/no-multi-spaces.js
Expand Up @@ -143,8 +143,7 @@ module.exports = {

const source = sourceCode.getText(),
allComments = sourceCode.getAllComments(),
JOINED_LINEBEAKS = Array.from(astUtils.LINEBREAKS).join(""),
pattern = new RegExp(String.raw`[^ \t${JOINED_LINEBEAKS}].? {2,}`, "g"); // note: repeating space
pattern = /[^\s].*? {2,}/g;
let parent;

while (pattern.test(source)) {
Expand Down
14 changes: 13 additions & 1 deletion tests/lib/rules/no-multi-spaces.js
Expand Up @@ -94,7 +94,11 @@ ruleTester.run("no-multi-spaces", rule, {
{ code: "var x = 5;\n // comment", options: [{ ignoreEOLComments: true }] },
{ code: "var x = 5; \n// comment", options: [{ ignoreEOLComments: true }] },
{ code: "var x = 5;\n /* multiline\n * comment\n */", options: [{ ignoreEOLComments: true }] },
{ code: "var x = 5; \n/* multiline\n * comment\n */", options: [{ ignoreEOLComments: true }] }
{ code: "var x = 5; \n/* multiline\n * comment\n */", options: [{ ignoreEOLComments: true }] },

"foo\n\f bar",
"foo\n\u2003 bar",
"foo\n \f bar"
],

invalid: [
Expand Down Expand Up @@ -592,6 +596,14 @@ ruleTester.run("no-multi-spaces", rule, {
message: "Multiple spaces found before '/*comment...*/'.",
type: "Block"
}]
},
{
code: "foo\n\f bar + baz",
output: "foo\n\f bar + baz",
errors: [{
message: "Multiple spaces found before '+'.",
type: "Punctuator"
}]
}
]
});