Skip to content

Commit

Permalink
Feature: linting (#20)
Browse files Browse the repository at this point in the history
* feat(ci): add revive linter config

Signed-off-by: ArtemTrofimushkin <[email protected]>

* feat(ci): fix linting issues

Signed-off-by: ArtemTrofimushkin <[email protected]>

* chore(ci): move revive settings to .golangci.yaml

Signed-off-by: ArtemTrofimushkin <[email protected]>

* chore(ci): restrict parallel test execution for ci mode to improve stability

Signed-off-by: ArtemTrofimushkin <[email protected]>
  • Loading branch information
ArtemTrofimushkin authored Feb 23, 2022
1 parent c812d26 commit 93d33c3
Show file tree
Hide file tree
Showing 16 changed files with 104 additions and 26 deletions.
68 changes: 68 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,71 @@ run:

issues:
fix: true

linters:
enable:
- revive

linters-settings:
revive:
ignore-generated-header: true
severity: error
confidence: 0.8
error-code: 1
warning-code: 1
directive:
specify-disable-reason: true
rules:
- name: atomic
- name: argument-limit
arguments: 5
- name: blank-imports
- name: bool-literal-in-expr
- name: cognitive-complexity
arguments: 25
- name: confusing-results
- name: context-as-argument
- name: context-keys-type
- name: constant-logical-expr
- name: cyclomatic
arguments: 50
- name: deep-exit
- name: dot-imports
- name: duplicated-imports
- name: empty-lines
- name: empty-block
- name: errorf
- name: error-return
- name: error-strings
- name: error-naming
- name: function-result-limit
arguments: 4
- name: if-return
- name: imports-blacklist
- name: increment-decrement
- name: indent-error-flow
- name: line-length-limit
arguments: 120
- name: max-public-structs
arguments: 4
- name: modifies-parameter
- name: modifies-value-receiver
- name: package-comments
- name: range
- name: range-val-address
- name: range-val-in-closure
- name: receiver-naming
- name: redefines-builtin-id
- name: string-of-int
- name: struct-tag
- name: superfluous-else
- name: time-naming
- name: unexported-return
- name: unnecessary-stmt
- name: unreachable-code
- name: unused-receiver
- name: unused-parameter
- name: var-declaration
- name: var-naming
arguments: [["ID"]]
- name: waitgroup-by-value
3 changes: 3 additions & 0 deletions cli/cmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func NewGCDumpCommand() *cobra.Command {
}

// NewTraceCommand return command that start dumper with dotnet-trace tool
// revive:disable:line-length-limit, This is an extended description
func NewTraceCommand() *cobra.Command {
builder := NewCommandBuilder(flags.NewDotnetTrace)
return builder.Build(
Expand All @@ -52,6 +53,8 @@ func NewTraceCommand() *cobra.Command {
)
}

// revive:enable:line-length-limit

// NewDumpCommand return command that start dumper with dotnet-dump tool
func NewDumpCommand() *cobra.Command {
builder := NewCommandBuilder(flags.NewDotnetDump)
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/launch.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (cb *CommandBuilder) copyOutput(pod *kubernetes.PodInfo, output string) err
return nil
}

func (cb *CommandBuilder) storeOutputOnHost(pod *kubernetes.PodInfo, output string) error {
func (*CommandBuilder) storeOutputOnHost(pod *kubernetes.PodInfo, output string) error {
hostOutput := fmt.Sprintf("%s/%s/%s", globals.PathTmpFolder, globals.PluginName, output)
fmt.Printf("Output located on host: %s, at path: %s\n", pod.Node, hostOutput)
return nil
Expand Down
2 changes: 1 addition & 1 deletion dumper/cmd/launch.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (cb *CommandBuilder) launch() error {
}

// for dotnet tools, in /tmp folder must exists sockets to running dotnet apps
// https://github.com/dotnet/diagnostics/blob/main/documentation/design-docs/ipc-protocol.md#naming-and-location-conventions
// https://github.com/dotnet/diagnostics/blob/main/documentation/design-docs/ipc-protocol.md#diagnostic-ipc-protocol
if err := os.Symlink(tmpSource, globals.PathTmpFolder); err != nil {
events.NewErrorEvent(err, "unable to mount tmp folder for container")
return err
Expand Down
2 changes: 2 additions & 0 deletions hacks/run-integration-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ flags=""

if [ -z "$ci" ]; then
flags="-parallel 1"
else
flags="-parallel 4"
fi

echo "Running tests..."
Expand Down
4 changes: 2 additions & 2 deletions internal/flags/dotnet_dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ func (d *DotnetDump) FormatArgs(args *Args) {
args.Append("type", d.Type.String())
}

func (d *DotnetDump) BinaryName() string {
func (*DotnetDump) BinaryName() string {
return "dotnet-dump"
}

func (d *DotnetDump) ToolName() string {
func (*DotnetDump) ToolName() string {
return "dump"
}

Expand Down
4 changes: 2 additions & 2 deletions internal/flags/dotnet_gcdump.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ func (gc *DotnetGCDump) FormatArgs(args *Args) {
}
}

func (gc *DotnetGCDump) BinaryName() string {
func (*DotnetGCDump) BinaryName() string {
return "dotnet-gcdump"
}

func (gc *DotnetGCDump) ToolName() string {
func (*DotnetGCDump) ToolName() string {
return "gcdump"
}

Expand Down
4 changes: 2 additions & 2 deletions internal/flags/dotnet_trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ func (t *DotnetTrace) FormatArgs(args *Args) {
}
}

func (t *DotnetTrace) BinaryName() string {
func (*DotnetTrace) BinaryName() string {
return "dotnet-trace"
}

func (t *DotnetTrace) ToolName() string {
func (*DotnetTrace) ToolName() string {
return "trace"
}

Expand Down
6 changes: 3 additions & 3 deletions internal/flags/types/clreventlevel.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ func (c *CLREventLevel) Set(str string) error {
if !ContainsItemString(supportedCLREventLevels, str) {
return fmt.Errorf("unsupported CLR Event Level \"%s\", must be one of: [%s]",
str, strings.Join(supportedCLREventLevels, ", "))

}

*c = CLREventLevel(str)
return nil
}

func (c *CLREventLevel) Type() string {
func (*CLREventLevel) Type() string {
return "clreventlevel"
}

func (c *CLREventLevel) Description() string {
func (*CLREventLevel) Description() string {
return "Verbosity of CLR events to be emitted. Supported levels:\n" +
strings.Join(supportedCLREventLevels, ", ")
}
7 changes: 5 additions & 2 deletions internal/flags/types/clrevents.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,18 @@ func (c *CLREvents) Set(str string) error {
return nil
}

func (c *CLREvents) Type() string {
func (*CLREvents) Type() string {
return "clrevents"
}

func (c *CLREvents) Description() string {
// revive:disable:line-length-limit This is extended description
func (*CLREvents) Description() string {
return fmt.Sprintf(
"A list of CLR runtime provider keywords to enable separated by \"%s\" signs.\n"+
"This is a simple mapping that lets you specify event keywords via string aliases rather than their hex values.\n"+
"More info here: https://docs.microsoft.com/en-us/dotnet/core/diagnostics/dotnet-trace#options-1",
CLREventsDelimiter,
)
}

// revive:enable:line-length-limit
8 changes: 5 additions & 3 deletions internal/flags/types/dumptype.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,23 @@ func (dt *DumpType) Set(str string) error {
if !ContainsItemString(supportedDumpTypes, str) {
return fmt.Errorf("unsupported Dump Type \"%s\", must be one of: [%s]",
str, strings.Join(supportedCLREventLevels, ", "))

}
*dt = DumpType(str)
return nil
}

func (dt *DumpType) Type() string {
func (*DumpType) Type() string {
return "type"
}

func (dt *DumpType) Description() string {
// revive:disable:line-length-limit This is an extended description
func (*DumpType) Description() string {
return "The kinds of information that are collected from process. Supported types:\n" +
strings.Join(supportedDumpTypes, ", ") + "\n" +
"Full - The largest dump containing all memory including the module images\n" +
"Heap - A large and relatively comprehensive dump containing module lists, thread lists, all stacks, exception information and all memory except for mapped images\n" +
"Mini - A small dump containing module lists, thread lists, exception information and all stacks\n" +
"Triage - A small dump containing minimal information"
}

// revive:enable:line-length-limit
4 changes: 2 additions & 2 deletions internal/flags/types/duration.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ func (d *Duration) checkDuration() error {
return nil
}

func (d *Duration) Type() string {
func (*Duration) Type() string {
return "duration"
}

func (d *Duration) Description() string {
func (*Duration) Description() string {
return "Trace for the given timespan and then automatically stop the trace." +
fmt.Sprintf(
"Provided in the form of dd:hh:mm:ss or "+
Expand Down
4 changes: 2 additions & 2 deletions internal/flags/types/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ func (f *Format) Set(str string) error {
return nil
}

func (f *Format) Type() string {
func (*Format) Type() string {
return "format"
}

func (f *Format) Description() string {
func (*Format) Description() string {
return "Sets the output format for the trace file conversion. Supported formats:\n" +
strings.Join(supportedFormats, ", ") +
fmt.Sprintf(" (default \"%s\")", defaultFormat)
Expand Down
4 changes: 2 additions & 2 deletions internal/flags/types/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ func (p *Profile) Set(str string) error {
return nil
}

func (p *Profile) Type() string {
func (*Profile) Type() string {
return "profile"
}

func (p *Profile) Description() string {
func (*Profile) Description() string {
return "A named pre-defined set of provider configurations that allows" +
"common tracing scenarios to be specified succinctly.\n" +
"The following profiles are available:\n" +
Expand Down
4 changes: 2 additions & 2 deletions internal/flags/types/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (p *Providers) Set(str string) error {
return nil
}

func (p *Providers) Description() string {
func (*Providers) Description() string {
return "A comma-separated list of EventPipe providers to be enabled.\n" +
"These providers supplement any providers implied by --profile <profile-name>.\n" +
"If there's any inconsistency for a particular provider,\n" +
Expand All @@ -37,6 +37,6 @@ func (p *Providers) Description() string {
"https://docs.microsoft.com/en-us/dotnet/core/diagnostics/well-known-event-providers"
}

func (p *Providers) Type() string {
func (*Providers) Type() string {
return "providers"
}
4 changes: 2 additions & 2 deletions internal/flags/types/timeout.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ func (t *Timeout) checkDuration() error {
return nil
}

func (t *Timeout) Type() string {
func (*Timeout) Type() string {
return "timeout"
}

func (t *Timeout) Description() string {
func (*Timeout) Description() string {
return "Give up on collecting the GC dump if it takes longer than this many seconds.\n" +
"Valid time units are \"ns\", \"us\" (or \"µs\"), \"ms\", \"s\", \"m\", \"h\".\n" +
"Will be rounded to seconds. If no unit provided defaults to seconds.\n" +
Expand Down

0 comments on commit 93d33c3

Please sign in to comment.