dart-effective-style
Maintain code consistency by following official Dart style and naming conventions.
How do I install this agent skill?
npx skills add https://github.com/dart-lang/skills --skill dart-effective-styleIs this agent skill safe to install?
- Gen Agent Trust Hubpass
This skill is safe. It provides standard instructions for applying official Dart styling, naming conventions, and code formatting using the official Dart SDK tools.
- Socketpass
No alerts
- Snykpass
Risk: LOW · No issues
- ZeroLeakspass
2 findings · Score: 80/100
What does this agent skill do?
Styling Dart Code
Contents
Naming Conventions
Apply the following naming conventions strictly to maintain consistency across the Dart ecosystem.
- Types: Name classes, enum types, typedefs, extensions, and type parameters using
UpperCamelCase. - Variables & Members: Name class members, top-level definitions, variables, parameters, and named parameters using
lowerCamelCase. - Constants: Prefer
lowerCamelCasefor constant variables, including enum values.- Conditional: If editing existing code that uses
SCREAMING_CAPSor working with generated code (e.g., protobufs), maintain consistency with the existing style.
- Conditional: If editing existing code that uses
- Files & Directories: Name packages, directories, and source files using
lowercase_with_underscores. - Import Prefixes: Name import prefixes using
lowercase_with_underscores. - Acronyms: Capitalize acronyms and abbreviations longer than two letters like regular words (e.g.,
Http,Uri). Keep two-letter acronyms fully capitalized (e.g.,ID,UI). If an abbreviation begins alowerCamelCaseidentifier, make it entirely lowercase (e.g.,httpConnection). - Privacy: Use a leading underscore
_for members and top-level declarations to indicate library privacy. Do not use leading underscores for local variables, parameters, local functions, or library prefixes. - Unused Parameters: Prefer using wildcards (
_,__, etc.) for unused callback parameters to explicitly signal intent. - Prefixes: Do not use prefix letters (e.g., Hungarian notation like
kDefaultTimeout). - Libraries: Do not explicitly name libraries (e.g., avoid
library my_library;).
Examples
// GOOD
class SliderMenu {}
typedef Predicate<T> = bool Function(T value);
const defaultTimeout = 1000;
var httpConnection = connect();
futureOfVoid.then((_) {
print('Operation complete.');
});
// BAD
class slider_menu {}
const DEFAULT_TIMEOUT = 1000;
var HTTPConnection = connect();
const kDefaultTimeout = 1000;
Ordering Directives
Organize file preambles using the following strict order. Separate each section with a blank line and sort directives alphabetically within each section.
- Place
dart:imports first. - Place
package:imports second. - Place relative imports third.
- Best Practice: Prefer relative imports for files located inside the
libdirectory of the same package.
- Best Practice: Prefer relative imports for files located inside the
- Specify
exportdirectives in a separate section after all imports.
Example
// GOOD
import 'dart:async';
import 'dart:collection';
import 'package:bar/bar.dart';
import 'package:foo/foo.dart';
import 'src/util.dart';
export 'src/error.dart';
Formatting Rules
- Mandatory Formatting: Run
dart formatas a mandatory step before committing any code. The official whitespace-handling rules for Dart are defined entirely by whatdart formatproduces. - Line Length: Prefer lines of 80 characters or fewer. Reorganize deeply nested expressions or extract variables if
dart formatproduces unreadable output due to line length constraints. - Flow Control: Use curly braces for all flow control statements to avoid the dangling else problem.
- Exception: You may omit braces for an
ifstatement with noelseclause if the entire statement fits on a single line.
- Exception: You may omit braces for an
Example
// GOOD
if (isWeekDay) {
print('Bike to work!');
} else {
print('Go dancing or read a book!');
}
if (arg == null) return defaultValue;
// BAD
if (overflowChars != other.overflowChars)
return overflowChars < other.overflowChars;
Workflows
Pre-Commit Formatting & Linting Workflow
Execute this workflow before finalizing any Dart code modifications to ensure style compliance.
- Task Progress
- 1. Review code against naming conventions (e.g.,
UpperCamelCasefor types,lowerCamelCasefor variables). - 2. Verify import ordering (
dart:->package:-> relative -> exports). - 3. Run
dart format .on the modified files. - 4. Run
dart analyzeto catch static analysis and linting errors. - 5. Run validator -> review errors -> fix any issues reported by the analyzer.
- 1. Review code against naming conventions (e.g.,
How can the creator link this skill?
Add the canonical catalog link to the repository README so users can inspect current installs and available audits. The publishing guide covers the complete discovery path.
<a href="https://skillzs.dev/skills/dart-lang/skills/dart-effective-style">View dart-effective-style on skillZs</a>