microsoft / terraform-provider-power-platform

Power Platform Terraform Provider
https://registry.terraform.io/providers/microsoft/power-platform/latest/docs
MIT License
35 stars 13 forks source link

Implement golangci linter to improve static analysis of provider code #366

Closed mattdot closed 4 months ago

mattdot commented 4 months ago

This pull request primarily focuses on integrating golangci-lint into the project's workflow and settings. There are three main changes: a new GitHub workflow was added to run golangci-lint on push and pull request events, the Visual Studio Code settings were updated to use golangci-lint as the Go linting tool, and the makefile was updated to use golangci-lint in the lint command.

GitHub Workflow:

Visual Studio Code Settings:

Makefile:

mattdot commented 4 months ago

@mawasile please fix these linting errors on this branch/pr

Error: internal/powerplatform/services/data_record/api_data_record.go:280:16: Error return value of json.Unmarshal is not checked (errcheck) json.Unmarshal(response.BodyAsBytes, &mapResponse) ^ Error: internal/powerplatform/services/data_record/api_data_record.go:309:16: Error return value of json.Unmarshal is not checked (errcheck) json.Unmarshal(response.BodyAsBytes, &mapResponse) ^ Error: internal/powerplatform/services/data_record/api_data_record.go:425:17: Error return value of json.Unmarshal is not checked (errcheck) json.Unmarshal(response.BodyAsBytes, &result) ^ Error: internal/powerplatform/services/application/api_application.go:148:22: Error return value of response.MarshallTo is not checked (errcheck) response.MarshallTo(&appCreatedResponse) ^ Error: internal/powerplatform/services/environment/api_environment.go:377:25: Error return value of apiResponse.MarshallTo is not checked (errcheck) apiResponse.MarshallTo(&envCreatedResponse) ^ Error: internal/powerplatform/resource_data_record_test.go:1119:17: Error return value of req.Body.Read is not checked (errcheck) req.Body.Read(bodyAsBytes) ^ Error: internal/powerplatform/services/rest/api_rest.go:100:29: func (*WebApiClient).getEnvironmentUrlById is unused (unused) func (client WebApiClient) getEnvironmentUrlById(ctx context.Context, environmentId string) (string, error) { ^ Error: internal/powerplatform/services/rest/api_rest.go:109:29: func `(WebApiClient).getEnvironmentis unused (unused) func (client *WebApiClient) getEnvironment(ctx context.Context, environmentId string) (*EnvironmentIdDto, error) { ^ Error: internal/powerplatform/services/dlp_policy/models_dlp_policy.go:165:5: varenvironmentSetObjectType` is unused (unused) var environmentSetObjectType = types.ObjectType{ ^ Error: internal/powerplatform/services/authorization/api_user.go:295:111: S1039: unnecessary use of fmt.Sprintf (gosimple) return nil, powerplatform_helpers.WrapIntoProviderError(err, powerplatform_helpers.ERROR_OBJECT_NOT_FOUND, fmt.Sprintf("security roles not found")) ^ Error: internal/powerplatform/api/api_client.go:92:3: ineffectual assignment to isStatusCodeValid (ineffassign) isStatusCodeValid = true ^ Error: internal/powerplatform/api/auth.go:70:24: ineffectual assignment to err (ineffassign) azureCertCredentials, err := azidentity.NewClientCertificateCredential( ^ Error: internal/powerplatform/api/auth.go:276:2: ineffectual assignment to tokenExpiry (ineffassign) tokenExpiry := time.Time{} ^ Error: internal/powerplatform/mocks/known_state_value.go:37:9: SA4001: &x will be simplified to x. It will not copy x. (staticcheck) return &v.value.Value ^