Open vijaymsc opened 3 weeks ago
Is lib/main.dart in git staged state?(aka git add lib/main.dart
)
Also, you can add DEBUG=true
before dart run lint_staged
in .husky/pre-commit
to make the verbose logging message visible
DEBUG=true dart run lint_staged
yes my main.dart file is git added file, i check three scenario my main.dart file have parint statement and some methods not use const key also main.dart file not fomarmated. i add main.dart file in git and then try commit my file the pre commit file executed.
Actual Output:- ✗ dart analyze --fatal-infos --fatal-warnings lib/main.dart Analyzing main.dart...
error - main.dart:35:3 - Don't invoke 'print' in production code. Try using a logging framework. - avoid_print info - main.dart:53:14 - Use 'const' with the constructor to improve performance. Try adding the 'const' keyword to the constructor invocation. - prefer_const_con
lint_stageed commands: lint_staged: 'lib/**.dart': dart format . -l 120 --fix && dart fix --apply && dart analyze --fatal-infos --fatal-warnings
My goal is: when i try commit format my staged files and auto fix and apply lint issues like const keys and then finely execute dart analyze still have any issue like print statement that issue only return in output. not entire analyze issue
If i remove flutter analyze command and run flutter format and dart fix --apply this is working fine.
If you run these three scripts by hand, does they all succeed or any failure happens?
lint_staged
will revert tasks' modification when script fails
I set 'lib/**.dart': dart format . -l 120 --fix && dart fix --apply && dart analyze --fatal-infos --fatal-warnings. command in pubspec.yaml file.
main.dart have this lint issues error - main.dart:35:3 - Don't invoke 'print' in production code. Try using a logging framework. - avoid_print info - main.dart:53:14 - Use 'const' with the constructor to improve performance. Try adding the 'const' keyword to the constructor invocation. - prefer_const_con
git add lib/main.dart
and try commit the file using lint staged
again give two issues
error - main.dart:35:3 - Don't invoke 'print' in production code. Try using a logging framework. - avoid_print
info - main.dart:53:14 - Use 'const' with the constructor to improve performance. Try adding the 'const' keyword to the constructor invocation. - prefer_const_con.
=> dart fix --apply command clear a const key issues in automaticaly and only give print statement issue but actual result result is again give two warning const,print in lint staged commit. dart fix --apply not workking
@vijaymsc Thanks for the detailed information, this is working by design:
dart fix --apply
did work, it fixed the const key issue, but it could not fix the avoid_print
issuedart analyze --fatal-infos --fatal-warnings
failed with the avoid_print
issuelint_staged
reverted the modification of dart fix --apply
because script failure happened@hyiso thanks for clarification but i need another doubt.
@hyiso thanks for clarification but i need another doubt.
- my main.dart file only have have const key issue that time dart fix --apply did work right. but dart analyze --fatal-infos --fatal-warnings failed with the const key .
Do you mean dart fix --apply
fixed the issue but dart analyze --fatal-infos --fatal-warnings
still report the issue?
- also when i try to commit my file using lint staged its take time to long , is there any chance to reduce commit execution time.
This is because dart analyze
takes time to analyze code.
lint_staged
's work is find out the staged files and passes every file to every script configured under lint_staged
Yes i have only const key lint error only dart fix --apply fixed the issue but dart analyze --fatal-infos --fatal-warnings still report the issue
This is unexpected, could you provide a small reproducible code example?
pubspec.yaml dev_dependencies: husky: 0.1.7 lint_staged: 0.5.1 lint_staged: 'lib/**.dart': dart format . -l 120 --fix && dart fix --apply && dart analyze --fatal-infos --fatal-warnings
husky pre_commit file
!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
dart run lint_staged
Outpute is
✗ dart analyze --fatal-infos --fatal-warnings lib/main.dart Analyzing main.dart...
error - main.dart:35:3 - Don't invoke 'print' in production code. Try using a logging framework. - avoid_print info - main.dart:53:14 - Use 'const' with the constructor to improve performance. Try adding the 'const' keyword to the constructor invocation. - prefer_const_con structors
2 issues found. husky - pre-commit hook exited with code 1 (error)
Expected is
then check flutter anlyze the issue
error - main.dart:35:3 - Don't invoke 'print' in production code. Try using a logging framework. - avoid_print
note: I think first two rules are executed and if run third one before rules are reverted and final result is third rule outputes