import_sorter 3.0.6

  • Readme
  • Changelog
  • Example
  • Installing
  • 77
 ___  _____ ______   ________  ________  ________  _________
|\  \|\   _ \  _   \|\   __  \|\   __  \|\   __  \|\___   ___\
\ \  \ \  \\\__\ \  \ \  \|\  \ \  \|\  \ \  \|\  \|___ \  \_|
 \ \  \ \  \\|__| \  \ \   ____\ \  \\\  \ \   _  _\   \ \  \
  \ \  \ \  \    \ \  \ \  \___|\ \  \\\  \ \  \\  \|   \ \  \
   \ \__\ \__\    \ \__\ \__\    \ \_______\ \__\\ _\    \ \__\
    \|__|\|__|     \|__|\|__|     \|_______|\|__|\|__|    \|__|
    ________  ________  ________  _________  _______   ________
   |\   ____\|\   __  \|\   __  \|\___   ___\\  ___ \ |\   __  \
   \ \  \___|\ \  \|\  \ \  \|\  \|___ \  \_\ \   __/|\ \  \|\  \
    \ \_____  \ \  \\\  \ \   _  _\   \ \  \ \ \  \_|/_\ \   _  _\
     \|____|\  \ \  \\\  \ \  \\  \|   \ \  \ \ \  \_|\ \ \  \\  \|
       ____\_\  \ \_______\ \__\\ _\    \ \__\ \ \_______\ \__\\ _\
      |\_________\|_______|\|__|\|__|    \|__|  \|_______|\|__|\|__|
      \|_________|

import_sorter Pub Version #

Flutter Community: import_sorter

Analyzer Dart CI

🎯 Dart package that automatically sorts all your flutter and dart imports. Any dart project supported! Sorts imports and reorders them based off 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/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/physics.dart';
import 'package:flutter/painting.dart';

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

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

🚀 Installing #

Simply add import_sorter: ^3.0.6 to your pubspec.yaml's dev_dependencies

🏃‍♂️ Running #

Once you've installed it simply run flutter pub run import_sorter:main (pub run import_sorter:main 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 your using a config in the pubspec.yaml you can have the program ignore it by adding --ignore-config
  • Add the -h flag if you need any help from the command line!

🏗️ Config #

If you use import_sorter a lot or need to ignore certain files you should really look at using the config you put in your pubspec.yaml. Below is an example config:

import_sorter:
  emojis: false # Optional, defaults to false
  ignored_files: # Optional, defaults to []
    - /lib/main.dart

If you need another example check the example app

🙋‍♀️🙋‍♂️ Contributing #

All contributions are welcome! Just make sure that its not an already existing issue or pull request.

3.0.6 #

  • Remove pub get feature. Was causing problems on linux (#14)

3.0.5 #

  • Improve cli doc
  • Change flutter emoji to 🐦

3.0.4 #

  • Actually exit the program when pub get fails

3.0.3 #

  • Fix removal of blank line when no imports

3.0.2 #

  • Improve user output

3.0.1 #

  • Move issue templates to correct location

3.0.0 #

  • Fix problem with imports in multiline strings.
  • Fix problem with code before imports.
  • Add GitHub issue templates.
  • Use args for arguments. This brings the addition of the --help flag.
  • Add some sick looking terminal with colors. File names are now in green so its easier to see.

2.0.3 #

  • Fix problem when no dev_dependencies are present

2.0.2 #

  • Drop process_run dependant
  • Change run emoji

2.0.1 #

  • Resolve minor linting issues

2.0.0 #

  • Add pubspec.yaml config option
  • Improve terminal output
  • Clean up code
  • Add ignore_files file options in config

1.0.10 #

  • Moved package to Flutter Community

1.0.9 #

  • Resolve issue #3 with commented out files

1.0.8 #

  • Resolve issue #2 with transitive dependencies

1.0.7 #

  • Fix duplicate imports when contain same package name

1.0.6 #

  • Ignore /lib/generated_plugin_registrant.dart for flutter projects

1.0.5 #

  • Update documentation
  • Add emoji flag

1.0.4 #

  • Fix spacing of import blocks

1.0.3 #

  • Fix dev dependency problem
  • Add new line to end of file even if there are no imports

1.0.2 #

  • Resolve dart lint issues

1.0.1 #

  • Remove double call to sort
  • Add pub badge to README.md

1.0.0 #

  • Initial release

example/README.md

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/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/physics.dart';
import 'package:flutter/painting.dart';

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

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

Example Application #

Example flutter app using import_sorter

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  import_sorter: ^3.0.6

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:import_sorter/args.dart';
import 'package:import_sorter/files.dart';
import 'package:import_sorter/sort.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
53
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
77
Learn more about scoring.

We analyzed this package on May 23, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.1
  • pana: 0.13.8-dev

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
args ^1.6.0 1.6.0
colorize ^2.0.0 2.0.0
yaml ^2.2.0 2.2.1
Transitive dependencies
charcode 1.1.3
collection 1.14.12
meta 1.1.8
path 1.7.0
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
Dev dependencies
test ^1.14.3