diff --git a/Makefile b/Makefile index f2c86cbc1e8..ad5a27c3ad5 100644 --- a/Makefile +++ b/Makefile @@ -113,7 +113,7 @@ lint_yarn_lock: package.json yarn.lock lint_lockfiles: lint_gemfile_lock lint_yarn_lock ## Lints to ensure lockfiles are in sync -lintfix: ## Try to automatically fix any ruby, ERB, javascript, or CSS lint errors +lintfix: ## Try to automatically fix any Ruby, ERB, JavaScript, YAML, or CSS lint errors @echo "--- rubocop fix ---" bundle exec rubocop -a @echo "--- erblint fix ---" @@ -122,6 +122,8 @@ lintfix: ## Try to automatically fix any ruby, ERB, javascript, or CSS lint erro yarn lint --fix @echo "--- stylelint fix ---" yarn lint:css --fix + @echo "--- normalize yaml ---" + make normalize_yaml brakeman: ## Runs brakeman bundle exec brakeman diff --git a/app/javascript/packages/normalize-yaml/cli.js b/app/javascript/packages/normalize-yaml/cli.js index 1c417bb67a8..905d56f7d6f 100755 --- a/app/javascript/packages/normalize-yaml/cli.js +++ b/app/javascript/packages/normalize-yaml/cli.js @@ -1,4 +1,7 @@ #!/usr/bin/env node + +/* eslint-disable no-console */ + import { promises as fsPromises } from 'fs'; import { join } from 'path'; import prettier from 'prettier'; @@ -24,10 +27,19 @@ const options = { ), }; -Promise.all( +let exitCode = 0; + +await Promise.all( files.map(async (relativePath) => { const absolutePath = join(process.cwd(), relativePath); const content = await readFile(absolutePath, 'utf8'); - await writeFile(absolutePath, normalize(content, options)); + try { + await writeFile(absolutePath, normalize(content, options)); + } catch (error) { + console.error(`Error normalizing ${relativePath}: ${error.message}`); + exitCode = 1; + } }), ); + +process.exit(exitCode);