From 09ce3c2f998f819f36dc216a3286681cde63196f Mon Sep 17 00:00:00 2001 From: Pierre Krafft Date: Sat, 6 Jan 2018 16:02:17 +0100 Subject: [PATCH] Normalize line endings in sample-linter This prevents accidental mixing of line endings if the repo is checked out with autocrlf=false on Windows --- utils/sample-linter.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/utils/sample-linter.js b/utils/sample-linter.js index 8795299ed2..e33b0bc0b9 100644 --- a/utils/sample-linter.js +++ b/utils/sample-linter.js @@ -57,7 +57,7 @@ function splitLines(text) { return lines; } -var EOL = require('os').EOL; +var EOL = '\n'; var userFunctions = [ 'draw', @@ -94,12 +94,15 @@ module.exports = { '.js': { supportsAutofix: true, preprocess: function(text) { + // Normalize line endings + text = text.replace(/(\r|\n)+/, EOL); + this.lines = splitLines(text); var m; var comments = []; - var reComment = /\/\*\*(?:.|\r|\n)*?\*\//g; + var reComment = /\/\*\*(?:.|\n)*?\*\//g; while ((m = reComment.exec(text)) != null) { var value = m[0]; comments.push({ @@ -114,7 +117,7 @@ module.exports = { var comment = comments[i]; var commentText = comment.value; - var re = /(]*>\s*(?:\r\n|\r|\n))((?:.|\r|\n)*?)<\/code>/gm; + var re = /(]*>\s*(?:\n))((?:.|\n)*?)<\/code>/gm; while ((m = re.exec(commentText)) != null) { var code = m[2]; if (!code) continue;