Skip to content
This repository was archived by the owner on Jul 16, 2023. It is now read-only.

feat: add static code diagnostic arguments-ordering #1047

Merged
merged 1 commit into from
Nov 27, 2022
Merged

feat: add static code diagnostic arguments-ordering #1047

merged 1 commit into from
Nov 27, 2022

Conversation

roman-petrov
Copy link
Contributor

@roman-petrov roman-petrov commented Oct 21, 2022

arguments-ordering rule

Enforces named argument order in function and constructor invocations to be the same as corresponding named parameter declaration order.

The rule can be used together with sort_child_properties_last rule by setting child-last: true in rule configuration.

⚙️ Config example

dart_code_metrics:
  ...
  rules:
    ...
    - arguments-ordering:
        child-last: true

Example

❌ Bad:

Person buildPerson({ String name, String surname, String age });
// LINT
final person = buildPerson(age: 42, surname: 'The Pooh', name: 'Winnie');

✅ Good:

Person buildPerson({ String name, String surname, String age });
// LINT
final person = buildPerson(name: 'Winnie', surname: 'The Pooh', age: 42);

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@roman-petrov roman-petrov marked this pull request as draft October 21, 2022 04:12
@roman-petrov roman-petrov changed the title [WIP] feat: add static code diagnostic arguments-ordering feat: add static code diagnostic arguments-ordering Nov 25, 2022
@codecov
Copy link

codecov bot commented Nov 25, 2022

Codecov Report

Merging #1047 (465c0cd) into master (2bce6fb) will increase coverage by 0.11%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #1047      +/-   ##
==========================================
+ Coverage   84.74%   84.86%   +0.11%     
==========================================
  Files         327      330       +3     
  Lines        7196     7253      +57     
==========================================
+ Hits         6098     6155      +57     
  Misses       1098     1098              
Impacted Files Coverage Δ
...c/analyzers/lint_analyzer/rules/rules_factory.dart 75.00% <ø> (ø)
...st/arguments_ordering/arguments_ordering_rule.dart 100.00% <100.00%> (ø)
...s/rules_list/arguments_ordering/config_parser.dart 100.00% <100.00%> (ø)
...r/rules/rules_list/arguments_ordering/visitor.dart 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@roman-petrov roman-petrov marked this pull request as ready for review November 25, 2022 03:05
@roman-petrov
Copy link
Contributor Author

roman-petrov commented Nov 25, 2022

I finally finished this PR :)

This rule might be a bit hard to adopt for large code bases without CLI "auto-fix". However, I managed to test this rule on our relatively large code base and spent just about half a hour to fix all ~250 issues in VSCode by just monkey clicking "Fix" light bulb in problems panel:)

I didn't found any issues with this rule on our code base, auto fix also worked pretty well. So I assume this implementation should be quite ready to ship.

@dkrutskikh , @incendial - could you please take a look?

I've got a strange issue with automated checks for this PR and don't have any idea how it can be fixed:

image

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@incendial incendial added type: enhancement New feature or request area-rules labels Nov 26, 2022
@incendial incendial added this to the 5.1.0 milestone Nov 26, 2022
Copy link
Member

@incendial incendial left a comment

Choose a reason for hiding this comment

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

Looks great 🔥

But I bet someone might want to have a specific order 😁

@roman-petrov
Copy link
Contributor Author

roman-petrov commented Nov 27, 2022

But I bet someone might want to have a specific order 😁

Sure 😁 But it will be quite easy to implement new sorting options having "core" rule part completed.

@incendial incendial merged commit dea2cc0 into dart-code-checker:master Nov 27, 2022
@roman-petrov roman-petrov deleted the arguments-ordering-rule branch November 28, 2022 06:22
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-rules type: enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants