lint_staged
0.5.1, released 3 years ago by an unverified publisher
Run linters and custom commands on git staged files for Flutter and Dart projects
What it does
Runs arbitrary shell commands and linters on a subset of git staged files matched by glob patterns before a commit. It supports backing up uncommitted changes via git stash and can be used as a pre-commit git hook or via Dart code.
AI-written summary of version 0.5.1, based on the package's README and metadata. Report an inaccuracy
Use it when
- You want to automatically run code formatters or linters like dart format on staged files before committing
- You want to prevent errors and ensure code style consistency in git commits
Skip it when
- You want to lint the entire project repository instead of only staged files
- You are not using git for version control
Strengths
- Speeds up linting by only checking files that are about to be committed
- Supports custom glob pattern matching for file filtering
- Provides built-in backup stashing and error recovery
Weaknesses
- Requires manual configuration of git hooks (such as using Husky)
- Behavior depends on external git commands and local executable environments
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 7
Add as a dev dependency via pub add, configure rules in pubspec.yaml, and set up git hooks using a tool like husky.
import 'package:lint_staged/lint_staged.dart';
try {
final success = await lintStaged();
print(success ? 'Linting was successful!' : 'Linting failed!');
} catch (e) {
print(e);
}Alternatives
Packages that do the same job and could replace lint_staged.
- bdd_framework
Create BDD tests in Dart code with readable error messages and Gherkin feature file export.
77Compare - codemod
Write and run automated code modifications and refactors on a codebase.
74Compare - freezed_lint
Linter plugin that enforces correct usage of freezed classes.
71Compare - shutter
Renders Flutter widget previews to PNG and diffs two runs pixel by pixel.
70Compare
Works with
Packages commonly used together with lint_staged: ones it builds on, ones built on it, and its own family.
- yamllint_staged depends on itA Dart library for parsing YAML documents into Dart data structures.
- globlint_staged depends on itA file and directory globbing library that supports Bash-style path matching and listing.
- argslint_staged depends on itLibrary for parsing raw command-line arguments into options and values using GNU and POSIX styles.
- ansilint_staged depends on itTerminal string styling with builtin style functions and string extensions.
- ansi_escapeslint_staged depends on itANSI escape codes for terminal manipulation