directives-ordering

Same as directives_ordering in Dart lints

Group
Style
Path
lint/style/directives-ordering
Default
Off, opt in
Origin
Dart lints
Rule
219 of 512

Flags import and export directives that break the Effective Dart ordering.

Directives are grouped into sections — dart: first, then package:, then relative URIs — with exports in their own section after every import, and each section sorted alphabetically. Every directive is reported at most once, with the first broken convention in this order:

import 'package:a/a.dart';
import 'dart:async';          // flagged: 'dart:' imports go first
import 'package:c/c.dart';
import 'package:b/b.dart';    // flagged: sort sections alphabetically
import 'x.dart';
export 'y.dart';              // flagged: exports go after all imports
import 'package:d/d.dart';    // flagged: 'package:' before relative

All package: directives form one section; the analyzer does not separate the current package from third-party packages. @docImports of the library documentation comment form their own sections, checked like imports.

Invalid

example.dartdart
// 'dart:' imports must come first.
import 'package:collection/collection.dart';
import 'dart:async';
import 'dart:math';

void main() {}
Place `dart:` imports before other imports.
2import 'package:collection/collection.dart';
3import 'dart:async';
Place `dart:` imports before other imports.
3import 'dart:async';
4import 'dart:math';

Valid

example.dartdart
// The Effective Dart order: dart, package, relative; exports last.
library;

import 'dart:async';
import 'dart:math';

import 'package:collection/collection.dart';
import 'package:http/http.dart';
import 'package:http_parser/http_parser.dart';
import 'package:path/path.dart';

import 'a.dart';
import 'b.dart';
import 'src/c.dart';

export 'dart:io';

export 'package:collection/collection.dart';

export 'a.dart';

part 'part.dart';

void main() {}

Configure directives-ordering

Set its severity in falcon.json. See the configuration guide.

falcon.jsonjson
{
  "linter": {
    "rules": {
      "style": {
        "directives-ordering": "error"
      }
    }
  }
}

Or silence one occurrence with a suppression comment; the reason is required.

example.dartdart
// falcon-ignore lint/style/directives-ordering: <reason>
  • do-not-use-environmentdo_not_use_environment

    Disallow reading compilation environment declarations, including type aliases.

  • double-literal-formatdouble-literal-format

    Flags double literals written with redundant or missing digits.

  • empty-constructor-bodiesempty_constructor_bodiesrecommended

    Flags constructors with an empty block body {}.

  • enum-constants-ordering

    Flags enum constants whose declared names violate the configured order.

  • eol-at-end-of-fileeol_at_end_of_filerecommended

    Flags a non-empty file that does not end with exactly one line break.

  • extend-equatableequatable

    Require Equatable semantics for configured class/file name patterns.

  • file-namesfile_namesrecommended

    Enforces lowercase_with_underscores for source file names.

  • flutter-style-todosflutter_style_todos

    Flags TODO comments that do not follow the Flutter style // TODO(username): message, https://URL-to-issue.