English
@mmd-toolkit/no-duplicate-init-key
Disallow a key written twice in one object of the JSON of an init directive.
✅ The recommended configuration enables this rule.
💡 This rule is manually fixable by editor suggestions.
When one JSON object in an init directive contains a key twice, mermaid.js uses its last value without an error. The earlier value is lost.
Rule Details
This rule applies to every diagram type. It reports a key repeated with a different value in the same JSON object of an init directive, at any depth. Keys are compared as JSON reads them after replacing each ' with ", as mermaid.js does.
Repeating an equal value is not reported. Nor is repeating a key in separate init directives: combining their settings with the last value of each key is a documented way of writing. Invalid JSON is reported by no-invalid-init-directive instead.
The examples are flowcharts.
Examples of incorrect code for this rule:
mmd
%% eslint @mmd-toolkit/no-duplicate-init-key: error
%%{init: {"theme": "dark", "theme": "forest"}}%%
flowchart LR
A --> BExamples of correct code for this rule:
mmd
%% eslint @mmd-toolkit/no-duplicate-init-key: error
%%{init: {"theme": "forest"}}%%
flowchart LR
A --> BOptions
This rule has no options.
Related Rules
Further Reading
Version
This rule was introduced in @mmd-toolkit/eslint-plugin v0.1.0.