Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
komalkhatri08 opened this issue Oct 3, 2023 · 4 comments
Open

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

komalkhatri08 opened this issue Oct 3, 2023 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@komalkhatri08
Copy link

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. :)

@komalkhatri08 komalkhatri08 added the enhancement New feature or request label Oct 3, 2023
@rrousselGit
Copy link
Collaborator

You're likely looking for #80

@komalkhatri08
Copy link
Author

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
Copy link
Collaborator

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

@komalkhatri08
Copy link
Author

ok Thanks @rrousselGit . Will be waiting for same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants