Rules / Style / no-leading-underscores-for-library-prefixes

no-leading-underscores-for-library-prefixes

lint/style/no-leading-underscores-for-library-prefixes
recommended
Same as no_leading_underscores_for_library_prefixes · Dart lints

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 _;

How to configure

Set the severity of no-leading-underscores-for-library-prefixes in your falcon.json:

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