Created
April 25, 2023 01:00
-
-
Save farhansolodev/7c2d3c12e651dac35c969f60cef6930c to your computer and use it in GitHub Desktop.
Prevent Go from compiling if golangci-lint issues persist by using this alias
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
alias go='go_with_lint' | |
function go_with_lint() { | |
local args=("$@") | |
local lint_cmd=("golangci-lint run .") | |
# Check if "run" or "build" command is being used | |
if [[ ${args[0]} == "run" || ${args[0]} == "build" ]]; then | |
# If a file or directory argument is provided, add it to the lint command | |
if [[ ${#args[@]} -gt 1 ]]; then | |
local file_or_dir="${args[1]}" | |
# If the file or directory argument is not a flag, add it to the lint command | |
if [[ ! ${file_or_dir} == -* ]]; then | |
lint_cmd=("golangci-lint run ${file_or_dir}") | |
# Remove the file or directory argument from the original arguments | |
args=("${args[@]:0:1}" "${args[@]:2}") | |
fi | |
fi | |
# Execute the lint command followed by the original "go" command with arguments | |
${lint_cmd[@]} && command go "${args[@]}" | |
else | |
# If not "run" or "build" command, execute the original "go" command with arguments | |
command go "${args[@]}" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment