Viewing version 0.0.4. Open the latest package page.
custom_lint
0.0.4A package to help writing custom linters
Readme
About
Lint rules are a powerful way to improve the maintainability of a project.
The more, the merrier!
But while Dart offers a wide variety of lint rules by default, it cannot
reasonably include every possible lint. For example, Dart does not
include lints related to third-party packages.
Custom_lint fixes that by allowing package authors to write custom lint rules.
Custom_lint is similar to analyzer_plugin, but goes deeper by trying to provide a better developer experience.
That includes:
- A command-line to obtain the list of lints in your CI without having to write a command line yourself.
- A simplified project setup.
No need to deal with theanalyzerserver or error handling. Custom_lint takes care of that for you, so that you can focus on writing lints. - Support for hot-restart.
Updating the source code of a linter plugin will dynamically restart it, without having to restart your IDE/analyzer server - Built-in support for
// ignore:and// ignore_for_file:. - Support for
print(...)and exceptions.
If your plugin somehow throws or print debug messages, custom_lint will generate a log file with the messages/errors.
Usage
Using custom_lint is split in two parts:
- how to define a custom_lint package
- how users can install our package in their application to see our newly defined lints
Creating a custom lint package
To create a custom lint, you will need two things:
-
updating your
pubspec.yamlto includecustom_lint_builderas a dependency:# pubspec.yaml name: my_custom_lint_package environment: sdk: ">=2.16.0 <3.0.0" dependencies: # we will use analyzer for inspecting Dart files analyzer: # custom_lint_builder will give us tools for writing lints custom_lint_builder: -
create a
bin/custom_lint.dartfile in your project with the following:// This is the entrypoint of our custom linter void main(List<String> args, SendPort sendPort) { startPlugin(sendPort, _ExampleLinter()); } // This class is the one that will analyze Dart files and return lints class _ExampleLinter extends PluginBase { @override Iterable<Lint> getLints(ResolvedUnitResult resolvedUnitResult) sync* { // A basic lint that shows at the top of the file. yield Lint( code: 'my_custom_lint_code', message: 'This is the description of our custom lint', // where your lint will appear within the Dart file. location: LintLocation.fromOffsets( offset: 0, length: 10, ), ); } }
That's it for defining a custom lint package!
Let's use it in an application now.
Using our custom lint package in an application
For users to run custom_lint packages, there are a few steps:
-
The application must contain an
analysis_options.yamlwith the following:analyzer: plugins: - custom_lint -
The application also needs to add
custom_lintand our package(s) as dev dependency in their application:# The pubspec.yaml of an application using our lints name: example_app environment: sdk: ">=2.16.0 <3.0.0" dev_dependencies: custom_lint: my_custom_lint_package:
That's all!
After running pub get (and possibly restarting their IDE), users should now
see our custom lints in their Dart files:
screenshot of our custom lints in the IDE
Obtaining the list of lints in the CI
Unfortunately, running dart analyze does not pick up our newly defined lints.
We need a separate command for this.
To do that, users of our custom lint package can run inside the application the following:
$ dart run custom_lint
lib/main.dart:0:0 • This is the description of our custom lint • my_custom_lint_code
Changelog
0.0.4
- Fixed a bug where the command line could show IDE-only meant for debugging
0.0.3
PluginBase.getLints now receive a ResolvedUnitResult instead of a LibraryElement.
0.0.2
-
Compilation errors are now visible within the
pubspec.yamlof applications that are using the plugin. -
Plugins that are currently loading are now highlighted inside the
pubspec.yamlof applications that are using the plugin. -
If a plugin throws when trying to analyze a Dart file, the IDE will now show the exception at the top of the analyzed file.
-
Compilation errors, exceptions and prints are now accessible within a log file (
custom_lint.log) inside applications using the plugin.
0.0.1
Initial release
Installing
export PUB_HOSTED_URL=https://pub.mirror.p-hatan.ir
flutter pub add 'custom_lint:0.0.4'pubspec.yaml
name: custom_lint
version: 0.0.4
description: A package to help writing custom linters
repository: https://github.com/invertase/dart_custom_lint
environment:
sdk: ">=2.17.1 <3.0.0"
dependencies:
analyzer: ^4.0.0
analyzer_plugin: ^0.10.0
async: ^2.8.2
cli_util: ^0.3.5
collection: ^1.15.0
meta: ^1.7.0
package_config: ^2.0.2
path: ^1.8.0
pub_semver: ^2.1.1
pubspec_parse: ^1.2.0
recase: ^4.0.0
riverpod: ^2.0.0-dev.5
uuid: ^3.0.6
yaml: ^3.1.0
dev_dependencies:
test: ^1.20.2
executables:
custom_lint: custom_lint
Version history
| Version | Published | Archive | SHA-256 |
|---|---|---|---|
| 0.0.1 | Cached · Upstream SHA-256 matched | Download | 9cdc3741…ae137a |
| 0.0.2 | Cached · Upstream SHA-256 matched | Download | e952987a…0fa094 |
| 0.0.3 | Cached · Upstream SHA-256 matched | Download | 7b684ff0…1e0a4a |
| 0.0.4 | Cached · Upstream SHA-256 matched | Download | d9dec598…10f894 |
| 0.0.5 | Cached · Upstream SHA-256 matched | Download | 269f8d70…104c9c |
| 0.0.6 | Cached · Upstream SHA-256 matched | Download | 09c32f0b…3a6f41 |
| 0.0.7 | Cached · Upstream SHA-256 matched | Download | 2ad9dd35…ba648c |
| 0.0.8 | Cached · Upstream SHA-256 matched | Download | baa4661f…7ad350 |
| 0.0.9 | Cached · Upstream SHA-256 matched | Download | a14dff85…78a8aa |
| 0.0.9+1 | Cached · Upstream SHA-256 matched | Download | 4c4cc2ac…83f4f3 |
| 0.0.10 | Cached · Upstream SHA-256 matched | Download | d58a9c28…737894 |
| 0.0.10+1 | Cached · Upstream SHA-256 matched | Download | 2c49e6a1…595761 |
| 0.0.11 | Cached · Upstream SHA-256 matched | Download | 2f97dc48…cc024e |
| 0.0.12 | Cached · Upstream SHA-256 matched | Download | 4db71584…427436 |
| 0.0.13 | Cached · Upstream SHA-256 matched | Download | 0f19aaf6…868b7f |
| 0.0.14 | Cached · Upstream SHA-256 matched | Download | 6eab9aae…a6efd6 |
| 0.0.15 | Cached · Upstream SHA-256 matched | Download | 2264aea4…0bf52a |
| 0.0.16 | Cached · Upstream SHA-256 matched | Download | fa0b5088…3a21df |
| 0.1.0 | Cached · Upstream SHA-256 matched | Download | 244cb887…f2a18f |
| 0.1.1 | Cached · Upstream SHA-256 matched | Download | ee61018e…13898b |
| 0.1.2-dev | Cached · Upstream SHA-256 matched | Download | c0dcebfb…5c431a |
| 0.2.0 | Cached · Upstream SHA-256 matched | Download | c14f8759…521a38 |
| 0.2.2 | Cached · Upstream SHA-256 matched | Download | ced9a173…c73084 |
| 0.2.5 | Cached · Upstream SHA-256 matched | Download | 29b7e51b…eb42c0 |
| 0.2.11 | Cached · Upstream SHA-256 matched | Download | 8df4335b…ab572e |
| 0.2.12 | Cached · Upstream SHA-256 matched | Download | 324e7026…46120b |
| 0.3.0 | Cached · Upstream SHA-256 matched | Download | 32d120ce…f151ad |
| 0.3.2 | Cached · Upstream SHA-256 matched | Download | 32648ef4…7e821a |
| 0.3.3 | Cached · Upstream SHA-256 matched | Download | 80ccf10b…5c16a5 |
| 0.3.4 | Cached · Upstream SHA-256 matched | Download | e8717601…4638f6 |
| 0.4.0 | Cached · Upstream SHA-256 matched | Download | 3ce36c04…9bb942 |
| 0.5.0 | Cached · Upstream SHA-256 matched | Download | b09a939c…1cb3ff |
| 0.5.1 | Cached · Upstream SHA-256 matched | Download | 99e3cd20…e40640 |
| 0.5.2 | Cached · Upstream SHA-256 matched | Download | ae3cf0f8…2a9b80 |
| 0.5.3 | Cached · Upstream SHA-256 matched | Download | 837821e4…31ceba |
| 0.5.4 | Cached · Upstream SHA-256 matched | Download | 32ca9248…038a33 |
| 0.5.5 | Cached · Upstream SHA-256 matched | Download | 68671c7b…8913bd |
| 0.5.6 | Cached · Upstream SHA-256 matched | Download | f9a828b6…506778 |
| 0.5.7 | Cached · Upstream SHA-256 matched | Download | 198ec6b8…a96d90 |
| 0.5.8 | Cached · Upstream SHA-256 matched | Download | dfb893ff…a6dedb |
| 0.5.11 | Cached · Upstream SHA-256 matched | Download | 22bd87a3…46cb5d |
| 0.6.0 | Cached · Upstream SHA-256 matched | Download | f89ff83e…481217 |
| 0.6.2 | Cached · Upstream SHA-256 matched | Download | 44524237…c8f981 |
| 0.6.3 | Cached · Upstream SHA-256 matched | Download | 7dbb45d9…266e1a |
| 0.6.4 | Cached · Upstream SHA-256 matched | Download | 7c0aec12…dda799 |
| 0.6.5 | Cached · Upstream SHA-256 matched | Download | 4939d89e…aec663 |
| 0.6.6 | Cached · Upstream SHA-256 matched | Download | cbea60b2…36673e |
| 0.6.7 | Cached · Upstream SHA-256 matched | Download | 6e1ec474…5baca0 |
| 0.6.8 | Cached · Upstream SHA-256 matched | Download | 832fcdc6…3026e6 |
| 0.6.9 | Cached · Upstream SHA-256 matched | Download | 18f7982b…8c7bea |
| 0.6.10 | Cached · Upstream SHA-256 matched | Download | 4500e888…8d5545 |
| 0.7.0 | Cached · Upstream SHA-256 matched | Download | 3486c470…15bba9 |
| 0.7.1 | Cached · Upstream SHA-256 matched | Download | 6d509673…5d2a62 |
| 0.7.2 | Cached · Upstream SHA-256 matched | Download | 7e6a73e1…e019f6 |
| 0.7.3 | Cached · Upstream SHA-256 matched | Download | 021897cc…42ed9e |
| 0.7.4 | Cached · Upstream SHA-256 matched | Download | 3a9fcbcb…63ebe0 |
| 0.7.5 | Cached · Upstream SHA-256 matched | Download | 409c485f…bda7f1 |
| 0.7.6 | Cached · Upstream SHA-256 matched | Download | 96569256…2d9a84 |
| 0.7.7 | Cached · Upstream SHA-256 matched | Download | 9f0f0c83…490f71 |
| 0.8.0 | Cached · Upstream SHA-256 matched | Download | 78085fbe…15e796 |
| 0.8.1 | Cached · Upstream SHA-256 matched | Download | 751ee944…fcece5 |
Dependencies
analyzer "^4.0.0"
analyzer_plugin "^0.10.0"
async "^2.8.2"
cli_util "^0.3.5"
collection "^1.15.0"
meta "^1.7.0"
package_config "^2.0.2"
path "^1.8.0"
pub_semver "^2.1.1"
pubspec_parse "^1.2.0"
recase "^4.0.0"
riverpod "^2.0.0-dev.5"
uuid "^3.0.6"
yaml "^3.1.0"