diff --git a/CHANGELOG.md b/CHANGELOG.md index 5392d670..566110ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,8 @@ - `no_empty_bloc` - `number_of_parameters` - BREAKING CHANGE: Renamed `excludeNames` parameter to `exclude` for `function_lines_of_code` lint. -- Fixed an issue with `prefer_early_retrun` for throw expression +- Fixed an issue with `prefer_early_retrun` for throw expression +- `number_of_parameters` lint: added `copyWith` to the default exclude list. ## 0.2.3 diff --git a/lib/analysis_options.yaml b/lib/analysis_options.yaml index 9eeaace1..1d6ba832 100644 --- a/lib/analysis_options.yaml +++ b/lib/analysis_options.yaml @@ -85,6 +85,8 @@ custom_lint: - number_of_parameters: max_parameters: 7 + exclude: + - method_name: copyWith - prefer_conditional_expressions: ignore_nested: true diff --git a/lint_test/analysis_options.yaml b/lint_test/analysis_options.yaml index 10c18f33..e5a001c3 100644 --- a/lint_test/analysis_options.yaml +++ b/lint_test/analysis_options.yaml @@ -15,7 +15,7 @@ custom_lint: exclude: - class_name: Exclude method_name: avoidNumberOfParameters - - method_name: avoidNumberOfParameters + - method_name: avoidNumberOfParameters - function_lines_of_code: max_lines: 50 - avoid_non_null_assertion diff --git a/lint_test/number_of_parameters_copy_with_test/analysis_options.yaml b/lint_test/number_of_parameters_copy_with_test/analysis_options.yaml new file mode 100644 index 00000000..3fdd2d5e --- /dev/null +++ b/lint_test/number_of_parameters_copy_with_test/analysis_options.yaml @@ -0,0 +1 @@ +include: ../../lib/analysis_options.yaml diff --git a/lint_test/number_of_parameters_copy_with_test/lib/src/number_of_parameters_copy_with_test.dart b/lint_test/number_of_parameters_copy_with_test/lib/src/number_of_parameters_copy_with_test.dart new file mode 100644 index 00000000..60a6f42f --- /dev/null +++ b/lint_test/number_of_parameters_copy_with_test/lib/src/number_of_parameters_copy_with_test.dart @@ -0,0 +1,90 @@ +// ignore_for_file: prefer_match_file_name, public_member_api_docs +// Check number of parameters fail +/// +/// `number_of_parameters: max_parameters` + +class UserDto { + final String a; + final String b; + final String c; + final String d; + final String e; + final String f; + final String g; + final String h; + + const UserDto({ + required this.a, + required this.b, + required this.c, + required this.d, + required this.e, + required this.f, + required this.g, + required this.h, + }); + + /// Excluded by method_name + UserDto copyWith({ + String? a, + String? b, + String? c, + String? d, + String? e, + String? f, + String? g, + String? h, + }) { + return UserDto( + a: a ?? this.a, + b: b ?? this.b, + c: c ?? this.c, + d: d ?? this.d, + e: e ?? this.e, + f: f ?? this.f, + g: g ?? this.g, + h: h ?? this.h, + ); + } + + /// expect_lint: number_of_parameters + UserDto noCopyWith({ + String? a, + String? b, + String? c, + String? d, + String? e, + String? f, + String? g, + String? h, + }) { + return UserDto( + a: a ?? this.a, + b: b ?? this.b, + c: c ?? this.c, + d: d ?? this.d, + e: e ?? this.e, + f: f ?? this.f, + g: g ?? this.g, + h: h ?? this.h, + ); + } + + /// Allow + UserDto noLongCopyWith({ + String? a, + String? b, + String? c, + }) { + return UserDto( + a: a ?? this.a, + b: b ?? this.b, + c: c ?? this.c, + d: '', + e: '', + f: '', + g: '', + h: '', + ); + } +} diff --git a/lint_test/number_of_parameters_copy_with_test/pubspec.yaml b/lint_test/number_of_parameters_copy_with_test/pubspec.yaml new file mode 100644 index 00000000..e753375a --- /dev/null +++ b/lint_test/number_of_parameters_copy_with_test/pubspec.yaml @@ -0,0 +1,15 @@ +name: solid_lints_number_of_parameters_copy_with_test +description: A starting point for Dart libraries or applications. +publish_to: none + +environment: + sdk: '>=3.0.0 <4.0.0' + +dependencies: + flutter: + sdk: flutter + +dev_dependencies: + solid_lints: + path: ../../ + test: ^1.20.1