no-leading-underscores-for-library-prefixes

Same as no_leading_underscores_for_library_prefixes in Dart lints

Group
Style
Path
lint/style/no-leading-underscores-for-library-prefixes
Default
On (recommended)
Origin
Dart lints
Rule
288 of 512
recommended

Flags import prefixes that begin with an underscore.

In Dart a leading underscore signals library privacy, but an import prefix is only a local alias — it is never exported and cannot be made private, so the underscore is meaningless noise that only muddies the privacy convention. Rename the prefix without the leading underscore. A wildcard prefix composed solely of underscores (e.g. _) is exempt, since it is an intentional throwaway name rather than a misapplied privacy marker.

Invalid

example.dartdart
// Import prefixes must not start with an underscore.

import 'dart:math' as _math;
import 'dart:async' as _async;
import 'dart:convert' as _convert;
import 'dart:io' as _io;
import 'dart:collection' as _collection;
import 'dart:typed_data' as _typed_data;
Avoid leading underscores for library prefixes.
2
3import 'dart:math' as _math;
Avoid leading underscores for library prefixes.
3import 'dart:math' as _math;
4import 'dart:async' as _async;
Avoid leading underscores for library prefixes.
4import 'dart:async' as _async;
5import 'dart:convert' as _convert;
Avoid leading underscores for library prefixes.
5import 'dart:convert' as _convert;
6import 'dart:io' as _io;
Avoid leading underscores for library prefixes.
6import 'dart:io' as _io;
7import 'dart:collection' as _collection;
Avoid leading underscores for library prefixes.
7import 'dart:collection' as _collection;
8import 'dart:typed_data' as _typed_data;

Valid

example.dartdart
// Import prefixes without leading underscores (all-underscore wildcard is fine).

import 'dart:math' as math;
import 'dart:async' as async_lib;
import 'dart:convert' as convert;
import 'dart:io' as io;
import 'dart:collection' as collection;
import 'dart:typed_data' as _;

Configure no-leading-underscores-for-library-prefixes

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

falcon.jsonjson
{
  "linter": {
    "rules": {
      "style": {
        "no-leading-underscores-for-library-prefixes": "error"
      }
    }
  }
}

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

example.dartdart
// falcon-ignore lint/style/no-leading-underscores-for-library-prefixes: <reason>