"New is always Better" β Barney Stinson
Disallow object literals, prefer Map (no-object
) β
πΌ This rule is enabled in the following configs: π all
, β
recommended
.
π§ This rule is automatically fixable by the --fix
CLI option.
π Rule details β
Leverage the modern and performance-optimized features of Map over traditional objects for key-value collections. This rule promotes the use of Map to ensure consistency, avoid prototype pitfalls, and harness the power of ES6 collections more effectively.
π‘ Examples β
ts
// β Incorrect
const obj = {
foo: 'bar',
bar: 2,
}
// β
Correct
const map = new Map([
['foo', 'bar'],
['bar', 2],
])
π§ Config β
js
{ rules: { 'ninja/object': 2 } }