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

I167 #171

Closed
wants to merge 7 commits into from
Closed

I167 #171

wants to merge 7 commits into from

Conversation

sufftea
Copy link
Collaborator

@sufftea sufftea commented May 2, 2024

No description provided.

Comment on lines 97 to 98
final isIgnored = config.parameters.matchMethod(node) ||
config.parameters.matchClass(node);
Copy link
Collaborator

Choose a reason for hiding this comment

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

The class_name parameter means that the method_name in the class_name should not be processed by this lint. Not the whole class.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It does work this way.

If you only specify the class name, then the entire class will be ignored, but if you specify both class and method name, then only this method in this class will be ignored.

exclude:
  # excludes a matching method in a matching class
  - method_name: excludeMethod
    class_name: ExcludeClass
  # excludes a matching method anywhere
  - method_name: excludeFunction
  # excludes all methods within a matching class
  - class_name: ExcludeEntireClass

Copy link
Collaborator

Choose a reason for hiding this comment

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

Then we should make it more clear here since currently it looks confusing. I'd suggest improving the naming.

@@ -48,6 +55,11 @@ class AvoidUnusedParametersVisitor extends RecursiveAstVisitor<void> {
parameters.parameters.isEmpty) {
return;
}

if (ignoredEntities.matchClass(node)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the idea is to create a mechanism that will allow us to easilly reuse such code between different linter rules instead of just implementing it separately for each rule.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It has to be used slightly differently in different rules. I.e. in this one, the check has to be performed in the visitor, instead of directly in the run function, and matchClass and matchMethod have to be used separately.

Most of the logic (parsing and matching against the list) is still inside the IgnoredEntitiesModel. Having two methods like that seemed like the minimal amount of code that is still flexible enough to adapt to different rules.


I just checked, and I think this particular rule can be implemented without the visitor. I can try that, but it won't change the way the check is performed here.

/// Threshold cyclomatic complexity level, exceeding it triggers a warning.
final int maxComplexity;
/// `max_complexity` configuration
final MaxCyclomaticComplexityParameters maxCyclomaticComplexity;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I do not think you need to create a separate class for extra params. Just go ahead and inherit this parameters class from the IgnoredEntitiesModel.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think it's easier to implement fromJson this way. Otherwise:

class CyclomaticComplexityParams extends IgnoredEntitiesModel {
  // ...  
  factory CyclomaticComplexityParams.fromJson(Map<String, Object?> json) {
    // With more properties, I'll have to go through all of them:
    final entities = IgnoredEntitiesModel.fromJson(json).entities;

    return CyclomaticComplexityParams(
      entities: entities,
      other: 1,
    );
  }
}

@sufftea sufftea force-pushed the i167 branch 2 times, most recently from bf44545 to 7cddd57 Compare May 2, 2024 15:22
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