Skip to content

"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 } }

πŸ§‘β€πŸ’» Demo ​

Released under the MIT License