Skip to content

Instantly share code, notes, and snippets.

@farhansolodev
Created April 25, 2023 01:00
Show Gist options
  • Save farhansolodev/7c2d3c12e651dac35c969f60cef6930c to your computer and use it in GitHub Desktop.
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
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