Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 41 additions & 11 deletions packages/altive_lints/example/lints/avoid_single_child.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ class MyWidget extends StatelessWidget {
],
),
// expect_lint: avoid_single_child
SliverMainAxisGroup(
slivers: [
SliverToBoxAdapter(child: Text('Hello')),
],
),
// expect_lint: avoid_single_child
SliverCrossAxisGroup(
slivers: [
SliverToBoxAdapter(child: Text('Hello')),
],
),
// expect_lint: avoid_single_child
Column(
children: [
if (random.nextBool()) const Text('Hello World'),
Expand All @@ -73,16 +85,16 @@ class MyWidget extends StatelessWidget {
// expect_lint: avoid_single_child
Column(
children: [
if(isValued)...[
if (isValued) ...[
Container(),
]else...[
] else ...[
Container(),
],
],
),
Column(
children: [
if(isValued)...[
if (isValued) ...[
Container(),
],
Container(),
Expand All @@ -91,31 +103,29 @@ class MyWidget extends StatelessWidget {
// expect_lint: avoid_single_child
Column(
children: [
if(isValued)...[
if (isValued) ...[
Container(),
],
],
),
Column(
children: [
if(isValued)...[
if (isValued) ...[
Container(),
Container(),
],
],
),
// expect_lint: avoid_single_child
Column(
children: [
if(isValued)...[]
else...[]
],
children: [if (isValued) ...[] else ...[]],
),
// expect_lint: avoid_single_child
Column(
children: [
if(isValued)...[]
else...[
if (isValued)
...[]
else ...[
Container(),
]
],
Expand Down Expand Up @@ -155,6 +165,26 @@ class MyWidget extends StatelessWidget {
for (final e in ['a', 'b', 'c']) Text('Hello $e'),
],
),
SliverMainAxisGroup(
slivers: [
SliverAppBar(
title: const Text('Sliver App Bar'),
),
SliverToBoxAdapter(
child: const Text('Hello World'),
),
],
),
SliverCrossAxisGroup(
slivers: [
SliverAppBar(
title: const Text('Sliver App Bar'),
),
SliverToBoxAdapter(
child: const Text('Hello World'),
),
],
),
Column(
children: [
if (random.nextBool()) const Text('Hello 1'),
Expand Down
2 changes: 1 addition & 1 deletion packages/altive_lints/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ dev_dependencies:
altive_lints:
path: ../
clock: ^1.1.2
custom_lint: ^0.7.0
custom_lint: ^0.7.5
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/element2.dart';
import 'package:analyzer/dart/element/type.dart';
import 'package:analyzer/error/listener.dart';
import 'package:custom_lint_builder/custom_lint_builder.dart';
Expand Down Expand Up @@ -65,8 +65,8 @@ class AvoidHardcodedColor extends DartLintRule {
context.registry.addPrefixedIdentifier((node) {
final prefix = node.prefix.name;
if (prefix == 'Colors') {
final element = node.staticElement;
if (element is PropertyAccessorElement) {
final element = node.element;
if (element is PropertyAccessorElement2) {
Comment on lines +68 to +69
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This addresses the warnings raised by the latest available analyzer version.

final returnType = element.returnType;
// Allow Colors.transparent as a valid hardcoded color, as it serves.
if (node.identifier.name == 'transparent') {
Expand Down
9 changes: 7 additions & 2 deletions packages/altive_lints/lib/src/lints/avoid_single_child.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:custom_lint_builder/custom_lint_builder.dart';
/// widgets intended for multiple children with only one child.
///
/// This includes widgets like `Column`, `Row`, `Stack`, `Flex`, `Wrap`,
/// `ListView`, and `SliverList`.
/// `ListView`, `SliverList`, `SliverMainAxisGroup`, and `SliverCrossAxisGroup`.
///
/// Using these widgets with a single child can lead to
/// unnecessary overhead and less efficient layouts.
Expand Down Expand Up @@ -60,9 +60,14 @@ class AvoidSingleChild extends DartLintRule {
'Stack',
'ListView',
'SliverList',
'SliverMainAxisGroup',
'SliverCrossAxisGroup',
].contains(className)) {
final childrenArg = node.argumentList.arguments.firstWhereOrNull(
(arg) => arg is NamedExpression && arg.name.label.name == 'children',
(arg) =>
arg is NamedExpression &&
(arg.name.label.name == 'children' ||
arg.name.label.name == 'slivers'),
);

final ListLiteral childrenList;
Expand Down
2 changes: 1 addition & 1 deletion packages/altive_lints/lib/src/utils/types_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ bool _isWidget(DartType? type) => type?.getDisplayString() == 'Widget';
bool _isSubclassOfWidget(DartType? type) =>
type is InterfaceType && type.allSupertypes.any(_isWidget);

bool _isWidgetState(DartType? type) => type?.element?.displayName == 'State';
bool _isWidgetState(DartType? type) => type?.element3?.displayName == 'State';

bool _isSubclassOfWidgetState(DartType? type) =>
type is InterfaceType && type.allSupertypes.any(_isWidgetState);
Expand Down
8 changes: 4 additions & 4 deletions packages/altive_lints/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ environment:
sdk: ^3.0.0

dependencies:
analyzer: ">=6.7.0 <8.0.0"
collection: ^1.18.0
custom_lint_builder: ^0.7.0
analyzer: ^7.4.5
collection: ^1.19.1
custom_lint_builder: ^0.7.5

dev_dependencies:
test: ^1.25.14
test: ^1.26.2
8 changes: 4 additions & 4 deletions packages/diffscrape/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ environment:
sdk: ^3.2.3

dependencies:
args: ^2.5.0
html: ^0.15.4
http: ^1.2.1
args: ^2.7.0
html: ^0.15.6
http: ^1.4.0

dev_dependencies:
altive_lints: ^1.21.0
test: ^1.25.7
test: ^1.26.2
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ environment:
dev_dependencies:
altive_lints:
path: packages/altive_lints
melos: ^6.1.0
melos: ^6.3.3