Skip to content

Commit

Permalink
Fixed LintCode analyzer issues (#178)
Browse files Browse the repository at this point in the history
* Fixed analyzer issue, fixed linter

* Fixed LintCode issue

* Fixed LintCode issue

* Fixed pubspec

* Try to update analyzer version

* Try to override analyzer dependency

* Add import as instead of hide

* Fixed tests fpr custom linter to work correctly
  • Loading branch information
solid-glebvorobey authored Sep 19, 2024
1 parent b93fde7 commit fcc0621
Show file tree
Hide file tree
Showing 18 changed files with 513 additions and 42 deletions.
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.0.0 <4.0.0"

dependencies:
flutter:
sdk: flutter

dev_dependencies:
custom_lint: ^0.6.0
custom_lint: ^0.6.7
solid_lints:
path: ../
test: ^1.20.1
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';
import 'package:analyzer/error/error.dart' as error;
import 'package:analyzer/error/listener.dart';
import 'package:analyzer/source/source_range.dart';
import 'package:custom_lint_builder/custom_lint_builder.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ class _UnnecessaryTypeAssertionsFix extends DartFix {
CustomLintResolver resolver,
ChangeReporter reporter,
CustomLintContext context,
AnalysisError analysisError,
List<AnalysisError> others,
error.AnalysisError analysisError,
List<error.AnalysisError> others,
) {
context.registry.addIsExpression((node) {
if (analysisError.sourceRange.intersects(node.sourceRange)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:analyzer/error/error.dart';
import 'package:analyzer/error/error.dart' as error;
import 'package:analyzer/error/listener.dart';
import 'package:analyzer/source/source_range.dart';
import 'package:custom_lint_builder/custom_lint_builder.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ class _DoubleLiteralFormatFix extends DartFix {
CustomLintResolver resolver,
ChangeReporter reporter,
CustomLintContext context,
AnalysisError analysisError,
List<AnalysisError> others,
error.AnalysisError analysisError,
List<error.AnalysisError> others,
) {
context.registry.addDoubleLiteral((node) {
// checks that the literal declaration is where our warning is located
Expand Down
4 changes: 2 additions & 2 deletions lib/src/models/rule_config.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:analyzer/error/error.dart';
import 'package:analyzer/error/error.dart' as error;
import 'package:custom_lint_builder/custom_lint_builder.dart';

/// Type definition of a value factory which allows us to map data from
Expand Down Expand Up @@ -38,6 +38,6 @@ class RuleConfig<T extends Object?> {
LintCode get lintCode => LintCode(
name: name,
problemMessage: _problemMessageFactory(parameters),
errorSeverity: ErrorSeverity.WARNING,
errorSeverity: error.ErrorSeverity.WARNING,
);
}
14 changes: 7 additions & 7 deletions lib/src/utils/parameter_utils.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/error/error.dart';
import 'package:analyzer/error/error.dart' as error;
import 'package:custom_lint_builder/custom_lint_builder.dart';

/// Checks if parameter name consists only of underscores
Expand All @@ -12,12 +12,12 @@ bool nameConsistsOfUnderscoresOnly(FormalParameter parameter) {
}

/// Decodes the severity parameter from the string
ErrorSeverity? decodeErrorSeverity(String? severity) {
error.ErrorSeverity? decodeErrorSeverity(String? severity) {
return switch (severity?.toLowerCase()) {
'info' => ErrorSeverity.INFO,
'warning' => ErrorSeverity.WARNING,
'error' => ErrorSeverity.ERROR,
'none' => ErrorSeverity.NONE,
'info' => error.ErrorSeverity.INFO,
'warning' => error.ErrorSeverity.WARNING,
'error' => error.ErrorSeverity.ERROR,
'none' => error.ErrorSeverity.NONE,
_ => null,
};
}
Expand All @@ -31,7 +31,7 @@ extension LintCodeCopyWith on LintCode {
String? correctionMessage,
String? uniqueName,
String? url,
ErrorSeverity? errorSeverity,
error.ErrorSeverity? errorSeverity,
}) =>
LintCode(
name: name ?? this.name,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
// ignore_for_file: unused_field
// ignore_for_file: unused_element
// ignore_for_file: prefer_match_file_name

/// Check the `member_ordering` rule
/// alphabetical-by-type option enabled
class CorrectAlphabeticalByTypeClass {
final double e = 1;
final int a = 1;
final double e = 1;
}

class WrongAlphabeticalByTypeClass {
final int a = 1;
final int e = 1;

// expect_lint: member_ordering
final double e = 1;
final double a = 1;
}

class PartiallyWrongAlphabeticalByTypeClass {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class ColorTween {}
/// `avoid_late_keyword`
/// allow_initialized option disabled
class AvoidLateKeyword {
/// expect_lint: avoid_late_keyword
late final Animation animation1;

late final animation2 = AnimationController();
Expand All @@ -23,27 +24,25 @@ class AvoidLateKeyword {
/// expect_lint: avoid_late_keyword
late final ColorTween colorTween1;

/// expect_lint: avoid_late_keyword
late final colorTween2 = ColorTween();

/// expect_lint: avoid_late_keyword
late final colorTween3 = colorTween2;

/// expect_lint: avoid_late_keyword
late final AnimationController controller1;

/// expect_lint: avoid_late_keyword
late final field1 = 'string';

/// expect_lint: avoid_late_keyword
late final String field2;

/// expect_lint: avoid_late_keyword
late final String field3 = 'string';

/// expect_lint: avoid_late_keyword
late final field4;

void test() {
/// expect_lint: avoid_late_keyword
late final Animation animation1;

late final animation2 = AnimationController();
Expand All @@ -53,21 +52,18 @@ class AvoidLateKeyword {
/// expect_lint: avoid_late_keyword
late final ColorTween colorTween1;

/// expect_lint: avoid_late_keyword
late final colorTween2 = ColorTween();

/// expect_lint: avoid_late_keyword
late final colorTween3 = colorTween2;

/// expect_lint: avoid_late_keyword
late final AnimationController controller1;

/// expect_lint: avoid_late_keyword
late final local1 = 'string';

/// expect_lint: avoid_late_keyword
late final String local2;

/// expect_lint: avoid_late_keyword
late final String local4 = 'string';

/// expect_lint: avoid_late_keyword
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,38 @@ class AvoidLateKeyword {
/// expect_lint: avoid_late_keyword
late final NotAllowed na1;

/// expect_lint: avoid_late_keyword
late final Subscription subscription1;

/// expect_lint: avoid_late_keyword
late final Subscription<ConcreteTypeWithNoGenerics> subscription2;

/// expect_lint: avoid_late_keyword
late final Subscription<List<int>> subscription3;

/// expect_lint: avoid_late_keyword
late final Subscription<List<List<int>>> subscription4;

/// expect_lint: avoid_late_keyword
late final Subscription<Map<dynamic, String>> subscription5;

void test() {
/// expect_lint: avoid_late_keyword
late final NotAllowed na1;

/// expect_lint: avoid_late_keyword
late final Subscription subscription1;

/// expect_lint: avoid_late_keyword
late final Subscription<ConcreteTypeWithNoGenerics> subscription2;

/// expect_lint: avoid_late_keyword
late final Subscription<List<int>> subscription3;

/// expect_lint: avoid_late_keyword
late final Subscription<List<List<int>>> subscription4;

/// expect_lint: avoid_late_keyword
late final Subscription<Map<dynamic, String>> subscription5;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ class ConcreteTypeWithNoGenerics {}
/// `avoid_late_keyword`
/// allow_initialized option enabled
class AvoidLateKeyword {
/// expect_lint: avoid_late_keyword
late final ColorTween colorTween;

/// expect_lint: avoid_late_keyword
late final AnimationController controller1;

/// expect_lint: avoid_late_keyword
late final SubAnimationController controller2;

late final controller3 = AnimationController();
Expand All @@ -44,24 +47,32 @@ class AvoidLateKeyword {
/// expect_lint: avoid_late_keyword
late final Subscription<String> subscription1;

/// expect_lint: avoid_late_keyword
late final Subscription<ConcreteTypeWithNoGenerics> subscription2;

/// expect_lint: avoid_late_keyword
late final Subscription<List<String>> subscription3;

/// expect_lint: avoid_late_keyword
late final Subscription<List<List<int>>> subscription4;

/// expect_lint: avoid_late_keyword
late final Subscription<Map<dynamic, String>> subscription5;

/// expect_lint: avoid_late_keyword
late final Subscription<Map<String, String>> subscription6;

/// expect_lint: avoid_late_keyword
late final Subscription<Map<String, dynamic>> subscription7;

void test() {
/// expect_lint: avoid_late_keyword
late final ColorTween colorTween;

/// expect_lint: avoid_late_keyword
late final AnimationController controller1;

/// expect_lint: avoid_late_keyword
late final SubAnimationController controller2;

late final controller3 = AnimationController();
Expand All @@ -84,8 +95,10 @@ class AvoidLateKeyword {
/// expect_lint: avoid_late_keyword
late final Subscription<String> subscription1;

/// expect_lint: avoid_late_keyword
late final Subscription<ConcreteTypeWithNoGenerics> subscription2;

/// expect_lint: avoid_late_keyword
late final Subscription<List<String>> subscription3;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Widget build() {
return Offstage();
}

// expect_lint: avoid_returning_widgets
SizedBox excludeMethod() => const SizedBox();

class ExcludeWidget extends StatelessWidget {
Expand All @@ -75,6 +76,7 @@ class ExcludeWidget extends StatelessWidget {
return const Placeholder();
}

// expect_lint: avoid_returning_widgets
Widget excludeWidgetMethod() => const SizedBox();

// expect_lint: avoid_returning_widgets
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
// expect_lint: avoid_global_state
int banned = 5;
17 changes: 11 additions & 6 deletions lint_test/avoid_using_api/external_source/lib/external_source.dart
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
class BannedCodeUsage {
BannedCodeUsage();
static String test2() {
return 'Hello World';
}
// ignore_for_file: prefer_match_file_name
// ignore_for_file: no_empty_block

class BannedCodeUsage {
final String test4 = 'Hello World';

void test() {}
BannedCodeUsage();

factory BannedCodeUsage.test3() {
return BannedCodeUsage();
}

void test() {}

static String test2() {
return 'Hello World';
}
}

const test2 = 'Hello World';

void test() {}

// expect_lint: avoid_global_state
int banned = 5;
Loading

0 comments on commit fcc0621

Please sign in to comment.