Skip to content
This repository has been archived by the owner on Jul 16, 2023. It is now read-only.

Flutter Pre-push not working with dart_code_metrics #1239

Open
redevrx opened this issue May 31, 2023 · 3 comments
Open

Flutter Pre-push not working with dart_code_metrics #1239

redevrx opened this issue May 31, 2023 · 3 comments
Assignees
Labels
type: bug Something isn't working

Comments

@redevrx
Copy link

redevrx commented May 31, 2023

Environment and configuration

DCM version:
Dart SDK version:

Configuration
<!-- Paste your configuration here -->
environment:
  sdk: '>=3.0.0 <4.0.0'
  flutter: ">=1.17.0"

dependencies:
  flutter:
    sdk: flutter
  dio: ^5.1.2
  http_parser: ^4.0.2

dev_dependencies:
  flutter_test:
    sdk: flutter
  mockito: ^5.4.0
  build_runner: ^2.3.3
  flutter_lints: ^2.0.1
  coverage: ^1.6.3
  dart_code_metrics: ^5.7.4

</details>


### What did you do?

<!-- Paste the source code below: -->
Flutter Pre-push not working with dart_code_metrics
i have error  Missing blank line before return. but pre-psuh not break.

#!/bin/sh

printf "\e[33;1m%s\e[0m\n" 'Pre-Commit is running now.'

Undo the stash of the files

pop_stash_files () {
if [ -n "$hasChanges" ]; then
printf "\e[33;1m%s\e[0m\n" '=== Applying git stash changes ==='
git stash pop
fi
}

Stash unstaged files

hasChanges=$(git diff)
if [ -n "$hasChanges" ]; then
printf "\e[33;1m%s\e[0m\n" 'Stashing unstaged changes'
git stash push --keep-index
fi

Flutter formatter

printf "\e[33;1m%s\e[0m\n" '=== Running Flutter Formatter ==='
dart format .

hasNewFilesFormatted=$(git diff)
if [ -n "$hasNewFilesFormatted" ]; then
git add .
printf "\e[33;1m%s\e[0m\n" 'Formmated files added to git stage'
fi
printf "\e[33;1m%s\e[0m\n" 'Finished running Flutter Formatter'
printf '%s\n' "${avar}"

Flutter Analyzer

printf "\e[33;1m%s\e[0m\n" '=== Running Flutter analyzer ==='
flutter analyze
if [ $? -ne 0 ]; then
printf "\e[31;1m%s\e[0m\n" '=== Flutter analyzer error ==='
pop_stash_files
exit 1
fi
printf "\e[33;1m%s\e[0m\n" 'Finished running Flutter analyzer'
printf '%s\n' "${avar}"

Run Flutter metrics analyze command

printf "\e[33;1m%s\e[0m\n" '=== Running Flutter metrics analyzer ==='
flutter pub run dart_code_metrics:metrics analyze lib
if [ $? -ne 0 ]; then
printf "\e[31;1m%s\e[0m\n" '=== Flutter analyzer error ==='
pop_stash_files
exit 1
fi
printf "\e[33;1m%s\e[0m\n" 'Finished running Flutter metrics analyzer'
printf '%s\n' "${avar}"

Unit tests

printf "\e[33;1m%s\e[0m\n" '=== Running Unit Tests ==='
flutter test
if [ $? -ne 0 ]; then
printf "\e[31;1m%s\e[0m\n" '=== Unit tests error ==='
pop_stash_files
exit 1
fi
printf "\e[33;1m%s\e[0m\n" 'Finished running Unit Tests'
printf '%s\n' "${avar}"

pop_stash_files



### What did you expect to happen?

pre-push want break when have error analyze

### What actually happened?

pre-push not working with dart_code_metrics

### Participation

- [X] I am willing to submit a pull request for this issue.

### Additional comments

_No response_
@redevrx redevrx added the type: bug Something isn't working label May 31, 2023
@incendial
Copy link
Member

@redevrx can you fix the description? And what is "Flutter Pre-push"?

@redevrx
Copy link
Author

redevrx commented Jun 5, 2023

@incendial Hello, I want to set up a pre-commit hook that runs the "flutter analyze" command. When it encounters incorrect code, it will report an error and prevent the commit from proceeding. This works well. However, when I use "flutter pub run dart_code_metrics:metrics analyze lib", it detects incorrect code but doesn't stop the process. It continues running until the pre-commit hook is finished.

@incendial
Copy link
Member

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants