Skip to content

Unify lints in flutter/flutter and flutter/packages #178827

@Piinks

Description

@Piinks

Last year we made some big improvements to how we work in order to accelerate development and improve quality of life. We merged flutter/flutter and flutter/engine and adopted the Dart formatter, bringing many of us into the same repository and removing the need to tediously hand format Dart code.

Since then, we have had one outstanding TODO to circle back on, adopting a consistent set of lints in flutter/flutter and flutter/packages. Having to switch between different styles of code increases cognitive load for everyone, and just like with the formatter, having one unified style has been a goal for us to get to this year.

The Dart team developed new lints this year in order to fit the needs we identified last year in the course of merging flutter/flutter and flutter/engine.
Test run from earlier this year: #170435

We are planning on making the following lint changes to apply to flutter/flutter and flutter/packages:

The flutter_tools package trialed some of these lints earlier this year.

Further, our API samples will be updated to adopt the official flutter_lints package so that our samples align with the style we have recommended to our users.

We are planning to close the tree to roll out this change in flutter/flutter and flutter/packages next week on Tuesday, November 25th.


How do I update my PR after the change?

After the change lands, outstanding PRs can re-sync by applying the lint changes locally, and updating the code diff before rebasing with the tip of tree.

Specific analysis_options.yaml changes

To update your PR, apply these changes to the appropriate files in relation to your change:

analysis_options.yaml

# Changes:

    # - always_specify_types
    - omit_obvious_local_variable_types
    - specify_nonobvious_local_variable_types
    - specify_nonobvious_property_types
    - type_annotate_public_apis

engine/src/flutter/analysis_options.yaml

# Changes

# Remove
    always_specify_types: false # see https://github.com/flutter/flutter/blob/main/engine/src/flutter/CONTRIBUTING.md#dart
    type_annotate_public_apis: true # to compensate for disabling always_specify_types, see https://github.com/flutter/flutter/blob/main/engine/src/flutter/CONTRIBUTING.md#dart

engine/src/flutter/lib/ui/analysis_options.yaml

# Changes

# Remove
    always_specify_types: true # dart:ui is shipped as part of flutter/flutter, let's keep them consistent for now

examples/api/analysis_options.yaml

# Changes

# Remove
include: ../../analysis_options.yaml

# Add
# The following line activates a set of recommended lints for Flutter apps,
# packages, and plugins designed to encourage good coding practices.
include: package:flutter_lints/flutter.yaml

examples/api/pubspec.yaml

# Changes 

# Add under dev_dependencies
flutter_lints: ^6.0.0

packages/flutter_tools/analysis_options.yaml

# Changes

# Remove
    always_specify_types: false # This isn't necessary for tool code which doesn't have the same explicit readability requirements as the framework.
    omit_obvious_local_variable_types: true # Reduce overall verbosity of tool code.
    omit_obvious_property_types: true # Reduce overall verbosity of tool code.
    specify_nonobvious_local_variable_types: true # Reduce overall verbosity of tool code.
    specify_nonobvious_property_types: true # Reduce overall verbosity of tool code.

After applying the changes, run:
dart fix --apply
dart format


Thanks everyone, we’re excited to finish this project to make it easier and more approachable to contribute to the Flutter project.

Metadata

Metadata

Labels

P1High-priority issues at the top of the work listframeworkflutter/packages/flutter repository. See also f: labels.r: fixedIssue is closed as already fixed in a newer versionteam-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions