Skip to content

Latest commit

 

History

History
34 lines (22 loc) · 705 Bytes

no-template-map.md

File metadata and controls

34 lines (22 loc) · 705 Bytes

Disallows array .map in templates (no-template-map)

Mapping arrays in templates can be difficult to read.

Instead, you should do something like so:

_render() {
  const items = this.arr.map((item) => html`<span>${item}</span>`);

  return html`<div>${items}</div>`;
}

Rule Details

This rule disallows using .map on arrays in templates.

The following patterns are considered warnings:

html`<div>${arr.map(i => i+1)}</div>`;
html`<div>${arr.map(i => html`<span>${i}</span>`)}</div>`;

The following patterns are not warnings:

html`foo ${someVar}`;

When Not To Use It

If you don't care about readability of your templates, then you will not need this rule.