Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add avoid unused parameters rule #49

Conversation

DenisBogatirov
Copy link
Contributor

No description provided.

Denis Bogatirov added 2 commits September 15, 2023 12:26
# Conflicts:
#	lib/solid_lints.dart
#	lint_test/analysis_options.yaml
Copy link
Collaborator

@yurii-prykhodko-solid yurii-prykhodko-solid left a comment

Choose a reason for hiding this comment

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

A couple questions on behavior.

Comment on lines +70 to +71
// Allowed same way as override
final MaxFun maxFunInstance = (int a, int b) => 1;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would make sense for named params, but for positional ones -- not so sure. I'd say either use it, or make it an underscore.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@DenisBogatirov What's your take on this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Didn't quite get the question.

Type is MaxFun so we are obliged to provide given set of params, if we remove one then there would be a type mismatch. That would work same way with with name params because if we remove namedParam it wouldn't be a defined type.

Or do you want to create another test case for named params with typedef?

Copy link
Collaborator

Choose a reason for hiding this comment

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

With positional params, we have the freedom to create a placeholder arg with the correct type. Just need to match the signature.
Here's how I see it:

// expect_lint: avoid-unused-parameters
final MaxFun maxFunLint = (int a, int b) => 1;
  
final MaxFun maxFunOk = (int _, int __) => 1;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Original rule does not care about parameter name as long as function or method is implemented.

