prefer_library_prefixes

SeverityQuick FixOptions
Info

Details

DO use library prefixes to avoid name conflicts and increase code readability.

Default libraries:

  • 'dart:developer'
  • 'dart:math'
Bad
import 'dart:developer';
import 'dart:math';

print(log(e));
log('message');
Good
import 'dart:developer' as developer;
import 'dart:math' as math;

print(math.log(math.e));
developer.log('message');

Usage

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

custom_lint:
  rules:
    - prefer_library_prefixes

Options

OptionTypeDescriptionDefault Value
include_default_librariesboolWhether to include default libraries.true
librariesList<String>A list of libraries to include.[]

To configure the rule, add the optional include_default_libraries and libraries parameters:

custom_lint:
  rules:
    - prefer_library_prefixes:
      include_default_libraries: false
      libraries: ['package:http/http.dart']