hyiso / lint_staged

Run linters on git staged files for your Flutter and Dart projects. Inspired by JavaScript lint-staged library
https://pub.dev/packages/lint_staged
Apache License 2.0
8 stars 2 forks source link

error when using dart format command #6

Closed w0aw closed 1 year ago

w0aw commented 1 year ago

i am using lint_staged with husky. with following configuration

a. husky/pre-commit

#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

dart run lint_staged

b. pubspec.yml

lint_staged:
  "lib/**.dart": dart format

everything is working fine when we have some actual changes in files. but for testing purpose when i added some extra space in lib/main.dart file, then on commit it is throwing following output and even it do not remove some extra space that i added recently to taste thing.

✔ Preparing lint_staged...                
✔ Running tasks for staged files...       
✔ Applying modifications from tasks...    
✔ Reverting to original state because of errors...
husky - pre-commit hook exited with code 1 (error)

to double check my dart command. when i execute "dart format ." it removes those extra spaces from main.dart.

CORRECT ME IF I AM AT WRONG PLACE.

thank you

hyiso commented 1 year ago

Thanks for your report.

✔ Reverting to original state because of errors... husky - pre-commit hook exited with code 1 (error)

This step indicates some errors happened during lint_staged running, you can add VERBOSE=true in pre-commit hook to print verbose log:

#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

VERBOSE=true dart run lint_staged
w0aw commented 1 year ago

lint_staged:execGit - git -c submodule.recurse=false log -1 lint_staged:execGit - git -c submodule.recurse=false diff --name-only -z --diff-filter=ACMR --staged lint_staged:run - Loaded list of staged files int git: [lib/main.dart] lint_staged:run - Found configs: {lib/.dart: [dart format]} lint_staged:run - lib/main.dart matches lib/.dart is true lint_staged:run - matched files: {lib/main.dart} lint_staged:run - matched file chunks: [[lib/main.dart]] lint_staged:execGit - git -c submodule.recurse=false rev-parse --git-dir ⠙ Preparing lint_staged...
lint_staged:GitWorkflow - Backing up original state... lint_staged:GitWorkflow - Getting partially staged files... lint_staged:execGit - git -c submodule.recurse=false status -z lint_staged:GitWorkflow - Found partially staged files: [] lint_staged:GitWorkflow - Backing up merge state... lint_staged:GitWorkflow - Done backing up merge state! lint_staged:GitWorkflow - Getting deleted files... lint_staged:execGit - git -c submodule.recurse=false ls-files --deleted lint_staged:GitWorkflow - Found deleted files: [] lint_staged:execGit - git -c submodule.recurse=false stash create lint_staged:execGit - git -c submodule.recurse=false stash store --quiet --message lint_staged automatic backup d58bab906eb4a43b61ecfd1ecf39a1b37f029001 lint_staged:GitWorkflow - Done backing up original state! ✔ Preparing lint_staged...
⠙ Running tasks for staged files...
lint_staged:LintRunner - dart format lib/main.dart ⠹ Running tasks for staged files...
⠸ Running tasks for staged files...
⠼ Running tasks for staged files...
⠴ Running tasks for staged files...
✔ Running tasks for staged files...
⠙ Applying modifications from tasks...
lint_staged:GitWorkflow - Adding task modifications to index... lint_staged:execGit - git -c submodule.recurse=false add -- lib/main.dart lint_staged:GitWorkflow - Done adding task modifications to index! lint_staged:execGit - git -c submodule.recurse=false diff --name-only -z --diff-filter=ACMR --staged lint_staged:GitWorkflow - #0 GitWorkflow.handleError (package:lint_staged/src/git_workflow.dart:403:24)

1 GitWorkflow.applyModifications (package:lint_staged/src/git_workflow.dart:318:7)

#2 runAll (package:lint_staged/src/run.dart:125:5) #3 lintStaged (package:lint_staged/lint_staged.dart:28:17) #4 main (file:///home/mipal/.pub-cache/hosted/pub.dev/lint_staged-0.3.0/bin/lint_staged.dart:26:20) ✔ Applying modifications from tasks... ⠙ Reverting to original state because of errors... lint_staged:GitWorkflow - Restoring original state... lint_staged:execGit - git -c submodule.recurse=false reset --hard HEAD lint_staged:execGit - git -c submodule.recurse=false stash list lint_staged:execGit - git -c submodule.recurse=false stash apply --quiet --index 0 lint_staged:GitWorkflow - Restoring merge state... lint_staged:GitWorkflow - Done restoring merge state! lint_staged:GitWorkflow - Restoring original state error: PathNotFoundException: Deletion failed, path = '/home/mipal/______$my_working_dir_here______/.git/lint_staged_unstaged.patch' (OS Error: No such file or directory, errno = 2) lint_staged:GitWorkflow - #0 GitWorkflow.handleError (package:lint_staged/src/git_workflow.dart:403:24) #1 GitWorkflow.restoreOriginState (package:lint_staged/src/git_workflow.dart:380:7) #2 runAll (package:lint_staged/src/run.dart:139:5) #3 lintStaged (package:lint_staged/lint_staged.dart:28:17) #4 main (file:///home/mipal/.pub-cache/hosted/pub.dev/lint_staged-0.3.0/bin/lint_staged.dart:26:20) ✔ Reverting to original state because of errors... lint_staged - lint_staged prevented an empty git commit. Use the --allow-empty option to continue, or check your task configuration husky - pre-commit hook exited with code 1 (error)
hyiso commented 1 year ago

Thanks for the detailed log message, I'll check it.

hyiso commented 1 year ago

Sorry to be late, now 0.4.0 has been published

w0aw commented 1 year ago

Thnaks i'll try it out