Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Precommit hook doesn't sort imports #39

Closed
martinloretzzz opened this issue Dec 27, 2020 · 12 comments
Closed

Precommit hook doesn't sort imports #39

martinloretzzz opened this issue Dec 27, 2020 · 12 comments
Labels
bug Something isn't working

Comments

@martinloretzzz
Copy link

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
@martinloretzzz martinloretzzz added the bug Something isn't working label Dec 27, 2020
@github-actions
Copy link

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

@gleich
Copy link
Member

gleich commented Dec 27, 2020

@lig worked on this. Any idea on why this isn't working?

@lig
Copy link
Contributor

lig commented Dec 27, 2020

@lig worked on this. Any idea on why this isn't working?

I have some suspicions. I'll look into this.

files: \.dart$

It seems like it worked for me.

@0b01001101 just to clarify: what pre-commit version do you use? Does replacing flutter-import-sorter with dart-import-sorter change anything?

@martinloretzzz
Copy link
Author

pre-commit 2.9.3

If i use dart-import-sorter i get this:

Dart Import Sorter.......................................................Failed
- hook id: dart-import-sorter
- exit code: 1

The Flutter SDK is not available.

If I remove the files completely, everything works fine(In my first example the ^lib/ regex has a pattern error, so I got the same effect).
I use Windows 10

@lig
Copy link
Contributor

lig commented Dec 28, 2020

@0b01001101 could you please run pre-commit autoupdate and try again with flutter-import-sorter? @Matt-Gleich has just merged a fix.

@gleich gleich closed this as completed Dec 28, 2020
@gleich gleich reopened this Dec 28, 2020
@martinloretzzz
Copy link
Author

Still doesn't work for me

It may have something to do with windows: https://stackoverflow.com/a/23384429

I will investigate the problem further tomorrow

@lig
Copy link
Contributor

lig commented Dec 28, 2020

Still doesn't work for me

Could you please provide the full output?

Please run it like this: pre-commit run --verbose --all-files flutter-import-sorter

@martinloretzzz
Copy link
Author

- hook id: flutter-import-sorter
- duration: 1.76s

┏━━🗂  Sorting 0 dart files
┃  ┃┃
┗━━🙌 Sorted 0 imports in 0.113 seconds

@lig
Copy link
Contributor

lig commented Dec 28, 2020

@0b01001101 have you run git add for any dart source files already? Files not known to git won't be checked by git hooks.

Also, consider removing any files patterns you still might have defined.

@lig
Copy link
Contributor

lig commented Dec 28, 2020

This might be windows related indeed. However, pre-commit should be able to handle that.

@martinloretzzz
Copy link
Author

It is strange: if I use types: [file] instead of types: [dart], then everything works like expected. It just doesn't like sorting only dart files.

For me the hotfix with sorting all files works more than good enough, I would say if nobody else has the same problem we close this issue for now. It may be a complex interaction between the flutter installation on a custom location, something related to windows or some other factors I can't even think of.

@CelestialGuru
Copy link

I am also having issues on Windows. This is my output of pre-commit run --verbose --all-files flutter-import-sorter:

Flutter Import Sorter....................................................Passed
- hook id: flutter-import-sorter
- duration: 4.79s

contains flutter: true
contains registrant: false
┏━━ Sorting 0 dart files
┗━━  Sorted 0 files in 0.266 seconds
contains flutter: true
contains registrant: false
┏━━ Sorting 0 dart files
┗━━  Sorted 0 files in 0.117 seconds

This is what I have in .pre-commit-config.yaml:

exclude: "build|debug-info|.git"
default_stages: [commit]
fail_fast: true

repos:
  - repo: "https://github.com/pre-commit/pre-commit-hooks"
    rev: v4.0.1
    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: "aeb26a791ea546506cc8cd2207b320b64a7ed6b5"
    hooks:
      - id: flutter-import-sorter

bors bot added a commit to batch-dart/batch.dart that referenced this issue Mar 17, 2022
41: fix: fix for the issue (#37) r=myConsciousness a=myConsciousness

# 1. Description

<!-- Provide a description of what this PR is doing.
If you're modifying existing behavior, describe the existing behavior, how this PR is changing it,
and what motivated the change. If this is a breaking change, specify explicitly which APIs have been
changed. -->

The warning is fixed and now we can execute this pre-commit hook.
However it's still have a bug related to [this](fluttercommunity/import_sorter#39).
Since further improvement is difficult, the correction is now complete.

## 1.1. Checklist

<!-- Before you create this PR confirm that it meets all requirements listed below by checking the
relevant checkboxes (`[x]`). This will ensure a smooth and quick review process. -->

- [x] The title of my PR starts with a [Conventional Commit] prefix (`fix:`, `feat:`, `docs:` etc).
- [x] I have read the [Contributor Guide] and followed the process outlined for submitting PRs.
- [x] I have updated/added tests for ALL new/updated/fixed functionality.
- [x] I have updated/added relevant documentation in `docs` and added dartdoc comments with `///`.
- [x] I have updated/added relevant examples in `examples`.

## 1.2. Breaking Change

<!-- Does your PR require batch.dart users to manually update their apps to accommodate your change?

If the PR is a breaking change this should be indicated with suffix "!"  (for example, `feat!:`, `fix!:`). See [Conventional Commit] for details.
-->

- [ ] Yes, this is a breaking change.
- [x] No, this is _not_ a breaking change.

## 1.3. Related Issues

<!-- Provide a list of issues related to this PR from the [issue database].
Indicate which of these issues are resolved or fixed by this PR, i.e. Fixes #xxxx* !-->

fluttercommunity/import_sorter#39

<!-- Links -->

[issue database]: https://github.com/batch-dart/batch.dart/issues
[contributor guide]: https://github.com/batch-dart/batch.dart/blob/main/CONTRIBUTING.md
[batch.dart style guide]: https://github.com/batch-dart/batch.dart/blob/main/STYLEGUIDE.md
[conventional commit]: https://conventionalcommits.org


Co-authored-by: Kato Shinya <kato.shinya.dev@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants