From b34ced72c61a9361e1f5ba485ec0d9787a8f86d6 Mon Sep 17 00:00:00 2001 From: Dave Rolsky Date: Sun, 5 Mar 2023 15:15:31 -0600 Subject: [PATCH] Add dev tooling to use precious --- .gitignore | 5 +++++ dev/bin/install-dev-tools.sh | 43 ++++++++++++++++++++++++++++++++++++ git/hooks/pre-commit.sh | 15 +++++++++++++ git/setup.pl | 26 ++++++++++++++++++++++ precious.toml | 26 ++++++++++++++++++++++ 5 files changed, 115 insertions(+) create mode 100644 .gitignore create mode 100755 dev/bin/install-dev-tools.sh create mode 100755 git/hooks/pre-commit.sh create mode 100755 git/setup.pl create mode 100644 precious.toml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7a616c2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +/node_modules +/package-lock.json +/package.json +.\#* +\#*\# diff --git a/dev/bin/install-dev-tools.sh b/dev/bin/install-dev-tools.sh new file mode 100755 index 0000000..9844d9a --- /dev/null +++ b/dev/bin/install-dev-tools.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +set -eo pipefail + +function run () { + echo $1 + eval $1 +} + +function install_tools () { + curl --silent --location \ + https://raw.githubusercontent.com/houseabsolute/ubi/master/bootstrap/bootstrap-ubi.sh | + sh + run "rustup component add clippy" + run "ubi --project houseabsolute/precious --in ~/bin" + run "npm install prettier" +} + +if [ "$1" == "-v" ]; then + set -x +fi + +mkdir -p $HOME/bin + +set +e +echo ":$PATH:" | grep --extended-regexp ":$HOME/bin:" >& /dev/null +if [ "$?" -eq "0" ]; then + path_has_home_bin=1 +fi +set -e + +if [ -z "$path_has_home_bin" ]; then + PATH=$HOME/bin:$PATH +fi + +install_tools + +echo "Tools were installed into $HOME/bin." +if [ -z "$path_has_home_bin" ]; then + echo "You should add $HOME/bin to your PATH." +fi + +exit 0 diff --git a/git/hooks/pre-commit.sh b/git/hooks/pre-commit.sh new file mode 100755 index 0000000..63595ad --- /dev/null +++ b/git/hooks/pre-commit.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +status=0 + +PRECIOUS=$(which precious) +if [[ -z $PRECIOUS ]]; then + PRECIOUS=./bin/precious +fi + +"$PRECIOUS" lint -s +if (( $? != 0 )); then + status+=1 +fi + +exit $status diff --git a/git/setup.pl b/git/setup.pl new file mode 100755 index 0000000..b3ffacc --- /dev/null +++ b/git/setup.pl @@ -0,0 +1,26 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +use Cwd qw( abs_path ); + +symlink_hook('pre-commit'); + +sub symlink_hook { + my $hook = shift; + + my $dot = ".git/hooks/$hook"; + my $file = "git/hooks/$hook.sh"; + my $link = "../../$file"; + + if ( -e $dot ) { + if ( -l $dot ) { + return if readlink $dot eq $link; + } + warn "You already have a hook at $dot!\n"; + return; + } + + symlink $link, $dot; +} diff --git a/precious.toml b/precious.toml new file mode 100644 index 0000000..6da1d01 --- /dev/null +++ b/precious.toml @@ -0,0 +1,26 @@ +exclude = [ + "target", +] + +[commands.prettier] +type = "both" +include = [ "**/*.md", "**/*.yml" ] +cmd = [ "./node_modules/.bin/prettier", "--no-config" ] +lint_flags = "--check" +tidy_flags = "--write" +ok_exit_codes = 0 +lint_failure_exit_codes = 1 +ignore_stderr = [ "Code style issues" ] + +[commands.omegasort-gitignore] +type = "both" +include = "**/.gitignore" +cmd = [ "omegasort", "--sort", "path", "--unique" ] +lint_flags = "--check" +tidy_flags = "--in-place" +ok_exit_codes = 0 +lint_failure_exit_codes = 1 +ignore_stderr = [ + "The .+ file is not sorted", + "The .+ file is not unique", +]