From 0972d60cfd9516d732df32b2a683f0484ca41b02 Mon Sep 17 00:00:00 2001 From: duaraghav8 Date: Sun, 11 Feb 2018 22:58:02 +0530 Subject: [PATCH] comma whitespace validation regexp bug fix (#162) --- lib/rules/whitespace.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/rules/whitespace.js b/lib/rules/whitespace.js index 267e8c8..81fb83a 100644 --- a/lib/rules/whitespace.js +++ b/lib/rules/whitespace.js @@ -55,8 +55,13 @@ module.exports = { let escapedEOL = jse(EOL), codeAfterCurrentAssignment = sourceCode.getNextChars(node.value, 3); + // thirdCharRegexp is used in validationRegExp if EOL is unix-style, ie, len(EOL) = 1. + // If len(EOL) is 2, then comma + EOL cover 3 chars, then thirdCharRegexp gets treated as a checked for 4th character, + // resulting in false positive. + const thirdCharRegexp = `[^${escapedEOL}\\/]`; validationRegexp = new RegExp( - `^((,[^ ${escapedEOL}\\/].)|(, [^ ${escapedEOL}\\/])|(,${escapedEOL}[^${escapedEOL}\\/]))$`); + `^((,[^ ${escapedEOL}\\/].)|(, [^ ${escapedEOL}\\/])|(,${escapedEOL}${EOL.length === 1 ? thirdCharRegexp : ""}))$` + ); (!validationRegexp.test(codeAfterCurrentAssignment)) && context.report({ location: {