rehlma / flutter-package-importsr1
Prefer package imports in production code
PublicUse package imports within lib and keep dart, package and relative directives in ordered groups.
tests, run by the registry7 passed · slowest 1.8 ms
✓fires1.6 ms
reports newly written problematic code
write lib/example.dart · in fixtures/flutterfired: line 1
import '../core/store.dart';✓quiet1.6 ms
allows the intended form
write lib/example.dart · in fixtures/flutterstayed quiet
import 'package:app/core/store.dart';✓quiet1.8 ms
does not apply to a pure Dart package
write lib/example.dart · in fixtures/dartstayed quiet
import '../core/store.dart';✓skips0.0 ms
does not judge reads
read lib/example.dart · in fixtures/flutterno handler of the detector wants this event
import '../core/store.dart';✓quiet1.5 ms
does not report an untouched legacy line
write lib/example.dart · in fixtures/flutter · wrote line 2stayed quiet
import '../core/store.dart';
final added = 1;✓quiet1.4 ms
allows relative test helpers and part directives
write test/a_test.dart · in fixtures/flutterno handler of the detector wants this event
import '../robot/robot.dart';write lib/a.dart · in fixtures/flutterstayed quiet
part 'a.g.dart';✓quiet1.6 ms
ignores commented imports
write lib/a.dart · in fixtures/flutterstayed quiet
/*
import 'old.dart';
*/detector.test.tseach detect() call runs the real detector
import { expect, test } from 'vitest';
import { detect, write, edit, read, command, output, prompt } from '@wellactually/sdk/v3/test';
const flutter = { project: 'fixtures/flutter' };
const dart = { project: 'fixtures/dart' };
test('reports newly written problematic code', () => {
expect(detect(write("lib/example.dart", "import '../core/store.dart';"), flutter)).toEqual([{ line: 1 }]);
});
test('allows the intended form', () => {
expect(detect(write("lib/example.dart", "import 'package:app/core/store.dart';"), flutter)).toEqual([]);
});
test('does not apply to a pure Dart package', () => {
expect(detect(write("lib/example.dart", "import '../core/store.dart';"), dart)).toEqual([]);
});
test('does not judge reads', () => {
expect(detect(read("lib/example.dart", "import '../core/store.dart';"), flutter)).toEqual([]);
});
test('does not report an untouched legacy line', () => {
expect(detect(edit("lib/example.dart", "import '../core/store.dart';\nfinal added = 1;", { written: 'final added = 1;' }), flutter)).toEqual([]);
});
test('allows relative test helpers and part directives', () => {
expect(detect(write('test/a_test.dart', "import '../robot/robot.dart';"), flutter)).toEqual([]);
expect(detect(write('lib/a.dart', "part 'a.g.dart';"), flutter)).toEqual([]);
});
test('ignores commented imports', () => {
expect(detect(write('lib/a.dart', "/*\nimport 'old.dart';\n*/"), flutter)).toEqual([]);
});