This document describes the coding standards for the Zstandard project. Following these keeps the codebase consistent and maintainable.
- Follow the official Dart style guide.
- Use flutter_lints (or the project’s chosen lint set) and fix all reported issues. The project’s
pubspec.yamlfiles typically includeflutter_lints: ^5.0.0underdev_dependencies. - Run
dart analyzeorflutter analyzefrom the package directory and fix analyzer warnings and errors.
- Use
dart format(ordart format .in each package) to format code. The project may use a line length of 80 characters; match the existing code. - Format before committing. Many projects enable format-on-save in the IDE.
- Classes:
PascalCase(e.g.ZstandardPlatform,ZstandardLinux). - Libraries and files:
snake_case(e.g.zstandard_platform_interface.dart,zstandard_impl_native.dart). - Variables, parameters, methods:
camelCase(e.g.compressionLevel,getPlatformVersion). - Constants:
camelCaseorlowerCamelCasefor const variables (e.g._token,_libName). UselowerCamelCasefor const values that are not private.
- Add dartdoc comments to all public APIs (classes, methods, parameters, return values). See the plan’s dartdoc task and the API docs.
- Use
///for documentation comments. Include a brief summary, parameter and return descriptions, and mention exceptions or null when relevant. - Prefer linking to related APIs with
[ClassName]or[methodName].
- Prefer returning
nullfor recoverable failures (e.g. compress/decompress failure) when the API returnsUint8List?. - Use
UnimplementedErrorin abstract or default platform implementations for methods that must be overridden. - Avoid swallowing errors; log or rethrow when appropriate, and document possible exceptions in dartdoc.
- Order imports: Dart SDK, Flutter, then third-party packages, then project packages. Use alphabetical order within each group if the project does.
- Use
package:imports for project packages (e.g.package:zstandard_platform_interface/zstandard_platform_interface.dart).
- In FFI code, always free allocated memory in a
finallyblock (or use the same pattern the project uses) to avoid leaks. - Use the project’s existing patterns for opening the native library and for calling into C (e.g. generated bindings, error checking).
- Use descriptive
group()andtest()names (e.g.'compress and decompress roundtrip for large data'). - Prefer
setUp()andtearDown()for shared initialization and cleanup. - Mock the platform in unit tests rather than depending on a real native implementation when testing plugin logic.
- Use clear, imperative messages (e.g. "Add compression level validation", "Fix memory leak in Linux decompress").
- Reference issues when applicable (e.g. "Fix #123: null check in extension").
Consistency with the existing codebase takes precedence when the style guide is silent; when in doubt, match surrounding code.