添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Dart 3.2 blog post ! This release brings enhancements to type promotion, interop capabilities, DevTools, and more.

Adhere to Effective Dart Guide directives sorting conventions.

This rule is available as of Dart 2.0.0.

This rule has a quick fix available.

Details

DO follow the directive ordering conventions in Effective Dart :

DO place dart: imports before other imports.

import 'package:bar/bar.dart';
import 'package:foo/foo.dart';
import 'dart:async';  // LINT
import 'dart:html';  // LINT
import 'dart:html';  // OK
import 'package:bar/bar.dart';
import 'dart:async';  // LINT
import 'package:foo/foo.dart';

GOOD:

import 'dart:async';  // OK
import 'dart:html';  // OK
import 'package:bar/bar.dart';
import 'package:foo/foo.dart';

DO place package: imports before relative imports.

import 'a.dart';
import 'b.dart';
import 'package:bar/bar.dart';  // LINT
import 'package:foo/foo.dart';  // LINT
import 'package:bar/bar.dart';  // OK
import 'a.dart';
import 'package:foo/foo.dart';  // LINT
import 'b.dart';

GOOD:

import 'package:bar/bar.dart';  // OK
import 'package:foo/foo.dart';  // OK
import 'a.dart';
import 'b.dart';

DO specify exports in a separate section after all imports.

import 'src/error.dart';
export 'src/error.dart'; // LINT
import 'src/string_source.dart';

GOOD:

import 'src/error.dart';
import 'src/string_source.dart';
export 'src/error.dart'; // OK

DO sort sections alphabetically.

import 'package:foo/bar.dart'; // OK
import 'package:bar/bar.dart'; // LINT
import 'a/b.dart'; // OK
import 'a.dart'; // LINT

GOOD:

import 'package:bar/bar.dart'; // OK
import 'package:foo/bar.dart'; // OK
import 'a.dart'; // OK
import 'a/b.dart'; // OK
Usage

To enable the directives_ordering rule, add directives_ordering under linter > rules in your analysis_options.yaml file:

linter:
  rules:
    - directives_ordering
      Except as otherwise noted, this site is licensed under a
      Creative Commons Attribution 4.0 International License,
      and code samples are licensed under the
      3-Clause BSD License.
        
  • Terms
  • Privacy
  • Security
  •