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

Unused Capture List Violation: Unused reference self when self only used in guard let #4804

Closed
2 tasks done
bobbradley opened this issue Mar 10, 2023 · 1 comment · Fixed by #4814
Closed
2 tasks done
Assignees
Labels
bug Unexpected and reproducible misbehavior.

Comments

@bobbradley
Copy link

bobbradley commented Mar 10, 2023

New Issue Checklist

Describe the bug

If a closure uses [weak self] and it's only use of self is to guard let self then it still warns that self is not used. This use of guard let self allows subsequent code in the block to not require prefixing with self. But this makes SwiftLint think self is not used.

Complete output when running SwiftLint, including the stack trace and command used
$ swiftlint lint MyFile.swift
warning: Unused Capture List Violation: Unused reference self in a capture list should be removed. (unused_capture_list)

Environment

  • SwiftLint version (run swiftlint version to be sure)? 0.50.3
  • Installation method used (Homebrew, CocoaPods, building from source, etc)? homebrew
  • Paste your configuration file:
disabled_rules:
  - file_length
  - for_where
  - implicit_return  
  - large_tuple
  - nesting
  - todo
  - strict_fileprivate
  - trailing_comma

analyzer_rules:
  - unused_declaration
  - unused_import

opt_in_rules:
  - array_init
  - attributes
  - comment_spacing
  - closure_end_indentation
  - closure_spacing
  - collection_alignment
  - control_statement
  - convenience_type
  - discouraged_object_literal
  - duplicate_imports
  - duplicated_key_in_dictionary_literal
  - empty_collection_literal
  - empty_count
  - empty_parameters
  - empty_parentheses_with_trailing_closure
  - empty_string
  - enum_case_associated_values_count
  - fatal_error_message
  - file_name_no_space
  - first_where
  - force_cast
  - force_try
  - force_unwrapping
  - implicitly_unwrapped_optional
  - indentation_width
  - last_where
  - leading_whitespace
  - legacy_random
  - literal_expression_end_indentation
  - mark
  - missing_docs
  - modifier_order
  - multiline_arguments
  - multiline_function_chains
  - multiline_literal_brackets
  - multiline_parameters
  - multiline_parameters_brackets
  - no_space_in_method_call
  - opening_brace
  - operator_usage_whitespace
  - operator_whitespace
  - overridden_super_call
  - pattern_matching_keywords
  - prefer_self_type_over_type_of_self
  - prefer_zero_over_explicit_init
  - redundant_nil_coalescing
  - redundant_set_access_control
  - redundant_string_enum_value
  - redundant_type_annotation
  - redundant_void_return
  - return_arrow_whitespace
  - self_in_property_initialization
  - shorthand_operator
  - sorted_imports
  - statement_position
  - switch_case_alignment
  - toggle_bool
  - trailing_closure
  - trailing_newline
  - type_body_length
  - unavailable_function
  - unneeded_parentheses_in_closure_argument
  - unowned_variable_capture
  - vertical_whitespace_closing_braces
  - vertical_whitespace_opening_braces
  - weak_delegate
  - xct_specific_matcher
  - yoda_condition

# Overrides
attributes:
  always_on_line_above: ["@objc"]
  always_on_same_line: ["@_spi"]

colon:
  flexible_right_spacing: true

cyclomatic_complexity:
  ignores_case_statements: true

function_body_length:
  warning: 100

generic_type_name:
  max_length: 50

identifier_name:
  allowed_symbols: [_]
  min_length:
    warning: 1
  max_length: 60

indentation_width:
  indentation_width: 4
  include_comments: true

line_length:
  ignores_interpolated_strings: true
  ignores_urls: true
  
missing_docs:
  excludes_inherited_types: false

trailing_whitespace:
  ignores_empty_lines: true

type_body_length:
  warning: 500
  error: 1000

vertical_whitespace:
  max_empty_lines: 1
  • Are you using nested configurations? No
  • Which Xcode version are you using (check xcodebuild -version)? Running standalone.
  • Do you have a sample that shows the issue? Yes
closure = { [weak self] in
	guard let self else {
		return
	}
	someInstanceFunction() // Implicitly uses self.
}
@bobbradley
Copy link
Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected and reproducible misbehavior.
Projects
None yet
2 participants