{"id":17602599,"url":"https://github.com/skycoder42/dart_pre_commit","last_synced_at":"2026-02-19T20:00:52.183Z","repository":{"id":56827805,"uuid":"297241692","full_name":"Skycoder42/dart_pre_commit","owner":"Skycoder42","description":"A small collection of pre commit hooks to format and lint dart code","archived":false,"fork":false,"pushed_at":"2025-11-22T06:16:05.000Z","size":677,"stargazers_count":12,"open_issues_count":0,"forks_count":7,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-11-22T07:14:45.581Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://pub.dev/packages/dart_pre_commit","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Skycoder42.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2020-09-21T05:52:54.000Z","updated_at":"2025-11-22T06:04:49.000Z","dependencies_parsed_at":"2025-03-09T00:32:00.640Z","dependency_job_id":"088ea542-5ff5-416d-8dde-8e0541e38aa4","html_url":"https://github.com/Skycoder42/dart_pre_commit","commit_stats":null,"previous_names":[],"tags_count":46,"template":false,"template_full_name":null,"purl":"pkg:github/Skycoder42/dart_pre_commit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Skycoder42%2Fdart_pre_commit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Skycoder42%2Fdart_pre_commit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Skycoder42%2Fdart_pre_commit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Skycoder42%2Fdart_pre_commit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Skycoder42","download_url":"https://codeload.github.com/Skycoder42/dart_pre_commit/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Skycoder42%2Fdart_pre_commit/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29629630,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-19T18:02:07.722Z","status":"ssl_error","status_checked_at":"2026-02-19T18:01:46.144Z","response_time":117,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-22T13:09:03.498Z","updated_at":"2026-02-19T20:00:52.170Z","avatar_url":"https://github.com/Skycoder42.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dart_pre_commit\n[![Continuos Integration](https://github.com/Skycoder42/dart_pre_commit/actions/workflows/ci.yaml/badge.svg)](https://github.com/Skycoder42/dart_pre_commit/actions/workflows/ci.yaml)\n[![Pub Version](https://img.shields.io/pub/v/dart_pre_commit)](https://pub.dev/packages/dart_pre_commit)\n\nA small collection of pre commit hooks to format and lint dart code\n\n## Table of Contents\n- [Features](#features)\n- [Installation](#installation)\n- [Activation](#activation)\n  * [Simple dart wrapper](#simple-dart-wrapper)\n  * [When using FVM](#when-using-fvm)\n  * [Using git_hooks](#using-git_hooks)\n    + [Handling the case where the git_hooks is setup in a child folder of the repository](#handling-the-case-where-the-git_hooks-is-setup-in-a-child-folder-of-the-repository)\n- [Configuration](#configuration)\n  * [Format task](#format-task)\n    + [Options](#options)\n  * [Analyze Task](#analyze-task)\n    + [Options](#options-1)\n  * [Flutter Compatibility Task](#flutter-compatibility-task)\n  * [Outdated Task](#outdated-task)\n    + [Options](#options-3)\n  * [Pull Up Dependencies Task](#pull-up-dependencies-task)\n    + [Options](#options-4)\n  * [OSV-Scanner Task](#osv-scanner-task)\n- [Documentation](#documentation)\n\n\u003csmall\u003e\u003ci\u003e\u003ca href='https://ecotrust-canada.github.io/markdown-toc/'\u003eTable of contents generated with markdown-toc\u003c/a\u003e\u003c/i\u003e\u003c/small\u003e\n\n## Features\n- Provides multiple built in hooks to run on staged files\n  - Run `dart format`\n  - Check for invalid imports in test files\n  - Run `dart analyze`\n  - Ensure all src files that are publicly visible are exported somewhere\n  - Checks if a dart package is compatible with the current stable flutter version\n  - Checks if any packages are outdated\n  - Checks if any packages have newer versions in the lock file\n- Only processes staged files\n  - Automatically stages modified files again\n  - Fails if partially staged files had to be modified\n- Can be used as binary or as library\n- Integrates well with most git hook solutions\n\n## Installation\nSimply add `dart_pre_commit` to your `pubspec.yaml` (preferably as dev dependency) and run `dart pub get` (or\n`flutter pub get`).\n\n```sh\ndart pub add --dev dart_pre_commit\n```\n\n## Activation\nTo make use of the hooks, you have to activate them first. This package only comes with the hook-code itself, **not**\nwith a way to integrate it with git as actual hook. Here are a few examples on how to do so:\n\n### Simple dart wrapper\nIf this is the only hook you need and you don't really need anything more then \"just run the thing\", you can simply\ncreate a file named `tool/setup_git_hooks.dart` as detailed below and run `dart run tool/setup_git_hooks.dart` to\ninitialize the hooks on each of your machines.\n\n```dart\nimport 'dart:io';\n\nFuture\u003cvoid\u003e main() async {\n  final preCommitHook = File('.git/hooks/pre-commit');\n  await preCommitHook.parent.create();\n  await preCommitHook.writeAsString(\n    '''\n#!/bin/sh\nexec dart run dart_pre_commit # specify custom options here\n# exec flutter pub run dart_pre_commit # Use this instead when working on a flutter project\n''',\n  );\n\n  if (!Platform.isWindows) {\n    final result = await Process.run('chmod', ['a+x', preCommitHook.path]);\n    stdout.write(result.stdout);\n    stderr.write(result.stderr);\n    exitCode = result.exitCode;\n  }\n}\n```\n\n### When using FVM\nWhen using [FVM](https://fvm.app/), you may want to adjust the dart script from above to run `dart_pre_commit` via FVM:\n\n```dart\nimport 'dart:io';\n\nFuture\u003cvoid\u003e main() async {\n  // Add this part\n  final useFvm = !arguments.contains('--no-fvm');\n  final command = useFvm\n      ? 'fvm dart run dart_pre_commit'  // or \"fmv flutter pub run dart_pre_commit\" for flutter projects\n      : 'dart run dart_pre_commit';  // or \"flutter pub run dart_pre_commit\" for flutter projects\n\n  final preCommitHook = File('.git/hooks/pre-commit');\n  await preCommitHook.parent.create();\n  await preCommitHook.writeAsString(\n    '''\n#!/bin/sh\nexec $command # use the previously selected command here\n''',\n  );\n\n  if (!Platform.isWindows) {\n    final result = await Process.run('chmod', ['a+x', preCommitHook.path]);\n    stdout.write(result.stdout);\n    stderr.write(result.stderr);\n    exitCode = result.exitCode;\n  }\n}\n```\n\n### Using git_hooks\nThe second example uses the [git_hooks](https://pub.dev/packages/git_hooks) package to activate the hook. Take the\nfollowing steps to activate the hook:\n\n1. Add `git_hooks` as dev dependency to your project\n2. Follow the installation instructions here: https://pub.dev/packages/git_hooks#create-files-in-githooks\n3. Modify `bin/git_hooks.dart` to look like the following:\n```dart\nimport \"package:dart_pre_commit/dart_pre_commit.dart\";\nimport \"package:git_hooks/git_hooks.dart\";\n\nvoid main(List\u003cString\u003e arguments) {\n  final params = {\n    Git.preCommit: _preCommit\n  };\n  GitHooks.call(arguments, params);\n}\n\nFuture\u003cbool\u003e _preCommit() async {\n  final result = await DartPreCommit.run();\n  return result.isSuccess;\n}\n```\n\n#### Handling the case where the git_hooks is setup in a child folder of the repository\nIn cases where your project is in a child folder of the repository ie. Repo/project, when you run `DartPreCommit.run()`,\nit'll run from the root of your repository and hence will not be able to find `pubspec.yaml` file. To handle this case\nwe need to direct the DartPreCommit to run its command from a child folder. To do so, you need to add the following line\nin the `_preCommit()` function before we invoke DartPreCommit:\n\n```dart\nFuture\u003cbool\u003e _preCommit() async {\n  Directory.current = '/project_sub_directory'; // \u003c--- This line switches the scan directory to a subdirectory\n  final result = await DartPreCommit.run();\n  return result.isSuccess;\n}\n```\n\n## Configuration\nThe tool follows the zero config principle - this means you can run it without having to configure anything. However,\nthere are a bunch of configuration options if you need to adjust the tool. For simplicity, you can just define them\nin your `pubspec.yaml` below the `dart_pre_commit` key, but it is also possible to move it to a separate file.\n\nThe configuration uses the following pattern:\n```yaml\ndart_pre_commit:\n  exclude: null # special key\n  task_1: null\n  task_2: false\n  task_3: true\n  task_4:\n    option1: true\n    option2: info\n    option3:\n      - a\n      - b\n    ...\n  ...\n```\n\nEach task corresponds to the configuration of the task with that name. The values can be:\n- `null` (or missing): The default configuration of the task is used\n- `true` or `false`: Explicitly enable or disable the task. If enabled, still uses the default configuration.\n- `\u003cconfig-map\u003e`: Explicitly enable the task and use the given configuration in addition to the default configuration.\nThis allows you to overwrite either some or all of the configuration options of a task.\n\nThe default tasks and their options, if they have any, are defined follows. However, you can always create your own,\ncustom tasks with customized configurations.\n\nThe tool also accepts some command line arguments. Run `dart_pre_commit --help` to get more information on them.\n\nOne special key is the `exclude` key. If specified, it can either be a simple string or a list of strings, each\ntreated as a **Regular Expression** to match staged files against. If any staged file is matched by any of those\npatterns, it will be excluded. Path are tested relative to the scanned dart project root.\n\n**Important:** This does NOT mean these files will not have any impact on the results, it only means that they are not\ndetected as staged. That leads to per file tasks not being executed on those files and may or may not influence the\nbehavior of repository tasks. For example, the `analyze` task will still report errors for these files, unless\n`ignore-unstaged-files` is set to `true`.\n\n### Format task\n**Task-ID:** `format`\u003cbr/\u003e\n**Configurable:** Yes\u003cbr/\u003e\n**Enabled**: Always\u003cbr/\u003e\n\nThis tasks checks all staged files for their formatting and corrects the formatting, if necessary. Internally, it uses\nthe `dart format` command to accomplish this.\n\n#### Options\n Option        | Type   | Default | Description\n---------------|--------|---------|-------------\n `line-length` | `int?` | `null`  | The line length the formatter should use. If unset, the recommended default for dart (currently 80) is used.\n\n### Analyze Task\n**Task-ID:** `analyze`\u003cbr/\u003e\n**Configurable:** Yes\u003cbr/\u003e\n**Enabled**: Always\u003cbr/\u003e\n\nThis tasks checks all files for static analysis issues. Internally, this runs `dart analyze` to check for problems.\n\n#### Options\n Option                  | Type   | Default | Description\n-------------------------|--------|---------|-------------\n `error-level`           | `enum` | `info`  | The severity level that should cause the task to reject the commit. See possible values below.\n `ignore-unstaged-files` | `bool` | `false` | If set to `true`, analysis errors in unstaged files will be reported, but will not cause the task to fail.\n\nValues for `error-level`:\n- `error`: Only fatal errors are reported\n- `warning`: fatal errors and warnings are reported\n- `info`: fatal errors, warnings and linter issues are reported\n\n### Flutter Compatibility Task\n**Task-ID:** `flutter-compat`\u003cbr/\u003e\n**Configurable:** No\u003cbr/\u003e\n**Enabled**: Only for pure dart projects\u003cbr/\u003e\n\nIf changes have been made to the `pubspec.yaml`, this task will try to add this project as dependency to an empty, newly\ncreated flutter project to check if all version constraints of all dependencies are compatible with the latest flutter\nversion.\n\n**Important:** This task requires you to have flutter installed the the `flutter` binary to be available in your path.\nIf this is not the case, you should explicitly disable the task.\n\n### Outdated Task\n**Task-ID:** `outdated`\u003cbr/\u003e\n**Configurable:** Yes\u003cbr/\u003e\n**Enabled**: Always\u003cbr/\u003e\n\nChecks if any packages have available updates. This task always runs, even if no changes to the dependencies have been\nmade. If any package has updates greater than the defined allowed level, the commit will fail.\n\n#### Options\n Option    | Type           | Default | Description\n-----------|----------------|---------|-------------\n `level`   | `enum`         | `any`   | The level of \"outdated-ness\" that is allowed. See possible values below.\n `allowed` | `List\u003cString\u003e` | `[]`    | A list of packages that are allowed to be outdated, even if the `level` would otherwise reject them. Sometimes needed if updates break your code.\n\nValues for `level`:\n- `major`: only check for major package updates\n- `minor`: check for major and minor updates\n- `patch`: check for major, minor and patch updates\n- `any`: check for all updates, except pre-releases\n\n### Pull Up Dependencies Task\n**Task-ID:** `pull-up-dependencies`\u003cbr/\u003e\n**Configurable:** Yes\u003cbr/\u003e\n**Enabled**: Always\u003cbr/\u003e\n\nChecks if any dependencies in the `pubspec.yaml` have version constraints that allow lower versions than the ones\nresolved in the lockfile. If thats the case, the task will reject the commit. If the lockfile is ignored, this task\nalways runs, otherwise it only runs if changes to the lockfile have been staged.\n\n#### Options\n Option    | Type           | Default | Description\n-----------|----------------|---------|-------------\n `allowed` | `List\u003cString\u003e` | `[]`    | A list of packages that are allowed to not be pulled up, even if their version constrains imply it. Can be useful to keep backwards compatibility.\n\n### OSV-Scanner Task\n**Task-ID:** `osv-scanner`\u003cbr/\u003e\n**Configurable:** Yes\u003cbr/\u003e\n**Enabled**: Only if the `osv-scanner` binary is found in your PATH\u003cbr/\u003e\n\nWhen enabled, the `pubspec.lock` file is analyzed by the [OSV-Scanner](https://github.com/google/osv-scanner) for known\nvulnerabilities in dependent packages. The task will fail in case such dependencies are found.\n\n#### Options\n Option          | Type      | Default | Description\n-----------------|-----------|---------|-------------\n `lockfile-only` | `bool`    | `true`  | If set to true, then only the pubspec.lock itself is scanned. Otherwise, the whole source folder is scanned.\n `config`        | `String?` | `null`  | If specified, the config file path will be passed to the osv scanner. Otherwise, the scanner tries to auto-detect the configuration.\n `legacy`        | `bool`    | `false` | If set to true, assume the installed osv-scanner is Version 1.x. By default, Version 2.x is expected.\n\n## Documentation\nThe documentation is available at\nhttps://pub.dev/documentation/dart_pre_commit/latest/. A full example can be\nfound at https://pub.dev/packages/dart_pre_commit/example.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskycoder42%2Fdart_pre_commit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fskycoder42%2Fdart_pre_commit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskycoder42%2Fdart_pre_commit/lists"}