Skip to content

Commit

Permalink
refactor: Enable revive and fix up lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandear committed Nov 11, 2024
1 parent 1f5fe3c commit c7a9af3
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 41 deletions.
31 changes: 31 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ linters:
- nakedret
- perfsprint
- paralleltest
- revive
- stylecheck
- tparallel
- unconvert
Expand All @@ -34,6 +35,36 @@ linters-settings:
perfsprint:
errorf: true
strconcat: false
revive:
rules:
- name: blank-imports
- name: bool-literal-in-expr
- name: context-as-argument
- name: context-keys-type
- name: dot-imports
- name: early-return
- name: empty-block
- name: error-naming
- name: error-return
- name: error-strings
- name: errorf
- name: filename-format
arguments:
- "^[_a-z][_a-z0-9]*.go$"
- name: increment-decrement
- name: indent-error-flow
- name: package-comments
- name: range
- name: receiver-naming
- name: redefines-builtin-id
- name: superfluous-else
- name: time-equal
- name: time-naming
- name: unexported-naming
- name: unexported-return
- name: unreachable-code
- name: var-declaration
- name: var-naming
issues:
exclude-use-default: false
exclude-rules:
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions github/event_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestEditChange_Marshal_BaseChange(t *testing.T) {
t.Parallel()
testJSONMarshal(t, &EditChange{}, "{}")

Base := EditBase{
base := EditBase{
Ref: &EditRef{
From: String("BaseRefFrom"),
},
Expand All @@ -68,7 +68,7 @@ func TestEditChange_Marshal_BaseChange(t *testing.T) {
u := &EditChange{
Title: nil,
Body: nil,
Base: &Base,
Base: &base,
}

want := `{
Expand Down
10 changes: 5 additions & 5 deletions github/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1153,8 +1153,8 @@ func TestDo_rateLimit(t *testing.T) {
t.Errorf("Client rate remaining = %v, want %v", got, want)
}
reset := time.Date(2013, time.July, 1, 17, 47, 53, 0, time.UTC)
if resp.Rate.Reset.UTC() != reset {
t.Errorf("Client rate reset = %v, want %v", resp.Rate.Reset, reset)
if !resp.Rate.Reset.UTC().Equal(reset) {
t.Errorf("Client rate reset = %v, want %v", resp.Rate.Reset.UTC(), reset)
}
}

Expand Down Expand Up @@ -1263,7 +1263,7 @@ func TestDo_rateLimit_errorResponse(t *testing.T) {
t.Errorf("Client rate remaining = %v, want %v", got, want)
}
reset := time.Date(2013, time.July, 1, 17, 47, 53, 0, time.UTC)
if resp.Rate.Reset.UTC() != reset {
if !resp.Rate.Reset.UTC().Equal(reset) {
t.Errorf("Client rate reset = %v, want %v", resp.Rate.Reset, reset)
}
}
Expand Down Expand Up @@ -1303,7 +1303,7 @@ func TestDo_rateLimit_rateLimitError(t *testing.T) {
t.Errorf("rateLimitErr rate remaining = %v, want %v", got, want)
}
reset := time.Date(2013, time.July, 1, 17, 47, 53, 0, time.UTC)
if rateLimitErr.Rate.Reset.UTC() != reset {
if !rateLimitErr.Rate.Reset.UTC().Equal(reset) {
t.Errorf("rateLimitErr rate reset = %v, want %v", rateLimitErr.Rate.Reset.UTC(), reset)
}
}
Expand Down Expand Up @@ -1361,7 +1361,7 @@ func TestDo_rateLimit_noNetworkCall(t *testing.T) {
if got, want := rateLimitErr.Rate.Remaining, 0; got != want {
t.Errorf("rateLimitErr rate remaining = %v, want %v", got, want)
}
if rateLimitErr.Rate.Reset.UTC() != reset {
if !rateLimitErr.Rate.Reset.UTC().Equal(reset) {
t.Errorf("rateLimitErr rate reset = %v, want %v", rateLimitErr.Rate.Reset.UTC(), reset)
}
}
Expand Down
4 changes: 2 additions & 2 deletions github/issues_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,11 +470,11 @@ func TestIssuesService_Unlock(t *testing.T) {
func TestIsPullRequest(t *testing.T) {
t.Parallel()
i := new(Issue)
if i.IsPullRequest() == true {
if i.IsPullRequest() {
t.Errorf("expected i.IsPullRequest (%v) to return false, got true", i)
}
i.PullRequestLinks = &PullRequestLinks{URL: String("http://example.com")}
if i.IsPullRequest() == false {
if !i.IsPullRequest() {
t.Errorf("expected i.IsPullRequest (%v) to return true, got false", i)
}
}
Expand Down
6 changes: 3 additions & 3 deletions github/orgs_codesecurity_configurations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ func TestOrganizationsService_AttachCodeSecurityConfigurationsToRepositories(t *
testMethod(t, r, "POST")
type request struct {
Scope string `json:"scope"`
SelectedRepositoryIDS []int64 `json:"selected_repository_ids,omitempty"`
SelectedRepositoryIDs []int64 `json:"selected_repository_ids,omitempty"`
}
v := new(request)
err := json.NewDecoder(r.Body).Decode(v)
Expand All @@ -337,8 +337,8 @@ func TestOrganizationsService_AttachCodeSecurityConfigurationsToRepositories(t *
if v.Scope != "selected" {
t.Errorf("Organizations.AttachCodeSecurityConfigurationsToRepositories request body scope = %s, want selected", v.Scope)
}
if !reflect.DeepEqual(v.SelectedRepositoryIDS, []int64{5, 20}) {
t.Errorf("Organizations.AttachCodeSecurityConfigurationsToRepositories request body selected_repository_ids = %+v, want %+v", v.SelectedRepositoryIDS, []int64{5, 20})
if !reflect.DeepEqual(v.SelectedRepositoryIDs, []int64{5, 20}) {
t.Errorf("Organizations.AttachCodeSecurityConfigurationsToRepositories request body selected_repository_ids = %+v, want %+v", v.SelectedRepositoryIDs, []int64{5, 20})
}
w.WriteHeader(http.StatusAccepted)
})
Expand Down
6 changes: 3 additions & 3 deletions github/orgs_properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ func (cpv *CustomPropertyValue) UnmarshalJSON(data []byte) error {
case []interface{}:
strSlice := make([]string, len(v))
for i, item := range v {
if str, ok := item.(string); ok {
strSlice[i] = str
} else {
str, ok := item.(string)
if !ok {
return errors.New("non-string value in string array")
}
strSlice[i] = str
}
cpv.Value = strSlice
default:
Expand Down
6 changes: 3 additions & 3 deletions github/repos_properties_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,20 @@ func TestRepositoriesService_CreateOrUpdateCustomProperties(t *testing.T) {
})

ctx := context.Background()
RepoCustomProperty := []*CustomPropertyValue{
repoCustomProperty := []*CustomPropertyValue{
{
PropertyName: "environment",
Value: "production",
},
}
_, err := client.Repositories.CreateOrUpdateCustomProperties(ctx, "usr", "r", RepoCustomProperty)
_, err := client.Repositories.CreateOrUpdateCustomProperties(ctx, "usr", "r", repoCustomProperty)
if err != nil {
t.Errorf("Repositories.CreateOrUpdateCustomProperties returned error: %v", err)
}

const methodName = "CreateOrUpdateCustomProperties"

testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
return client.Repositories.CreateOrUpdateCustomProperties(ctx, "usr", "r", RepoCustomProperty)
return client.Repositories.CreateOrUpdateCustomProperties(ctx, "usr", "r", repoCustomProperty)
})
}
44 changes: 22 additions & 22 deletions github/repos_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,26 +404,26 @@ type CodeScanningTool struct {
// This helps us handle the fact that RepositoryRule parameter field can be of numerous types.
func (r *RepositoryRule) UnmarshalJSON(data []byte) error {
type rule RepositoryRule
var RepositoryRule rule
if err := json.Unmarshal(data, &RepositoryRule); err != nil {
var repositoryRule rule
if err := json.Unmarshal(data, &repositoryRule); err != nil {
return err
}

r.RulesetID = RepositoryRule.RulesetID
r.RulesetSourceType = RepositoryRule.RulesetSourceType
r.RulesetSource = RepositoryRule.RulesetSource
r.Type = RepositoryRule.Type
r.RulesetID = repositoryRule.RulesetID
r.RulesetSourceType = repositoryRule.RulesetSourceType
r.RulesetSource = repositoryRule.RulesetSource
r.Type = repositoryRule.Type

switch RepositoryRule.Type {
switch repositoryRule.Type {
case "creation", "deletion", "non_fast_forward", "required_linear_history", "required_signatures":
r.Parameters = nil
case "update":
if RepositoryRule.Parameters == nil {
if repositoryRule.Parameters == nil {
r.Parameters = nil
return nil
}
params := UpdateAllowsFetchAndMergeRuleParameters{}
if err := json.Unmarshal(*RepositoryRule.Parameters, &params); err != nil {
if err := json.Unmarshal(*repositoryRule.Parameters, &params); err != nil {
return err
}

Expand All @@ -432,12 +432,12 @@ func (r *RepositoryRule) UnmarshalJSON(data []byte) error {

r.Parameters = &rawParams
case "merge_queue":
if RepositoryRule.Parameters == nil {
if repositoryRule.Parameters == nil {
r.Parameters = nil
return nil
}
params := MergeQueueRuleParameters{}
if err := json.Unmarshal(*RepositoryRule.Parameters, &params); err != nil {
if err := json.Unmarshal(*repositoryRule.Parameters, &params); err != nil {
return err
}

Expand All @@ -447,7 +447,7 @@ func (r *RepositoryRule) UnmarshalJSON(data []byte) error {
r.Parameters = &rawParams
case "required_deployments":
params := RequiredDeploymentEnvironmentsRuleParameters{}
if err := json.Unmarshal(*RepositoryRule.Parameters, &params); err != nil {
if err := json.Unmarshal(*repositoryRule.Parameters, &params); err != nil {
return err
}

Expand All @@ -457,7 +457,7 @@ func (r *RepositoryRule) UnmarshalJSON(data []byte) error {
r.Parameters = &rawParams
case "commit_message_pattern", "commit_author_email_pattern", "committer_email_pattern", "branch_name_pattern", "tag_name_pattern":
params := RulePatternParameters{}
if err := json.Unmarshal(*RepositoryRule.Parameters, &params); err != nil {
if err := json.Unmarshal(*repositoryRule.Parameters, &params); err != nil {
return err
}

Expand All @@ -467,7 +467,7 @@ func (r *RepositoryRule) UnmarshalJSON(data []byte) error {
r.Parameters = &rawParams
case "pull_request":
params := PullRequestRuleParameters{}
if err := json.Unmarshal(*RepositoryRule.Parameters, &params); err != nil {
if err := json.Unmarshal(*repositoryRule.Parameters, &params); err != nil {
return err
}

Expand All @@ -477,7 +477,7 @@ func (r *RepositoryRule) UnmarshalJSON(data []byte) error {
r.Parameters = &rawParams
case "required_status_checks":
params := RequiredStatusChecksRuleParameters{}
if err := json.Unmarshal(*RepositoryRule.Parameters, &params); err != nil {
if err := json.Unmarshal(*repositoryRule.Parameters, &params); err != nil {
return err
}

Expand All @@ -487,7 +487,7 @@ func (r *RepositoryRule) UnmarshalJSON(data []byte) error {
r.Parameters = &rawParams
case "workflows":
params := RequiredWorkflowsRuleParameters{}
if err := json.Unmarshal(*RepositoryRule.Parameters, &params); err != nil {
if err := json.Unmarshal(*repositoryRule.Parameters, &params); err != nil {
return err
}

Expand All @@ -497,7 +497,7 @@ func (r *RepositoryRule) UnmarshalJSON(data []byte) error {
r.Parameters = &rawParams
case "file_path_restriction":
params := RuleFileParameters{}
if err := json.Unmarshal(*RepositoryRule.Parameters, &params); err != nil {
if err := json.Unmarshal(*repositoryRule.Parameters, &params); err != nil {
return err
}
bytes, _ := json.Marshal(params)
Expand All @@ -506,7 +506,7 @@ func (r *RepositoryRule) UnmarshalJSON(data []byte) error {
r.Parameters = &rawParams
case "code_scanning":
params := RequiredCodeScanningRuleParameters{}
if err := json.Unmarshal(*RepositoryRule.Parameters, &params); err != nil {
if err := json.Unmarshal(*repositoryRule.Parameters, &params); err != nil {
return err
}
bytes, _ := json.Marshal(params)
Expand All @@ -515,7 +515,7 @@ func (r *RepositoryRule) UnmarshalJSON(data []byte) error {
r.Parameters = &rawParams
case "max_file_path_length":
params := RuleMaxFilePathLengthParameters{}
if err := json.Unmarshal(*RepositoryRule.Parameters, &params); err != nil {
if err := json.Unmarshal(*repositoryRule.Parameters, &params); err != nil {
return err
}
bytes, _ := json.Marshal(params)
Expand All @@ -524,7 +524,7 @@ func (r *RepositoryRule) UnmarshalJSON(data []byte) error {
r.Parameters = &rawParams
case "file_extension_restriction":
params := RuleFileExtensionRestrictionParameters{}
if err := json.Unmarshal(*RepositoryRule.Parameters, &params); err != nil {
if err := json.Unmarshal(*repositoryRule.Parameters, &params); err != nil {
return err
}
bytes, _ := json.Marshal(params)
Expand All @@ -533,7 +533,7 @@ func (r *RepositoryRule) UnmarshalJSON(data []byte) error {
r.Parameters = &rawParams
case "max_file_size":
params := RuleMaxFileSizeParameters{}
if err := json.Unmarshal(*RepositoryRule.Parameters, &params); err != nil {
if err := json.Unmarshal(*repositoryRule.Parameters, &params); err != nil {
return err
}
bytes, _ := json.Marshal(params)
Expand All @@ -543,7 +543,7 @@ func (r *RepositoryRule) UnmarshalJSON(data []byte) error {
default:
r.Type = ""
r.Parameters = nil
return fmt.Errorf("RepositoryRule.Type %q is not yet implemented, unable to unmarshal (%#v)", RepositoryRule.Type, RepositoryRule)
return fmt.Errorf("RepositoryRule.Type %q is not yet implemented, unable to unmarshal (%#v)", repositoryRule.Type, repositoryRule)
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion script/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

set -e

GOLANGCI_LINT_VERSION="1.61.0"
GOLANGCI_LINT_VERSION="1.62.0"

CDPATH="" cd -- "$(dirname -- "$0")/.."
BIN="$(pwd -P)"/bin
Expand Down

0 comments on commit c7a9af3

Please sign in to comment.