Linter Overview
此内容尚不支持你的语言。
Linting is the process of statically analyzing code for potential bugs in addition to programmatic and stylistic errors.
Bloc has a built-in linter, which can be used through your IDE or the
bloc command-line tools
with the
bloc lint
command.
With the help of the bloc linter, you can improve the quality of your codebase and enforce consistency without executing a single line of code.
For example, perhaps you accidentally imported a Flutter dependency into your cubit:
import 'package:bloc/bloc.dart';import 'packages:flutter/material.dart';
class CounterCubit extends Cubit<int> { CounterCubit() : super(0);}
If properly configured, the bloc linter will point to the import and produce the following warning:
warning[avoid_flutter_imports]: Avoid importing Flutter within bloc instances. --> counter_cubit.dart:2 | | import 'package:flutter/material.dart'; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = hint: Blocs should be decoupled from Flutter. docs: https://bloclibrary.dev/lint-rules/avoid_flutter_imports
1 issue foundAnalyzed 1 file
In the following sections, we’ll cover how to install, configure, and customize the bloc linter so that you can take advantage of static analysis in your codebase.
Quick Start
Section titled “Quick Start”Get started using the bloc linter in just a few quick and easy steps.
-
Install the bloc command-line tools
Terminal window dart pub global activate bloc_tools -
Install the bloc_lint package
Terminal window dart pub add --dev bloc_lint:^0.2.0-dev.0 -
Add an
analysis_options.yaml
to the root of your project with the recommended rulesanalysis_options.yaml include: package:bloc_lint/recommended.yaml -
Run the linter
Terminal window bloc lint .
That’s all there is to it 🎉
Continue reading for a more in-depth look at configuring and customizing the bloc linter.