Skip to content

fix: include lengths when hashing configuration for incremental formatting - #1343

Merged
dsherret merged 2 commits into
mainfrom
fix-config-hash-lengths
Oct 11, 2026
Merged

dsherret merged 2 commits into
mainfrom
fix-config-hash-lengths

Conversation

@dsherret

Copy link
Copy Markdown
Member

The hash used for incremental formatting fed variable-length values to the hasher without their lengths, so different configurations could produce the same bytes and so the same hash. For example, these hashed the same:

  • [[1], 2] and [[1, 2]]
  • ["a", "b"] and ["a\0b"]
  • a plugin named ab at version c and a plugin named a at version bc

When that happens a config change isn't seen and files that need reformatting are skipped as already formatted.

Now the length is hashed before the contents for:

  • strings, arrays, objects, and object keys in ConfigKeyValue::hash (dprint-core)
  • the plugin name, version, config keys, number of config properties, and serialized resolved config in a plugin's incremental hash
  • the number of plugins in a scope's hash

Whether a plugin has associations is also hashed, so no associations and an empty associations array are different.

This changes the hash of every config, so the incremental cache is discarded once after upgrading.

@dsherret
dsherret merged commit 725e425 into main Oct 11, 2026
21 checks passed
@dsherret
dsherret deleted the fix-config-hash-lengths branch October 11, 2026 16:03
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.

1 participant