class-members-ordering
Same as class_members_ordering in Pyramid Lint
- Group
- Style
- Path
lint/style/class-members-ordering- Default
- Off, opt in
- Origin
- Pyramid Lint
- Rule
- 202 of 512
Flags class members declared out of a canonical order.
A consistent member layout lets readers find fields, constructors, and
methods in the same place across every class. Without options the built-in
order applies: static constants, static fields, instance final fields,
instance mutable fields, constructors, public getters and setters, public
methods, then private members. Members are ranked by category and any pair
found out of sequence is reported.
Options
order (list of category tokens, default: the built-in order above) — the
required member sequence. Supported tokens are public-fields,
private-fields, fields, static-fields, constructors,
named-constructors, static-methods, private-methods, public-methods,
methods, getters, and setters. A member is ranked by the earliest
token it qualifies for; members matching no token are ignored.
Invalid
class BadOrdering {
/// Instance field appears before static const
int instanceField = 0;
static const String kAppName = 'MyApp';
/// Method appears before fields
void method() {
print('method');
}
static final String kVersion = '1.0.0';
/// Private field after public methods
int _privateField = 0;
/// Constructor after methods
BadOrdering();
/// Getter after constructor
String get name => 'name';
static var _internalConfig = <String>[];
void publicMethod() {
print('public');
}
/// Private method
void _privateMethod() {
print('private');
}
} /// Instance field appears before static const int instanceField = 0; /// Method appears before fields void method() { /// Private field after public methods int _privateField = 0; /// Constructor after methods BadOrdering(); /// Getter after constructor String get name => 'name'; static var _internalConfig = <String>[];Valid
class GoodOrdering {
/// Static const first
static const String kAppName = 'MyApp';
static const int kMaxRetries = 3;
/// Static final next
static final String kVersion = '1.0.0';
static final List<String> kValidDomains = ['example.com'];
/// Static var
static var _internalConfig = <String>[];
/// Instance final fields
final String name;
final int value;
/// Instance var fields
String _description = '';
int count = 0;
/// Constructors: const first, then default, then named
const GoodOrdering(this.name, this.value);
GoodOrdering.empty()
: name = '',
value = 0;
GoodOrdering.named({required this.name, this.value = 0});
/// Factory constructors
factory GoodOrdering.fromMap(Map<String, dynamic> data) {
return GoodOrdering(
data['name'] as String,
data['value'] as int? ?? 0,
);
}
/// Public getters/setters
String get displayName => name;
set description(String value) {
_description = value;
}
/// Public methods
void publicMethod() {
print('public');
}
String process() {
return 'processed';
}
/// Private getter
bool get _isValid => name.isNotEmpty;
/// Private methods
void _privateMethod() {
print('private');
}
void _initialize() {
count = 0;
}
}Configure class-members-ordering
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"style": {
"class-members-ordering": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/style/class-members-ordering: <reason>More style rules
- combinators-ordering
combinators_orderingFlags
show/hidecombinators whose names are not sorted alphabetically. - conditional-uri-does-not-exist
conditional_uri_does_not_existrecommendedRequire the targets of conditional import and export URIs to exist.
- constant-identifier-names
constant_identifier_namesrecommendedFlags constant identifiers that are not lowerCamelCase.
- curly-braces-in-flow-control-structures
curly_braces_in_flow_control_structuresrecommendedRequires curly braces around the bodies of flow-control statements.
- dangling-library-doc-comments
dangling_library_doc_commentsrecommendedAttach library documentation to an explicit
librarydirective. - deprecated-consistency
deprecated_consistencyrecommendedFlags deprecations that are not carried through to related declarations.
- directives-ordering
directives_orderingFlags import and export directives that break the Effective Dart ordering.
- do-not-use-environment
do_not_use_environmentDisallow reading compilation environment declarations, including type aliases.