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

[BUG] avoid-unused-parameter: false positive for switch expressions #1242

Open
@NANASHI0X74

Description

@NANASHI0X74

Environment and configuration

DCM version: 5.7.4
Dart SDK version: 3.0.0

Configuration
include: package:flutter_lints/flutter.yaml

linter:
  rules:
    - always_declare_return_types
    - always_use_package_imports
    - avoid_bool_literals_in_conditional_expressions
    - avoid_catches_without_on_clauses
    - avoid_catching_errors
    - avoid_classes_with_only_static_members
    - avoid_double_and_int_checks
    - avoid_dynamic_calls
    - avoid_empty_else
    - avoid_equals_and_hash_code_on_mutable_classes
    - avoid_escaping_inner_quotes
    - avoid_final_parameters
    - avoid_implementing_value_types
    - avoid_js_rounded_ints
    - avoid_multiple_declarations_per_line
    - avoid_positional_boolean_parameters
    - avoid_private_typedef_functions
    - avoid_redundant_argument_values
    - avoid_returning_null
    - avoid_returning_null_for_future
    - avoid_returning_this
    - avoid_setters_without_getters
    - avoid_shadowing_type_parameters
    - avoid_slow_async_io
    - avoid_type_to_string
    - avoid_types_as_parameter_names
    - avoid_types_on_closure_parameters
    - avoid_unused_constructor_parameters
    - avoid_void_async
    - await_only_futures
    - camel_case_extensions
    - camel_case_types
    - cancel_subscriptions
    - cascade_invocations
    - cast_nullable_to_non_nullable
    - close_sinks
    - comment_references
    - conditional_uri_does_not_exist
    - curly_braces_in_flow_control_structures
    - depend_on_referenced_packages
    - directives_ordering
    - discarded_futures
    - do_not_use_environment
    - empty_catches
    - eol_at_end_of_file
    - file_names
    - flutter_style_todos
    - hash_and_equals
    - iterable_contains_unrelated_type
    - join_return_with_assignment
    - leading_newlines_in_multiline_strings
    - list_remove_unrelated_type
    - literal_only_boolean_expressions
    - missing_whitespace_between_adjacent_strings
    - no_adjacent_strings_in_list
    - no_default_cases
    - no_duplicate_case_values
    - no_runtimeType_toString
    - non_constant_identifier_names
    - noop_primitive_operations
    - null_check_on_nullable_type_parameter
    - omit_local_variable_types
    - one_member_abstracts
    - only_throw_errors
    - package_api_docs
    - parameter_assignments
    - prefer_asserts_in_initializer_lists
    - prefer_asserts_with_message
    - prefer_constructors_over_static_methods
    - prefer_expression_function_bodies
    - prefer_final_in_for_each
    - prefer_final_locals
    - prefer_foreach
    - prefer_generic_function_type_aliases
    - prefer_if_elements_to_conditional_expressions
    - prefer_int_literals
    - prefer_is_empty
    - prefer_is_not_empty
    - prefer_iterable_whereType
    - prefer_mixin
    - prefer_null_aware_method_calls
    - prefer_single_quotes
    - prefer_typing_uninitialized_variables
    - require_trailing_commas
    - secure_pubspec_urls
    - sized_box_shrink_expand
    - sort_constructors_first
    - sort_pub_dependencies
    - sort_unnamed_constructors_first
    - test_types_in_equals
    - throw_in_finally
    - tighten_type_of_initializing_formals
    - type_annotate_public_apis
    - unawaited_futures
    - unnecessary_await_in_return
    - unnecessary_lambdas
    - unnecessary_null_aware_operator_on_extension_on_nullable
    - unnecessary_null_checks
    - unnecessary_overrides
    - unnecessary_parenthesis
    - unnecessary_raw_strings
    - unnecessary_statements
    - unnecessary_to_list_in_spreads
    - unrelated_type_equality_checks
    - use_colored_box
    - use_decorated_box
    - use_enums
    - use_if_null_to_convert_nulls_to_bools
    - use_is_even_rather_than_modulo
    - use_late_for_private_fields_and_variables
    - use_named_constants
    - use_raw_strings
    - use_setters_to_change_properties
    - use_string_buffers
    - use_super_parameters
    - use_test_throws_matchers
    - use_to_and_as_if_applicable
    - valid_regexps
    - void_checks

