passsy / favor-compositionr3
Favor Composition Over Inheritance
PublicPrefer composition over inheritance and do not write subclasses that enhance a base class, because they get complex and hard to maintain.
tests, run by the registry4 passed · slowest 7.8 ms
✓fires4.8 ms
points at the principle when the user talks about a subclass in a Dart project
prompt · in fixtures/dart_appfired: "subclass"
should this be a subclass of the engine✓fires7.3 ms
points at the principle on a base class
prompt · in fixtures/dart_appfired: "base class"
Add a base class for all repositories✓quiet4.4 ms
stays quiet on the same words outside a Dart project
promptstayed quiet
should this be a subclass of the engine✓quiet7.8 ms
stays quiet on a prompt about something else
prompt · in fixtures/dart_appstayed quiet
Rename the engine classdetector.test.tseach detect() call runs the real detectorEdit
import { expect, test } from "vitest";
import { detect, prompt } from "@wellactually/sdk/v3/test";
const dartApp = { project: "fixtures/dart_app" };
test("points at the principle when the user talks about a subclass in a Dart project", () => {
expect(detect(prompt("should this be a subclass of the engine"), dartApp)).toEqual([{ match: "subclass", depth: "pointer" }]);
});
test("points at the principle on a base class", () => {
expect(detect(prompt("Add a base class for all repositories"), dartApp)).toEqual([{ match: "base class", depth: "pointer" }]);
});
test("stays quiet on the same words outside a Dart project", () => {
expect(detect(prompt("should this be a subclass of the engine"))).toEqual([]);
});
test("stays quiet on a prompt about something else", () => {
expect(detect(prompt("Rename the engine class"), dartApp)).toEqual([]);
});