Fix eslint error @typescript-eslint/no-base-to-string causing test failures #6113
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
- Run the command:
pnpm test
- Observe the eslint error:
@typescript-eslint/no-base-to-string
- Test fail due to error
Screenshots
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
.