From 0ed9f65ea032557ae023d8f5c43227eb99d94606 Mon Sep 17 00:00:00 2001 From: Alex Parlato Date: Thu, 14 Apr 2022 12:17:23 -0400 Subject: [PATCH] Lint all style paths (#2) --- bin/mapbox-gl-style-lint | 46 +++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/bin/mapbox-gl-style-lint b/bin/mapbox-gl-style-lint index 543ba79..3427dac 100755 --- a/bin/mapbox-gl-style-lint +++ b/bin/mapbox-gl-style-lint @@ -21,31 +21,37 @@ Usage: ${process.argv[1]} files...`); } return { filepaths }; -} +}; -const outputErrors = (file, errors) => { - errors.forEach(e => { - console.log(`${file}:${e.line}: ${e.message}`); - }); -} +const getErrorOutput = (file, error) => { + return `${file}:${error.line}: ${error.message}`; +}; const { filepaths } = parseArguments(process.argv); -filepaths.forEach(file => { - fs.readFile(file, 'utf8', (err, data) => { - if (err) { - console.error(err); - process.exit(1); - } +let errors = []; + +filepaths.map(file => { + let style; + try { + style = fs.readFileSync(file, 'utf8'); + } catch (err) { + console.error(err); + process.exit(1); + } - // Use jsonlint to get line numbers - const style = jsonlint.parse(data); + // Use jsonlint to get line numbers + style = jsonlint.parse(style); - const errors = lint(style); + let styleErrors = lint(style); - if (errors) { - outputErrors(file, errors); - process.exit(1); - } - }); + if (styleErrors) { + styleErrors = styleErrors.map(e => getErrorOutput(file, e)); + errors = errors.concat(styleErrors); + } }); + +if (errors.length) { + errors.forEach(e => console.log(e)); + process.exit(1); +}