Skip to content

@mmd-toolkit/requirement-no-duplicate-field ​

Disallow a field that the body of a requirement or an element already has.

✅ The recommended configuration enables this rule.

💡 This rule is manually fixable by editor suggestions.

Each field of a requirement, id, text, risk, and verifyMethod, and of an element, type and docRef, holds one value. When a body writes a field twice, mermaid.js keeps the first value and drops the later ones without an error.

Rule Details ​

This rule applies to requirement diagrams (requirementDiagram). It reports each repeated field in a requirement or element body whose value differs from the first value of that field in the same body. Field keywords are read in any case.

Values are compared without surrounding whitespace or string quotes; risk and verifyMethod are also compared without case. A field that repeats the first value is not reported: id: 1, id: 2, and id: 1 give one report, while id: 1, id: 2, and id: 3 give two. An empty description block between fields does not affect the comparison.

The last correct example is shown as written: its two risk values differ in case, which the formatter would print in one case, and that difference is what the example shows.

Examples of incorrect code for this rule:

mmd
%% eslint @mmd-toolkit/requirement-no-duplicate-field: error
requirementDiagram
  requirement r {
    id: 1
    
id: 2
}

Examples of correct code for this rule:

mmd
%% eslint @mmd-toolkit/requirement-no-duplicate-field: error
requirementDiagram
  requirement r {
    id: 1
    text: second
  }
mmd
%% eslint @mmd-toolkit/requirement-no-duplicate-field: error
requirementDiagram
  requirement r {
    id: 1
    risk: low
    risk: Low
  }

Options ​

This rule has no options.

Version ​

This rule was introduced in @mmd-toolkit/eslint-plugin v0.1.0.

Resources ​

Third-party tools for Mermaid diagram text.