prefer_library_prefixes
Severity | Quick Fix | Options |
---|---|---|
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
Option | Type | Description | Default Value |
---|---|---|---|
include_default_libraries | bool | Whether to include default libraries. | true |
libraries | List<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']