leancode_lint 24.0.0 👁 Copy "leancode_lint: ^24.0.0" to clipboard
leancode_lint: ^24.0.0 copied to clipboard
Metadata
Robust and high-quality lint rules used at LeanCode.
leancode_lint #
An opinionated set of high-quality, robust, and up-to-date lint rules used at LeanCode.
Usage #
There are two supported ways to use this package:
- As-is (default configuration) – enable the built-in
leancode_lintanalyzer plugin. This usesconst LeanCodeLintConfig()defaults. - With custom configuration – create your own analyzer plugin package that
instantiates
LeanCodeLintPluginwith yourLeanCodeLintConfig, then enable your plugin instead (see “Configuration (custom plugin package)” below).
If you only want to toggle individual rules on/off, you can do that in
analysis_options.yaml (see “Custom lint rules”).
Installation #
-
Add
leancode_lintas a dev dependency in your project'spubspec.yaml.dart pub add leancode_lint --dev -
In your
analysis_options.yamladdinclude: package:leancode_lint/analysis_options.yaml. You might want to exclude some files (e.g generated json serializable) from analysis. -
Enable the analyzer plugin in
analysis_options.yaml.- For default behavior, enable
leancode_lint. - For custom configuration, enable your own plugin package instead (see “Configuration (custom plugin package)” below).
- For default behavior, enable
-
Run
flutter pub getin your project main directory and restart the analysis server in your IDE. You're ready to go!
Example analysis_options.yaml:
include: package:leancode_lint/analysis_options.yaml
plugins:
leancode_lint: ^20.0.0
analyzer:
exclude:
- '**/*.g.dart'
Tip
See the example/ directory for complete, runnable examples with both default and custom configuration.
Configuration (custom plugin package) #
This section is optional. You only need it if you want to customize the behavior of configurable rules beyond the built-in defaults.
To configure leancode_lint rules programmatically, create your own analyzer
plugin package (e.g. my_lints) that depends on leancode_lint and exposes a
top-level plugin variable.
my_lints/lib/main.dart:
import 'package:leancode_lint/plugin.dart';
final plugin = LeanCodeLintPlugin(
name: 'my_lints',
config: LeanCodeLintConfig(
applicationPrefix: 'Lncd',
catchParameterNames: CatchParameterNamesConfig(
exception: 'error',
stackTrace: 'stackTrace',
),
designSystemItemReplacements: {
'AppText': [
DesignSystemForbiddenItem(name: 'Text', packageName: 'flutter'),
DesignSystemForbiddenItem(name: 'RichText', packageName: 'flutter'),
],
'AppScaffold': [
DesignSystemForbiddenItem(name: 'Scaffold', packageName: 'flutter'),
],
},
),
);
Then enable your plugin in the consuming project’s analysis_options.yaml:
include: package:leancode_lint/analysis_options.yaml
plugins:
my_lints:
path: ./path/to/my_lints
Usage in libraries #
If your package is a library rather than a binary application, you will expose some public API for users of your library. Therefore, you should use lint rules optimized for this case by just changing your include entry in analysis_options.yaml:
include: package:leancode_lint/analysis_options_package.yaml
Custom lint rules #
Disabling custom lint rules #
To disable a particular custom lint rule, set the rule to false in analysis_options.yaml. For example, to disable prefix_widgets_returning_slivers:
plugins:
leancode_lint:
version: ^20.0.0
diagnostics:
prefix_widgets_returning_slivers: false
Assists #
Assists are IDE refactorings not related to a particular issue. They can be triggered by placing your cursor over a relevant piece of code and opening the code actions dialog. For instance, in VSCode this is done with + or +.
See linked source code containing explanation in dart doc.
- Convert positional to named formal
- Convert record into nominal type
- Convert iterable map to collection-for
🛠️ Maintained by LeanCode #
This package is built with 💙 by LeanCode. We are top-tier experts focused on Flutter Enterprise solutions.
Why LeanCode? #
-
Creators of Patrol – the next-gen testing framework for Flutter.
-
Production-Ready – We use this package in apps with millions of users.
-
Full-Cycle Product Development – We take your product from scratch to long-term maintenance.
← Metadata
Documentation
Publisher
👁 Published by a pub.dev verified publisher
leancode.co
Weekly Downloads
Metadata
Robust and high-quality lint rules used at LeanCode.
Homepage
Repository (GitHub)
View/report issues
Topics
#analysis #analyzer #code-style #lint #lints
License
Dependencies
analysis_server_plugin, analyzer, analyzer_plugin, meta, path, source_span, yaml
