fluttercommunity / import_sorter

🎯 Automatically organize your dart imports. Maintainer: @gleich
https://pub.dev/packages/import_sorter
MIT License
174 stars 40 forks source link

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

Open lig opened 3 years ago

lig commented 3 years ago

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.

lig commented 3 years ago

Another option is to use python hook type as a wrapper. From the pre-commit docs: Support: python hooks work without any system-level dependencies. It has been tested on linux, macOS, windows, and cygwin. https://pre-commit.com/#python

A simple python script will work on any platform and it is easy enough to parse arguments and invoke the proper command from it.

lig commented 3 years ago

Well, according to the docs the entire repo must be installable as a python package. This will require some additional files in the repo root. Seems a bit inconvenient.

gleich commented 2 years ago

See #63