Orientação gerada a partir de informações públicas. Apenas para referência.
Import Sorter é uma ferramenta para desenvolvedores do Flutter que organiza automaticamente as declarações de importação em Dart no seu código. Garante que as importações sejam ordenadas de forma consistente, melhorando a legibilidade e manutenibilidade. O pacote se integra perfeitamente aos fluxos de trabalho de desenvolvimento, suportando todas as principais plataformas, incluindo Android, iOS, macOS, Windows e Linux. Ao executar um simples comando, os desenvolvedores podem formatar suas listas de importação de acordo com regras pré-definidas, reduzindo o esforço manual e minimizando conflitos de mesclagem. Ideal para equipes que exigem estilo de código consistente entre projetos.
Casos de uso
Automatizando a organização de importações
Forçar estilo de código consistente
Reduzindo conflitos de mesclagem
Melhorar a legibilidade do código
Simplificando fluxos de trabalho da equipe
Principais recursos
Ordenação automática de importações
Integração de linha de comando
Suporta múltiplas plataformas
Evita erros de importação manual
Integração com fluxos de trabalho do Flutter
Indicado para
Equipes Flutter
defensores da qualidade de código
Projetos em grande escala
pipelines de CI/CD
Desenvolvedores priorizando consistência
Considerações
Requer configuração no projeto
Pode entrar em conflito com outros formatadores
Precisa de atualizações regulares
Depende da configuração correta
Não adequado para scripts pontuais
README original
Snapshot do README original do repositório-fonte vinculado. Consulte o repositório para o conteúdo mais recente.
🎯 Dart package to automatically organize your dart imports. Any dart project supported! Will sorts imports alphabetically and then group them in the following order:
Simply add import_sorter: ^4.6.0 to your pubspec.yaml's dev_dependencies.
🏃♂️ Running
Once you've installed it simply run flutter pub run import_sorter (pub run import_sorter if normal dart application) to format every file dart file in your lib, bin, test, and tests folder! Don't worry if these folders don't exist.
💻 Command Line
Add the -e flag to the run command and have emojis added to your imports 😄.
If you're using a config in the pubspec.yaml you can have the program ignore it by adding --ignore-config.
Want to make sure your files are sorted? Add --exit-if-changed to make sure the files are sorted. Good for things like CI.
Have no comments before your imports by adding the --no-comments flag.
Add the -h flag if you need any help from the command line!
You can only run import_sorter on certain files by passing in a regular expression(s) that will only sort certain files. Below are two examples:
pub run import_sorter bin/main.dart lib/args.dart (only sorts bin/main.dart and lib/args.dart)
pub run import_sorter lib\/* test\/* (only sorts files in the lib and test folders)
🏗️ Config
If you use import_sorter a lot or need to ignore certain files you should look at using the config you put in your pubspec.yaml. Ignored files are in the format of regex. This regex is then applied to the project root path (the one outputted to the terminal). Below is an example config setting emojis to true and ignoring all files in the lib folder:
import_sorter:emojis:true# Optional, defaults to falsecomments:false# Optional, defaults to trueignored_files:# Optional, defaults to []-\/lib\/*
There are two pre-commit hooks available: dart-import-sorter and flutter-import-sorter. They use pub run and flutter pub run respectively. Use the former for a generic Dart project and the latter for a Flutter project.
Using pre-commit hooks in your project:
Install and configure pre-commit.
Install and configure import_sorter using instructions above.
Add the following to the repos section of your .pre-commit-config.yaml:
-repo:https://github.com/fluttercommunity/import_sorterrev:'master'hooks:-id:dart-import-sorter# use `flutter-import-sorter` for a Flutter project
Run initial sort:
pre-commit run --all-files
🙋♀️🙋♂️ Contributing
All contributions are welcome! Just make sure that it's not an already existing issue or pull request.