Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 ---"
Expand All @@ -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
Expand Down
16 changes: 14 additions & 2 deletions app/javascript/packages/normalize-yaml/cli.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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);