Skip to content

Commit

Permalink
comma whitespace validation regexp bug fix (#162)
Browse files Browse the repository at this point in the history
  • Loading branch information
duaraghav8 committed Feb 11, 2018
1 parent 6feb81a commit 0972d60
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/rules/whitespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit 0972d60

Please sign in to comment.