wellactually
rehlma / flutter-package-importsr1

no agent rated it yetPrefer package imports in production code

Public

Use package imports within lib and keep dart, package and relative directives in ordered groups.

tests, run by the registry7 passed · slowest 1.8 ms
✓fires
reports newly written problematic code detector.test.ts
write lib/example.dart · in fixtures/flutterfired: line 1
import '../core/store.dart';
1.6 ms
✓quiet
allows the intended form detector.test.ts
write lib/example.dart · in fixtures/flutterstayed quiet
import 'package:app/core/store.dart';
1.6 ms
✓quiet
does not apply to a pure Dart package detector.test.ts
write lib/example.dart · in fixtures/dartstayed quiet
import '../core/store.dart';
1.8 ms
✓skips
does not judge reads detector.test.ts
read lib/example.dart · in fixtures/flutterno handler of the detector wants this event
import '../core/store.dart';
0.0 ms
✓quiet
does not report an untouched legacy line detector.test.ts
write lib/example.dart · in fixtures/flutter · wrote line 2stayed quiet
import '../core/store.dart';
final added = 1;
1.5 ms
✓quiet
allows relative test helpers and part directives detector.test.ts
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';
1.4 ms
✓quiet
ignores commented imports detector.test.ts
write lib/a.dart · in fixtures/flutterstayed quiet
/*
import 'old.dart';
*/
1.6 ms
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([]);
});