diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 030fcd58..64a0b9ec 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -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 diff --git a/lib/src/lints/avoid_unnecessary_type_assertions/avoid_unnecessary_type_assertions_rule.dart b/lib/src/lints/avoid_unnecessary_type_assertions/avoid_unnecessary_type_assertions_rule.dart index 20d088c9..c973b609 100644 --- a/lib/src/lints/avoid_unnecessary_type_assertions/avoid_unnecessary_type_assertions_rule.dart +++ b/lib/src/lints/avoid_unnecessary_type_assertions/avoid_unnecessary_type_assertions_rule.dart @@ -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'; diff --git a/lib/src/lints/avoid_unnecessary_type_assertions/fixes/avoid_unnecessary_type_assertions_fix.dart b/lib/src/lints/avoid_unnecessary_type_assertions/fixes/avoid_unnecessary_type_assertions_fix.dart index 90c1c91d..40afae08 100644 --- a/lib/src/lints/avoid_unnecessary_type_assertions/fixes/avoid_unnecessary_type_assertions_fix.dart +++ b/lib/src/lints/avoid_unnecessary_type_assertions/fixes/avoid_unnecessary_type_assertions_fix.dart @@ -8,8 +8,8 @@ class _UnnecessaryTypeAssertionsFix extends DartFix { CustomLintResolver resolver, ChangeReporter reporter, CustomLintContext context, - AnalysisError analysisError, - List others, + error.AnalysisError analysisError, + List others, ) { context.registry.addIsExpression((node) { if (analysisError.sourceRange.intersects(node.sourceRange)) { diff --git a/lib/src/lints/double_literal_format/double_literal_format_rule.dart b/lib/src/lints/double_literal_format/double_literal_format_rule.dart index d32664b4..45429ef4 100644 --- a/lib/src/lints/double_literal_format/double_literal_format_rule.dart +++ b/lib/src/lints/double_literal_format/double_literal_format_rule.dart @@ -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'; diff --git a/lib/src/lints/double_literal_format/fixes/double_literal_format_fix.dart b/lib/src/lints/double_literal_format/fixes/double_literal_format_fix.dart index 2bc7e874..6452df89 100644 --- a/lib/src/lints/double_literal_format/fixes/double_literal_format_fix.dart +++ b/lib/src/lints/double_literal_format/fixes/double_literal_format_fix.dart @@ -8,8 +8,8 @@ class _DoubleLiteralFormatFix extends DartFix { CustomLintResolver resolver, ChangeReporter reporter, CustomLintContext context, - AnalysisError analysisError, - List others, + error.AnalysisError analysisError, + List others, ) { context.registry.addDoubleLiteral((node) { // checks that the literal declaration is where our warning is located diff --git a/lib/src/models/rule_config.dart b/lib/src/models/rule_config.dart index d2429b9d..23f08f39 100644 --- a/lib/src/models/rule_config.dart +++ b/lib/src/models/rule_config.dart @@ -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 @@ -38,6 +38,6 @@ class RuleConfig { LintCode get lintCode => LintCode( name: name, problemMessage: _problemMessageFactory(parameters), - errorSeverity: ErrorSeverity.WARNING, + errorSeverity: error.ErrorSeverity.WARNING, ); } diff --git a/lib/src/utils/parameter_utils.dart b/lib/src/utils/parameter_utils.dart index fdbd647c..df045978 100644 --- a/lib/src/utils/parameter_utils.dart +++ b/lib/src/utils/parameter_utils.dart @@ -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 @@ -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, }; } @@ -31,7 +31,7 @@ extension LintCodeCopyWith on LintCode { String? correctionMessage, String? uniqueName, String? url, - ErrorSeverity? errorSeverity, + error.ErrorSeverity? errorSeverity, }) => LintCode( name: name ?? this.name, diff --git a/lint_test/alphabetize_by_type_test/alphabetize_by_type_test.dart b/lint_test/alphabetize_by_type_test/alphabetize_by_type_test.dart index bd7522a7..498188fa 100644 --- a/lint_test/alphabetize_by_type_test/alphabetize_by_type_test.dart +++ b/lint_test/alphabetize_by_type_test/alphabetize_by_type_test.dart @@ -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 { diff --git a/lint_test/avoid_late_keyword/allow_initialized/avoid_late_keyword_allow_initialized_test.dart b/lint_test/avoid_late_keyword/allow_initialized/avoid_late_keyword_allow_initialized_test.dart index 04dbfe1d..8136b96a 100644 --- a/lint_test/avoid_late_keyword/allow_initialized/avoid_late_keyword_allow_initialized_test.dart +++ b/lint_test/avoid_late_keyword/allow_initialized/avoid_late_keyword_allow_initialized_test.dart @@ -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(); @@ -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(); @@ -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 diff --git a/lint_test/avoid_late_keyword/no_generics/avoid_late_keyword_no_generics_test.dart b/lint_test/avoid_late_keyword/no_generics/avoid_late_keyword_no_generics_test.dart index 486b1936..12fea482 100644 --- a/lint_test/avoid_late_keyword/no_generics/avoid_late_keyword_no_generics_test.dart +++ b/lint_test/avoid_late_keyword/no_generics/avoid_late_keyword_no_generics_test.dart @@ -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 subscription2; + /// expect_lint: avoid_late_keyword late final Subscription> subscription3; + /// expect_lint: avoid_late_keyword late final Subscription>> subscription4; + /// expect_lint: avoid_late_keyword late final Subscription> 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 subscription2; + /// expect_lint: avoid_late_keyword late final Subscription> subscription3; + /// expect_lint: avoid_late_keyword late final Subscription>> subscription4; + /// expect_lint: avoid_late_keyword late final Subscription> subscription5; } } diff --git a/lint_test/avoid_late_keyword/with_generics/avoid_late_keyword_with_generics_test.dart b/lint_test/avoid_late_keyword/with_generics/avoid_late_keyword_with_generics_test.dart index a0468217..576ade7b 100644 --- a/lint_test/avoid_late_keyword/with_generics/avoid_late_keyword_with_generics_test.dart +++ b/lint_test/avoid_late_keyword/with_generics/avoid_late_keyword_with_generics_test.dart @@ -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(); @@ -44,24 +47,32 @@ class AvoidLateKeyword { /// expect_lint: avoid_late_keyword late final Subscription subscription1; + /// expect_lint: avoid_late_keyword late final Subscription subscription2; + /// expect_lint: avoid_late_keyword late final Subscription> subscription3; + /// expect_lint: avoid_late_keyword late final Subscription>> subscription4; + /// expect_lint: avoid_late_keyword late final Subscription> subscription5; + /// expect_lint: avoid_late_keyword late final Subscription> subscription6; /// expect_lint: avoid_late_keyword late final Subscription> 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(); @@ -84,8 +95,10 @@ class AvoidLateKeyword { /// expect_lint: avoid_late_keyword late final Subscription subscription1; + /// expect_lint: avoid_late_keyword late final Subscription subscription2; + /// expect_lint: avoid_late_keyword late final Subscription> subscription3; } } diff --git a/lint_test/avoid_returning_widget_test/avoid_returning_widget_test.dart b/lint_test/avoid_returning_widget_test/avoid_returning_widget_test.dart index ff20d272..a1f3677f 100644 --- a/lint_test/avoid_returning_widget_test/avoid_returning_widget_test.dart +++ b/lint_test/avoid_returning_widget_test/avoid_returning_widget_test.dart @@ -65,6 +65,7 @@ Widget build() { return Offstage(); } +// expect_lint: avoid_returning_widgets SizedBox excludeMethod() => const SizedBox(); class ExcludeWidget extends StatelessWidget { @@ -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 diff --git a/lint_test/avoid_using_api/external_source/lib/banned_library.dart b/lint_test/avoid_using_api/external_source/lib/banned_library.dart index d36ffcde..abad4800 100644 --- a/lint_test/avoid_using_api/external_source/lib/banned_library.dart +++ b/lint_test/avoid_using_api/external_source/lib/banned_library.dart @@ -1 +1,2 @@ +// expect_lint: avoid_global_state int banned = 5; diff --git a/lint_test/avoid_using_api/external_source/lib/external_source.dart b/lint_test/avoid_using_api/external_source/lib/external_source.dart index 2bab9af4..4b2d78dc 100644 --- a/lint_test/avoid_using_api/external_source/lib/external_source.dart +++ b/lint_test/avoid_using_api/external_source/lib/external_source.dart @@ -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; diff --git a/lint_test/function_lines_of_code_test/function_lines_of_code_test.dart b/lint_test/function_lines_of_code_test/function_lines_of_code_test.dart index aa4211a9..e35d5d6f 100644 --- a/lint_test/function_lines_of_code_test/function_lines_of_code_test.dart +++ b/lint_test/function_lines_of_code_test/function_lines_of_code_test.dart @@ -1,29 +1,278 @@ +// ignore_for_file: prefer_match_file_name + class ClassWithLongMethods { - int notLongMethod() { + // expect_lint: function_lines_of_code + int longMethod() { var i = 0; i++; i++; i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + return i; } - // expect_lint: function_lines_of_code - int longMethod() { + // Excluded by excludeNames + int longMethodExcluded() { var i = 0; i++; i++; i++; i++; + return i; } - // Excluded by excludeNames - int longMethodExcluded() { + int notLongMethod() { var i = 0; i++; i++; i++; - i++; + return i; } } @@ -33,6 +282,7 @@ int notLongFunction() { i++; i++; i++; + return i; } @@ -43,6 +293,191 @@ int longFunction() { i++; i++; i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + return i; } @@ -53,5 +488,6 @@ int longFunctionExcluded() { i++; i++; i++; + return i; } diff --git a/lint_test/no_magic_number_allowed_in_widget_params_test/no_magic_number_allowed_in_widget_params_test.dart b/lint_test/no_magic_number_allowed_in_widget_params_test/no_magic_number_allowed_in_widget_params_test.dart index a01e12fa..7d603d21 100644 --- a/lint_test/no_magic_number_allowed_in_widget_params_test/no_magic_number_allowed_in_widget_params_test.dart +++ b/lint_test/no_magic_number_allowed_in_widget_params_test/no_magic_number_allowed_in_widget_params_test.dart @@ -1,3 +1,6 @@ +// ignore_for_file: avoid_returning_widgets +// ignore_for_file: prefer_match_file_name + // Allowed for numbers in a Widget subtype parameters. abstract interface class Widget {} @@ -21,7 +24,9 @@ class MyWidgetDecoration { Widget build() { return MyWidget( + // expect_lint: no_magic_number decoration: MyWidgetDecoration(size: 12), + // expect_lint: no_magic_number value: 23, ); } diff --git a/lint_test/prefer_conditional_expressions_ignore_nested_test/prefer_conditional_expressions_ignore_nested_test.dart b/lint_test/prefer_conditional_expressions_ignore_nested_test/prefer_conditional_expressions_ignore_nested_test.dart index 954e77fa..150b9e4b 100644 --- a/lint_test/prefer_conditional_expressions_ignore_nested_test/prefer_conditional_expressions_ignore_nested_test.dart +++ b/lint_test/prefer_conditional_expressions_ignore_nested_test/prefer_conditional_expressions_ignore_nested_test.dart @@ -8,7 +8,9 @@ void fun() { // Allowed because ignore_nested flag is enabled if (1 > 0) { - _result = 1 > 2 ? 2 : 1; + if (true) { + _result = 1 > 0 ? 0 : 1; + } } else { _result = 0; } diff --git a/pubspec.yaml b/pubspec.yaml index eea0b1af..4a3f3291 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,7 +11,7 @@ environment: sdk: ">=3.0.0 <4.0.0" dependencies: - analyzer: ^6.6.0 + analyzer: ^6.7.0 collection: ^1.17.2 custom_lint_builder: ^0.6.7 glob: ^2.1.2