Closed eduardodfmex closed 4 months ago
I think tfproviderlint has been updated to fix the go versioning issues. We should re-enable that first
Here's an updated set of current linting errors. @mawasile can you fix these so we can implement linting.
internal/powerplatform/services/application/api_application.go:148:22: Error return value of
response.MarshallTo
is not checked (errcheck) response.MarshallTo(&appCreatedResponse) ^ internal/powerplatform/services/data_record/api_data_record.go:280:16: Error return value ofjson.Unmarshal
is not checked (errcheck) json.Unmarshal(response.BodyAsBytes, &mapResponse) ^ internal/powerplatform/services/data_record/api_data_record.go:309:16: Error return value ofjson.Unmarshal
is not checked (errcheck) json.Unmarshal(response.BodyAsBytes, &mapResponse) ^ internal/powerplatform/services/data_record/api_data_record.go:425:17: Error return value ofjson.Unmarshal
is not checked (errcheck) json.Unmarshal(response.BodyAsBytes, &result) ^ internal/powerplatform/services/environment/api_environment.go:377:25: Error return value ofapiResponse.MarshallTo
is not checked (errcheck) apiResponse.MarshallTo(&envCreatedResponse) ^ internal/powerplatform/resource_data_record_test.go:1119:17: Error return value ofreq.Body.Read
is not checked (errcheck) req.Body.Read(bodyAsBytes) ^ 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) { ^ 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) { ^ internal/powerplatform/services/dlp_policy/models_dlp_policy.go:165:5: var
environmentSetObjectType` is unused (unused) var environmentSetObjectType = types.ObjectType{ ^ 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")) ^ internal/powerplatform/api/api_client.go:92:3: ineffectual assignment to isStatusCodeValid (ineffassign) isStatusCodeValid = true ^ internal/powerplatform/api/auth.go:70:24: ineffectual assignment to err (ineffassign) azureCertCredentials, err := azidentity.NewClientCertificateCredential( ^ internal/powerplatform/api/auth.go:276:2: ineffectual assignment to tokenExpiry (ineffassign) tokenExpiry := time.Time{} ^ 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
Description
Since we won't have the tfproviderlint, I was looking for alternatives to go lint.
I was testing golangci-lint locally, which also has GitHub action, the local installation is simple and it seems that it can be configured / tunned in the pipeline, also looks like the lint is well supported by go community.
They recommend that it be executed independently, in their own words "We recommend running this action in a job separate from other jobs (go test, etc.) because different jobs run in parallel." . if you like we can talk about it on Monday.
On the other hand, these are the results of the execution, with 9 warnings that we may need to fix:
vscode ➜ /workspaces/terraform-provider-power-platform (eduardodfmex/274-tfproviderlint-is-not-updated-with-latest-golang-version-causing-codeql-failure) $ golangci-lint run internal/powerplatform/services/environment_templates/api_environment_templates.go:46:14: Error return value of
os.WriteFile
is not checked (errcheck) os.WriteFile("response.json", response.BodyAsBytes, 0644) ^ internal/powerplatform/services/application/api_application.go:147:22: Error return value ofresponse.MarshallTo
is not checked (errcheck) response.MarshallTo(&appCreatedResponse) ^ internal/powerplatform/services/environment/api_environment.go:369:25: Error return value ofapiResponse.MarshallTo
is not checked (errcheck) apiResponse.MarshallTo(&envCreatedResponse) ^ internal/powerplatform/resource_solution_test.go:574:12: Error return value offile.Write
is not checked (errcheck) file.Write([]byte(content)) ^ internal/powerplatform/services/dlp_policy/models_dlp_policy.go:165:5: varenvironmentSetObjectType
is unused (unused) var environmentSetObjectType = types.ObjectType{ ^ internal/powerplatform/api/auth.go:252:2: ineffectual assignment to tokenExpiry (ineffassign) tokenExpiry := time.Time{} ^ internal/powerplatform/resource_solution_test.go:26:2: SA1019: rand.Seed has been deprecated since Go 1.20 and an alternative has been available since Go 1.0: As of Go 1.20 there is no reason to call Seed with a random value. Programs that call Seed with a known value to get a specific sequence of results should use New(NewSource(seed)) to obtain a local random generator. (staticcheck) rand.Seed(time.Now().UnixNano()) ^ internal/powerplatform/resource_solution_test.go:157:2: SA1019: rand.Seed has been deprecated since Go 1.20 and an alternative has been available since Go 1.0: As of Go 1.20 there is no reason to call Seed with a random value. Programs that call Seed with a known value to get a specific sequence of results should use New(NewSource(seed)) to obtain a local random generator. (staticcheck) rand.Seed(time.Now().UnixNano()) ^ internal/powerplatform/resource_solution_test.go:438:2: SA1019: rand.Seed has been deprecated since Go 1.20 and an alternative has been available since Go 1.0: As of Go 1.20 there is no reason to call Seed with a random value. Programs that call Seed with a known value to get a specific sequence of results should use New(NewSource(seed)) to obtain a local random generator. (staticcheck) rand.Seed(time.Now().UnixNano()) ^Definition of Done
Contributions
Do you plan to raise a PR to address this issue? YES / NO?
See the contributing guide for more information about what's expected for contributions.