indentation_width warning when preprocessor statements are used #4030
Closed
Description
New Issue Checklist
- Updated SwiftLint to the latest version
- I searched for existing GitHub issues
Describe the bug
With enabled rule indentation_width
you will get warnings for preprocessor statements in nested structures. Xcode's cmd + i
formats the code correctly (preprocessor statements always at the beginning of a line, all other commands, view modifiers etc. indented as expected.
Code Snippet
private struct MyView: View {
#if os(iOS)
@State var scrollViewHeight: CGFloat = .zero
#endif
@EnvironmentObject var config: MyConfig
var body: some View {
#if os(iOS)
ScrollView { // <- This triggers warning
content
}
.frame(maxHeight: scrollViewHeight)
#else
content // <- This triggers warning
#endif
}
}
Complete output when running SwiftLint, including the stack trace and command used
$ swiftlint lint
Warning Output
Indentation Width Violation: Code should be indented using one tab or 4 spaces. (indentation_width)
Environment
- SwiftLint version (run
swiftlint version
to be sure)? -0.47.1
- Installation method used (Homebrew, CocoaPods, building from source, etc)? -
SPM Build Tool Plugin
- Paste your configuration file:
excluded:
disabled_rules:
- identifier_name
- notification_center_detachment
- orphaned_doc_comment
- statement_position
- todo
- unused_capture_list
opt_in_rules:
- array_init
- attributes
- closure_end_indentation
- closure_spacing
- collection_alignment
- colon
- convenience_type
- discarded_notification_center_observer
- discouraged_object_literal
- empty_collection_literal
- empty_count
- empty_string
- enum_case_associated_values_count
- explicit_init
- fatal_error_message
- first_where
- force_unwrapping
- identical_operands
- implicitly_unwrapped_optional
- indentation_width
- last_where
- leading_whitespace
- legacy_random
- literal_expression_end_indentation
- modifier_order
- multiline_arguments
- multiline_function_chains
- multiline_literal_brackets
- multiline_parameters
- multiline_parameters_brackets
- number_separator
- operator_usage_whitespace
- pattern_matching_keywords
- prefer_self_type_over_type_of_self
- redundant_nil_coalescing
- redundant_type_annotation
- required_deinit
- sorted_imports
- static_operator
- strict_fileprivate
- switch_case_alignment
- switch_case_on_newline
- toggle_bool
- trailing_closure
- unavailable_function
- unneeded_parentheses_in_closure_argument
- vertical_whitespace_closing_braces
- vertical_whitespace_opening_braces
- yoda_condition
analyzer_rules:
- unused_declaration
- unused_import
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
force_cast: warning
force_try: warning
function_body_length:
warning: 60
legacy_hashing: error
identifier_name:
excluded:
- i
- id
- x
- y
- z
line_length:
warning: 140
error: 240
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: false
ignores_comments: true
vertical_whitespace:
max_empty_lines: 1
reporter: "xcode"
- Are you using nested configurations? -
NO
- Which Xcode version are you using (check
xcodebuild -version
)?
Xcode 14.0
Build version 14A5270f
- Do you have a sample that shows the issue? -
see example above