dart-code-checker / dart-code-metrics

Software analytics tool that helps developers analyse and improve software quality.
https://dcm.dev
Other
856 stars 265 forks source link

Flutter Pre-push not working with dart_code_metrics #1239

Open redevrx opened 1 year ago

redevrx commented 1 year ago

Environment and configuration

DCM version: Dart SDK version:

Configuration ```yaml 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

What did you do?

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

Additional comments

No response

incendial commented 1 year ago

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

redevrx commented 1 year ago

@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 commented 1 year ago

@redevrx have you tried passing dedicated flags to the CLI https://github.com/dart-code-checker/dart-code-metrics/blob/master/lib/src/cli/commands/analyze_command.dart#L176?