import_sorter icon indicating copy to clipboard operation
import_sorter copied to clipboard

Sorter ignores // ignore: implementation_imports above imports when sorting

Open SchnMar opened this issue 5 years ago • 5 comments

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.

SchnMar avatar Dec 06 '20 10:12 SchnMar

👋 Hello! Thanks for submitting a issue! @Matt-Gleich will try to respond as soon as possible.

github-actions[bot] avatar Dec 06 '20 10:12 github-actions[bot]

Hello @SchnMar! Mind sending an example file so it easier for me to debug? Thanks!

gleich avatar Dec 06 '20 20:12 gleich

Hallo @Matt-Gleich,

thank you for your help and sorry for the late reply.

I have the following imports prior to sorting:

// Flutter imports:
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

// Package imports:
// ignore: implementation_imports
import 'package:chewie/src/chewie_player.dart';
// ignore: implementation_imports
import 'package:chewie/src/chewie_progress_colors.dart';
// ignore: implementation_imports
import 'package:chewie/src/cupertino_progress_bar.dart';
// ignore: implementation_imports
import 'package:chewie/src/utils.dart';
import 'package:open_iconic_flutter/open_iconic_flutter.dart';
import 'package:video_player/video_player.dart';

After sorting, the imports appear like this:

// Flutter imports:
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

// Package imports:
import 'package:chewie/src/chewie_player.dart';
import 'package:chewie/src/chewie_progress_colors.dart';
import 'package:chewie/src/cupertino_progress_bar.dart';
import 'package:chewie/src/utils.dart';
import 'package:open_iconic_flutter/open_iconic_flutter.dart';
import 'package:video_player/video_player.dart';

// Package imports:
// ignore: implementation_imports
// ignore: implementation_imports
// ignore: implementation_imports
// ignore: implementation_imports

This leads to me annotating with ```//ignore: implementation_imports after every sort.

What do you think? I'm aware that I shouldn't be doing this, but in this case I think it's reasonable to do so.

SchnMar avatar Dec 09 '20 21:12 SchnMar

I also encounter this issue.

My Dart file:

import 'package:flutter/widgets.dart';

import 'package:easy_localization/easy_localization.dart';
// ignore: implementation_imports
import 'package:easy_localization/src/localization.dart';
import 'package:logging/logging.dart';

import 'l10n.dart';

import_sorter ignores the //ignore.. statement and messed this up to the following state:

import 'package:flutter/widgets.dart';

import 'package:easy_localization/easy_localization.dart';
import 'package:easy_localization/src/localization.dart';
import 'package:logging/logging.dart';

import 'l10n.dart';

// ignore: implementation_imports


A workaround I found is to put // ignore_for_file: implementation_imports in the file's first line. Then import_sorter works fine, but it's just a workaround.

bartekpacia avatar Aug 25 '21 22:08 bartekpacia

See #63

gleich avatar Dec 07 '21 20:12 gleich