-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add pre-commit for sorting go imports
- Loading branch information
Showing
29 changed files
with
150 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v4.3.0 | ||
hooks: | ||
- id: trailing-whitespace | ||
- id: end-of-file-fixer | ||
- id: check-added-large-files | ||
- repo: local | ||
hooks: | ||
- id: goimports | ||
name: goimports | ||
entry: goimports.sh | ||
language: script | ||
types: [ go ] | ||
pass_filenames: true | ||
- repo: https://github.com/tekwizely/pre-commit-golang | ||
rev: v1.0.0-beta.5 | ||
hooks: | ||
- id: go-mod-tidy-repo | ||
- id: golangci-lint-mod |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module github.com/bibliolater/bookhunter | ||
module github.com/bookstairs/bookhunter | ||
|
||
go 1.18 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#!/bin/bash | ||
|
||
## | ||
# parse_file_hook_args | ||
# Creates global vars: | ||
# OPTIONS: List of options to passed to command | ||
# FILES : List of files to process, filtered against ignore_file_pattern_array | ||
# | ||
function parse_file_hook_args { | ||
OPTIONS=() | ||
# If arg doesn't pass [ -f ] check, then it is assumed to be an option | ||
# | ||
while [ $# -gt 0 ] && [ "$1" != "--" ] && [ ! -f "$1" ]; do | ||
OPTIONS+=("$1") | ||
shift | ||
done | ||
|
||
local all_files | ||
all_files=() | ||
# Assume start of file list (may still be options) | ||
# | ||
while [ $# -gt 0 ] && [ "$1" != "--" ]; do | ||
all_files+=("$1") | ||
shift | ||
done | ||
|
||
# If '--' next, then files = options | ||
# | ||
if [ "$1" == "--" ]; then | ||
shift | ||
# Append to previous options | ||
# | ||
OPTIONS+=("${all_files[@]}") | ||
all_files=() | ||
fi | ||
|
||
# Any remaining arguments are assumed to be files | ||
# | ||
all_files+=("$@") | ||
|
||
# Filter out vendor entries and ignore_file_pattern_array | ||
# | ||
FILES=() | ||
local file pattern | ||
ignore_file_pattern_array+=( "vendor/*" "*/vendor/*" "*/vendor" ) | ||
for file in "${all_files[@]}"; do | ||
for pattern in "${ignore_file_pattern_array[@]}"; do | ||
if [[ "${file}" == ${pattern} ]] ; then # pattern => unquoted | ||
continue 2 | ||
fi | ||
done | ||
FILES+=("${file}") | ||
done | ||
} | ||
|
||
parse_file_hook_args "$@" | ||
|
||
## | ||
# Remove all blank lines in go 'imports' statements, then sort with default goimports. | ||
# This scripts only works in macOS with `brew install gnu-sed` | ||
# Change gsed to sed in case of you are developing under the Linux. | ||
# | ||
for file in "${FILES[@]}"; do | ||
gsed -i ' | ||
/^import/,/)/ { | ||
/^$/ d | ||
} | ||
' "${file}" | ||
goimports -l -d -local github.com/bookstairs/bookhunter -w "${file}" | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.