Skip to content

no-dupe-keys

Forbid duplicate keys in associative arrays

INFO

☑️ The predefined configuration "mslint:recommended" enables this rule.

Rule details

This rule prohibits duplicate keys in the same associative array.

Example of incorrect code for this rule:

maniascript
declare Integer[Text] ArrayA = [
  "A" => 1,
  "A" => 2
];
declare Integer[Integer] ArrayB = [
  1 => 1,
  1 => 2
];
declare Integer[Integer][Integer] ArrayC = [
  1 => [
    10 => 10,
    10 => 11
  ],
  1 => [
    10 => 20,
    11 => 21
  ]
];

Example of correct code for this rule:

maniascript
declare Integer[Text] ArrayA = [
  "A" => 1,
  "B" => 2
];
declare Integer[Integer] ArrayB = [
  1 => 1,
  2 => 2
];
declare Integer[Integer][Integer] ArrayC = [
  1 => [
    10 => 10,
    11 => 11
  ],
  2 => [
    10 => 20,
    11 => 21
  ]
];

Resources