From f1d3f71beb76ea1a74f84f5a17dd0fe508c3e786 Mon Sep 17 00:00:00 2001 From: Veetaha Date: Fri, 21 Mar 2025 11:25:54 +0000 Subject: [PATCH] Add prettier --- .githooks/pre-commit | 44 ++++++++++++++++++++++++++++++++++++++++ .github/workflows/ci.yml | 11 ++++++++++ README.md | 1 - package-lock.json | 27 ++++++++++++++++++++++++ package.json | 8 ++++++++ 5 files changed, 90 insertions(+), 1 deletion(-) create mode 100755 .githooks/pre-commit create mode 100644 package-lock.json create mode 100644 package.json diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100755 index 0000000..1d69abe --- /dev/null +++ b/.githooks/pre-commit @@ -0,0 +1,44 @@ +#!/usr/bin/env bash +# +# Pre-commit hook to run lightweight checks and auto-format the code. It's designed +# to be blazingly fast, so it checks only changed files. Run the following command +# to install this hook for yourself. It's a symlink, to make sure it stays always +# up-to-date. +# +# ```bash +# ln -s ../../.githooks/pre-commit .git/hooks/pre-commit +# ``` + +set -euxo pipefail + +function command_exists() { + bin_name=$(basename "$1") + + if command -v "$1" &> /dev/null; then + printf "\e[0;32m[INFO] Using %s...\e[0m\n" "$bin_name" + return 0 + fi + + printf "\e[0;33m[WARN] %s CLI was not found. Ignoring it...\e[0m\n" "$bin_name" >&2 + return 1 +} + +files=$(git diff --cached --name-only --diff-filter=ACMR | sed 's| |\\ |g') + +if [[ -z "$files" ]]; then + echo "No files changed. Exiting the pre-commit hook..." + exit 0 +fi + +if command_exists typos; then + echo "$files" | xargs typos +fi + +if command_exists ./node_modules/.bin/prettier; then + echo "$files" | xargs ./node_modules/.bin/prettier --ignore-unknown --write +fi + +# Add the modified/prettified files to staging +echo "$files" | xargs git add + +exit 0 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dc36be4..c27df31 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,3 +46,14 @@ jobs: - run: terraform validate working-directory: ${{ matrix.project }} + + prettier: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: "22" + cache: "npm" + - run: npm ci --ignore-scripts + - run: npx prettier --check . diff --git a/README.md b/README.md index b07bd42..b454227 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,6 @@ This repository contains necessary IaC code to deploy the resources of elastio s Elastio terraform modules are published to the public Cloudsmith registry. In order to use them from that registry add this to your [`.terraformrc`](https://developer.hashicorp.com/terraform/cli/config/config-file), which should reside in your home directory (if you are on Linux): - ```hcl credentials "terraform.cloudsmith.io" { token = "elastio/public/" diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..a3ada7b --- /dev/null +++ b/package-lock.json @@ -0,0 +1,27 @@ +{ + "name": "elastio-stack", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "devDependencies": { + "prettier": "^3.5.3" + } + }, + "node_modules/prettier": { + "version": "3.5.3", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.5.3.tgz", + "integrity": "sha512-QQtaxnoDJeAkDvDKWCLiwIXkTgRhwYDEQCghU9Z6q03iyek/rxRh/2lC3HB7P8sWT2xC/y5JDctPLBIGzHKbhw==", + "dev": true, + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..76e7bb9 --- /dev/null +++ b/package.json @@ -0,0 +1,8 @@ +{ + "scripts": { + "fmt": "prettier --write ." + }, + "devDependencies": { + "prettier": "^3.5.3" + } +}