Skip to content

fix(rules): read every copy of a duplicated array property - #88

Merged
nozaq merged 1 commit into
mainfrom
claude/duplicate-property-last-value-nem9u8
Aug 1, 2026
Merged

fix(rules): read every copy of a duplicated array property#88
nozaq merged 1 commit into
mainfrom
claude/duplicate-property-last-value-nem9u8

Conversation

@nozaq

@nozaq nozaq commented Aug 1, 2026

Copy link
Copy Markdown
Member

Summary

Refactor array member lookup to handle duplicate JSON object members correctly. JSON parsers keep only the last copy of a duplicate member, but decolint now reads all copies to avoid incorrectly reporting settings as unset when they appear in earlier duplicates.

Key Changes

  • Replace arrayMember() function with arrayMembers() iterator that yields all array members with a given name, using Go 1.22's iter.Seq type
  • Update stringArrayContains() to use the new iterator, checking all duplicate members instead of returning early
  • Update checkRequireCapDropAll() and checkRequireNoNewPrivileges() to iterate over all matching array members
  • Add comprehensive test cases for duplicate member scenarios in both require_no_new_privileges_test.go and require_cap_drop_all_test.go

Implementation Details

The new arrayMembers() function uses a closure-based iterator pattern to yield each array-valued member matching the given name. This allows rules to check all copies of a duplicated member rather than just the first one found. The iterator skips non-array members gracefully, making the code more robust to malformed JSON structures.

Test cases verify that:

  • When a member is duplicated, the rule correctly identifies if ANY copy satisfies the requirement
  • Mixed types (e.g., string and array) are handled properly
  • Rules pass when the last copy sets the required value, even if earlier copies don't

https://claude.ai/code/session_01Qzzd7Dgx9WfSJHWQzJs8nC

stringArrayContains and arrayMember stopped at the first member with a
given name, so a devcontainer.json that repeated a property was linted
against only its first copy. Since a JSON parser keeps the last one, a
document that plainly set an option was reported as not setting it:

  {"securityOpt": [], "securityOpt": ["no-new-privileges"]}
  {"runArgs": ["--init"], "runArgs": ["--cap-drop=ALL"]}

both produced a false positive from require-no-new-privileges and
require-cap-drop-all respectively.

Replace arrayMember with arrayMembers, an iterator over every array
member of that name, skipping copies whose value is not an array, and
scan them all. Reading what the document says beats guessing which copy
a parser discards.
@nozaq nozaq changed the title Handle duplicate JSON object members in rule checks fix(rules): read every copy of a duplicated array property Aug 1, 2026
@nozaq
nozaq merged commit 6b06f6e into main Aug 1, 2026
11 checks passed
@nozaq
nozaq deleted the claude/duplicate-property-last-value-nem9u8 branch August 1, 2026 07:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants