passsy / early-returnsr3
Use Early Returns
PublicReturn early from guards to flatten nesting, but keep symmetric forks as if-else and independent checks as positive parallel if blocks.
tests, run by the registry4 passed · slowest 5.1 ms
- The advice links to wellactually.dev
✓fires5.1 ms
points at the principle when the user talks about nesting in a Dart project
prompt · in fixtures/dart_appfired: "nested if"
flatten this nested if pyramid✓fires3.7 ms
points at the principle when the user asks for early returns
prompt · in fixtures/dart_appfired: "early return"
Use an early return for the null case✓quiet3.0 ms
stays quiet on the same words outside a Dart project
promptstayed quiet
flatten this nested if pyramid✓quiet4.8 ms
stays quiet on a prompt about something else
prompt · in fixtures/dart_appstayed quiet
Return the user list sorted by namedetector.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 nesting in a Dart project", () => {
expect(detect(prompt("flatten this nested if pyramid"), dartApp)).toEqual([{ match: "nested if", depth: "pointer" }]);
});
test("points at the principle when the user asks for early returns", () => {
expect(detect(prompt("Use an early return for the null case"), dartApp)).toEqual([{ match: "early return", depth: "pointer" }]);
});
test("stays quiet on the same words outside a Dart project", () => {
expect(detect(prompt("flatten this nested if pyramid"))).toEqual([]);
});
test("stays quiet on a prompt about something else", () => {
expect(detect(prompt("Return the user list sorted by name"), dartApp)).toEqual([]);
});