SAP / spartacus

Spartacus is a lean, Angular-based JavaScript storefront for SAP Commerce Cloud that communicates exclusively through the Commerce REST API.
Apache License 2.0
744 stars 389 forks source link

SonarC. Reliability Rating. Use forEach Instead of Map #8823

Closed giancorderoortiz closed 3 years ago

giancorderoortiz commented 4 years ago

This issue affects our overall Reliability Rating in Sonar Cloud. Visible to CX.

Reliability Rating: C

Link https://sonarcloud.io/component_measures?id=sap_cloud-commerce-spartacus-storefront&metric=reliability_rating&view=list

Files:

  1. projects/core/src/occ/services/occ-fields.service.ts
  2. feature-libs/my-account/src/test.ts
  3. feature-libs/product/test.ts
  4. integration-libs/cdc/src/test.ts

Issue: Consider using "forEach" instead of "map" as its return value is not being used here.

Explanation: When the call to a function doesn't have any side effects, what is the point of making the call if the results are ignored? In such case, either the function call is useless and should be dropped or the source code doesn't behave as expected.

giancorderoortiz commented 4 years ago

Screen Shot 2020-09-07 at 6 18 05 AM

giancorderoortiz commented 4 years ago

Screen Shot 2020-09-07 at 6 29 22 AM Screen Shot 2020-09-07 at 6 29 37 AM Screen Shot 2020-09-07 at 6 29 53 AM

giancorderoortiz commented 4 years ago

https://sonarcloud.io/component_measures?id=sap_cloud-commerce-spartacus-storefront&metric=reliability_rating&selected=sap_cloud-commerce-spartacus-storefront%3Aprojects%2Fcore%2Fsrc%2Focc%2Fservices%2Focc-fields.service.ts

https://sonarcloud.io/component_measures?id=sap_cloud-commerce-spartacus-storefront&metric=reliability_rating&selected=sap_cloud-commerce-spartacus-storefront%3Afeature-libs%2Fmy-account%2Fsrc%2Ftest.ts

https://sonarcloud.io/component_measures?id=sap_cloud-commerce-spartacus-storefront&metric=reliability_rating&selected=sap_cloud-commerce-spartacus-storefront%3Aintegration-libs%2Fcdc%2Fsrc%2Ftest.ts

giancorderoortiz commented 4 years ago

https://sonarcloud.io/component_measures?id=sap_cloud-commerce-spartacus-storefront&metric=reliability_rating&selected=sap_cloud-commerce-spartacus-storefront%3Afeature-libs%2Fproduct%2Ftest.ts

Xymmer commented 4 years ago

Fix ...projectscoresrcoccservicesocc-fields.service.ts (change from map to for-each) Set other files to be ignored in sonarscans (talk to Gil how to do this).

Parthlakhani commented 4 years ago

https://sonarcloud.io/component_measures?id=sap_cloud-commerce-spartacus-storefront&metric=new_reliability_rating&pullRequest=9833&selected=sap_cloud-commerce-spartacus-storefront%3Aprojects%2Fcore%2Fsrc%2Focc%2Fservices%2Focc-fields.service.ts

https://sonarcloud.io/component_measures?id=sap_cloud-commerce-spartacus-storefront&metric=new_reliability_rating&pullRequest=9833&selected=sap_cloud-commerce-spartacus-storefront%3Afeature-libs%2Forganization%2Ftest.ts

https://sonarcloud.io/component_measures?id=sap_cloud-commerce-spartacus-storefront&metric=new_reliability_rating&pullRequest=9833&selected=sap_cloud-commerce-spartacus-storefront%3Afeature-libs%2Fproduct%2Ftest.ts

https://sonarcloud.io/component_measures?id=sap_cloud-commerce-spartacus-storefront&metric=new_reliability_rating&pullRequest=9833&selected=sap_cloud-commerce-spartacus-storefront%3Aintegration-libs%2Fcdc%2Fsrc%2Ftest.ts

Screen Shot 2020-11-17 at 4 27 58 PM
Parthlakhani commented 4 years ago

Talked to @hackergil about setting files to ignore in sonarscans, he suggested that changes should be made as suggested by sonar.

giancorderoortiz commented 4 years ago

Eager to see this fixed.

giancorderoortiz commented 3 years ago

Issue fixed. Thanks. Screen Shot 2020-12-07 at 7 42 50 AM

apurvageete commented 3 years ago

@giancorderoortiz can u please paste the screenshot for this issue again .. I cannot see the last line in this screen shot

shobha-source commented 1 year ago

Can you please any one help here consider using foreach instead of map as it's return value is not being used here.