#!/usr/bin/env bash

#MISE description="Run checks before a commit"

set -e

source "$(git rev-parse --show-toplevel)/scripts/_helpers.sh"

ensure_working_directory!

debug_msg "Running shellcheck..."
fd . 'scripts/' --exclude '*.hurl' -t file --exec shellcheck --color

debug_msg "Running credo..."
mix credo --strict

debug_msg "Running sobelow..."
mix sobelow --compact --exit

debug_msg "Checking translations..."
mix gettext.extract --check-up-to-date

debug_msg "Checking formatting..."
mix format --check-formatted
prettier --check '.pi/extensions/**/*.{ts,js,json}'
prettier --check 'assets/css/**/*.css' 'assets/js/**/*.js'
prettier --check 'docs/**/*.md' 'docs/**/*.livemd' 'README.md'
prettier --check 'backlog/archive/**/*.md' 'backlog/completed/**/*.md' 'backlog/tasks/**/*.md' 'backlog/docs/**/*.md'

debug_msg "Checking unused deps..."
mix deps.unlock --unused

debug_msg "Running tests..."
mix test
