Skip to content

refactor(fingerprint): extract platformToDisplayName helper to remove duplication#559

Merged
giuliovv merged 1 commit intomainfrom
refactor/logging-utils
Apr 28, 2026
Merged

refactor(fingerprint): extract platformToDisplayName helper to remove duplication#559
giuliovv merged 1 commit intomainfrom
refactor/logging-utils

Conversation

@giuliovv
Copy link
Copy Markdown
Collaborator

No description provided.

… duplication

Co-Authored-By: Giulio Vaccari <io@giuliovaccari.it>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 28, 2026

Caution

Review failed

Pull request was closed or merged during review

Walkthrough

This change refactors the platform-to-display-name mapping in src/plugin/fingerprint.ts by extracting duplicated logic into shared utilities. A platformToDisplayName() helper function and a typed PLATFORM_CHOICES constant were introduced. The generateFingerprint() function now selects randomized platforms from PLATFORM_CHOICES and derives clientMetadata.platform via the helper, while collectCurrentFingerprint() replaces its inline conditional mapping with the same helper. These changes consolidate platform handling logic previously duplicated across two functions. No public API changes were made.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive No pull request description was provided by the author, making it impossible to assess whether a description exists and is related to the changeset. Add a pull request description explaining the rationale, benefits, and any testing performed for this refactoring.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main refactoring change: extracting a platformToDisplayName helper to eliminate code duplication in the fingerprint module.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 28, 2026

Greptile Summary

This PR extracts a platformToDisplayName helper function and a PLATFORM_CHOICES constant to eliminate the duplicated platform === \"win32\" ? \"WINDOWS\" : \"MACOS\" ternary that appeared in both generateFingerprint and collectCurrentFingerprint. The refactor is clean and correct — there are two minor follow-up items worth addressing: a PlatformChoice type that is declared but never referenced, and a pre-existing silent Linux→MACOS fallback that is now more visible at the centralised call site.

Confidence Score: 4/5

Safe to merge; findings are P2 style/clarity issues with no functional regression.

Only P2 findings: an unused type and a documented pre-existing fallback now surfaced by the centralisation. No new bugs introduced.

src/plugin/fingerprint.ts — unused PlatformChoice type and Linux→MACOS silent fallback worth clarifying.

Important Files Changed

Filename Overview
src/plugin/fingerprint.ts Extracts platformToDisplayName helper and PLATFORM_CHOICES constant to remove duplicated ternary; introduces an unused PlatformChoice type and preserves a pre-existing silent Linux→MACOS fallback.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[generateFingerprint] -->|randomFrom PLATFORM_CHOICES| B["platform: 'darwin' | 'win32'"]
    C[collectCurrentFingerprint] -->|os.platform| D["platform: NodeJS.Platform\n(darwin/win32/linux/...)"]
    B --> E[platformToDisplayName]
    D --> E
    E -->|=== 'win32'| F["'WINDOWS'"]
    E -->|anything else| G["'MACOS' ⚠️ Linux also maps here"]
    F --> H[clientMetadata.platform]
    G --> H
Loading
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/plugin/fingerprint.ts
Line: 74

Comment:
**Unused type declaration**

`PlatformChoice` is defined but never referenced anywhere in the file. `platformToDisplayName` accepts `string` rather than `PlatformChoice`, and nothing else uses this type. It's dead code that should be removed.

```suggestion
```

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: src/plugin/fingerprint.ts
Line: 80-82

Comment:
**Linux platform silently maps to MACOS**

`collectCurrentFingerprint` passes the real `os.platform()` result, which can be `"linux"` (or any other platform). The helper maps every non-`win32` value to `"MACOS"`, so Linux hosts will report `platform: "MACOS"` in the fingerprint. This logic was already present before the refactor, but now it's centralised — making it a good time to add an explicit guard or a comment for `"linux"`.

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "refactor(fingerprint): extract platformT..." | Re-trigger Greptile

Comment thread src/plugin/fingerprint.ts
}

const PLATFORM_CHOICES = ["darwin", "win32"] as const;
type PlatformChoice = typeof PLATFORM_CHOICES[number];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Unused type declaration

PlatformChoice is defined but never referenced anywhere in the file. platformToDisplayName accepts string rather than PlatformChoice, and nothing else uses this type. It's dead code that should be removed.

Suggested change
type PlatformChoice = typeof PLATFORM_CHOICES[number];
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/plugin/fingerprint.ts
Line: 74

Comment:
**Unused type declaration**

`PlatformChoice` is defined but never referenced anywhere in the file. `platformToDisplayName` accepts `string` rather than `PlatformChoice`, and nothing else uses this type. It's dead code that should be removed.

```suggestion
```

How can I resolve this? If you propose a fix, please make it concise.

Comment thread src/plugin/fingerprint.ts
Comment on lines +80 to +82
function platformToDisplayName(platform: string): "WINDOWS" | "MACOS" {
return platform === "win32" ? "WINDOWS" : "MACOS";
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Linux platform silently maps to MACOS

collectCurrentFingerprint passes the real os.platform() result, which can be "linux" (or any other platform). The helper maps every non-win32 value to "MACOS", so Linux hosts will report platform: "MACOS" in the fingerprint. This logic was already present before the refactor, but now it's centralised — making it a good time to add an explicit guard or a comment for "linux".

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/plugin/fingerprint.ts
Line: 80-82

Comment:
**Linux platform silently maps to MACOS**

`collectCurrentFingerprint` passes the real `os.platform()` result, which can be `"linux"` (or any other platform). The helper maps every non-`win32` value to `"MACOS"`, so Linux hosts will report `platform: "MACOS"` in the fingerprint. This logic was already present before the refactor, but now it's centralised — making it a good time to add an explicit guard or a comment for `"linux"`.

How can I resolve this? If you propose a fix, please make it concise.

@giuliovv giuliovv merged commit 5bd9f3c into main Apr 28, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant