Skip to content

fix(sonar): type-dependent — 10 issues - #226

Open
huandrey wants to merge 13 commits into
mainfrom
fix/sonar-type_dependent-20260902120656
Open

huandrey wants to merge 13 commits into
mainfrom
fix/sonar-type_dependent-20260902120656

Conversation

@huandrey

@huandrey huandrey commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

SonarQube auto-fix — type-dependent

Generated by sonar-autofix. Each commit resolves one issue (two combined pairs where the flagged lines share one statement and cannot be split independently). All fixes were independently reviewed by a judge-agent before being committed. Two follow-up commits are Prettier-only reflow, triggered by the shorter lines now fitting the width limit.

Rule File Line Issue
javascript:S6582 react/ModalState.js 66 optional chaining — componentDidMount address.geoCoordinates.value
javascript:S6582 react/ModalState.js 94 optional chaining — componentDidUpdate thisAddressCoords
javascript:S6582 react/ModalState.js 422 optional chaining — data.logisticsInfo.find
javascript:S6582 react/PickupPointsModal.js 41 optional chaining — searchAddress.street.value
javascript:S6582 react/PickupPointsModal.js 112,115 optional chaining — ARG postal-code guard
javascript:S6353 react/PickupPointsModal.js 118 \d instead of [0-9] in the ARG postal-code regex
javascript:S6582 react/PickupPointsModal.js 126 optional chaining — address.postalCode.value getter
javascript:S6582 react/PickupPointsModal.js 154,155 optional chaining — validatedPostalCode value/valid
javascript:S6582 react/PickupPointsModal.js 171 optional chaining — searchAddress.country
typescript:S6582 react/components/GoogleMarker.tsx 135 optional chaining — marker position-sync effect

Skipped in this group: 0 issues

Overlap note: react/ModalState.js and react/PickupPointsModal.js are root/public components per AGENTS.md and require human approval before merge. This PR's ModalState.js/PickupPointsModal.js fixes substantially overlap with the already-open #223 (branch fix/sonar-t1-t2-round2), opened before this autofix run — same rules, same or adjacent lines, produced independently. @huandrey: please compare both and close whichever isn't kept.

…oordinates.value in ModalState.componentDidMount

Consumed only via a truthiness check (thisAddressCoords && thisAddressCoords.length > 0); every falsy-but-defined intermediate short-circuits to the same falsy outcome under both forms.

File: react/ModalState.js:66
Rule: javascript:S6582
…oords in ModalState.componentDidUpdate

address, address.geoCoordinates and address.geoCoordinates.value are always either nullish or an object/array — never another falsy primitive — so && and ?. short-circuit identically here.

File: react/ModalState.js:94
Rule: javascript:S6582
…dress.street.value guard chain

Feeds a || '' fallback further down, which coalesces every falsy outcome to '' under both the guard-chain and optional-chain forms.

File: react/PickupPointsModal.js:41
Rule: javascript:S6582
…l-code guard

address.country.value === 'ARG' still short-circuits correctly and keeps address non-null for the postalCode check that follows.

File: react/PickupPointsModal.js:112,115
Rule: javascript:S6582
…tal-code regex

\d is exactly [0-9] under every flag combination used on this literal (only 'g'), so the match result is unchanged.

File: react/PickupPointsModal.js:118
Rule: javascript:S6353
…alCode.value getter

Only caller site is inside an if (address.postalCode) block, which already guarantees address.postalCode is truthy here.

File: react/PickupPointsModal.js:126
Rule: javascript:S6582
…talCode value/valid access

validatedPostalCode is a local object literal built a few lines above in the same function, always truthy at this point.

File: react/PickupPointsModal.js:154,155
Rule: javascript:S6582
…s.country in PickupPointsModal

Flows into newAddress, which normalizes country with 'country || null' — every falsy input collapses to null identically under both forms.

File: react/PickupPointsModal.js:171
Rule: javascript:S6582
…sition-sync effect

The null guard and the two coordinate comparisons collapse into optional chaining: when getPosition() returns null, currentPosition?.lat() is undefined, and undefined !== lat is always true (lat defaults to a real number), reproducing the original short-circuit.

File: react/components/GoogleMarker.tsx:135
Rule: typescript:S6582
…line

Prettier reflow only, no functional change.

File: react/ModalState.js:64
…to one line

Prettier reflow only, no functional change.

File: react/PickupPointsModal.js:106
@huandrey
huandrey requested a review from a team as a code owner September 2, 2026 15:12
@vtex-io-ci-cd

vtex-io-ci-cd Bot commented Sep 2, 2026

Copy link
Copy Markdown

Hi! I'm VTEX IO CI/CD Bot and I'll be helping you to publish your app! 🤖

Please select which version do you want to release:

  • Patch (backwards-compatible bug fixes)

  • Minor (backwards-compatible functionality)

  • Major (incompatible API changes)

And then you just need to merge your PR when you are ready! There is no need to create a release commit/tag.

  • No thanks, I would rather do it manually 😞

@vtex-pr-sentinel

Copy link
Copy Markdown

🛡️ SDD Check — action required

I couldn't detect an SDD in this PR. Please check one option below (requires write access to the repo):

  • SDD lives in another PR — paste the SDD PR URL here:
  • This PR doesn't need an SDD
  • SDD applies, but I'm not adopting it in this PR

…csInfo.find in ModalState

data.logisticsInfo is always either nullish or an array (an API response field, never another falsy primitive), so && and ?. short-circuit identically. The adjacent unflagged availablePickupLI && findSla(...) chain two lines below is untouched — it's a separate expression outside this issue's range.

File: react/ModalState.js:422
Rule: javascript:S6582
@huandrey huandrey changed the title fix(sonar): type-dependent — 9 issues fix(sonar): type-dependent — 10 issues Sep 2, 2026
@sonar-workflows

Copy link
Copy Markdown

@huandrey huandrey added the sonar label Sep 2, 2026
@huandrey huandrey self-assigned this Sep 2, 2026

@huandrey huandrey left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Self-review before asking for approval: I checked each optional-chaining conversion for a falsy-but-defined divergence (null/0/'' short-circuiting differently than ?.). None change behavior; the two non-obvious ones are noted inline.

currentPosition.lat() !== lat ||
currentPosition.lng() !== lng
) {
if (currentPosition?.lat() !== lat || currentPosition?.lng() !== lng) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Equivalent to the old currentPosition == null || …: when currentPosition is null, currentPosition?.lat() is undefined, and undefined !== lat is always true because lat/lng come from position ?? [0, 0] (line 107), so they are never undefined. The marker is still repositioned in that case.

searchAddress &&
searchAddress.country &&
searchAddress.country.value,
country: searchAddress?.country?.value,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old searchAddress && searchAddress.country && searchAddress.country.value could return null/false, while ?. returns undefined. That difference disappears because newAddress normalizes it with country || null. The same reasoning covers validatedPostalCode?.value (always an object literal) and address.postalCode?.value (only reached after getValidPostalCode checked address.postalCode is truthy).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant