skycoder42 / dart_pre_commit Goto Github PK
View Code? Open in Web Editor NEWA 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
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
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.
$ 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.
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.
The following samples should work:
// this is a comment
import '...';
import '...'; // this is also comment
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
.
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
I prefer my project to have > 80 char line length.
dart format --line-length 150
in combination with VS Code settings outlined here works, but I don't see how to pass the --line-length
option down to the pre-commit hook.
This breaks if my project is inside a folder and not in the root of the project, because scripts run from root of git project.
Please assign this task to me, I want to work on it.
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".
Leftover issue of ad6ec72 - was forgotten there
I played around with this and am left wondering why the install instructions don't include a route that looks similar to this:
https://gist.github.com/ryanhanks-bestow/db0c4b3c901465fcbe6651d02dc44e2c
This is my first day here so please forgive me for missing the obvious
Not all tools report their console status correctly. Git, for example, is not detected as terminal, which is correct, but should still be able to use the rich logger.
Except of course files that only have internal classes
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.
The following examples confuse the hook:
// comment
import '...';
import '...'
as stuff;
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.
New to this libarary. The method in README mostly does not work...
Windows 10. dart_pre_commit 3.0.0
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.