solid-software / solid_lints

🟧 Lints for Dart and Flutter based on software industry standards and best practices.
Other
36 stars 17 forks source link

Change the baseline from 2 to 10 as described in the docs for `cyclomatic_complexity` lint #146

Closed arthurbcd closed 3 months ago

arthurbcd commented 3 months ago

In the docs, you say the baseline is 10:

cyclomatic_complexity

According to the reference, we use 10 as the baseline value.

Reference: NIST 500-235 item 2.5

Reference: https://lints.solid.software/docs/rulesets/main

But in the actual code, we find this:

/// Cyclomatic complexity metric limits configuration.
class CyclomaticComplexityParameters {
  /// Threshold cyclomatic complexity level, exceeding it triggers a warning.
  final int maxComplexity;

  static const _defaultMaxComplexity = 2; // <- Why it's 2?

  /// Constructor for [CyclomaticComplexityParameters] model
  const CyclomaticComplexityParameters({
    required this.maxComplexity,
  });

  /// Method for creating from json data
  factory CyclomaticComplexityParameters.fromJson(Map<String, Object?> json) =>
      CyclomaticComplexityParameters(
        maxComplexity: json['max_complexity'] as int? ?? _defaultMaxComplexity,
      );
}
illia-romanenko commented 3 months ago

Hi @arthurbcd, this is an interesting observation. I think that 2 was used by default there, and it might not be very reasonable in the end.

Assumption is that our bundled analysis options will be used as it contains other configuration rules that are based on standards where cyclomatic_complexity it's set to 10: https://github.com/solid-software/solid_lints/blob/383581ee8dbbd09e52915d52cd821bd27f5293c5/lib/analysis_options.yaml#L55

image
illia-romanenko commented 3 months ago

Closed in the latest commit.