Giter Site home page Giter Site logo

skycoder42 / dart_pre_commit Goto Github PK

View Code? Open in Web Editor NEW
9.0 9.0 5.0 565 KB

A small collection of pre commit hooks to format and lint dart code

Home Page: https://pub.dev/packages/dart_pre_commit

License: BSD 3-Clause "New" or "Revised" License

Dart 99.37% Shell 0.63%

dart_pre_commit's People

Contributors

f22hd avatar felix-barz-brickmakers avatar skycoder42 avatar taosif7-dreamorbit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

dart_pre_commit's Issues

`error-level` option does not work under `analyze` task

I am looking to specify error-level as error, implying that the analyzer should only fail in the event that an "error" is found. However, it is still failing to commit when a "warning" is found.

Here is my configuration in the pubspec.yaml file:

dart_pre_commit:
  analyze:
    error-level: error
    scan-mode: staged

I then made a change to a file that does have a linter warning present (the variable _authHandler is not used), and tried to commit.

Because this is just a warning, and not an error, I should be allowed to commit.
After running git commit -m "dummy commit", this is what my terminal shows:

git commit -m "dummy commit"
โœ… Accepted file lib/services/org_chart_service.dart
๐Ÿ”Ž Running analyze...
      warning - lib/services/org_chart_service.dart:13:21 - The value of the field '_authHandler' isn't used. Try removing the field, or using it. - unused_field
    1 issue(s) found.
โŒ Completed analyze, found problems

So, it seems to me that the error-level config is not actually respecting the value that is being passed in, and always falls back on the default of "info".

Document custom-lint task

I can't find any documentation for the new custom-lint task.

It was causing the commit hook to fail with this error in my project:

Could not find package `custom_lint` or file `custom_lint`
  [EXC] "dart run custom_lint" failed with exit code 255
#0      ProgramRunner.stream (package:dart_pre_commit/src/util/program_runner.dart:91:11)
<asynchronous suspension>

I've managed to turn it off by adding

dart_pre_commit:
  custom-lint: false

to pubspec.yaml.

pre-commit fails in VSCode due to `version solving failed` in flutter project

When committing via the VSCode built in source control panel in my flutter project, the pre-commit fails with following error:

Because emotely depends on flutter_driver from sdk which doesn't exist (the Flutter SDK is not available), version solving failed.

Flutter users should run `flutter pub get` instead of `dart pub get`.

I was able to fix this by replacing the content of the git pre-commit file

#!/bin/sh
exec dart run dart_pre_commit # specify custom options here

with

#!/bin/sh
exec flutter pub run dart_pre_commit # specify custom options here

This might be worth adding to the documentation.

Support import comments

The following samples should work:

// this is a comment
import '...';

import '...'; // this is also comment

dart_test_tools-4.7.0/.../test_import_linter.dart: Error: A value of type 'String?' can't be assigned to a variable of type 'DirectiveUri?'.

I'm getting an error trying to run this:

% dart run dart_pre_commit
Building package executable... 
Failed to build dart_pre_commit:dart_pre_commit:
../../.pub-cache/hosted/pub.dartlang.org/dart_test_tools-4.7.0/lib/src/lint/test_import_linter.dart:105:32: Error: A value of type 'String?' can't be assigned to a variable of type 'DirectiveUri?'.
 - 'DirectiveUri' is from 'package:analyzer/dart/element/element.dart' ('../../.pub-cache/hosted/pub.dartlang.org/analyzer-4.7.0/lib/dart/element/element.dart').
      directiveUri = directive.element?.uri;
                               ^
../../.pub-cache/hosted/pub.dartlang.org/dart_test_tools-4.7.0/lib/src/lint/test_import_linter.dart:107:32: Error: A value of type 'String?' can't be assigned to a variable of type 'DirectiveUri?'.
 - 'DirectiveUri' is from 'package:analyzer/dart/element/element.dart' ('../../.pub-cache/hosted/pub.dartlang.org/analyzer-4.7.0/lib/dart/element/element.dart').
      directiveUri = directive.element?.uri;
                               ^
Failed to build dart_pre_commit:dart_pre_commit:
../../.pub-cache/hosted/pub.dartlang.org/dart_test_tools-4.7.0/lib/src/lint/test_import_linter.dart:105:32: Error: A value of type 'String?' can't be assigned to a variable of type 'DirectiveUri?'.
 - 'DirectiveUri' is from 'package:analyzer/dart/element/element.dart' ('../../.pub-cache/hosted/pub.dartlang.org/analyzer-4.7.0/lib/dart/element/element.dart').
      directiveUri = directive.element?.uri;
                               ^
../../.pub-cache/hosted/pub.dartlang.org/dart_test_tools-4.7.0/lib/src/lint/test_import_linter.dart:107:32: Error: A value of type 'String?' can't be assigned to a variable of type 'DirectiveUri?'.
 - 'DirectiveUri' is from 'package:analyzer/dart/element/element.dart' ('../../.pub-cache/hosted/pub.dartlang.org/analyzer-4.7.0/lib/dart/element/element.dart').
      directiveUri = directive.element?.uri;

It was working so I'm guessing its related to flutter and other package upgrades in my project.

Add support for fvm

Since this plugin directly runs the flutter ... and dart ... commands, the projects that are using different version of flutter via fvm, fail to use the fvm flutter version for analysis. We need to add support for fvm in flutter and dart analyse commands.

A proposed solution is that we can detect .fvm folder in the project root and add "fvm" prefix before all flutter and dart commands in execution.

lib-exports on flutter skeleton app

A flutter skeleton creates public MyApp class that consumes a public SampleItemListView class. These aren't exported and I'm not sure it makes sense to do so for a flutter app.

Should the lib-exports script handle this different? Should I start exporting my Flutter app components? Should I just not use the lib-exports script for flutter? Perhaps documenting this is the solution.

dart run dart_pre_commit -l debug
...
๐Ÿ”Ž Running lib-exports...
    lib/src/app.dart:10:1 - File has package-public declaration
    lib/src/sample_feature/sample_item_list_view.dart:7:1 - File has package-public declaration
    lib/src/app.dart - Source file is not exported anywhere
    lib/src/sample_feature/sample_item_list_view.dart - Source file is not exported anywhere
โŒ Completed lib-exports, found problems

Add outdated packages check

  • should use pub outdated to check for upgradable/resolvable packages
  • should also support the nullsafe check

Pull up crashes when pubspec.yaml contains dependency not found in lockfile

$ git commit -m "use final fields instead of getters"
> Running pre_commit hook...
Scanning lib/src/firebase_account.dart...
Scanning lib/src/firebase_auth.dart...
Scanning lib/src/profile_update.dart...
Scanning lib/src/rest_api.dart...
Running dart analyze...
0 issue(s) found.
Checking for updates packages...
Unhandled exception:
NoSuchMethodError: The method '>' was called on null.
Receiver: null
Tried calling: >(Instance of 'Version')
#0      Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
#1      PullUpDependencies._pullUpVersions (package:dart_pre_commit/src/pull_up_dependencies.dart:99:31)
#2      PullUpDependencies.call (package:dart_pre_commit/src/pull_up_dependencies.dart:32:21)
<asynchronous suspension>
#3      Hooks.call (package:dart_pre_commit/src/hooks.dart:224:38)
<asynchronous suspension>
#4      main (file:///C:/Users/felix.barz/repos/other/firebase_rest_auth/tool/pre_commit.dart:9:29)
<asynchronous suspension>
#5      _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:299:32)
#6      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)

> Error detected in pre_commit hook.

run specific tasks on staged files only

I would like to run the analyze and custom-lint tasks only on staged files, is there a way I could achieve that?
I have some changes on some files that I'm not trying to commit yet, therefore, I'm not able to commit one file that would actually pass the dart analyzer.

the tool should not prevent me from committing a file because other unstaged files have some issues with the analyze task.

thank you.

Export all sub-steps

  • All steps (fixImports, format, analyze, pullUpDependencies) should be exported
  • They should not directly depend on git anymore, so they can be invoked as pleased

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.