Skip to content

Fix eslint error @typescript-eslint/no-base-to-string causing test failures #6113

Open
@Shahir-47

Description

Description

When running pnpm test, the eslint checker flags the following error, preventing all tests from running:

'DOMPurify.sanitize(sanitizeMore(text, config), config.dompurifyConfig)' may use Object's default stringification format ('[object Object]') when stringified @typescript-eslint/no-base-to-string
This issue occurs in the file: /packages/mermaid/src/diagrams/common/common.ts on line 86.

The error is caused because the toString method may stringify an object using the default [object Object] format.

Steps to reproduce

  1. Run the command: pnpm test
  2. Observe the eslint error: @typescript-eslint/no-base-to-string
  3. Test fail due to error

Screenshots

image

image

Code Sample

text = DOMPurify.sanitize(sanitizeMore(text, config), config.dompurifyConfig).toString();

Setup

  • Mermaid version: v11.4.1
  • Browser and Version: Not applicable (eslint issue)
  • Node.js version: v20.18.0
  • Operating System: Xubuntu

Suggested Solutions

The issue can be fixed by explicitly converting the output of DOMPurify.sanitize to a string using the String() method instead of relying on toString(). For example:
text = String(DOMPurify.sanitize(sanitizeMore(text, config), config.dompurifyConfig));
This resolves the eslint error: @typescript-eslint/no-base-to-string.

Additional Context

This fix ensures compatibility with the eslint rule @typescript-eslint/no-base-to-string, allowing tests to run successfully using pnpm test.

Metadata

Assignees

No one assigned

    Labels

    Status: TriageNeeds to be verified, categorized, etcType: Bug / ErrorSomething isn't working or is incorrect

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions