Skip to content

SonarCloud: JavaScript code-quality modernization (×68) #421

Description

@don-petry

JavaScript code-quality modernization

SonarCloud open findings in petry-projects/google-app-scripts68 issue(s) grouped as one workstream. Part of the org SonarCloud tuning initiative petry-projects/.github#593.

Findings

Rule Count Representative message
javascript:S6582 10 Prefer using an optional chain expression instead, as it's more concise and easier to read
javascript:S7781 9 Prefer String#replaceAll() over String#replace().
javascript:S7764 8 Prefer globalThis over window.
javascript:S7773 5 Prefer Number.parseInt over parseInt.
javascript:S7772 4 Prefer node:fs over fs.
javascript:S8786 4 Simplify this regular expression to reduce its runtime, as it has super-linear performance
javascript:S2486 3 Handle this exception or don't catch it at all.
javascript:S5869 3 Remove duplicates in this character class.
javascript:S3358 2 Extract this nested ternary operation into an independent statement.
javascript:S7735 2 Unexpected negated condition.
css:S7924 2 Text does not meet the minimal contrast requirement with its background.
javascript:S6557 2 Use the 'String#endsWith' method instead.
javascript:S6644 2 Unnecessary use of conditional expression for default assignment.
javascript:S7759 2 Prefer Date.now() over Date#getTime().
javascript:S4624 1 Refactor this code to not use nested template literals.
javascript:S1788 1 Default parameters should be last.
javascript:S1481 1 Remove the declaration of the unused 'safeId' variable.
javascript:S1854 1 Remove this useless assignment to variable "safeId".
javascript:S6353 1 Use concise character class syntax '\w' instead of '[a-zA-Z0-9_]'.
javascript:S7744 1 The empty object is useless.
javascript:S7786 1 new Error() is too unspecific for a type check. Use new TypeError() instead.
javascript:S4138 1 Expected a for-of loop instead of a for loop with this simple iteration.
javascript:S4043 1 Move this array "sort" operation to a separate statement or replace it with "toSorted".
javascript:S7765 1 Use .includes(), rather than .lastIndexOf(), when checking for existence.

Affected files

  • deploy/index.html (20)
  • src/gmail-to-drive-by-labels/src/index.js (9)
  • src/gas-utils.js (8)
  • src/calendar-to-briefing-doc/src/index.js (6)
  • test-utils/setup.js (6)
  • gas-installer/Index.html (5)
  • src/calendar-to-sheets/src/index.js (4)
  • test-utils/mocks.js (3)
  • gas-installer/src/index.js (3)
  • scripts/check-coverage.js (3)
  • src/deploy/index.js (1)

Approach

Apply the flagged idiom fixes: optional chaining (S6582), replaceAll (S7781), globalThis over window (S7764), Number.parseInt (S7773), and the other per-line suggestions. Each carries SonarCloud's exact recommendation. Mechanical; behavior identical.

Acceptance

  • All listed SonarCloud findings for this repo/workstream resolved to zero
  • No behavior change; existing tests/CI green
  • Fixes are real (no blanket NOSONAR unless a confirmed false positive, noted inline)

Filed from the 2026-07-03 org SonarCloud review.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions