altive_lints 1.19.1 copy "altive_lints: ^1.19.1" to clipboard
altive_lints: ^1.19.1 copied to clipboard

Provides `all_lint_rules.yaml` that activates all rules and `altive_lints.yaml` with Altive recommended rule selection.

Altive Lints #

Provides all_lint_rules.yaml that activates all rules and altive_lints.yaml with Altive recommended rule selection.

There are also Altive-made rules by custom_lint.

Table of content #

Getting started #

altive_lints #

  1. Add altive_lints to your pubspec.yaml:
dev_dependencies:
  altive_lints:
copied to clipboard
  1. Include altive_lints in analysis_options.yaml.
    If not, create a new one or copy analysis_options.yaml and use it.
include: package:altive_lints/altive_lints.yaml
copied to clipboard

Enable custom_lint #

altive_lints comes bundled with its own rules using custom_lints.

  • Add both altive_lints and custom_lint to your pubspec.yaml:

    dev_dependencies:
      altive_lints:
      custom_lint: # <- add this
    
    copied to clipboard
  • Enable custom_lint's plugin in your analysis_options.yaml:

    include: package:altive_lints/altive_lints.yaml
    analyzer:
      plugins:
        - custom_lint
    
    copied to clipboard

Disabling lint rules #

By default when installing altive_lints, most of the lints will be enabled. To change this, you have a few options.

include: package:altive_lints/altive_lints.yaml
analyzer:
  plugins:
    - custom_lint

linter:
  rules:
    # Explicitly disable one lint rule.
    - public_member_api_docs: false

custom_lint:
  rules:
    # Explicitly disable one custom-lint rule.
    - avoid_hardcoded_color: false
copied to clipboard

All custom-lint rules in altive_lints #

avoid_consecutive_sliver_to_box_adapter #

SliverToBoxAdapter must not be placed consecutively in slivers of CustomScrollView.

Bad:

CustomScrollView(
  slivers: [
    SliverToBoxAdapter(child: Text('Item 1')), // Consecutive usage
    SliverToBoxAdapter(child: Text('Item 2')), // LINT
  ],
);
copied to clipboard

Good:

CustomScrollView(
  slivers: [
    SliverList.list(
      children: [
        Text('Item 1')
        Text('Item 2')
      ],
    ),
  ],
);
copied to clipboard

avoid_hardcoded_color #

Do not use hard-coded Color. However, Colors.transparent can be used.

Bad:

ColoredBox(
  color: Color(0xFF00FF00), // LINT
);
copied to clipboard

Good:

ColoredBox(
  color: Theme.of(context).colorScheme.primary,
);
copied to clipboard

avoid_hardcoded_japanese #

Hard-coded Japanese text strings must not be used. Use AppLocalizations, etc. to support internationalization.

Not applicable on test files.

Bad:

final message = 'こんにちは'; // LINT
print('エラーが発生しました'); // LINT
copied to clipboard

Good:

final message = AppLocalizations.of(context).hello;
print(AppLocalizations.of(context).errorOccurred);
copied to clipboard

avoid_shrink_wrap_in_list_view #

The shrinkWrap property must not be used in a ListView.

Use CustomScrollView and SliverList instead.

However, it is OK to use shrinkWrap if it is used to reduce the size of a dialog, such as when there is extra height in the dialog, so use ignore explicitly in such cases.

Bad:

ListView(
  shrinkWrap: true, // LINT
  children: [
    Text('Hello'),
    Text('World'),
  ],
);
copied to clipboard

Good:

CustomScrollView(
  slivers: [
    SliverList.list(
      children: [
        Text('Hello'),
        Text('World'),
      ],
    ),
  ],
);
copied to clipboard

avoid_single_child #

The children property is intended to have multiple elements and should not be used with only one child element.

Bad:

Column(
  children: [YourWidget()], // LINT
);
copied to clipboard

Good:

Center(child: YourWidget());
// or
Column(
  children: [YourWidget1(), YourWidget2()],
);
copied to clipboard

prefer_clock_now #

Prefer using clock.now() instead of DateTime.now().

By using the clock package and clock.now(), you can use the withClock method to replace the date and time at test time.

Bad:

var now = DateTime.now(); // LINT
copied to clipboard

Good:

var now = clock.now(); // Using 'clock' package
copied to clipboard

prefer_dedicated_media_query_methods #

Prefer to use dedicated MediaQuery methods instead of MediaQuery.of or MediaQuery.maybeOf.

This is to reduce unnecessary widget rebuilding and improve performance by using dedicated methods such as MediaQuery.sizeOf and MediaQuery.viewInsetsOf.

Bad:

var size = MediaQuery.of(context).size; // LINT
var padding = MediaQuery.maybeOf(context)?.padding; // LINT
copied to clipboard

Good:

var size = MediaQuery.sizeOf(context);
var padding = MediaQuery.viewInsetsOf(context);
copied to clipboard

prefer_to_include_sliver_in_name #

Prefer to include ‘Sliver’ in the class name or named constructor of a widget that returns a Sliver-type widget.

This makes it easy for the user to know at a glance that it is a Sliver type Widget, and improves readability and consistency.

Bad:

class MyCustomList extends StatelessWidget { // LINT
  @override
  Widget build(BuildContext context) {
    return SliverList(...);
  }
}

copied to clipboard

Good:

class SliverMyCustomList extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return SliverList(...);
  }
}
copied to clipboard

prefer_space_between_elements #

Prefer to insert blank lines for spacing rules in class definitions. between constructors and fields, and between constructors and build methods.

The purpose of proper spacing is to improve code readability and organization and to make it easier to visually distinguish between different sections of a class.

Bad:

class MyWidget extends StatelessWidget {
  MyWidget(this.title);
  final String title; // LINT
  @override // LINT
  Widget build(BuildContext context) {
    return Text(title);
  }
}
copied to clipboard

Good:

class MyWidget extends StatelessWidget {
  MyWidget(this.title);

  final String title;

  @override
  Widget build(BuildContext context) {
    return Text(title);
  }
}
copied to clipboard

All assists in altive_lints #

Add macro template documentation comment #

Adds a Macros template to class declarations.
When you place the cursor on the class declaration and execute "Add macro template documentation comment", the documentation is created.

Before:

class MyClass {
  // Class implementation
}
copied to clipboard

After applying the assist:

/// {@template my_package.MyClass}
///
/// {@endtemplate}
class MyClass {
  // Class implementation
}
copied to clipboard

Add macro documentation comment #

Adds Macros comments to constructors and method declarations.
When you place the cursor on a constructor or method declaration and execute "Add macro documentation comment", the documentation is created.

Before:

void myFunction() {
  // Function implementation
}
copied to clipboard

After applying the assist:

/// {@macro my_package.myFunction}
void myFunction() {
  // Function implementation
}
copied to clipboard

Wrap with macro template documentation comment #

Wraps existing documentation comments with a Macros template.
When you select the documentation comment and execute "Wrap with macro template documentation comment", the documentation is created.

Before:

/// Some comment
/// More comments
class MyClass {
  // Class implementation
}
copied to clipboard

After applying the assist:

/// {@template my_package.MyClass}
/// Some comment
/// More comments
/// {@endtemplate}
class MyClass {
  // Class implementation
}
copied to clipboard

Lint rules adopted by altive_lints and why #

Reasons for adopting each lint rule.

All lint rules disabled by altive_lints and their reasons can be found in altive_lints.yaml.

public_member_api_docs #

Even the best naming is difficult to grasp the big picture unless it is very simple.

An overview of it and documentation of why it exists and how to use it will help your teammates and future self.

Note

If there are too many applicable sections, such as when introducing the rule to an existing project, it is recommended to disable the rule once and then gradually address the issue.

Bad:

class DashboardCard extends StatelessWidget {
  DashboardCard({required this.title, required this.content});

  final String title;
  final Widget content;
  ...
}
copied to clipboard

Good:

/// Cards to display an overview of each function on the dashboard.
///
/// [title] and [content] are required and cannot be omitted.
class DashboardCard extends StatelessWidget {

  /// Creates a card-like widget to be placed on the dashboard.
  DashboardCard({required this.title, required this.content});

  /// A title string indicating the content to be displayed on the card.
  final String title;

  /// A widget to be displayed below the title.
  ///
  /// We assume text, images, graphs, etc., but basically anything can be included.
  /// Consider using [Column] if you want to arrange multiple pieces of content vertically.
  final Widget content;
  ...
}

copied to clipboard

Migration guide #

v1.12.0 #

The public_member_api_docs prompt to add documents has been activated. Please add documentation comments to public members.

If there are too many issues, disable them in analysis_options.yaml.

14
likes
160
points
7.36k
downloads

Publisher

verified publisheraltive.co.jp

Weekly Downloads

2024.09.16 - 2025.03.31

Provides `all_lint_rules.yaml` that activates all rules and `altive_lints.yaml` with Altive recommended rule selection.

Homepage
Repository (GitHub)
View/report issues

Topics

#lints #analysis #code-style

Documentation

API reference

License

MIT (license)

Dependencies

analyzer, collection, custom_lint_builder

More

Packages that depend on altive_lints