-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
Describe the rule you'd like to see implemented
I would like to request a lint rule to prefer absolute imports over relative & package imports for local source files.
Lints like always_use_package_imports and avoid_relative_lib_imports currently do not permit absolute imports.
I wonder if this lint would be technically possible, or if there is a reason why this is not allowed.
Examples
// GOOD:
import 'package:flutter/material.dart';
import '/screen/home_screen.dart';
import '/screen/about_screen.dart';
// BAD:
import 'package:flutter/material.dart';
import 'package:example/screen/about_screen.dart';
import 'package:example/screen/home_screen.dart';
// BAD:
import 'package:flutter/material.dart';
import '../../../about_screen.dart';
import '../../../screen/home_screen.dart';Context
In our recent projects we have used the absolute import for local source files: import '/a/b.dart';. I like this solution as it clearly separates local source code and third party libraries. Main improvement over the package import is that the absolute import will not change across the project. Also, with absolute imports you avoid the ugly ../../../b.dart.
Android Studio allows to organize imports on save. By default, it makes empty line between package and other imports. In my opinion this again improves readability and works well with absolute imports.
Thank you!