realm / realm/SwiftLint

Possible closure_end_indentation rule issue

Open
#4,730 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

discussion enhancement
Dominant language
Swift
Stars
19.7k
Forks
2.3k
Avg merge
1d 1h
Merged PRs (30d)
11

Description

New Issue Checklist
Describe the bug

It seems that in a specific case of a function call with a completion block, triggering the closure_end_indentation rule to fail.

return reqMan.run(
	url: "api/Data/templates",
	method: .post,
	params: params) { result in
		switch result {
		case .success(let data):
			let templates = try? MemeTemplateModel.array(data)
			completion(.success(templates))
		case .failure(let error):
			completion(.failure(error))
		}
	}

Sorry if I'm missing something. I have read the rules and it seems to me that this is the correct piece of code.

Complete output when running SwiftLint, including the stack trace and command used
$ swiftlint lint
Linting Swift files in current working directory
warning: Closure End Indentation Violation: Closure end should have the same indentation as the line that started it. Expected 2, got 3. (closure_end_indentation)
Done linting! Found 1 violation, 0 serious in 9 files.
Environment
  • SwiftLint version 0.50.3
  • Installation method used Homebrew
  • Paste your configuration file:
excluded:
  - ${PWD}/Carthage
  - ${PWD}/Pods
  - ${PWD}/DerivedData

disabled_rules:
  - discarded_notification_center_observer
  - notification_center_detachment
  - orphaned_doc_comment
  - todo
  - unused_capture_list
  - function_parameter_count

opt_in_rules:
  - array_init
  - attributes
  - closure_spacing
  - collection_alignment
  - closure_end_indentation
  - colon # promote to error
  - convenience_type
  - discouraged_object_literal
  - empty_collection_literal
  - empty_count
  - empty_string
  - enum_case_associated_values_count
  - fatal_error_message
  - first_where
  - force_unwrapping
  - implicitly_unwrapped_optional
  - indentation_width
  - last_where
  - legacy_random
  - literal_expression_end_indentation
  - multiline_arguments
  - multiline_function_chains
  - multiline_literal_brackets
  - multiline_parameters
  - multiline_parameters_brackets
  - operator_usage_whitespace
  - overridden_super_call
  - pattern_matching_keywords
  - prefer_self_type_over_type_of_self
  - redundant_nil_coalescing
  - redundant_type_annotation
  - strict_fileprivate
  - toggle_bool
  - trailing_closure
  - unneeded_parentheses_in_closure_argument
  - vertical_whitespace_closing_braces
  - vertical_whitespace_opening_braces
  - yoda_condition


custom_rules:
  array_constructor:
    name: "Array/Dictionary initializer"
    regex: '[let,var] .+ = (\[.+\]\(\))'
    capture_group: 1
    message: "Use explicit type annotation when initializing empty arrays and dictionaries"
    severity: warning


attributes:
  always_on_same_line:
    - "@IBSegueAction"
    - "@IBAction"
    - "@NSManaged"
    - "@objc"

force_cast: warning
force_try: warning
function_body_length:
    warning: 60

legacy_hashing: error

identifier_name:
  min_length:
    warning: 1
  excluded:
    - i
    - id
    - x
    - y
    - z

indentation_width:
  indentation_width: 4

line_length:
  ignores_urls: true
  ignores_function_declarations: true
  ignores_comments: true

multiline_arguments:
  first_argument_location: next_line
  only_enforce_after_first_closure_on_first_line: true
  
private_over_fileprivate:
  validate_extensions: true

trailing_whitespace:
  ignores_empty_lines: true
  ignores_comments: true

vertical_whitespace:
  max_empty_lines: 2

analyzer_rules:
  - unused_import

  • Are you using nested configurations? No
  • Which Xcode version are you using? Xcode 14.2 Build version 14C18
  • Do you have a sample that shows the issue? Run echo "[string here]" | swiftlint lint --no-cache --use-stdin --enable-all-rules
    to quickly test if your example is really demonstrating the issue. If your example is more
    complex, you can use swiftlint lint --path [file here] --no-cache --enable-all-rules.
// This triggers a violation:
// Closure End Indentation Violation: Closure end should have the same indentation as the line that started it. Expected 0, got 1. (closure_end_indentation)
// Multiline Arguments Brackets Violation: Multiline arguments should have their surrounding brackets in a new line. (multiline_arguments_brackets)
UIView.animate(
	withDuration: 1,
	delay: 0) {
		// sample
		print("a")
	}

I use codestyle RayWenderlich, so I don't consider multiline_arguments_brackets a mistake

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the provided UIView.animate and completion-block samples through swiftlint lint --no-cache --use-stdin --enable-all-rules, focusing on the closure_end_indentation rule. Trace how the rule determines the closure's starting indentation and compare that with the reported expected values. Done means the sample's valid indentation is handled without the reported false violation, with coverage for the case.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.