analyzer:
  plugins:
    - dart_code_metrics
  language:
    strict-casts: true
    strict-inference: true
    strict-raw-types: true
  errors:
    invalid_annotation_target: ignore

dart_code_metrics:
  metrics:
    cyclomatic-complexity: 10
    technical-debt:
      threshold: 1000
      todo-cost: 150
      ignore-cost: 250
      ignore-for-file-cost: 400
      as-dynamic-cost: 300
      deprecated-annotations-cost: 50
      unit-type: "Points"
    number-of-parameters: 4
    maximum-nesting-level: 3
    source-lines-of-code: 30
  metrics-exclude:
    - test/**
    - config/**
    - lib/firebase_options.dart
  rules:
    - always-remove-listener
    - ban-name:
        entries:
          - ident: Segment
            description: Please use InstanceableSegment instead.
          - ident: LDClient
            description: Please use LaunchDarkly instead.
          - ident: SharedPreferences
            description: Please use Preferences instead.
    - avoid-banned-imports:
      entries:
        - paths: [ "lib/.*" ]
          deny: [ "package:flutter/cupertino.dart" ]
          message: "Do not import Flutter Cupertino Design library, we should not depend on it! This is an Android only app"
    - avoid-collection-methods-with-unrelated-types
    - avoid-duplicate-exports
    - avoid-expanded-as-spacer
    - avoid-global-state
    - avoid-returning-widgets
    - avoid-missing-enum-constant-in-map
    - avoid-nested-conditional-expressions:
        acceptable-level: 2
    - avoid-non-ascii-symbols
    - avoid-shrink-wrap-in-lists
    - avoid-throw-in-catch-block
    - avoid-top-level-members-in-tests
    - avoid-unnecessary-setstate
    - avoid-unrelated-type-assertions
    - avoid-unused-parameters
    - avoid-wrapping-in-padding
    - binary-expression-operand-order
    - check-for-equals-in-render-object-setters
    - consistent-update-render-object
    - double-literal-format
    - no-boolean-literal-compare
    - no-empty-block
    - no-equal-then-else
    - no-object-declaration
    - prefer-commenting-analyzer-ignores
    - prefer-conditional-expressions
    - prefer-conditional-expressions
    - prefer-correct-edge-insets-constructor
    - prefer-correct-identifier-length:
        exceptions: [ 'id','i' ]
        max-identifier-length: 45
        min-identifier-length: 3
    - prefer-correct-test-file-name
    - prefer-correct-type-name
    - prefer-enums-by-name
    - prefer-extracting-callbacks:
        allowed-line-count: 3
    - prefer-first
    - prefer-immediate-return
    - prefer-iterable-of
    - prefer-last
    - prefer-match-file-name:
      exclude:
        - test/**
    - prefer-moving-to-variable
    - prefer-single-widget-per-file:
        ignore-private-widgets: true
    - tag-name

  anti-patterns:
    - long-method
    - long-parameter-list

What did you do?

sealed class HubRepoValue {
  Hub? get asOption => switch (this) { 
       //                      ^^^^  lint here (yellow underline)
        HubRepoLoading() || HubRepoHubUnset() => null,
        HubRepoHubSet(value: final value) => value,
      };
}

class HubRepoLoading extends HubRepoValue {}

class HubRepoHubUnset extends HubRepoValue {}

class HubRepoHubSet extends HubRepoValue {
  HubRepoHubSet(this.value);
  final Hub value;
}

What did you expect to happen?

no lint, code doesn't have unused paramters

What actually happened?

running flutter pub run dart_code_metrics:metrics analyze lib won't actually output this issue- I've noticed that sometimes issues I see in my Editor (emacs), reported from the dart analyzer as lsp server with the dcm plugin, aren't output when using pub run and also are only shown after the dartanalyzer has been running for some time. I'm not sure whether this is a known problem, but it's something I've not had the time to look into more closely.

But from my IDE's list of issues:

warn   common/lib/src/data/repository/hub_repository.dart:53 Parameter is unused.

this is the line with the switch(this) expression, where "this" is underlined.

Participation

  • I am willing to submit a pull request for this issue.

Additional comments

No response

Metadata

Metadata

Assignees

Labels

type: bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions