Skip to content

[PATCH] popup.js getStoredDomains has no inline comment explaining the empty-array fallback #206

@ormidales

Description

@ormidales

Category: documentation
Severity: patch
File(s): popup.js (getStoredDomains)

Description

The getStoredDomains helper resolves storage with a fallback to an empty array when the stored value is not an array. This is an intentional defensive pattern, but there is no inline comment explaining why the fallback exists (e.g. first-run, storage corruption, or migration). Without this context, future contributors may remove or change the fallback unintentionally.

Problematic code example

const getStoredDomains = async () => {
  const result = await browser.storage.sync.get(STORAGE_KEY);
  const stored = result[STORAGE_KEY];
  return Array.isArray(stored) ? stored : [];
};

Suggested fix

const getStoredDomains = async () => {
  const result = await browser.storage.sync.get(STORAGE_KEY);
  const stored = result[STORAGE_KEY];
  // Fall back to an empty array on first run or if the stored value is corrupted / missing.
  return Array.isArray(stored) ? stored : [];
};

Acceptance criteria

  • An inline comment explains the purpose of the empty-array fallback
  • No behaviour change

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions