Git Product home page Git Product logo

dart-import-sorter's Introduction


About Me

I'm a fullstack web developer. I program web apps with Angular or React for frontend and NestJS / Express (depending on size of app) for backend. I make mobile apps with Flutter.

I take care of the entire process of creating an application, starting with design, then planning, followed by development and testing, and finally deployment.


My Languages & Tools

Development Tools
Frameworks / Toolkits
Cloud Providers
Programming, Markup, and Other Languages
Libraries, Utilities, and Standards
Design Utilities
Browsers

My Medium Articles


Featured Projects

dart-import-sorter's People

Contributors

aziznal avatar nani-sore avatar

Stargazers

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

Watchers

 avatar

Forkers

nani-sore

dart-import-sorter's Issues

Develop basic extension

The following features are the bare minimum that will be provided:

  • Group imports based on namespace / filename / characters right before '.dart' string
  • Sort imports alphabetically

Flutter regex match also pub packages

Hi, you can add a slash after the flutter word like this:

{
  "label": "Flutter",
  "regex": "^package:flutter/.*$",
  "order": 10,
  "regexFlags": ["m"]
}

It will prevent match package line package:flutter_riverpod

Thanks for this extension btw, much better than default import sort ๐Ÿ‘.

Option for relative files to be the last ones

If I want to sort a relative path import and have my own package also imported, the default configuration will put import '../../mocks/common.dart'; with an empty line before since it's a different group, which I don't want.

If I unify the two last groups (my packages and relative paths), now import '../../mocks/common.dart'; appears first before my packages.

Is there a way to configure it as desired?

Example

If I have:

import 'dart:convert';
import '../../mocks/common.dart';

import 'package:mockito/mockito.dart';

import 'package/<my-package>.dart';

The desired outcome would be:

import 'dart:convert';

import 'package:mockito/mockito.dart';

import 'package/<my-package>.dart';
import '../../mocks/common.dart';

Thanks!

Bug: Sort on Save garbles current file when refactoring

1st: love the ext, love the sort on save feature.

But I had to switch it off - too annoying too often. If I e.g. rename a function, I get a block of imports (most probably the last sorted ones) on top of current file - often leads to a lot of confusing project errors. I can Cmd-Z it away, but it totally breaks my flow.

Here is what I think happens: The refactor does an auto-save itself. Somehow import-sorter is hooked in and applies cached imports. It may only apply, if multiple files get changed thru the refactoring.

Please fix :)

Allow adding a description for import sections.

Hi,

could you please add the following feature:

Lets say we have the following imports.

import 'package:flutter/material.dart';

import 'package:flutter_riverpod/flutter_riverpod.dart';

import 'package:oppa_tmdb/constants/constants.dart';
import 'package:oppa_tmdb/providers/providers.dart';
import 'package:oppa_tmdb/screens/screens.dart';

Now, add an additional option to have a comment above each section.
So that the formatted code looks like:

// Flutter Imports
import 'package:flutter/material.dart';

// Package Imports
import 'package:flutter_riverpod/flutter_riverpod.dart';

// Project Imports
import 'package:oppa_tmdb/constants/constants.dart';
import 'package:oppa_tmdb/providers/providers.dart';
import 'package:oppa_tmdb/screens/screens.dart';

Would be nice to be able to set the comment per section.
E.g.:

{
    "label": "Flutter",
    "regex": "^package:flutter.*$",
    "order": 1,
   "description": "Flutter Imports", 
    "regexFlags": ["m"]
}

Breaks multiline imports

This import gets messed up after running sort

import 'package:flutter_web_plugins/flutter_web_plugins.dart'
    if (dart.library.io) 'package:app_name/fake_url_strategy.dart';

Duplicating imports

I have these two files:

index.dart

library solid_repositories;

import 'package:flutter/foundation.dart';

part 'i_authentication_repository.dart';

i_authentication_repository.dart

part of solid_repositories;

@immutable
abstract class IAuthenticationRepository {}

Whenever the sort is triggered, it duplicates the import 'package:flutter/foundation.dart';:

library solid_repositories;

import 'package:flutter/foundation.dart';

import 'package:flutter/foundation.dart';

part 'i_authentication_repository.dart';

Add support for double qutoes

Hi,
I have a issue with double quotes import.
It's only sort by alphabetical order on one blocs like this:

import "package:epicture/services/navigation/navigation_provider.dart";
import "package:epicture/theme.dart";
import "package:flutter/material.dart";
import "package:flutter/services.dart";
import "package:timeago/timeago.dart" as timeago;

And not like this:

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

import 'package:timeago/timeago.dart' as timeago;

import 'package:epicture/services/navigation/navigation_provider.dart';
import 'package:epicture/theme.dart';

My local config:

{
    "dartimportsorter.sortOnSave": true,
    "dartimportsorter.leaveEmptyLinesBetweenGroups": true,
    "dartimportsorter.matchingRules": [
        {
            "label": "Dart",
            "regex": "^dart:.*$",
            "order": 1,
            "regexFlags": [
                "m"
            ]
        },
        {
            "label": "Flutter",
            "regex": "^package:flutter/.*$",
            "order": 10,
            "regexFlags": [
                "m"
            ]
        },
        {
            "label": "Package imports that are NOT your app",
            "regex": "^package:(?!epicture|openapi_sdk).*$",
            "order": 100,
            "regexFlags": [
                "m"
            ]
        },
        {
            "label": "Everything else",
            "regex": ".*",
            "order": 101,
            "regexFlags": [
                "m"
            ]
        }
    ]
}

Support imports having multiple lines (incl. conditionals, comments, and/or annotations)

Before:

import 'package:kfx_dependency_injection/kfx_dependency_injection/platform_info.dart';
import 'package:mockito/annotations.dart';

// This is required:
import 'package:mockito/mockito.dart';

@GenerateNiceMocks([MockSpec<IAppSettingsRepository>(), MockSpec<IToDoRepository>()])
import "test_environment.mocks.dart";

After sorting:

import 'package:kfx_dependency_injection/kfx_dependency_injection/platform_info.dart';
import 'package:mockito/annotations.dart';

import 'package:mockito/mockito.dart';

import "test_environment.mocks.dart";

Both the comment and @GenerateNiceMocks are deleted when the sort occurs.

This package should stick // and @ lines to the same place they were before.

Or, at least, give us some option to ignore certain files, such as:

"dartImport.excludeGeneratedFiles": [
    "g.dart",
    "config.dart",
    "freezed.dart",
    "test_environment.dart"
  ],

line ending symbols bug

When looking for app name extension splits package.yaml by '/n', but does not remove '/r' therefore breaking app name detection
i.e. 'name: app_test' becomes 'app_test/r'

I fixed it by wrapping return in getProjectNameFromPubspecFile with Utils.removeNewLines

image

Remove unused imports option

With the

 "editor.codeActionsOnSave": {
            "source.organizeImports": "always",
}

unused imports are removed. Is there an option to also configure this for the dartimportsorter ?

It seems the "dartimportsorter.sortOnSave": true, overrides the "source.organizeImports": "always" in the sense that it does not run ?

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.