Skip to content
Open
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
## 0.3.2

- Added `named_parameters_ordering` rule.
- Update dependencies:
- Update min Dart SDK constraint to 3.8.0
- Update `analyzer` dependency to 8.1.1
- Update `custom_lint_builder` dependency to 0.8.1

## 0.3.1

Expand Down
4 changes: 2 additions & 2 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ description: A starting point for Dart libraries or applications.
publish_to: none

environment:
sdk: ">=3.0.0 <4.0.0"
sdk: ">=3.8.0 <4.0.0"

dependencies:
flutter:
sdk: flutter

dev_dependencies:
custom_lint: ^0.7.1
custom_lint: ^0.8.1
solid_lints:
path: ../
test: ^1.25.14
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ class ExcludedIdentifiersListParameter {
) {
final excludeList =
json[ExcludedIdentifiersListParameter.excludeParameterName]
as Iterable? ??
[];
as Iterable? ??
[];

return ExcludedIdentifiersListParameter.fromJson(
excludeList: excludeList,
Expand All @@ -55,7 +55,7 @@ class ExcludedIdentifiersListParameter {

/// Returns whether the target node should be ignored during analysis.
bool shouldIgnore(Declaration node) {
final declarationName = node.declaredFragment?.name2;
final declarationName = node.declaredFragment?.name;

final excludedItem = exclude.firstWhereOrNull(
(e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ your `debugPrint` call in a `!kReleaseMode` check.""",
@override
void run(
CustomLintResolver resolver,
ErrorReporter reporter,
DiagnosticReporter reporter,
CustomLintContext context,
) {
context.registry.addFunctionExpressionInvocation(
Expand Down Expand Up @@ -102,7 +102,7 @@ your `debugPrint` call in a `!kReleaseMode` check.""",
void _checkIdentifier({
required Identifier identifier,
required AstNode node,
required ErrorReporter reporter,
required DiagnosticReporter reporter,
}) {
if (!_isDebugPrintNode(identifier)) {
return;
Expand Down Expand Up @@ -137,7 +137,7 @@ your `debugPrint` call in a `!kReleaseMode` check.""",
/// Handles variable assignment and declaration
void _handleVariableAssignmentDeclaration({
required AstNode node,
required ErrorReporter reporter,
required DiagnosticReporter reporter,
}) {
final rightOperand = _getRightOperand(node.childEntities.toList());

Expand All @@ -159,10 +159,10 @@ your `debugPrint` call in a `!kReleaseMode` check.""",
case PrefixedIdentifier():
final prefix = node.prefix.name;
name = node.name.replaceAll('$prefix.', '');
sourcePath = node.element?.library2?.uri.toString() ?? '';
sourcePath = node.element?.library?.uri.toString() ?? '';
case SimpleIdentifier():
name = node.name;
sourcePath = node.element?.library2?.uri.toString() ?? '';
sourcePath = node.element?.library?.uri.toString() ?? '';

default:
return false;
Expand All @@ -172,11 +172,10 @@ your `debugPrint` call in a `!kReleaseMode` check.""",
}

bool _isNotReleaseCheck(Expression node) {
if (node.childEntities.toList()
case [
final Token token,
final Identifier identifier,
]) {
if (node.childEntities.toList() case [
final Token token,
final Identifier identifier,
]) {
return token.type == TokenType.BANG &&
_isReleaseModeIdentifier(identifier);
}
Expand All @@ -193,10 +192,10 @@ your `debugPrint` call in a `!kReleaseMode` check.""",
final prefix = node.prefix.name;

name = node.name.replaceAll('$prefix.', '');
sourcePath = node.element?.library2?.uri.toString() ?? '';
sourcePath = node.element?.library?.uri.toString() ?? '';
case SimpleIdentifier():
name = node.name;
sourcePath = node.element?.library2?.uri.toString() ?? '';
sourcePath = node.element?.library?.uri.toString() ?? '';
default:
return false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:analyzer/error/error.dart' as error;
import 'package:analyzer/diagnostic/diagnostic.dart';
import 'package:analyzer/error/listener.dart';
import 'package:analyzer/source/source_range.dart';
import 'package:custom_lint_builder/custom_lint_builder.dart';
Expand Down Expand Up @@ -56,7 +56,7 @@ class AvoidFinalWithGetterRule extends SolidLintRule {
@override
void run(
CustomLintResolver resolver,
ErrorReporter reporter,
DiagnosticReporter reporter,
CustomLintContext context,
) {
context.registry.addCompilationUnit((node) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ class _FinalWithGetterFix extends DartFix {
CustomLintResolver resolver,
ChangeReporter reporter,
CustomLintContext context,
error.AnalysisError analysisError,
List<error.AnalysisError> others,
Diagnostic analysisError,
List<Diagnostic> others,
) {
context.registry.addMethodDeclaration((node) {
if (analysisError.sourceRange.intersects(node.sourceRange)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/visitor.dart';
import 'package:analyzer/dart/element/element2.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:solid_lints/src/lints/avoid_final_with_getter/visitors/getter_variable_visitor.dart';

/// A visitor that checks for final private fields with getters.
Expand All @@ -13,16 +13,15 @@ class AvoidFinalWithGetterVisitor extends RecursiveAstVisitor<void> {

@override
void visitMethodDeclaration(MethodDeclaration node) {
if (node
case MethodDeclaration(
isGetter: true,
declaredFragment: ExecutableFragment(
element: ExecutableElement2(
isAbstract: false,
isPublic: true,
)
)
)) {
if (node case MethodDeclaration(
isGetter: true,
declaredFragment: ExecutableFragment(
element: ExecutableElement(
isAbstract: false,
isPublic: true,
),
),
)) {
final visitor = GetterVariableVisitor(node);
node.parent?.accept(visitor);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/visitor.dart';
import 'package:analyzer/dart/element/element2.dart';
import 'package:analyzer/dart/element/element.dart';

/// A visitor that checks the association of the getter with
/// the final private variable
Expand All @@ -10,7 +10,7 @@ class GetterVariableVisitor extends RecursiveAstVisitor<void> {

/// Creates a new instance of [GetterVariableVisitor]
GetterVariableVisitor(MethodDeclaration getter)
: _getterId = getter.getterReferenceId;
: _getterId = getter.getterReferenceId;

/// Is there a variable associated with the getter
VariableDeclaration? get variable => _variable;
Expand All @@ -36,8 +36,8 @@ extension on MethodDeclaration {
final expression = (body as ExpressionFunctionBody).expression;
if (expression is SimpleIdentifier) {
final element = expression.element;
if (element is PropertyAccessorElement2) {
return element.variable3?.id;
if (element is PropertyAccessorElement) {
return element.variable.id;
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/src/lints/avoid_global_state/avoid_global_state_rule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class AvoidGlobalStateRule extends SolidLintRule {
@override
void run(
CustomLintResolver resolver,
ErrorReporter reporter,
DiagnosticReporter reporter,
CustomLintContext context,
) {
context.registry.addTopLevelVariableDeclaration(
Expand All @@ -77,7 +77,7 @@ class AvoidGlobalStateRule extends SolidLintRule {
extension on VariableDeclaration {
bool get isMutable => !isFinal && !isConst;

bool get isPrivate => declaredElement2?.isPrivate ?? false;
bool get isPrivate => declaredElement?.isPrivate ?? false;

bool get isPublicMutable => isMutable && !isPrivate;
}
5 changes: 3 additions & 2 deletions lib/src/lints/avoid_late_keyword/avoid_late_keyword_rule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ class AvoidLateKeywordRule extends SolidLintRule<AvoidLateKeywordParameters> {
configs: configs,
name: lintName,
paramsParser: AvoidLateKeywordParameters.fromJson,
problemMessage: (_) => 'Avoid using the "late" keyword. '
problemMessage: (_) =>
'Avoid using the "late" keyword. '
'It may result in runtime exceptions.',
);

Expand All @@ -71,7 +72,7 @@ class AvoidLateKeywordRule extends SolidLintRule<AvoidLateKeywordParameters> {
@override
void run(
CustomLintResolver resolver,
ErrorReporter reporter,
DiagnosticReporter reporter,
CustomLintContext context,
) {
context.registry.addVariableDeclaration((node) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ class AvoidLateKeywordParameters {
factory AvoidLateKeywordParameters.fromJson(Map<String, Object?> json) =>
AvoidLateKeywordParameters(
allowInitialized: json['allow_initialized'] as bool? ?? false,
ignoredTypes:
List<String>.from(json['ignored_types'] as Iterable? ?? []),
ignoredTypes: List<String>.from(
json['ignored_types'] as Iterable? ?? [],
),
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ class AvoidNonNullAssertionRule extends SolidLintRule {
final rule = RuleConfig(
configs: configs,
name: lintName,
problemMessage: (_) => 'Avoid using the bang operator. '
problemMessage: (_) =>
'Avoid using the bang operator. '
'It may result in runtime exceptions.',
);

Expand All @@ -60,7 +61,7 @@ class AvoidNonNullAssertionRule extends SolidLintRule {
@override
void run(
CustomLintResolver resolver,
ErrorReporter reporter,
DiagnosticReporter reporter,
CustomLintContext context,
) {
context.registry.addPostfixExpression((node) {
Expand All @@ -77,7 +78,8 @@ class AvoidNonNullAssertionRule extends SolidLintRule {
if (operand is IndexExpression) {
final type = operand.target?.staticType;
final isInterface = type is InterfaceType;
final isMap = isInterface &&
final isMap =
isInterface &&
(type.isDartCoreMap ||
type.allSupertypes.any((v) => v.isDartCoreMap));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ class AvoidReturningWidgetsRule
name: lintName,
paramsParser: AvoidReturningWidgetsParameters.fromJson,
problemMessage: (_) =>
'Returning a widget from a function is considered an anti-pattern. '
'Unless you are overriding an existing method, '
'Returning a widget from a function is considered '
'an anti-pattern. Unless you are overriding an existing method, '
'consider extracting your widget to a separate class.',
);

Expand All @@ -77,16 +77,15 @@ class AvoidReturningWidgetsRule
@override
void run(
CustomLintResolver resolver,
ErrorReporter reporter,
DiagnosticReporter reporter,
CustomLintContext context,
) {
context.registry.addDeclaration((node) {
// Check if declaration is function or method,
// simultaneously checks if return type is [DartType]
final DartType? returnType = switch (node) {
FunctionDeclaration(returnType: TypeAnnotation(:final type?)) ||
MethodDeclaration(returnType: TypeAnnotation(:final type?)) =>
type,
MethodDeclaration(returnType: TypeAnnotation(:final type?)) => type,
_ => null,
};

Expand All @@ -101,11 +100,12 @@ class AvoidReturningWidgetsRule
final isOverriden = switch (node) {
FunctionDeclaration(:final functionExpression) =>
functionExpression.parent is MethodDeclaration &&
(functionExpression.parent! as MethodDeclaration)
.metadata
.any((m) => m.name.name == _override),
MethodDeclaration(:final metadata) =>
metadata.any((m) => m.name.name == _override),
(functionExpression.parent! as MethodDeclaration).metadata.any(
(m) => m.name.name == _override,
),
MethodDeclaration(:final metadata) => metadata.any(
(m) => m.name.name == _override,
),
_ => false,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ class AvoidUnnecessarySetStateRule extends SolidLintRule {
final rule = RuleConfig(
name: lintName,
configs: configs,
problemMessage: (_) => 'Avoid calling unnecessary setState. '
problemMessage: (_) =>
'Avoid calling unnecessary setState. '
'Consider changing the state directly.',
);
return AvoidUnnecessarySetStateRule._(rule);
Expand All @@ -77,7 +78,7 @@ class AvoidUnnecessarySetStateRule extends SolidLintRule {
@override
void run(
CustomLintResolver resolver,
ErrorReporter reporter,
DiagnosticReporter reporter,
CustomLintContext context,
) {
context.registry.addClassDeclaration((node) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ class AvoidUnnecessarySetStateVisitor extends RecursiveAstVisitor<void> {
}

final methods = node.members.whereType<MethodDeclaration>();
final classMethodsNames =
methods.map((declaration) => declaration.name.lexeme).toSet();
final classMethodsNames = methods
.map((declaration) => declaration.name.lexeme)
.toSet();
final methodBodies = methods.map((declaration) => declaration.body).toSet();

final checkedMethods = methods.where(_isMethodChecked);
Expand Down Expand Up @@ -105,8 +106,10 @@ class AvoidUnnecessarySetStateVisitor extends RecursiveAstVisitor<void> {
return true;
}

final visitor =
AvoidUnnecessarySetStateMethodVisitor(classMethodsNames, bodies);
final visitor = AvoidUnnecessarySetStateMethodVisitor(
classMethodsNames,
bodies,
);
declaration.visitChildren(visitor);

final hasSetState = visitor.setStateInvocations.isNotEmpty;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/element/type.dart';
import 'package:analyzer/error/error.dart' as error;
import 'package:analyzer/diagnostic/diagnostic.dart';
import 'package:analyzer/error/listener.dart';
import 'package:analyzer/source/source_range.dart';
import 'package:custom_lint_builder/custom_lint_builder.dart';
Expand Down Expand Up @@ -72,7 +72,7 @@ class AvoidUnnecessaryTypeAssertions extends SolidLintRule {
@override
void run(
CustomLintResolver resolver,
ErrorReporter reporter,
DiagnosticReporter reporter,
CustomLintContext context,
) {
context.registry.addIsExpression((node) {
Expand Down
Loading