Skip to content

Commit

Permalink
Add Makefile with lint and format targets for better DX
Browse files Browse the repository at this point in the history
Using shellcheck and shfmt.
  • Loading branch information
stefanmaric committed Dec 18, 2019
1 parent 70409ba commit 01ea2ee
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,16 @@ indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[Makefile]
indent_size = 4
indent_style = tab

# These are shfmt extensions
# See: https://github.com/mvdan/sh

[bin/*]
shell_variant = posix
binary_next_line = true
switch_case_indent = true
space_redirects = true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.tmp/
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Improve self-upgrade script
- Improve previous installation detection on g-install
- Make self-upgrade throw if g was not installed via g-install
- Add Makefile with lint and format targets for better DX

## 0.6.0 - 2019-10-13

Expand Down
40 changes: 40 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
.POSIX:

PLATFORM=$(shell uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(shell uname -m | tr '[:upper:]' '[:lower:]')
ARCH_SIMPLE=$(shell echo $(ARCH) | sed 's/x86_64/amd64/g')

SHELLCHECK_VERSION=0.7.0
SHELLCHECK_DOWNLOAD_URL=https://shellcheck.storage.googleapis.com/shellcheck-v$(SHELLCHECK_VERSION).$(PLATFORM).$(ARCH).tar.xz
SHELLCHECK_TAR_PATH=shellcheck-v$(SHELLCHECK_VERSION)/shellcheck

SHFMT_VERSION=3.0.0
SHFMT_DOWNLOAD_URL=https://github.com/mvdan/sh/releases/download/v$(SHFMT_VERSION)/shfmt_v$(SHFMT_VERSION)_$(PLATFORM)_$(ARCH_SIMPLE)

.PHONY: prepare
prepare: .tmp/shellcheck .tmp/shfmt

.PHONY: lint
lint: prepare
@./.tmp/shellcheck bin/*
@./.tmp/shfmt -d bin/*

.PHONY: format
format: prepare
@./.tmp/shfmt -w bin/*

.tmp/shellcheck:
@echo "Downloading shellcheck"
@echo
@mkdir -p .tmp
@curl '$(SHELLCHECK_DOWNLOAD_URL)' | tar -xJO '$(SHELLCHECK_TAR_PATH)' > .tmp/shellcheck
@chmod +x .tmp/shellcheck
@echo

.tmp/shfmt:
@echo "Downloading shfmt"
@echo
@mkdir -p .tmp
@curl --location '$(SHFMT_DOWNLOAD_URL)' > .tmp/shfmt
@chmod +x .tmp/shfmt
@echo

0 comments on commit 01ea2ee

Please sign in to comment.