搜索插件、代码仓与 APP 分类

插件详情v2.14.0

lint

一个有明确立场的、由社区驱动的 Dart 和 Flutter 项目 lint 规则集合。类似于 pedantic,但更严格

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
25.5万
喜欢数
863
Pub 分数
160

安装插件

flutter pub add lint

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一套严格的、由社区驱动的 Dart 和 Flutter 项目代码检查规则,旨在强制执行一致的代码质量和最佳实践。在 `pedantic` 的基础上,它应用了更严格的标准,帮助开发者编写更清晰、更易维护的代码。该包非常适合希望在多个平台上采用标准化、有明确意见的代码分析方法的团队。

适合场景

  • 在团队项目中强制执行一致的代码风格
  • 通过严格的 linting 提高代码质量
  • 使用静态分析自动化代码审查
  • 在Flutter应用中保持统一的编码标准
  • 将 linting 集成到 CI/CD 流水线中

主要特点

  • 严格且具有明确立场的 lint 规则
  • 社区维护且保持最新
  • 通过更严格的标准扩展 pedantic
  • 支持所有主要的Flutter平台
  • 通过 pub add 命令轻松集成

适合对象

  • 注重代码一致性的团队
  • 需要高代码质量的项目
  • 跨多个平台使用的 Flutter 开发人员
  • 需要自动化 lint 检查的 CI/CD 环境
  • 采用现代 Dart 实践的项目

使用建议

  • 可能需要大量代码调整
  • 不适合非常宽松的编码风格
  • 可能增加初始设置的复杂性
  • 需要持续维护 lint 配置
  • 可能与其他 linter 包冲突

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Pub style: lint

Lint for Dart/Flutter

Lint logo

lint is a hand-picked, open-source, community-driven collection of lint rules for Dart and Flutter projects. The set of rules follows the Effective Dart: Style Guide.

This package can be used as a replacement for package:lints or the discontinued package:pedantic for those who prefer stricter rules.

lint supports 3 different set of rules:

  • strict: tries to be strict but not annoying. Perfect for production app code
  • casual: great when prototyping, to be used in code samples, any non-production code
  • package: like strict but for dart packages, that have a public API

Install

Add lint as dependency to your pubspec.yaml. Version ^1.0.0 means you're automatically getting the latest version for lint when running pub upgrade

dev_dependencies:
  lint: ^2.0.0

Create an analysis_options.yaml file in the root of your project with the following content:

# This file configures the analyzer to use the lint rule set from `package:lint`

include: package:lint/strict.yaml # For production apps
# include: package:lint/casual.yaml # For code samples, hackathons and other non-production code
# include: package:lint/package.yaml # Use this for packages with public API


# You might want to exclude auto-generated files from dart analysis.
# Uncomment the section below and the files you want to exclude.
# analyzer:
#   exclude:
#     - '**.freezed.dart'
#     - '**.g.dart'

# You can customize the lint rules set to your own liking. A list of all rules
# can be found at https://dart.dev/tools/linter-rules
# Uncomment the section below and the rules you want to customize.
# linter:
#   rules:
    # Util classes are awesome!
    # avoid_classes_with_only_static_members: false
    
    # Make constructors the first thing in every class
    # sort_constructors_first: true

    # Choose wisely, but you don't have to
    # prefer_double_quotes: true
    # prefer_single_quotes: true

Lint badge

You're using lint in your open-source project? Add the badge to your README.md show that you honor strict lint rules

style: lint

[![style: lint](https://img.shields.io/badge/style-lint-4BC0F5.svg)](https://pub.dev/packages/lint)

Comparison with other lint packages

A detailed comparison of all linting packages for dart can be found at rydmike.com/blog_flutter_linting.html

lint is among the strictest but not the strictest. It tires to find the right balance between useful and annoying.

Which version to use?

Generally, you can just put lint: ^2.0.0 in your pubspec.yaml and pub get the latest version compatible with your Dart version.

Dart Version Lint Version
3.13 2.14.0
3.12 2.13.0
3.11 2.12.0
3.10 2.11.0
3.9 2.10.0
3.8 2.9.0
3.7 2.8.0
3.6 2.7.0
3.5 2.6.1
3.4 2.5.0
3.3 2.4.0
3.2 2.3.0
3.1 2.2.0
3.0 2.1.0
2.18 2.0.0
2.17 1.10.0
2.16 1.9.0
2.15 1.8.0
2.14 1.7.0
2.13 1.6.0
2.12 1.5.0

Comparison to discontinued package:pedantic

Google publicly shares their internal rules as package:pedantic in open-source. It represents what Google is enforcing internally throughout all Dart code. For a lint rule to be added to pedantic, Google has to change all code which doesn't follow the style.

This strict practice results in only 27/150+ rules to be enabled. While some are contradictory to each other and can not enabled together, a big chunk of rules isn't enabled because it requires too much work to update all of Googles existing code.

For developers outside Google, it is the norm to have separate lint rules per project. One project might enable more rules then others.

lint enables a majority of lint rules, leaving out contradictory and very opinionated rules.

License

Copyright 2022 Pascal Welsch

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

所属分类

源码仓库

使用此插件的项目

所在榜单