Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
//If this is not the last node of its parent array, ensure the comma spacing is acceptable
let parentArray = node.parent.arguments;
if (node.start === parentArray.slice(-1) [0].start) {
return;
}
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}${EOL.length === 1 ? thirdCharRegexp : ""}))$`
);
(!validationRegexp.test(codeAfterCurrentAssignment)) && context.report({
location: {
column: sourceCode.getEndingColumn(node.value) + 1
},
node: node,
message: "\"" + sourceCode.getText(node.value) + "\" should be immediately followed by a comma, then an optional space."
});
}
var newIndent;
var saveWaypoints = this.saveWaypoints;
for (; nextEnd < data.length;) {
nextStart = data.indexOf(EXPRESSION_PREFIX, nextEnd);
if (nextStart == -1)
break;
nextEnd = findEnd(data, nextStart);
var expression = data.substring(nextStart, nextEnd);
if (saveWaypoints) {
breaksCount = expression.split(lineBreak).length - 1;
lastBreakAt = expression.lastIndexOf(lineBreak);
newIndent = lastBreakAt > 0 ?
expression.substring(lastBreakAt + lineBreak.length).length :
indent + expression.length;
}
var metadata = saveWaypoints ? [breaksCount, newIndent] : null;
var placeholder = this.expressions.store(expression, metadata);
tempData.push(data.substring(cursor, nextStart));
tempData.push(placeholder);
if (saveWaypoints)
indent = newIndent + 1;
cursor = nextEnd;
}
return tempData.length > 0 ?
tempData.join('') + data.substring(cursor, data.length) :
data;
return new UrlScanner(data, this.context).reduce(function (url, tempData) {
if (saveWaypoints) {
breaksCount = url.split(lineBreak).length - 1;
lastBreakAt = url.lastIndexOf(lineBreak);
indent = lastBreakAt > 0 ?
url.substring(lastBreakAt + lineBreak.length).length :
url.length;
}
var placeholder = self.urls.store(url, saveWaypoints ? [breaksCount, indent] : null);
tempData.push(placeholder);
});
};
return new QuoteScanner(data).each(function (match, store) {
if (saveWaypoints) {
breaksCount = match.split(lineBreak).length - 1;
lastBreakAt = match.lastIndexOf(lineBreak);
indent = lastBreakAt > 0 ?
match.substring(lastBreakAt + lineBreak.length).length :
match.length;
metadata = [breaksCount, indent];
}
var placeholder = self.matches.store(match, metadata);
store.push(placeholder);
});
};
function iterate() {
result += stack;
stack = '';
//that.debug(1, 'Iterate ' + i + ' from ', blockData.chunks.length);
if (i >= blockData.chunks.length) {
for (l; l < blockData.lines.length; l++) {
result += blockData.lines[l] + EOL;
}
result = result.substr(0, result.length - EOL.length);
return callback(null, result);
}
chunk = blockData.chunks[i++];
if (chunk === null) {
console.error(chalk.red('There was an issue with chunk at index ' + i + '. Skipping chunk.'));
console.error(chalk.red(JSON.stringify(blockData, null, 4)));
return iterate();
}
for (l; l < chunk[0]; l++) result += blockData.lines[l] + EOL;
for (l; l <= chunk[1]; l++) stack += blockData.lines[l] + EOL;
section = blockData.lines.slice(chunk[0], chunk[1] + 1).join(EOL);
return new QuoteScanner(data).each(function (match, store) {
if (saveWaypoints) {
breaksCount = match.split(lineBreak).length - 1;
lastBreakAt = match.lastIndexOf(lineBreak);
indent = lastBreakAt > 0 ?
match.substring(lastBreakAt + lineBreak.length).length :
match.length;
metadata = [breaksCount, indent];
}
var placeholder = self.matches.store(match, metadata);
store.push(placeholder);
});
};
nextEnd = data.indexOf(COMMENT_SUFFIX, nextStart + COMMENT_PREFIX.length);
if (nextEnd == -1) {
this.context.warnings.push('Broken comment: \'' + data.substring(nextStart) + '\'.');
nextEnd = data.length - 2;
}
tempData.push(data.substring(cursor, nextStart));
var comment = data.substring(nextStart, nextEnd + COMMENT_SUFFIX.length);
var isSpecialComment = comment.indexOf(SPECIAL_COMMENT_PREFIX) === 0;
if (saveWaypoints) {
breaksCount = comment.split(lineBreak).length - 1;
lastBreakAt = comment.lastIndexOf(lineBreak);
newIndent = lastBreakAt > 0 ?
comment.substring(lastBreakAt + lineBreak.length).length :
indent + comment.length;
}
if (saveWaypoints || isSpecialComment) {
var metadata = saveWaypoints ? [breaksCount, newIndent] : null;
var placeholder = isSpecialComment ?
this.specialComments.store(comment, metadata) :
this.comments.store(comment, metadata);
tempData.push(placeholder);
}
if (saveWaypoints)
indent = newIndent + 1;
cursor = nextEnd + COMMENT_SUFFIX.length;
}
for (; cursor < data.length;) {
var nextMatch = from.nextMatch(data, cursor);
if (nextMatch.start < 0)
break;
tempData.push(data.substring(cursor, nextMatch.start));
var comment = from.restore(nextMatch.match);
if (isSpecial && (context.keepAll || (context.keepOne && context.restored === 0))) {
context.restored++;
tempData.push(comment);
cursor = nextMatch.end;
} else {
cursor = nextMatch.end + (context.keepBreaks && data.substring(nextMatch.end, nextMatch.end + lineBreak.length) == lineBreak ? lineBreak.length : 0);
}
}
return tempData.length > 0 ?
tempData.join('') + data.substring(cursor, data.length) :
data;
}
for (; cursor < data.length;) {
var nextMatch = from.nextMatch(data, cursor);
if (nextMatch.start < 0)
break;
tempData.push(data.substring(cursor, nextMatch.start));
var comment = from.restore(nextMatch.match);
if (isSpecial && (context.keepAll || (context.keepOne && context.restored === 0))) {
context.restored++;
tempData.push(comment);
cursor = nextMatch.end;
} else {
cursor = nextMatch.end + (context.keepBreaks && data.substring(nextMatch.end, nextMatch.end + lineBreak.length) == lineBreak ? lineBreak.length : 0);
}
}
return tempData.length > 0 ?
tempData.join('') + data.substring(cursor, data.length) :
data;
}