stringMappingKeys
Enforces mapping keys to be strings.
✅ This rule is included in the yamllogicalandlogicalStrictpresets.
YAML allows mapping keys of any type, including numbers, booleans, arrays, and objects. However, most programming languages and data interchange formats expect mapping keys to be strings. Non-string keys can cause interoperability issues, parsing failures, or unexpected type coercion when YAML documents are processed by different tools.
This rule reports on mapping keys that aren’t strings.
Examples
Section titled “Examples”123: "numeric key"true: "boolean key"null: "null key"[1, 2]: "array key"{ a: b }: "object key""123": "quoted numeric string""true": "quoted boolean string"name: "string key""key with spaces": "quoted string"Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If your YAML documents are only consumed by tools that support non-string keys and you intentionally use typed keys for semantic purposes, you may not need this rule. Some specialized YAML use cases, such as configuration files for specific frameworks, may rely on non-string keys.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- ESLint:
yml/require-string-key
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.