jaspr_lints package provides custom analyzer plugins with lints and code assists specifically designed for Jaspr projects.
Installation
Addjaspr_lints to your dev_dependencies in pubspec.yaml:
Setup
Configure the plugin in youranalysis_options.yaml:
After adding or updating the configuration, restart your IDE or run
dart pub get for the changes to take effect.Lints
All lints come with automatic fixes that can be applied via your IDE’s quick fix menu (usuallyCmd/Ctrl + . or lightbulb icon).
prefer_html_components
Prefers HTML component functions likediv(), p(), button() over the generic Component.element() constructor.
Bad:
sort_children_last
Enforces that thechildren parameter (the unnamed list parameter) comes last in HTML component calls.
Bad:
styles_ordering
Enforces alphabetical ordering of style properties inStyles() constructors and styles() function calls.
Bad:
prefer_styles_getter
Prefers using a getter over a variable declaration for@css style rules to support hot-reload.
Bad:
Code Assists
Code assists appear in your IDE’s quick fix menu when you place your cursor on relevant code.Component Creation
Create new components from scratch:- Create StatelessComponent - Generate a new stateless component class
- Create StatefulComponent - Generate a new stateful component class with state
- Create InheritedComponent - Generate a new inherited component for state sharing
Component Conversion
Convert between component types:- Convert StatelessComponent to StatefulComponent - Adds state management
- Convert StatelessComponent to AsyncStatelessComponent - Enables async build method
Component Tree Operations
Remove component from tree Removes a component and optionally replaces it with its children. Usage: Place cursor on a component constructor.Wrap component Wrap a component with another component:
- Wrap with
div(),section(),ul(), or any HTML component - Wrap with a custom component
- Wrap with
Builderfor context access
Extract subtree into StatelessComponent Extract a component subtree into a new reusable
StatelessComponent.
Usage: Select a component expression or place cursor on it.
Example:
Styling
Add styles to HTML component Quickly add astyles parameter to an HTML component.
Usage: Place cursor on an HTML component like div() or p().
Example:
Import Conversion
Convert import to web-only / server-only import Convert regular imports to conditional imports for web or server contexts. Usage: Place cursor on an import statement. Web-only import:Enabling/Disabling Lints
You can selectively enable or disable individual lints:Suppressing Warnings
To suppress a lint warning for a specific line:IDE Integration
VS Code
- Install the Dart extension
- The lints will appear automatically after
dart pub get - Use
Cmd/Ctrl + .to see quick fixes
IntelliJ IDEA / Android Studio
- Install the Dart plugin
- The lints will appear automatically after
dart pub get - Use
Alt + Enterto see quick fixes
Other Editors
As long as your editor has Dart analyzer support, the lints should work automatically.Running Analysis from CLI
Run analysis on your entire project:Complete Configuration Example
Troubleshooting
Lints Not Appearing
- Make sure you’ve run
dart pub get - Restart your IDE
- Check that the version in
analysis_options.yamlmatches yourpubspec.yaml - Verify the plugin is enabled in
analysis_options.yaml
Code Assists Not Working
- Ensure your cursor is on the correct element
- Try invoking the quick fix menu manually (usually
Cmd/Ctrl + .) - Check that your IDE’s Dart plugin is up to date
Performance Issues
If analysis is slow:- Exclude large directories in
analysis_options.yaml - Limit the scope of analysis to your project files
- Consider disabling resource-intensive lints
See Also
- Official jaspr_lints Documentation
- Dart Analyzer
- Jaspr Style Guide - Best practices for Jaspr development