Giter Club home page Giter Club logo

import_sorter's Introduction

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

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.

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

import_sorter's People

Contributors

actions-user avatar bartekpacia avatar gleich avatar imgbotapp avatar jlnrrg avatar lig avatar lsaudon avatar mrgnhnt96 avatar pythonhubdev avatar vhanda avatar vkammerer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

import_sorter's Issues

Yaml version update

With Flutter 2.0 Dart 2.12 is now in the stable channel.
Please consider updating the yaml package to the current version.

Issue
The artemis library is in the process of checking into null safety, but now depends on yaml: ^3.1.0, thus leading to incompatibilities with this package.

P.S. I know about dependency_overrides so it is not critical, just wanted to make you aware.:smile:

Pre-commit hook doesn't work with custom dart/flutter executable locations

At the moment, the pre-commit hook definition expects dart/flutter executables to be accessible in the search path.

However, it is a common practice to install several channels on the same machine and use different executable names for them. i.e. flutter-stable, dart-beta, etc.

It is possible to implement a hook that takes an executable name/path as an argument in the args parameter, see https://pre-commit.com/#passing-arguments-to-hooks. However, this requires transforming the definition in the script type and using an additional script that would construct the corresponding command to execute. The problem is we cannot just use bash for this as Windows users won't be able to use it.

Add option to not add empty lines between groups

Is your feature request related to a problem? Please describe.
Using this, empty lines are always added between import groups, which I don't want.

Describe the solution you'd like
Add boolean option to enable/disable add empty line between groups.

Describe alternatives you've considered

Additional context
No Empty lines like below:

// 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';

Exit with non-zero exit code when files were changed

Is your feature request related to a problem? Please describe.
In CI pipelines it would be handy to ensure that all imports are sorted. However, this requires checking for changes manually.

Describe the solution you'd like
If changes were done to any file, exit with exit code 1, otherwise exit code 0.

Describe alternatives you've considered
Checking if files have changed using git.

"Failed to run flutter pub get"

Describe the bug
When flutter pub run import_sorter:main is run, it exits with exit code 127, and fails to run flutter pub get. However, when flutter pub get is run individually of flutter pub run import_sorter:main, it works fine, and running flutter pub get -v produces the expected output, all exit codes 0.

To Reproduce
I ran flutter pub run import_sorter:main. I am using import_sorter 3.0.5, Ubuntu 19.10, Flutter 1.8.0-11.1.pre on channel beta, and Dart 2.9.0-8.2.beta.

Expected behavior
I expected the program to run properly, or at the very least, not fail on flutter pub get, but rather another step.

Screenshots
image
image

Meta Information:

  • Dart Version:
  • import_sorter Version: ^3.0.5
  • Is it a Flutter project? Yes.
  • What version of Flutter are you using (if flutter project): 1.8.0-11.1.pre on channel beta

Pre-commit now throws a warning when targeting a specific branch

Describe the bug

When running pre-commit with this config:

repos:
  - repo: https://github.com/fluttercommunity/import_sorter
    rev: "master"
    hooks:
      - id: flutter-import-sorter

A warning is thrown:

[WARNING] The 'rev' field of repo 'https://github.com/fluttercommunity/import_sorter' appears to be a mutable reference (moving tag / branch).  Mutable references are never updated after first install and are not supported.  See https://pre-commit.com/#using-the-latest-version-for-a-repository for more details.

Expected behavior

I would like a tag to be added to GitHub which I can reference in my pre-commit config.

Meta Information:

  • Dart Version: 2.10.5
  • import_sorter Version: master
  • Is it a Flutter project? Yes
  • What version of Flutter are you using (if flutter project): 1.22.6

flutter_gen Package Import Gets Deleted

Describe the bug
Without a comment on the same line the import 'package:flutter_gen/gen_l10n/translations.dart'; gets removed when running flutter pub run import_sorter:main.

To Reproduce
You can just add the import to your main.dart file after creating a new project. It won't be able to build, but running flutter pub run import_sorter:main after saving the file still deletes the import. Note: even after there are no build errors it still deletes it

Expected behavior
The import should not be deleted.

Meta Information:

  • Dart Version: 2.10.2
  • import_sorter Version: 4.2.2
  • Is it a Flutter project? Yes
  • What version of Flutter are you using (if flutter project): 1.22.2

Additional Context
The import is sorted correctly if you add a comment to the same line. For example:
import 'package:flutter_gen/gen_l10n/translations.dart'; // gets removed

import 'package:flutter_gen/gen_l10n/translations.dart'; // import_sorter:keep // gets sorted correctly

Changing package imports to relative

Is your feature request related to a problem? Please describe.
No

Describe the solution you'd like
An option in the config that when enabled would convert all package imports to relative path imports. Applied only to the Project imports: section.

Describe alternatives you've considered
Have considered a vscode extension but it didn't work as it is outdated.

Additional context
I feel like this would be a great addition to this package.

Feature Request: Add option for relative import

It would be great if this package can change our absolute imports to relative imports.

Example 1
import 'package:my_app/lib/src/foo.dart'
to
import 'foo.dart'

Example 2

import 'package:my_app/lib/src/p1/foo.dart'
import 'package:my_app/lib/src/p2/foo.dart'

to

import 'p1/foo.dart'
import 'p2/foo.dart'

if imported in src
to

import '../p1/foo.dart'
import 'foo.dart'

if imported in p2

I would like to contribute to this feature but can anyone guide me with this?

Actually sort imports

The import sorter does a great job at grouping the imports. This is a huge improvement already. However, it does not actually sort the imports. When re-ordering the imports, they stay in the relative order that they were before.

Describe the solution you'd like
The import sorter plugin should 1) group imports by origin (dart,flutter,packages,local) and 2) within each group sort the imports alphabetically. For files with longer import lists this makes maintenance and finding files easier.

Describe alternatives you've considered
Bascially there is none, except making sure manually that imports are sorted.

Grouping by folder inside project group

Is your feature request related to a problem? Please describe.
not a problem, but improvement

Describe the solution you'd like
Grouping by folder inside project group.

Describe alternatives you've considered
for example:

// ๐ŸŒŽ Project imports:

../aaa/bbb/foo.dart
../aaa/bbb/bar.dart

../aaa/ccc/ttt.dart
../aaa/ccc/eee.dart
../aaa/ccc/fff.dart

../zzz/ppp.dart

Specify config in an independent file

Is your feature request related to a problem? Please describe.
We are migrating our projects to a single monorepo and would love to have only one configuration set for all the stuff related to import sorting. Now, as ignoring files are only supported to be specified in the pubspec.yaml file we have to replicate that config per project instead of just once at the root of the monorepo.

Describe the solution you'd like
We would love to specify the config of import_sorter in a YAML file which could be passed using a relative path to the sort command.

Describe alternatives you've considered
I've tried to build a negative REGEX and pass it to the command (e.g. sort all imports here except those ending in *.g.dart), but without success. If such a regex is possible, no config file would be needed as all the config options could be passed in one global command.

Multiline import statements

Describe the bug
When an import statement being splitted in multiple lines (eg. because exceeding the default 80 characters with show or hide on any long import) the tool moves these lines to the end of the import list. It seems these import statements are not recognized, so they are put in afterImportLines here.

To Reproduce

  1. For example add flutter_local_notifications as a dependency, as this package will result quite long import lines.

  2. Import the package and let's say you want to hide a type (eg. because you have one with the same name in your current file already).

    import 'package:flutter_local_notifications/flutter_local_notifications.dart' hide PendingNotificationRequest;
  3. After saving (if you have autoformat on) or formatting (eg. with dart format . or flutter format .) this line is splitted to two, since its length is 110 characters (default and recommended max line length is 80 chars).

    import 'package:flutter_local_notifications/flutter_local_notifications.dart'
        hide PendingNotificationRequest;
  4. When running the import_sorter command, this import line "pair" is moved after all other imports.

Expected behavior
Move multiline imports to the section they belong to.

Meta Information:

  • Dart Version: 2.10.4 (stable) (Wed Nov 11 13:35:58 2020 +0100) on "windows_x64"
  • import_sorter Version: 4.4.1
  • Is it a Flutter project? Yes
  • What version of Flutter are you using (if flutter project): 1.22.5 (channel stable)

RangeError after executing flutter pub run import_sorter:main

Describe the bug
After executing the flutter pub run import_sorter:main command I get following error:

username@PC044-MacOS flutter_my_app % flutter pub run import_sorter:main

โ”โ”โ”๐Ÿ—‚  Sorting 94 dart files
โ”ƒ  โ”ƒ
โ”ƒ  โ”ฃโ”โ” โœ… Sorted 0 out of 7 imports in lib/drawer/drawer_navigation.dart
โ”ƒ  โ”ฃโ”โ” โœ… Sorted 0 out of 1 imports in lib/drawer/naviagtion_router.dart
Unhandled exception:
RangeError (index): Invalid value: Not in inclusive range 0..1: 2
#0      List.[] (dart:core-patch/growable_array.dart:177:60)
#1      main (file:///Users/username/development/flutter/.pub-cache/hosted/pub.dartlang.org/import_sorter-4.4.0/bin/main.dart:97:149)
#2      _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:299:32)
#3      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)
pub finished with exit code 255

To Reproduce
I installed the import_sorter package and did run flutter pub run import_sorter:main

Expected behavior
correct sorting, but it stopped after two files.

Screenshots
Bildschirmfoto 2020-11-23 um 17 25 56

Meta Information:

  • Dart Version: 2.10.4
  • import_sorter Version: 4.4.0
  • Is it a Flutter project? Yes
  • What version of Flutter are you using (if flutter project): 1.22.4

Ignored test_driver folder

Describe the bug
When running the import sorter, file in a test_driver folder are ignored.

To Reproduce
Create at test_driver folder in the root folder and place some dart files over there.

Expected behavior
Those files should have their imports sorted.

Meta Information:

  • Dart Version: 2.9.2
  • import_sorter Version: 4.2.1
  • Is it a Flutter project? Yes
  • What version of Flutter are you using (if flutter project): 1.20.4

Add support for sorting dart files in `packages` folder

Is your feature request related to a problem? Please describe.
Yes, some of the projects use a structure where only the main.dart file is present in the lib folder and the features of the app are present as packages in the packages folder.

Describe the solution you'd like
The import_sorter package should also run on the dart files present in the packages folder if it exists.

Describe alternatives you've considered
An alternative solution to this will be to write a script that goes through each folder in packages and run dart run import_sorter:main file_name. But it would be better if it's included in the package itself.

Additional context
NA

Sorter violates directives_ordering lint rule when file has named imports

Describe the bug

In a file that contains relative import paths, and an absolute path to a named import, then the Dart linting rule directives_ordering fails.

To Reproduce

  1. In your analysis_options.yaml file, enable the directives_ordering option (more info here: http://dart-lang.github.io/linter/lints/directives_ordering.html)
  2. Create a file that contains the following:
    1. An absolute path to a project import
    2. An absolute path to a named project import
    3. A relative path to a project import
  3. Run the sorter
  4. You should see a linting error (I'm using VSCode)

Expected behavior

The import sorter should respect conventional dart styling guidelines.

Screenshots
If applicable, add screenshots to help explain your problem.

Meta Information:

  • Dart Version: SDK version >=2.7.1 <3.0.0
  • import_sorter Version: 4.2.1
  • Is it a Flutter project? No
  • What version of Flutter are you using (if flutter project): N/a

Additional context
Add any other context about the problem here.

Archiving `import_sorter`

Hello everyone. I'm sad to say that today I am going to be archiving import_sorter. Unfortunately I no longer work with dart and flutter anymore and as I go into college I don't have a lot of free time to maintain the project. Anyone is free to fork the code or take over as maintainer but I am going to be archiving the project today. Sorry for any inconveniences this may cause and thank you so much for all the support.

Guidelines / solution to run compiled version

Is your feature request related to a problem? Please describe.
The current execution of flutter pub run import_sorter:main has a slow start due to the Dart VM initialisation. While it is acceptable if it is ran infrequently (like as a GIT commit hook for example), it is a lot more critical when running frequently (like every time a file is saved for example).

Describe the solution you'd like

  • Give users guidelines to use the natively compiled version of the library rather that its Dart version
  • OR find a way to distribute the compiled versions

Describe alternatives you've considered
I have tested the execution time of this library for three different versions:

Results:

  • 1 was the slowest, with an initialisation time of about 1 to 2 seconds on a i9 2019 Macbook Pro 16'.
  • 2 was faster, maybe twice faster.
  • 3 was the fastest, almost instantaneous

Additional context
The benefits of running a compiled version are also explained in https://dart.dev/tutorials/server/get-started#6-compile-for-production.

This is what I've done to get a nice experience using this lib:

  1. Compile to native code
dart compile exe bin/main.dart -o bin/import_sorter
  1. Add bin path to PATH
  2. Use lib in VSCode with https://marketplace.visualstudio.com/items?itemName=emeraldwalk.RunOnSave
    I've set it up with the following settings:
  "emeraldwalk.runonsave": {
    "commands": [
      {
        "match": "\\.dart$",
        "cmd": "import_sorter ${file}"
      }
    ]
  }

Now every time I save a file in my IDE, the imports are organised instantaneously! This makes it a lot more enjoyable.

Sort imports without adding comments

Thanks for this package! I've got a little suggestion.

I like the idea to sort my imports, but I would like to have the comments removed. A flag to sort the imports without adding comments like "Flutter imports:" would be great.

Sort alphabetically without groupings

Can an option be added to sort all imports alphabetically instead of grouping them?

This is the behaviour I get when organising imports in Android Studio.

import 'package:alpha/a.dart';
import 'package:beta/b.dart';
import 'package:charlie/c.dart';
import 'package:delta/d.dart';

Many thanks
James

Sorter ignores // ignore: implementation_imports above imports when sorting

Describe the bug
I use // ignore: implementation_imports in my project above some imports because I use some packages and their implementation.

To Reproduce
What command or actions did you take to produce this error?
I added these comments and ran flutter pub run import_sorter:main. Now these comments are listed below all the imports and not above the imports, which actually import implementation from packages.

Expected behavior
I expected that the comments are sorted with the imports.

Please let me know, if you need additional information. Thank you for your help.

Removes the import for the dart `meta` package

when running the command, it removes the imports for https://pub.dev/packages/meta

Way to reproduce:

import 'package:meta/meta.dart';

class PackageNotFound implements Exception {
  final String reason;
  PackageNotFound({@required this.reason});
}

example custom exception, within some file inside the working directory. Run the command
pub run import_sorter:main

Add possibility to sort export from barrel files

Describe the solution you'd like
It would be great if we could have the possibility to sort the export from our barrel files

Additional context
Let's supose we have a barrel file like this:

export 'a.dart';
export 'c.dart';
export 'd.dart';
export 'b.dart';
export 'e.dart';

It would be great if the tool also sorts these kind of files. The expected result would be something like this:

export 'a.dart';
export 'b.dart';
export 'c.dart';
export 'd.dart';
export 'e.dart';

Can generated files be ignored?

Is your feature request related to a problem? Please describe.
When I run code generation, the sorting and comments for imports are overridden and they aren't very relevant for generated code anyway.

Describe the solution you'd like
The option to provide a regular expression like **/*.g.dart that skips files matching it.

Say which file do not have their imports sorted

Is your feature request related to a problem? Please describe.
My project is quite big and has many files. That's the output I get after running flutter pub run import_sorter:main --exit-if-changed

โ”โ”โ” Sorting 165 dart files
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/repos/repository_social.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/repos/repository_geolocation.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/repos/repository_assets.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/repos/repository_user.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/repos/repository_info.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/routes.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/utils.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/models/track.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/models/place_distance_user.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/models/dayroom.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/models/dayroom_post.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/models/story.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/models/place.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/models/info.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/models/user_response.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/models/air_data.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/models/comment.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/models/location.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/models/section.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/models/like.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/models/info_login.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/models/visit.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/models/datafile.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/models/place_distance_social.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/models/models.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/login_info_bloc/login_info_bloc.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/login_info_bloc/bloc.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/login_info_bloc/login_info_event.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/login_info_bloc/login_info_state.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/bool_bloc/bool_bloc.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/datafile_bloc/datafile_bloc.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/datafile_bloc/datafile_event.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/datafile_bloc/bloc.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/datafile_bloc/datafile_state.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/comments_bloc/comments_event.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/comments_bloc/bloc.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/comments_bloc/comments_bloc.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/comments_bloc/comments_state.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/datafile_manage_bloc/datafile_manage_state.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/datafile_manage_bloc/datafile_manage_event.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/datafile_manage_bloc/bloc.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/datafile_manage_bloc/datafile_manage_bloc.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/section_bloc/section_bloc.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/section_bloc/bloc.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/section_bloc/section_event.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/section_bloc/section_state.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/location_bloc/location_state.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/location_bloc/location_event.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/location_bloc/bloc.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/location_bloc/location_bloc.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/likes_bloc/likes_bloc.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/likes_bloc/bloc.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/likes_bloc/likes_state.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/likes_bloc/likes_event.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/datafile_infos_bloc/datafile_infos_bloc.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/datafile_infos_bloc/datafile_infos_event.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/datafile_infos_bloc/bloc.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/datafile_infos_bloc/datafile_infos_state.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/map_type_bloc/map_type_bloc.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/login_bloc/login_bloc.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/login_bloc/login_event.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/login_bloc/bloc.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/login_bloc/login_state.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/simple_bloc_observer.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/distance_bloc/distance_state.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/distance_bloc/bloc.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/distance_bloc/distance_event.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/distance_bloc/distance_bloc.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/info_bloc/info_bloc.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/info_bloc/info_event.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/info_bloc/info_state.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/info_bloc/bloc.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/visits_bloc/visits_bloc.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/visits_bloc/visits_state.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/visits_bloc/bloc.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/visits_bloc/visits_event.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/home_bloc/home_bloc.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/auth_bloc/auth_event.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/auth_bloc/bloc.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/auth_bloc/auth_bloc.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/auth_bloc/auth_state.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/sort_mode_bloc/sort_mode_bloc.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/air_bloc/air_bloc.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/air_bloc/air_state.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/air_bloc/bloc.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/air_bloc/air_event.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/map_bloc/map_bloc.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/map_bloc/map_state.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/map_bloc/map_event.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/blocs/map_bloc/bloc.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/extensions/query_snapshot.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/extensions/date_time.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/extensions/sort_mode.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/extensions/map.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/extensions/location_permission.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/extensions/string.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/extensions/context.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/extensions/map_type.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/extensions/color.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/screens/home/screen_home.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/screens/home/pages/page_discover.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/screens/home/pages/page_info.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/screens/home/pages/page_my_profile.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/screens/home/widgets/card_dayroom.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/screens/home/widgets/card_story.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/screens/home/widgets/card_air_quality.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/screens/home/widgets/card_feature.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/screens/home/widgets/card_info.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/screens/home/widgets/card_section.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/screens/screen_story.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/screens/section/modal_sort_mode.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/screens/section/screen_section.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/screens/section/widgets/card_place.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/screens/intro/screen_intro.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/screens/intro/image_intro.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/screens/screen_full_photo_network.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/screens/screen_about.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/screens/dayroom/screen_dayroom.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/screens/air/screen_air.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/screens/air/widgets/air_indicator.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/screens/map/card_nearby_place.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/screens/map/screen_map.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/screens/map/modal_map_type.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/screens/screen_error.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/screens/datafiles/row_auth.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/screens/datafiles/screen_datafiles.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/screens/datafiles/card_datafile.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/screens/place/screen_place.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/screens/place/comment/bottom_sheet_add_comment.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/screens/place/comment/new_comment_state.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/screens/place/comment/new_comment_bloc.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/screens/place/comment/new_comment_event.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/screens/place/widgets/dialog_user.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/screens/place/widgets/row_comment.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/screens/place/widgets/card_place_overview.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/screens/place/widgets/hero_place_image_file.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/screens/place/widgets/row_like.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/screens/place/widgets/row_visit.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/screens/place/widgets/hero_place_image_network.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/screens/screen_full_photo_file.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/screens/login/screen_login.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/main.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/generated_plugin_registrant.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/config.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/data/app_data_parser.dart/

โ”—โ”โ”๐Ÿšจ 
pub finished with exit code 1

In the example above, I get error code 1 because imports in lib/app.dart are not sorted. I would like to import_sorter to explicitly tell me why it failed on which files. I'm encountering a very strange bug in my GitHub Actions and more information from import_sorter would greatly help me debug it!

Describe the solution you'd like
I'd like import_sorter to print more information, instead of just exiting with error code 1.

Example:

(...)
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/generated_plugin_registrant.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/config.dart/
โ”ƒ  โ”ฃโ”โ”  Sorted imports for /lib/data/app_data_parser.dart/

โ”—โ”โ”๐Ÿšจ 
Imports in `/lib/app.dart` are not sorted!

Describe alternatives you've considered
I don't know๐Ÿ˜…

Add argument to sort some files only?

Hi, I would like to use this together with my git hook, and have my changed files sorted only.
It would be great to having a way to sort only a subset of files, instead of sorting all of them.

Ignore files not working

Describe the bug
I am not able to ignore generated files by localization and freezed. I apologize if I am using the parameter wrong, but I am expecting to use the same syntax as in a .gitignore file. Regardless of the outcome of this issue: It would be great if the documentation covers all 3 cases described below and maybe provides an example.

To Reproduce
Create a file (for example t.dart under lib)
Use the following configuraion in pubspec.yaml

import_sorter:
  ignored_files:
    - lib/t.dart

File: lib/t.dart nothing happens
Extension: lib/\*\*.freezed.dart FormatException: Nothing to repeat lib/**.freezed.dart
Folder: lib/generated nothing happens

Expected behavior
File: lib/t.dart ignore the file
Extension: lib/**.freezed.dart ignore all files generated by freezed in folder lib
Folder: lib/generated ignore all files with lib/generated as a parent

Meta Information:

  • Dart Version: Dart SDK version: 3.3.0 (stable) (Tue Feb 13 10:25:19 2024 +0000) on "windows_x64"
  • import_sorter Version: 4.6.0
  • Is it a Flutter project? Yes
  • What version of Flutter are you using (if flutter project): Flutter 3.19.0 โ€ข channel stable

Additional Information
Weird is that when using the sorter the file is mentioned as a child of itself: generated\intl\messages_all.dart/messages_all.dart

Allow for global install

Allow for global system install using pub global activate import_sorter. When doing this allow the user to use an --install command for installing it the given project. Also, allow for a global config stored in ~/.import_sorter.

Distinguish what files were changed in the output

Is your feature request related to a problem? Please describe.
It is not clear what files were changed from the import_sorter output. In fact. all files appear to be changed. I would like to review files that were changed by the tool. This could be especially useful when running import_sorter as a pre-commit hook.

Describe the solution you'd like
I would like to see just an "Ok" for files that were not changed and the current output for those that were.

Describe alternatives you've considered
There is none.

ignored_files: example suggestion

Hi,

You'd do a favor to a lot of people who deal with regular expressions just once in a long while. Add to README a couple of variants, something like this:

import_sorter:
  ignored_files:
    - \/.*\.gr\.dart
    - \/.*\.freezed\.dart

Looks like a trifle, but really it's up to fifteen minutes' waste of time per [not so bright] a person like me...

Keep code before imports

I just ran the importer and it broke the project.

Reviewing the file that was reported by the analyzer as broken and comparing to GitHub I saw that library XXXXXX; had been stripped.

Don't delete newlines in one-line files

Describe the bug
In my CI, I use (or at least, I would love to use, because this very issue prevents me from doing so) dart format -l 100 --output none --set-exit-if-changed . to format my code. After that, I want to check if my imports are sorted using flutter pub run import_sorter:main --exit-if-changed. Now, it is just not possible for those two actions to complete successfully (they're mutually exclusive), and that is because import_sorter removes trailing newlines from files without any import ... statements (or at least it looks like so).

File 1
Example file that causes problems (i.e trailing newline is removed by import_sorter):

enum HomeEvent { showInfo, showDiscover, showProfile }

File 2
Example file that works fine (i.e trailing newline is not removed by import_sorter):

import 'dart:core';

enum HomeEvent { showInfo, showDiscover, showProfile }

To Reproduce

  1. Create a file with contents of file 1
  2. dart format -l 100 .
  3. The file will have 2 lines: 1 line of code and a trailing newline. That's what I want.
  4. flutter pub run import_sorter:main --no-comments
  5. Check file contents. There won't be a trailing newline at the end of the file. I don't want this.
  6. dart format -l 100 .. A trailing newline will be there again. Yay!

Expected behavior
import_sorter should not delete the trailing newline.

Useful resources

  • How to easily check if a file has a trailing newline
  • according to my experience (I'm on macOS), the easiest way to edit a file is using TextEdit.app (it does not insert a trailing newline automatically, while several other programs I've used do insert a trailing newline (e.g nano)). To open a file in with TextEdit, use open -e <file>

Meta Information:

  • Dart Version: 2.12.3
  • import_sorter Version: 4.5.0
  • Is it a Flutter project? Yes
  • What version of Flutter are you using (if flutter project): 2.0.6

Precommit hook doesn't sort imports

Describe the bug
Precommit hook doesn't sort imports

To Reproduce
What command or actions did you take to produce this error?
Followed the steps at https://pub.dev/packages/import_sorter
When I run 'pre-commit run --all-files' nothing happens

.pre-commit-config.yaml:

repos:
    - repo: https://github.com/pre-commit/pre-commit-hooks
      rev: v3.4.0
      hooks:
          - id: trailing-whitespace
          - id: end-of-file-fixer
          - id: check-yaml
          - id: check-added-large-files
    - repo: https://github.com/fluttercommunity/import_sorter
      rev: "master"
      hooks:
          - id: flutter-import-sorter

I got it working with this hotfix as .pre-commit-config.yaml:

repos:
    - repo: https://github.com/pre-commit/pre-commit-hooks
      rev: v3.4.0
      hooks:
          - id: trailing-whitespace
          - id: end-of-file-fixer
          - id: check-yaml
          - id: check-added-large-files
    - repo: local
      hooks:
          - id: imputsorter
            name: imputsorter
            entry: flutter pub run import_sorter:main
            language: system
            files: ^lib/

It may have something to do with the 'files: .dart$'

Meta Information:

  • Flutter Version: 1.24.0-10.2
  • import_sorter Version: ^4.4.1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.