Should I implement this logic? It will affect @override as well

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hm, is there no way to know that we're operating on a typedef instead of a class method override?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At least at this time I couldn't find any :(

Copy link
Collaborator

Choose a reason for hiding this comment

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

Well, in that case let's document this in an issue and get back to it later on.
You've done a great job expanding the rule to constructors already.

lint_test/avoid_unused_parameters_test.dart Show resolved Hide resolved
Copy link
Collaborator

@yurii-prykhodko-solid yurii-prykhodko-solid left a comment

Choose a reason for hiding this comment

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

LGTM!

Denis Bogatirov added 2 commits September 15, 2023 19:42
@yurii-prykhodko-solid yurii-prykhodko-solid merged commit c759f8d into solid-software:release-v0.1.0 Sep 15, 2023
1 check passed
solid-vovabeloded pushed a commit that referenced this pull request Nov 10, 2023
* Add avoid-unused-parameters rule

* Add tests for avoid-unused-parameters rule

* Fix function name, remove null check operator and remove negation

* Fix multiple reporting

* Add more test cases

* Fix formatting

* Rename method

* Add constructors and factories unused params handling

* Fix constructors with named field parameters

* Simplify rule run method

* Fix tests

* Fix tests after merge

* Fix tests after merge

---------

Co-authored-by: Denis Bogatirov <[email protected]>
illia-romanenko added a commit that referenced this pull request Nov 20, 2023
* Bump version to `0.1.0`

* Pull changes from `solid-metrics` repository

* Update .gitignore

Co-authored-by: Yuri Prykhodko <[email protected]>

* Update example/lib/solid_lints_example.dart

Co-authored-by: Yuri Prykhodko <[email protected]>

* Update `CHANGELOG.md`

* Add code checks with GitHub Actions

* Add support for the number of parameters metric

* Remove DCM references

* Change lint message

* Simplify configuration and remove redundant code

* Fix code comments

* Add missing tests

* Add `lines_of_code` lint

* Fix rule name

* Add test and fix an edge case

* Update lint to match the specification

* Add `avoid_non_null_assertion` lint

* Add missing comment

* Add `avoid_late_keyword` lint

* Update problem message

* Add `avoid_global_state` lint

* Fix failing tests

* Add `avoid_returning_widgets` lint

* Use pattern-matching

* Simplify `isWidgetReturned`

* Update lib/lints/avoid_returning_widgets/avoid_returning_widgets_rule.dart

Co-authored-by: Yuri Prykhodko <[email protected]>

* Cleanup of `getLintRules`

* Fix comment

* rename MetricRule -> RuleConfig

* add a sceleton for the double-literal-format rule

* implement the double-literal-format rule

* fix review warnings

* implement quick-fix for the double-literal-format rule

* fix lint warnings

* add avoid-unnecessary-type-assertions rule ('is' part)

* fix lint warning

* add avoid-unnecessary-type-assertions rule ('whereType' part)

* add quick-fix for unnecessary operator is

* add quick-fix for unnecessary whereType

* fix review warnings; fix a bug

* add utility class for type chekcking methods

* add constants for is and whereType names

* add needed comments

* rewrite _isUnnecessaryWhereType with pattern matching

* rewrite _areGenericsWithSameTypeArgs with pattern matching

* refactoring: move a castTypeInHierarchy to TypeCast class

* implement "avoid unnecessary setstate" rule (#44)

* implement "avoid unnecessary setstate" rule

* fix pr comments

* added idea files to gitignore

* fix pr comments

* Fix merge conflict

* Fix tests and improve GitHub workflow

* Fix workflow file

* Fix conflicts after merge

* Remove non-existing import

* Add missing rule to tests and remove unnecessary GitHub actions step

---------

Co-authored-by: Yaroslav Laptiev <[email protected]>
Co-authored-by: vladimir-beloded <[email protected]>

* Add avoid_unnecessary_type_casts_rule

* Refactor types_utils, extract common methods

* Add fix for avoid_unnecessary_type_casts_rule

* Add AvoidUnnecessaryTypeCastsRule.createRule to solid_lints.dart

* Fix 'quickFix' for avoid-unnecessary-type-casts

* Add tests for avoid-unnecessary-type-casts

* Fix formatting

* Add more test cases

* Group code for more readability

* Switch to getters, refactor areGenericsWithSameTypeArgs

* Avoid unrelated type assertions (#48)

* Add avoid-unrelated-type-assertions rule

* Add tests for avoid-unrelated-type-assertions rule

---------

Co-authored-by: Denis Bogatirov <[email protected]>

* Feature/newline before return (#52)

* Add newline-before-return rule

* Fix typos, remove unnecessary negation

* Add tests for newline-before-return

---------

Co-authored-by: Denis Bogatirov <[email protected]>

* Fixes Issue #54 multiple rule reporting (#55)

* Fix newline-before-return

* Fix avoid-unrelated-type-assertions

* Fix avoid-unnecessary-type-casts

---------

Co-authored-by: Denis Bogatirov <[email protected]>

* Feature/no empty block (#53)

* Add no-empty-block rule

* Add tests no-empty-block rule

* Add cyclomatic tests case, fix formatting

---------

Co-authored-by: Denis Bogatirov <[email protected]>

* Add no equal then else rule (#56)

* Add no-equal-then-else rule

* Add tests for no-equal-then-else rule

---------

Co-authored-by: Denis Bogatirov <[email protected]>

* Feature/member ordering (#51)

* Add required models for member-ordering rule

* Add member-ordering rule

* Add MIT License comments

* Fix parser type mismatch

* Add tests for member-ordering and enable rule

* Organize imports, ignore member-ordering in unrelated test

* Group *_member_group.dart into one directory

* Add more test cases

* Add more test cases

* Add alphabetize test cases

* Add tests for alphabetical-by-type option

* Ignore no-empty-block in test

* Ignore member-ordering in test

---------

Co-authored-by: Denis Bogatirov <[email protected]>

* Add avoid unused parameters rule (#49)

* Add avoid-unused-parameters rule

* Add tests for avoid-unused-parameters rule

* Fix function name, remove null check operator and remove negation

* Fix multiple reporting

* Add more test cases

* Fix formatting

* Rename method

* Add constructors and factories unused params handling

* Fix constructors with named field parameters

* Simplify rule run method

* Fix tests

* Fix tests after merge

* Fix tests after merge

---------

Co-authored-by: Denis Bogatirov <[email protected]>

* Added no magic number rule (#57)

* Add no-magic-number rule

* Add tests for no-magic-number rule

* Fix import lost in merge

* Ignore no-magic-number in test

---------

Co-authored-by: Denis Bogatirov <[email protected]>

* Added prefer condtional expressions rule and fix (#59)

* Add prefer-conditional-expressions rule and fix

* Add tests for prefer-conditional-expressions rule

* fix nested test plugin path

* Fix tests after merge

* Update lint_test/prefer_conditional_expressions_ignore_nested_test/prefer_conditional_expressions_ignore_nested_test.dart

---------

Co-authored-by: Denis Bogatirov <[email protected]>
Co-authored-by: Yurii Prykhodko <[email protected]>

* Added prefer first rule (#60)

* Add prefer-conditional-expressions rule and fix

* Add tests for prefer-conditional-expressions rule

* fix nested test plugin path

* Fix tests after merge

* Add prefer-first rule and fix

* Add tests for prefer-first rule

---------

Co-authored-by: Denis Bogatirov <[email protected]>
Co-authored-by: Yurii Prykhodko <[email protected]>

* Add prefer last rule (#61)

* Add prefer-conditional-expressions rule and fix

* Add tests for prefer-conditional-expressions rule

* fix nested test plugin path

* Fix tests after merge

* Add prefer-first rule and fix

* Add tests for prefer-first rule

* Add prefer-last rule & fix

* Add tests for prefer-last rule

---------

Co-authored-by: Denis Bogatirov <[email protected]>
Co-authored-by: Yurii Prykhodko <[email protected]>

* Add prefer match file name (#62)

* Add prefer-conditional-expressions rule and fix

* Add tests for prefer-conditional-expressions rule

* fix nested test plugin path

* Fix tests after merge

* Add prefer-first rule and fix

* Add tests for prefer-first rule

* Add prefer-last rule & fix

* Add tests for prefer-last rule

* Add prefer-match-file-name rule

* Add tests for prefer-match-file-name rule

* Typos, naming

* Typos, naming

* rm todo comment

* Update lint_test/prefer_match_file_name_test.dart

* Update lint_test/prefer_match_file_name_test.dart

---------

Co-authored-by: Denis Bogatirov <[email protected]>
Co-authored-by: Yurii Prykhodko <[email protected]>
Co-authored-by: Yurii Prykhodko <[email protected]>

* Rename custom lints to use snake_case (#66)

* Rename custom lints to use snake_case

* Rename missed parameter

---------

Co-authored-by: vladimir-beloded <[email protected]>

* Take into account the constructor initializer in the avoid_unused_parameters rule (#67)

Co-authored-by: vladimir-beloded <[email protected]>

* Fix linter issues

* Bump custom_lint_builder version

* Update LICENSE to include third party code license

* Allow magic numbers for default values (#72)

* Allow magic numbers for default values

* More tests

---------

Co-authored-by: vladimir-beloded <[email protected]>

* Ignore magic number in constructor initializer (#73)

* Ignore magic number in constructor initializer

* Minor naming improvement

---------

Co-authored-by: vladimir-beloded <[email protected]>

* Remove DCM steps from readme

* Fix avoid-late if initialized (#71)

* Implement proper-super-calls (#77)

* Fix avoid-late if initialized

* Update lint_test/avoid_late_keyword_test.dart

Co-authored-by: Yurii Prykhodko <[email protected]>

* Apply suggestions from code review

Co-authored-by: Yurii Prykhodko <[email protected]>

* Custom avoid-late

* Fix naming

* Apply suggestions from code review

Co-authored-by: Yurii Prykhodko <[email protected]>

* Avoid late simplified

* Update lib/lints/avoid_late_keyword/models/avoid_late_keyword_parameters.dart

Co-authored-by: Yurii Prykhodko <[email protected]>

* Avoid-late ignored_types

* Avoid-late ignored_types formatted

* Update lib/lints/avoid_late_keyword/models/avoid_late_keyword_parameters.dart

Co-authored-by: Yurii Prykhodko <[email protected]>

* Avoid-late ignored_types fix

* Avoid-late ignored_types Fix

* Avoid-late allow_initialized testcases

* Update lint_test/avoid_late_keyword_allow_initialized_test/pubspec.yaml

Co-authored-by: Yurii Prykhodko <[email protected]>

* Update lib/lints/avoid_late_keyword/models/avoid_late_keyword_parameters.dart

Co-authored-by: Yurii Prykhodko <[email protected]>

* Allow subclasses for avoid-late whitelist

* Fix naming

* Short-circuit of there's no ignored types

* Short-circuit earlier

* Update lib/lints/avoid_late_keyword/avoid_late_keyword_rule.dart

Co-authored-by: Yurii Prykhodko <[email protected]>

* Avoid-late ignored_types tests

* Avoid-late add testcases

* Proper-super-calls impl

* Proper-super-calls format

* Apply suggestions from code review

Co-authored-by: Yurii Prykhodko <[email protected]>

* Proper-super-calls refactoring

* Update lib/lints/proper_super_calls/proper_super_calls_rule.dart

Co-authored-by: Yurii Prykhodko <[email protected]>

* Proper-super-keyword annotation check

* Proper-super-keyword format

* Proper-super-calls cleanup

---------

Co-authored-by: Yurii Prykhodko <[email protected]>
Co-authored-by: Yurii Prykhodko <[email protected]>

* Ignore magic numbers in widget parameters (#74)

* Ignore magic numbers in widget parameters

* Add lint parameter to ignore magic numbers in widget params

* Improve the allowed_in_widget_params parameter to exclude magic numbers in nested objects of Widget parameters

* Add tests for disabled allowed_in_widget_params lint parameter

* Remove unnecessary dependency

---------

Co-authored-by: vladimir-beloded <[email protected]>

* Set default severity level to warning (#78)

Co-authored-by: vladimir-beloded <[email protected]>

---------

Co-authored-by: Nikodem Bernat <[email protected]>
Co-authored-by: Vadym Khokhlov <[email protected]>
Co-authored-by: Yaroslav <[email protected]>
Co-authored-by: Yaroslav Laptiev <[email protected]>
Co-authored-by: vladimir-beloded <[email protected]>
Co-authored-by: Denis Bogatirov <[email protected]>
Co-authored-by: DenisBogatirov <[email protected]>
Co-authored-by: Yurii Prykhodko <[email protected]>
Co-authored-by: solid-vovabeloded <[email protected]>
Co-authored-by: Illia Romanenko <[email protected]>
Co-authored-by: maxxlab <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants