Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Shahir-47 opened this issue Dec 5, 2024 · 0 comments · May be fixed by #6115
Open

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

Shahir-47 opened this issue Dec 5, 2024 · 0 comments · May be fixed by #6115
Labels
Status: Triage Needs to be verified, categorized, etc Type: Bug / Error Something isn't working or is incorrect

Comments

@Shahir-47
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Triage Needs to be verified, categorized, etc Type: Bug / Error Something isn't working or is incorrect
Projects
None yet
1 participant