-
Notifications
You must be signed in to change notification settings - Fork 84
Open
Description
Hi,
We've been getting tons of this warnings while compiling mermaid's grammar.
Found multiple assignments to 'title' with the '=' assignment operator. Consider using '+=' instead to prevent data loss.
The fix for the root cause is
fragment TitleAndAccessibilities:
- ((accDescr=ACC_DESCR | accTitle=ACC_TITLE | title=TITLE) EOL)+
+ ((accDescr+=ACC_DESCR | accTitle+=ACC_TITLE | title+=TITLE) EOL)+
;
but we only need the last defined title, which we are setting in our TS code.
export function populateCommonDb(ast: DiagramAST, db: DiagramDB) {
- if (ast.accDescr) {
- db.setAccDescription?.(ast.accDescr);
+ if (ast.accDescr?.length > 0) {
+ db.setAccDescription?.(ast.accDescr.pop() ?? '');
}
- if (ast.accTitle) {
- db.setAccTitle?.(ast.accTitle);
+ if (ast.accTitle?.length > 0) {
+ db.setAccTitle?.(ast.accTitle.pop() ?? '');
}
- if (ast.title) {
- db.setDiagramTitle?.(ast.title);
+ if (ast.title?.length > 0) {
+ db.setDiagramTitle?.(ast.title.pop() ?? '');
}
}
So the warning is valid, but we require the behaviour with data loss. In this case, would it be possible to suppress this warning for this particular line, to avoid clogging up the console with this warning?
I have created a draft PR to fix this with code changes, but it requires more work, as the types have changed, and it adds more complexity.
If there is a way similar to // eslint-disable-next-line rule-name
, that would be really helpful.
Originally posted by @sidharthv96 in #1907
Metadata
Metadata
Assignees
Labels
No labels