├── .pre-commit-hooks.yaml ├── LICENSE ├── README.md └── run /.pre-commit-hooks.yaml: -------------------------------------------------------------------------------- 1 | - id: flutter-format 2 | name: Format Flutter Code 3 | entry: run 4 | language: script 5 | files: \.dart$ 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Charles-William Crete 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Note: `flutter format` is now `dart format` 2 | 3 | Please use [dart-format-pre-commit](https://github.com/Cretezy/). This package will give a Flutter warning to migrate to `dart format`, which this other package is. 4 | 5 | --- 6 | 7 | # Flutter Format `pre-commit` 8 | 9 | [`pre-commit`](https://pre-commit.com) hook for formatting Flutter files. 10 | 11 | Add the following in your `.pre-commit-config.yaml`: 12 | ```yaml 13 | - repo: https://github.com/Cretezy/flutter-format-pre-commit 14 | rev: "master" 15 | hooks: 16 | - id: flutter-format 17 | ``` 18 | By default, the flutter format command uses a [line length of 80](https://github.com/dart-lang/dart_style/issues/833). You can customize what line length is used by passing the `--line-length` argument to the hook: 19 | ```yaml 20 | - repo: https://github.com/Cretezy/flutter-format-pre-commit 21 | rev: "master" 22 | hooks: 23 | - id: flutter-format 24 | args: [--line-length=100] 25 | ``` 26 | 27 | You can also only include/exclude some files (defaults to only `.dart`, is a pattern): 28 | 29 | ```yaml 30 | - repo: https://github.com/Cretezy/flutter-format-pre-commit 31 | rev: "master" 32 | hooks: 33 | - id: flutter-format 34 | files: lib/* # Only format source files 35 | exclude: lib/src/avatar.dart # Exclude the avatar widget 36 | ``` 37 | 38 | ## Dart 39 | 40 | Also see [Dart Format `pre-commit`](https://github.com/Cretezy/dart-format-pre-commit) for formatting only Dart code. 41 | -------------------------------------------------------------------------------- /run: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | flutter format $@ 4 | --------------------------------------------------------------------------------