agentleFS
evancaevanca/flutter-ai-rules/skills/effective-dart/SKILL.md

effective-dart

Skill669 starsChanged 3 months agoMITView on GitHub

Use when writing Dart code, reviewing for style, refactoring naming, adding doc comments, structuring imports, or enforcing type annotations.

The file

Show its rules and text

We split this skill into the rules it gives an agent

45 rules. About 0 are common, 26 are distinctive, and 19 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈26

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 19

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Avoid abbreviations unless the abbreviation is more common than the full term.

    line 23
  2. Distinctive:

    Prefer putting the most descriptive noun last in names.

    line 24
  3. Distinctive:

    Use terms consistently throughout your code.

    line 25
  4. Very specific:

    Follow mnemonic conventions for type parameters: E (element), K/V (key/value), T/S/U (generic types).

    line 26
  5. Distinctive:

    Consider making code read like a sentence when designing APIs.

    line 27
  6. Distinctive:

    Prefer a noun phrase for non-boolean properties or variables.

    line 28
  7. Distinctive:

    Prefer a non-imperative verb phrase for boolean properties or variables.

    line 29
  8. Distinctive:

    Consider omitting the verb for named boolean parameters.

    line 30
  9. Very specific:

    Avoid starting a function or method name with get.

    line 31
  10. Very specific:

    Use class modifiers (final, sealed, interface, base, mixin) to control whether a class can be extended or implemented.

    line 37
  11. Distinctive:

    Write type arguments on generic invocations that aren't inferred.

    line 42
  12. Very specific:

    Use Future<void> as the return type of async members that do not produce values.

    line 44
  13. Distinctive:

    Use getters for operations that conceptually access properties.

    line 45
  14. Distinctive:

    Use setters for operations that conceptually change properties.

    line 46
  15. Distinctive:

    Use a function declaration to bind a function to a name.

    line 47
  16. Distinctive:

    Use inclusive start and exclusive end parameters to accept a range.

    line 48
  17. Very specific:

    Don't annotate a return type on a setter — including the []= operator, which behaves like a setter.

    line 49
  18. Distinctive:

    Use curly braces for all flow control statements.

    line 74
  19. Very specific:

    Prefer final over var when variable values won't change.

    line 75
  20. Very specific:

    Use const for compile-time constants.

    line 76
  21. Distinctive:

    Prefer lines 80 characters or fewer for readability.

    line 77
  22. Very specific:

    Don't import libraries inside the src directory of another package.

    line 83
  23. Very specific:

    Don't allow import paths to reach into or out of lib.

    line 84
  24. Very specific:

    Don't use /lib/ or ../ in import paths.

    line 86
  25. Distinctive:

    Consider writing a library-level doc comment for library files.

    line 87
  26. Distinctive:

    Keep files focused on a single responsibility.

    line 93
  27. Very specific:

    Prefer making fields and top-level variables final.

    line 96
  28. Very specific:

    Consider making constructors const if the class supports it.

    line 97
  29. Very specific:

    Use whereType<T>() to filter a collection by type.

    line 133
  30. Very specific:

    Follow a consistent rule for var and final on local variables.

    line 134
  31. Very specific:

    Prefer specific exception handling: use on SomeException catch (e) instead of broad catch (e) or .catchError handlers.

    line 137
  32. Very specific:

    Use /// doc comments — not /* */ block comments — for types and members.

    line 151
  33. Distinctive:

    Prefer writing doc comments for public APIs.

    line 152
  34. Distinctive:

    Start doc comments with a single-sentence summary, separated into its own paragraph.

    line 153
  35. Distinctive:

    Avoid redundancy with the surrounding context.

    line 154
  36. Distinctive:

    Start function/method comments with a third-person verb if the main purpose is a side effect.

    line 155
  37. Distinctive:

    Start with a noun or non-imperative verb phrase if returning a value is the primary purpose.

    line 156
  38. Distinctive:

    Start boolean variable/property comments with "Whether" followed by a noun or gerund phrase.

    line 157
  39. Very specific:

    Use [identifier] in doc comments to refer to in-scope identifiers.

    line 158
  40. Distinctive:

    Use prose to explain parameters, return values, and exceptions (e.g., "The [param]", "Returns", "Throws" sections).

    line 159
  41. Distinctive:

    Put doc comments before metadata annotations.

    line 160
  42. Distinctive:

    Document why code exists or how it should be used, not just what it does.

    line 161
  43. Very specific:

    Write unit tests for business logic, using group and descriptive test names:

    line 167
  44. Very specific:

    Write widget tests using testWidgets and WidgetTester:

    line 193
  45. Distinctive:

    When reviewing Dart code for Effective Dart compliance, the agent should check:

    line 213

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Effective Dart Skill

This skill defines how to write idiomatic, high-quality Dart and Flutter code following Effective Dart guidelines.


1. Naming Conventions

KindConventionExample
Classes, enums, typedefs, type parameters, extensionsUpperCamelCaseMyWidget, UserState
Packages, directories, source fileslowercase_with_underscoresuser_profile.dart
Import prefixeslowercase_with_underscoresimport '...' as my_prefix;
Variables, parameters, named parameters, functionslowerCamelCaseuserName, fetchData()
  • Capitalize acronyms and abbreviations longer than two letters like words: HttpRequest, not HTTPRequest.
  • Avoid abbreviations unless the abbreviation is more common than the full term.
  • Prefer putting the most descriptive noun last in names.
  • Use terms consistently throughout your code.
  • Follow mnemonic conventions for type parameters: E (element), K/V (key/value), T/S/U (generic types).
  • Consider making code read like a sentence when designing APIs.
  • Prefer a noun phrase for non-boolean properties or variables.
  • Prefer a non-imperative verb phrase for boolean properties or variables; prefer the positive form.
  • Consider omitting the verb for named boolean parameters.
  • Avoid starting a function or method name with get; prefer removing get and using a getter when the API conceptually exposes a property.

2. Types and Functions

  • Use class modifiers (final, sealed, interface, base, mixin) to control whether a class can be extended or implemented.
  • Type annotate variables without initializers.
  • Type annotate fields and top-level variables if the type isn't obvious.
  • Annotate return types on function declarations.
  • Annotate parameter types on function declarations.
  • Write type arguments on generic invocations that aren't inferred.
  • Annotate with dynamic instead of letting inference fail.
  • Use Future<void> as the return type of async members that do not produce values.
  • Use getters for operations that conceptually access properties.
  • Use setters for operations that conceptually change properties.
  • Use a function declaration to bind a function to a name.
  • Use inclusive start and exclusive end parameters to accept a range.
  • Don't annotate a return type on a setter — including the []= operator, which behaves like a setter.
// Prefer: explicit class modifier
final class AppConfig {
  final String apiUrl;
  final int timeout;
  const AppConfig({required this.apiUrl, required this.timeout});
}

// Prefer: sealed for exhaustive pattern matching
sealed class Result<T> {}
class Success<T> extends Result<T> { final T value; Success(this.value); }
class Failure<T> extends Result<T> { final Exception error; Failure(this.error); }

3. Style

dart format .
  • Format code with dart format — don't manually format.
  • Use curly braces for all flow control statements.
  • Prefer final over var when variable values won't change.
  • Use const for compile-time constants.
  • Prefer lines 80 characters or fewer for readability.

4. Imports and Files

  • Don't import libraries inside the src directory of another package.
  • Don't allow import paths to reach into or out of lib.
  • Prefer relative import paths within a package.
  • Don't use /lib/ or ../ in import paths.
  • Consider writing a library-level doc comment for library files.

5. Structure

  • Keep files focused on a single responsibility.
  • Limit file length to maintain readability.
  • Group related functionality together.
  • Prefer making fields and top-level variables final.
  • Consider making constructors const if the class supports it.
  • Prefer making declarations private — only expose what's necessary.

6. Usage Patterns

// Adjacent string concatenation (not +)
final greeting = 'Hello, '
    'world!';

// Collection literals
final list = [1, 2, 3];
final map = {'key': 'value'};

// Initializing formals
class Point {
  final double x, y;
  Point(this.x, this.y);
}

// Empty constructor body
class Empty {
  Empty();  // not Empty() {}
}

// rethrow to preserve stack trace
try {
  doSomething();
} catch (e) {
  log(e);
  rethrow;
}
  • Use whereType<T>() to filter a collection by type.
  • Follow a consistent rule for var and final on local variables.
  • Initialize fields at their declaration when possible.
  • Override hashCode if you override ==; ensure == obeys mathematical equality rules.
  • Prefer specific exception handling: use on SomeException catch (e) instead of broad catch (e) or .catchError handlers.

7. Documentation

/// Returns the sum of [a] and [b].
///
/// Throws [ArgumentError] if either value is negative.
int add(int a, int b) { ... }
  • Format comments like sentences (capitalize, end with period).
  • Use /// doc comments — not /* */ block comments — for types and members.
  • Prefer writing doc comments for public APIs; consider them for private APIs too.
  • Start doc comments with a single-sentence summary, separated into its own paragraph.
  • Avoid redundancy with the surrounding context.
  • Start function/method comments with a third-person verb if the main purpose is a side effect.
  • Start with a noun or non-imperative verb phrase if returning a value is the primary purpose.
  • Start boolean variable/property comments with "Whether" followed by a noun or gerund phrase.
  • Use [identifier] in doc comments to refer to in-scope identifiers.
  • Use prose to explain parameters, return values, and exceptions (e.g., "The [param]", "Returns", "Throws" sections).
  • Put doc comments before metadata annotations.
  • Document why code exists or how it should be used, not just what it does.

8. Testing Patterns

  • Write unit tests for business logic, using group and descriptive test names:
import 'package:test/test.dart';

void main() {
  group('CartService', () {
    late CartService cart;

    setUp(() => cart = CartService());

    test('addItem increases item count', () {
      cart.addItem(Product(id: '1', name: 'Widget', price: 9.99));
      expect(cart.items, hasLength(1));
    });

    test('removeItem decreases total price', () {
      final product = Product(id: '1', name: 'Widget', price: 9.99);
      cart.addItem(product);
      cart.removeItem(product.id);
      expect(cart.totalPrice, equals(0.0));
    });
  });
}
  • Write widget tests using testWidgets and WidgetTester:
import 'package:flutter_test/flutter_test.dart';

void main() {
  testWidgets('LoginButton shows loading indicator when tapped',
      (WidgetTester tester) async {
    await tester.pumpWidget(const MaterialApp(home: LoginScreen()));
    await tester.tap(find.byType(ElevatedButton));
    await tester.pump();
    expect(find.byType(CircularProgressIndicator), findsOneWidget);
  });
}

9. Code Review Workflow

When reviewing Dart code for Effective Dart compliance, the agent should check:

  1. Naming — verify all identifiers follow the conventions in Section 1.
  2. Type annotations — confirm public API parameters, return types, and uninitialized variables are annotated.
  3. Class modifiers — verify final, sealed, or interface is used where appropriate.
  4. Documentation — confirm all public members have /// doc comments with a single-sentence summary.
  5. Style — run dart format --output=none --set-exit-if-changed . to verify formatting.
  6. Analysis — run dart analyze and confirm zero issues.

References

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.