🔧 This rule is automatically fixable by the --fix CLI option.
Enforce usage of @ember/reactive/collections imports instead of tracked-built-ins.
Per RFC #1068, the tracked collection utilities from the tracked-built-ins package are being moved into the framework as @ember/reactive/collections. The new API also changes from class constructors (new TrackedArray(...)) to factory functions (trackedArray(...)).
This rule detects imports from tracked-built-ins and provides an autofix to convert them to @ember/reactive/collections with the new function-based API.
The following mappings are applied:
Old (tracked-built-ins) |
New (@ember/reactive/collections) |
|---|---|
TrackedArray |
trackedArray |
TrackedObject |
trackedObject |
TrackedMap |
trackedMap |
TrackedSet |
trackedSet |
TrackedWeakMap |
trackedWeakMap |
TrackedWeakSet |
trackedWeakSet |
Additionally, new expressions using these imports are automatically converted to direct function calls.
Examples of incorrect code for this rule:
import { TrackedArray } from 'tracked-built-ins';
const arr = new TrackedArray([1, 2, 3]);import { TrackedObject, TrackedMap } from 'tracked-built-ins';
const obj = new TrackedObject({ a: 1 });
const map = new TrackedMap();Examples of correct code for this rule:
import { trackedArray } from '@ember/reactive/collections';
const arr = trackedArray([1, 2, 3]);import { trackedObject, trackedMap } from '@ember/reactive/collections';
const obj = trackedObject({ a: 1 });
const map = trackedMap();This rule provides automatic fixes via --fix. Running ESLint with the --fix flag will:
- Replace
import { TrackedArray } from 'tracked-built-ins'withimport { trackedArray } from '@ember/reactive/collections' - Replace
new TrackedArray(...)withtrackedArray(...)