-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow specifying golangci-lint custom
output path as argument
#5369
Comments
Hey, thank you for opening your first Issue ! 🙂 If you would like to contribute we have a guide for contributors. |
Hello,
I'm not sure to understand what to mean by "a generic harness for custom linters", can you provide more details? I think it's better to have a |
@ldez I'll have a concrete example for you shortly; it's a GitHub Action based on golangci/golangci-lint-action#1076 (comment). Probably won't maintain it for long; when the official action supports custom module plugins (i.e. golangci/golangci-lint-action#1076 is resolved) there's no longer any need.
Each repository using an action to run This will require tackling if/when you solve golangci/golangci-lint-action#1076 too. Thanks for all your work on this ecosystem! |
OK, the support of custom inside the GitHub Action will be added, I plan to work on it but after the v2. I plan to work on 2 issues on the GitHub Action:
As your request is related to the current limitations of the GitHub Action, and I don't want to add and maintain niche and "temporarily" options, I will decline this issue. I think I will work on this around mid and end of February (after go1.24 release and v2 release). |
@ldez would you consider a PR introducing this |
No, as I said in my previous comment.
|
Don't think the proposed feature is "niche and 'temporarily'" — it's relevant to the scenario I describe, but it's a worthwhile improvement in general:
Anyway, it's your prerogative to decline the change; I won't argue this point further. diff --git a/pkg/commands/custom.go b/pkg/commands/custom.go
index 1bc9f901..27117cb1 100644
--- a/pkg/commands/custom.go
+++ b/pkg/commands/custom.go
@@ -4,7 +4,9 @@ import (
"fmt"
"log"
"os"
+ "path"
+ "github.com/fatih/color"
"github.com/spf13/cobra"
"github.com/golangci/golangci-lint/pkg/commands/internal"
@@ -13,6 +15,10 @@ import (
const envKeepTempFiles = "CUSTOM_GCL_KEEP_TEMP_FILES"
+var (
+ outputArgument = ""
+)
+
type customCommand struct {
cmd *cobra.Command
@@ -33,6 +39,8 @@ func newCustomCommand(logger logutils.Log) *customCommand {
SilenceUsage: true,
}
+ customCmd.Flags().StringVarP(&outputArgument, "output", "o", "", color.GreenString("Path to output file"))
+
c.cmd = customCmd
return c
@@ -44,6 +52,12 @@ func (c *customCommand) preRunE(_ *cobra.Command, _ []string) error {
return err
}
+ if outputArgument != "" {
+ directory, name := path.Split(outputArgument)
+ cfg.Destination = directory
+ cfg.Name = name
+ }
+
err = cfg.Validate()
if err != nil {
return err
|
> [!NOTE] > `golangci-lint` maintainer [refuses to consider this change](golangci#5369 (comment)). Confirmed the help output is as expected: ``` Build a version of golangci-lint with custom linters Usage: golangci-lint custom [flags] Flags: -o, --output string Path to output file Global Flags: --color string Use color when printing; can be 'always', 'auto', or 'never' (default "auto") -h, --help Help for a command -v, --verbose Verbose output ```
> [!NOTE] > `golangci-lint` maintainer [refuses to consider this change](golangci#5369 (comment)). Confirmed the help output is as expected: ``` Build a version of golangci-lint with custom linters Usage: golangci-lint custom [flags] Flags: -o, --output string Path to output file Global Flags: --color string Use color when printing; can be 'always', 'auto', or 'never' (default "auto") -h, --help Help for a command -v, --verbose Verbose output ```
> [!NOTE] > `golangci-lint` maintainer [refuses to consider this change](golangci#5369 (comment)). Confirmed the help output is as expected: ``` Build a version of golangci-lint with custom linters Usage: golangci-lint custom [flags] Flags: -o, --output string Path to output file Global Flags: --color string Use color when printing; can be 'always', 'auto', or 'never' (default "auto") -h, --help Help for a command -v, --verbose Verbose output ```
Welcome
Your feature request related to a problem? Please describe
Currently
golangci-lint custom
write the resulting custom binary todestination
andname
specified in .custom-gcl.yml or equivalent../custom-gcl
by default.When building a generic harness for custom linters — one where users bring their own
.custom-gci.yml
files — I want to write a script that builds a custom linter and then invokes it, regardless of thedestination
andname
specified in YAML.Describe the solution you'd like
I want to be able to specify an output location with a command-line argument. For example, I'd like to run
This can behave analagously to the
-o output
argument ongo build
: if present, override the settings in YAML.Describe alternatives you've considered
name
,destination
) of a user's.custom-gcl.yml
file..custom-gcl.yml
files in my scripts to extractname
anddestination
, to recreate the path to the build target.Additional context
No response
Supporter
The text was updated successfully, but these errors were encountered: