Jaspr has its own linting and analyzer package called jaspr_lints. This comes pre-configured
with every new project and enables a set of lint rules and code assists.
Add jaspr_lints as a plugin to your analysis_options.yaml file:
plugins:
jaspr_lints:
version: ^0.6.0
diagnostics:
sort_children_last: true
prefer_html_components: true
styles_ordering: trueAfter running dart pub get you now get additional lints and code assists in your IDE or when running dart analyze.
Prefer using HTML components like div(...) over Component.element(tag: 'div', ...).
BAD:
return .element(
tag: 'div',
children: [
.element(
tag: 'p',
children: [.text('Hello World')],
),
],
);GOOD:
return div([
p([.text('Hello World')]),
]);Sort children properties last in HTML component methods.
This improves readability and best represents actual HTML.
BAD:
return div([
p([.text('Hello World')], classes: 'text-red'),
], id: 'main');GOOD:
return div(id: 'main', [
p(classes: 'text-red', [.text('Hello World')]),
]);Sort styles properties.
This improves readability and consistency across style rules.
BAD:
@css
static List<StyleRule> get styles => [
css('button').styles(
color: Colors.black,
padding: Padding.all(8.px),
),
css('input').styles(
padding: Padding.all(16.px),
color: Colors.black,
),
];GOOD:
@css
static List<StyleRule> get styles => [
css('button').styles(
padding: Padding.all(8.px),
color: Colors.black,
),
css('input').styles(
padding: Padding.all(16.px),
color: Colors.black,
),
];Prefer using a getter over a (final) variable declaration for style rules to support hot-reload.
BAD:
@css
static final List<StyleRule> styles = [
css('button').styles(
padding: Padding.all(8.px),
color: Colors.black,
),
];GOOD:
@css
static List<StyleRule> get styles => [
css('button').styles(
padding: Padding.all(8.px),
color: Colors.black,
),
];Warns about unsafe platform-specific imports in your code depending on whether it is executed on the server or the client.
Creates a new StatelessComponent class.
Creates a new StatefulComponent and respective State class.
Creates a new InheritedComponent class.
Converts a custom StatelessComponent into a StatefulComponent and respective State class.
Converts a custom StatelessComponent into an AsyncStatelessComponent.
Surgically removes the selected component from the component tree, making its children the new direct children of its parent.
Wraps the selected component with a new html component.
return div([
p([
span([text('Hello World')]),
]),
]);Wraps the selected component with a new component.
return div([
MyComponent(
child: span([text('Hello World')]),
),
]);Wraps the selected component with a Builder.
return div([
Builder(builder: (context) {
return span([text('Hello World')]);
}),
]);Extracts the selected component plus subtree into a new StatelessComponent.
Adds new css styles to the selected component.
This will either add a new class name:
return div(
classes: '[...]'
[],
);
/* ... */
@css
static List<StyleRule> styles = [
css('.[...]').box(...),
]; Or use an existing id or class name:
return div(id: 'content', []);
/* ... */
@css
static List<StyleRule> styles = [
css('#content').box(...),
]; Converts any import to a web-only import using the @Import annotation.
import 'dart:html';
@Import.onWeb('dart:html', show: [#window])
import 'filename.imports.dart'; This will auto-detect all used members from the import and add them to the show parameter.
Converts any import to a server-only import using the @Import annotation.
import 'dart:io';
@Import.onServer('dart:io', show: [#HttpRequest])
import 'filename.imports.dart'; This will auto-detect all used members from the import and add them to the show parameter.

