패키지, 저장소 및 앱 카테고리 검색

패키지 상세v4.6.0

import_sorter

다트 가져오기를 자동으로 정리하세요

AndroidiOSmacOSWindowsLinux
30일 다운로드
9.3만
좋아요
347
Pub 점수
130

패키지 설치

flutter pub add import_sorter

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

Import Sorter는 Flutter용 개발자 도구로, 코드 내 Dart 임포트 문을 자동으로 정렬합니다. 일관된 순서로 임포트를 정리하여 가독성과 유지보수성을 향상시킵니다. 이 패키지는 Android, iOS, macOS, Windows, Linux 등 모든 주요 플랫폼을 지원하며 개발 워크플로우에 원활하게 통합됩니다. 간단한 명령어를 실행함으로써 미리 정의된 규칙에 따라 임포트 목록을 포맷할 수 있어 수작업을 줄이고 병합 충돌을 최소화할 수 있습니다. 프로젝트 간 일관된 코드 스타일을 유지하고자 하는 팀에게 이상적입니다.

사용 사례

  • 수입 조직 자동화
  • 일관된 코드 스타일 강제 적용
  • 병합 충돌 줄이기
  • 코드 가독성 향상
  • 팀 워크플로우 개선

주요 기능

  • 자동 가져오기 정렬
  • 명령줄 통합
  • 여러 플랫폼을 지원합니다
  • 수동 가져오기 오류 방지
  • Flutter 워크플로우와 통합

적합한 대상

  • Flutter 팀
  • 코드 품질 옹호자
  • 대규모 프로젝트
  • CI/CD 파이프라인
  • 개발자들이 일관성을 우선시합니다

고려 사항

  • 프로젝트에서 설정이 필요합니다
  • 다른 포맷터와 충돌할 수 있습니다
  • 정기적인 업데이트 필요
  • 올바른 구성에 따라 달라집니다
  • 일회용 스크립트에는 적합하지 않습니다

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

 ___  _____ ______   ________  ________  ________  _________
|\  \|\   _ \  _   \|\   __  \|\   __  \|\   __  \|\___   ___\
\ \  \ \  \\\__\ \  \ \  \|\  \ \  \|\  \ \  \|\  \|___ \  \_|
 \ \  \ \  \\|__| \  \ \   ____\ \  \\\  \ \   _  _\   \ \  \
  \ \  \ \  \    \ \  \ \  \___|\ \  \\\  \ \  \\  \|   \ \  \
   \ \__\ \__\    \ \__\ \__\    \ \_______\ \__\\ _\    \ \__\
    \|__|\|__|     \|__|\|__|     \|_______|\|__|\|__|    \|__|
    ________  ________  ________  _________  _______   ________
   |\   ____\|\   __  \|\   __  \|\___   ___\\  ___ \ |\   __  \
   \ \  \___|\ \  \|\  \ \  \|\  \|___ \  \_\ \   __/|\ \  \|\  \
    \ \_____  \ \  \\\  \ \   _  _\   \ \  \ \ \  \_|/_\ \   _  _\
     \|____|\  \ \  \\\  \ \  \\  \|   \ \  \ \ \  \_|\ \ \  \\  \|
       ____\_\  \ \_______\ \__\\ _\    \ \__\ \ \_______\ \__\\ _\
      |\_________\|_______|\|__|\|__|    \|__|  \|_______|\|__|\|__|
      \|_________|

Request for a Maintainer

This project needs a maintainer as I no longer work with dart and flutter. Please see the issue thread for more information.

import_sorter Pub Version

Flutter Community: import_sorter

test format

🎯 Dart package to automatically organize your dart imports. Any dart project supported! Will sorts imports alphabetically and then group them in the following order:

  1. Dart imports
  2. Flutter imports
  3. Package imports
  4. Project imports

Below is an example:

Before
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/physics.dart';
import 'package:flutter/painting.dart';
import 'package:intl/intl.dart';
import 'package:mdi/mdi.dart';
import 'package:provider/provider.dart';
import 'anotherFile.dart';
import 'package:example_app/anotherFile2.dart';
import 'dart:async';
import 'dart:io';
import 'dart:js';
After
// Dart imports:
import 'dart:async';
import 'dart:io';
import 'dart:js';

// Flutter imports:
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/painting.dart';
import 'package:flutter/physics.dart';

// Package imports:
import 'package:intl/intl.dart';
import 'package:mdi/mdi.dart';
import 'package:provider/provider.dart';

// Project imports:
import 'package:example_app/anotherFile2.dart';
import 'anotherFile.dart';

🚀 Installing

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 false
  comments: false # Optional, defaults to true
  ignored_files: # Optional, defaults to []
    - \/lib\/*

If you need another example check the example app's import_sorter configuration.

🚨 pre-commit Hook

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_sorter
  rev: '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.

👥 Contributors

카테고리

의존성

의존성 목록 3 개

소스 저장소

이 패키지를 사용하는 프로젝트