invertase / dart_custom_lint

💡 Easily write powerful Dart & Flutter lint rules for your projects or for users of your packages.
https://pub.dev/packages/custom_lint
Apache License 2.0
280 stars 58 forks source link

Custom lint only on staged files in GIT while commit #190

Open komalkhatri08 opened 11 months ago

komalkhatri08 commented 11 months ago

So i have applied linting with git hooks in my pre-commit hook. When I commit my code it runs the script for 'flutter analyze' and 'custom_lint' (from invertase) commands on my project.. What if I want to run these commands only on files i have made changes in and not in entire project.? I have tried below code. But it does not work

#!/bin/bash

# Get the list of files staged for commit
staged_files=$(git diff --cached --name-only --diff-filter=ACM | grep ".dart$")

# Run custom_lint on staged files

if [ -n "$staged_files" ]; then
  echo "Running custom_lint on staged files..."
  echo "Staged Files: $staged_files"
  dart pub global run custom_lint $staged_files

# Run flutter analyze on all Dart files
echo "Running flutter analyze on all Dart files..."
flutter analyze $staged_files

# Check the exit code of flutter analyze
if [ $? -ne 0 ]; then
  echo "Linting issues found. Aborting commit."
  exit 1
fi
fi

'flutter_analyze' runs on my changed files only with above code but not custom_lint.

Please can anyone help with this. Thanks. :)

rrousselGit commented 11 months ago

You're likely looking for https://github.com/invertase/dart_custom_lint/issues/80

komalkhatri08 commented 11 months ago

hi @rrousselGit , I read across the #80 , Yes i am looking for same solution. But a bit confused on what steps should I take? Do I have to make changes in the custom_lint code or is there some new package to be included to support same .

Thanks :)

rrousselGit commented 11 months ago

Well it's not supported at the moment. So you can just wait. Or make a PR if you feel like it

komalkhatri08 commented 11 months ago

ok Thanks @rrousselGit . Will be waiting for same.