Freezed GoStyle Formatter 🎨

Freezed GoStyle Formatter Logo

pub package

A Dart formatter that applies Go-style alignment to Freezed models, making your code more readable and consistent.

Features

  • Go-style alignment - Beautiful column alignment for Freezed factory constructors
  • 🎯 Multiple annotations support - Proper alignment of multiple annotations per field
  • 🔄 Automatic formatting - Works seamlessly with dart format via CLI or VS Code extension
  • ⚙️ Zero configuration - Just add @FreezedGoStyle() annotation

Installation

Add to your pubspec.yaml:

dev_dependencies:
  freezed_go_style: ^1.0.4

Or install globally:

dart pub global activate freezed_go_style

Usage

1. Add annotation to your Freezed models

import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:freezed_go_style/freezed_go_style.dart';

part 'user.freezed.dart';
part 'user.g.dart';

@FreezedGoStyle()  // Add this annotation
@freezed
class User with _$User {
  const factory User({
    @JsonKey(name: 'id')           @Default(0)    int                    id,
    @JsonKey(name: 'email')                       required String        email,
    @JsonKey(name: 'full_name')    @Default('')   String                 fullName,
    @JsonKey(name: 'age')                         int?                   age,
    @JsonKey(name: 'is_active')    @Default(true) bool                   isActive,
    @JsonKey(name: 'tags')         @Default([])   List<String>           tags,
    @JsonKey(name: 'metadata')                    Map<String, dynamic>?  metadata,
  }) = _User;

  factory User.fromJson(Map<String, dynamic> json) => _$UserFromJson(json);
}

2. Format your code

CLI

# Format a single file
dart run freezed_go_style -f lib/models/user.dart

# Format entire directory
dart run freezed_go_style -d lib/models/

# Verbose output
dart run freezed_go_style -f lib/models/user.dart -v

VS Code / Cursor / Gravity Extension

Install the Freezed GoStyle Formatter extension:

How to use:

  1. Install the extension.
  2. Save your Dart file (Cmd+S / Ctrl+S) - formatting happens automatically if @FreezedGoStyle is present!
  3. Alternatively, use the command palette and run Format with Freezed GoStyle.

The extension:

  • Runs automatically after dart format on save
  • Only processes files with @FreezedGoStyle() annotation
  • Works seamlessly with your existing workflow

How it works

Before:

@freezed
class User with _$User {
  const factory User({
    @JsonKey(name: 'id') @Default(0) int id,
    @JsonKey(name: 'email') required String email,
    @JsonKey(name: 'full_name') @Default('') String fullName,
  }) = _User;
}

After:

@FreezedGoStyle()
@freezed
class User with _$User {
  const factory User({
    @JsonKey(name: 'id')         @Default(0)  int             id,
    @JsonKey(name: 'email')                   required String email,
    @JsonKey(name: 'full_name')  @Default('') String          fullName,
  }) = _User;
}

Configuration

No configuration needed! Just add the @FreezedGoStyle() annotation to classes you want to format.

Requirements

  • Dart SDK: ^3.10.4
  • Works with freezed and freezed_annotation

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Support

Support the project

If you find this package helpful, consider supporting its development:

Buy Me A Coffee

Donate

License

MIT License - see LICENSE file for details.

Libraries

freezed_go_style