No slash command · from dart-foundation
Enforces modern Dart 3+ idioms: null safety, sealed classes, records, patterns, async discipline, and Effective Dart conventions. Auto-applies to any .dart file.
Ships in dart-foundation. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Check the SDK constraint in pubspec.yaml (environment: sdk: ^3.x.y) before using a feature: records, patterns and class modifiers need >=3.0, extension types >=3.3, null-aware elements >=3.8. Never raise the lower bound just to use a feature — flag it in the report instead.
String?) only when "absent" is a real state of the domain.! operator. Promote with a local variable or a pattern:// ❌ two lookups, and a crash if the map changes in between
if (cache[key] != null) return cache[key]!;
// ✅ one lookup, promoted
final cached = cache[key];
if (cached != null) return cached;
// ✅ pattern
if (json case {'id': final int id, 'name': final String name}) {
return User(id: id, name: name);
}
late only when initialization is guaranteed before first read (e.g. initState, test setUp). A late field read too early throws LateInitializationError at runtime — the compiler cannot help.??, ??= and ?. for defaults; never == null ? x : y chains.Use a record for a small, local, anonymous grouping of values — typically a multi-value return:
(int count, Duration elapsed) measure(Iterable<Job> jobs) { ... }
final (count, elapsed) = measure(jobs);
Name the fields (({int count, Duration elapsed})) once there are more than two or the types repeat. When the grouping has behaviour, invariants or crosses a package boundary, make it a class.
Model "one of N shapes" with a sealed class; the compiler then checks every switch is exhaustive:
sealed class PaymentResult {}
final class PaymentSucceeded extends PaymentResult { PaymentSucceeded(this.receiptId); final String receiptId; }
final class PaymentDeclined extends PaymentResult { PaymentDeclined(this.reason); final String reason; }
final class PaymentFailed extends PaymentResult { PaymentFailed(this.error); final Object error; }
String describe(PaymentResult r) => switch (r) {
PaymentSucceeded(:final receiptId) => 'Paid ($receiptId)',
PaymentDeclined(:final reason) => 'Declined: $reason',
PaymentFailed() => 'Something went wrong',
};
Never add a default/_ arm to a switch over a sealed type — it silences the exhaustiveness check that catches the next added subtype.
| Modifier | Use for |
|---|---|
final class | Value/implementation classes nobody outside the library should extend or implement |
sealed class | Closed hierarchies switched on exhaustively |
interface class | Contracts others implement but must not extend |
base class | Classes that may be extended but whose implementation must be inherited |
abstract interface class | Pure interfaces (ports/repositories) |
mixin class | Only when a type must be usable both as a class and a mixin |
Match what the package already does — do not retrofit modifiers onto public API in an unrelated change (adding final to a public class is a breaking change).
final for every field and every local that is not reassigned. const constructors whenever all fields are final and the values can be compile-time constants.List.unmodifiable(items) or return Iterable.freezed, equatable or built_value, use the same one. Otherwise override == and hashCode (Object.hash(a, b)), never one without the other.copyWith returns a new instance; it never mutates.Future is either awaited, returned, or explicitly handed to unawaited(...) (from dart:async) with a reason. A dropped future swallows its error — unawaited_futures / discarded_futures lints catch this; keep them on.async functions return Future<T>, never void (except top-level event handlers that must match a void Function() signature).StreamSubscription you create; close every StreamController you own (await controller.close() in dispose/close).async*/yield and stream transformers over manual controllers for derived streams.Future.wait for independent work, not sequential awaits in a loop.Isolate.run for CPU-heavy synchronous work (parsing large JSON, image processing) — never block the event loop.on FormatException catch (e). Bare catch (e) only at a boundary that logs and rethrows or converts to a domain error. Never catch (_) {}.Exception subclasses for recoverable, expected conditions the caller should handle; Error subclasses (ArgumentError, StateError) for programmer mistakes. Do not catch Errors.ArgumentError.checkNotNull / RangeError.checkValueInInterval or an explicit throw ArgumentError.value(...).Error.throwWithStackTrace(DomainError(e), st).| Kind | Style |
|---|---|
| Types, extensions, typedefs, enums | UpperCamelCase |
| Members, variables, parameters, constants | lowerCamelCase (no kPrefix unless the codebase uses it) |
| Libraries, packages, directories, files | lowercase_with_underscores |
| Private | leading _ — library-private, not class-private |
Package layout:
lib/
my_package.dart # public API: export only what callers need
src/ # implementation, never imported by other packages directly
bin/ # CLI entry points (dart run my_package:tool)
test/ # mirrors lib/ — lib/src/foo.dart → test/src/foo_test.dart
package: imports in lib/; relative imports only inside lib/ for files in the same package. Never reach into another package's src/.dart: → package: → relative, each block sorted (directives_ordering lint).Enhanced enums (fields, constructors, methods) beat switch tables scattered across the codebase:
enum Plan {
free(maxProjects: 3),
pro(maxProjects: 50);
const Plan({required this.maxProjects});
final int maxProjects;
}
Parse external strings with Plan.values.byName(raw) inside a try (throws ArgumentError) or Plan.values.asNameMap()[raw] for a nullable lookup.
extension type UserId(String value) {} — prevents passing an OrderId where a UserId is expected.dynamic outside JSON decoding boundaries — decode into typed models immediately.as casts on untrusted data; use patterns (case {'id': final int id}) or is checks.print in library code — use package:logging or the project's logger (avoid_print lint).new keyword and redundant type annotations on initialized locals (final list = <int>[]).What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
3 skills in this plugin
/dart-testingTesting pure Dart code with package:test: file layout, group/test/setUp structure, matchers, async and stream expectations, mocktail mocks and fakes (mockito when the project already uses it), test tags and platforms, coverage. Stack-agnostic — referenced by every Dart plugin in the marketplace. Flutter widget, golden and integration tests live in flutter-plugin:flutter-testing.
Use this skill to:
- Write fast, isolated unit tests for Dart classes and functions.
- Mock collaborators at boundaries without over-mocking.
- Test Futures, Streams, timers and errors correctly.
- Run the suite and collect coverage the way CI does.
Do NOT use this skill for:
- Widget tests, goldens, integration_test — see flutter-plugin:flutter-testing.
- Language idioms — see dart-foundation:dart-conventions.
/dart-toolingDart and Flutter project tooling: pubspec.yaml dependency constraints, dart pub / flutter pub workflow, pubspec.lock policy, pub workspaces and melos monorepos, analysis_options.yaml with lint packages (lints, flutter_lints, very_good_analysis), dart format / dart analyze / dart fix, build_runner code generation (freezed, json_serializable, riverpod_generator, mockito). Stack-agnostic — referenced by every Dart plugin in the marketplace.
Use this skill to:
- Add a dependency with the right constraint in the right section.
- Run the project's own formatter, analyzer and generator the way CI does.
- Decide whether to commit pubspec.lock and generated files.
- Work inside a pub workspace or melos monorepo without breaking sibling packages.
Do NOT use this skill for:
- Language idioms — see dart-foundation:dart-conventions.
- Testing patterns — see dart-foundation:dart-testing.
npx claudepluginhub aratkruglik/claude-sdlc --plugin dart-foundationOther plugins' skills for the same job