From ef2bbd78e7d7a3bd84ccd524ad9b54533af025ea Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Thu, 17 Feb 2022 17:33:35 +0300 Subject: [PATCH] Update validate.js --- scripts/db/validate.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/scripts/db/validate.js b/scripts/db/validate.js index 4256a370..a3683080 100644 --- a/scripts/db/validate.js +++ b/scripts/db/validate.js @@ -21,7 +21,20 @@ async function main() { ] for (const filepath of files) { if (!filepath.endsWith('.csv')) continue - const data = await csv.load(filepath).catch(err => { + + const eol = await file.eol(filepath) + if (eol !== 'CRLF') { + logger.error(chalk.red(`\nError: file must have line endings with CRLF (${filepath})`)) + process.exit(1) + } + + const csvString = await file.read(filepath) + if (/\s+$/.test(csvString)) { + logger.error(chalk.red(`\nError: empty lines at the end of file not allowed (${filepath})`)) + process.exit(1) + } + + const data = await csv.fromString(csvString).catch(err => { logger.error(chalk.red(`\n${err.message} (${filepath})`)) process.exit(1) })