Dart Analyze

Dart Analyze

Community Analyzer

Avoid relative imports for files in lib/ DRT-W1001

Bug risk
Major

DO avoid relative imports for files in lib/.

When mixing relative and absolute imports it's possible to create confusion where the same member gets imported in two different ways. One way to avoid that is to ensure you consistently use absolute imports for files within the lib/ directory.

This is the opposite of 'preferrelativeimports'.

You can also use 'avoidrelativelib_imports' to disallow relative imports of files within lib/ directory outside of it (for example test/).

BAD:

import 'baz.dart';

import 'src/bag.dart'

import '../lib/baz.dart';

...

GOOD:

import 'package:foo/bar.dart';

import 'package:foo/baz.dart';

import 'package:foo/src/baz.dart';
...