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

Improved Tooling and Coding Standards #1090

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,6 @@ fastlane/test_output
# https://github.com/johnno1962/injectionforxcode

iOSInjectionProject/

# Local configuration overrides
Meshtastic/Configuration/Local.xcconfig
21 changes: 21 additions & 0 deletions .swift-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"version": 1,
"lineLength": 190,
"indentation": {
"spaces": 4
},
"tabWidth": 4,
"maximumBlankLines": 1,
"spacesBeforeEndOfLineComments": 1,
"respectsExistingLineBreaks": true,
"lineBreakBeforeControlFlowKeywords": false,
"lineBreakBeforeEachArgument": false,
"lineBreakBeforeEachGenericRequirement": false,
"lineBreakBetweenDeclarationAttributes": false,
"prioritizeKeepingFunctionOutputTogether": false,
"indentConditionalCompilationBlocks": false,
"lineBreakAroundMultilineExpressionChainComponents": false,
"spacesAroundRangeFormationOperators": true,
"multiElementCollectionTrailingCommas": true,
"indentBlankLines": false
}
215 changes: 161 additions & 54 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -1,60 +1,167 @@
# Exclude automatically generated Swift files
excluded:
excluded: # paths to ignore during linting. Takes precedence over `included`.
- MeshtasticProtobufs

line_length: 400

type_name:
min_length: 1
max_length:
warning: 60
error: 70
excluded: iPhone # excluded via string
allowed_symbols: ["_"] # these are allowed in type names
identifier_name:
min_length: 1
max_length:
warning: 60
allowed_symbols: ["_"] # these are allowed in type names

# TODO: should review
force_try:
severity: warning # explicitly

# TODO: should review
file_length:
warning: 3500
error: 4000

# TODO: should review
disabled_rules:
- nesting
- todo
- trailing_comma
- trailing_whitespace
analyzer_rules:
- capture_variable
- typesafe_array_init
- unused_declaration
- unused_import
opt_in_rules:
- accessibility_label_for_image
- accessibility_trait_for_button
- anonymous_argument_in_multiline_closure
- array_init
- attributes
- closure_body_length
- closure_end_indentation
- closure_spacing
- collection_alignment
- contains_over_filter_count
- contains_over_filter_is_empty
- contains_over_first_not_nil
- contains_over_range_nil_comparison
- direct_return
- discarded_notification_center_observer
- discouraged_assert
- discouraged_none_name
- discouraged_object_literal
- discouraged_optional_boolean
- empty_collection_literal
- empty_count
- empty_string
- enum_case_associated_values_count
- expiring_todo
- explicit_init
- fatal_error_message
- file_header
- file_name_no_space
#- file_types_order
- first_where
- flatmap_over_map_reduce
- force_unwrapping
- identical_operands
- implicit_return
- implicitly_unwrapped_optional
- joined_default_parameter
- last_where
- legacy_objc_type
- let_var_whitespace
- literal_expression_end_indentation
- lower_acl_than_parent
- modifier_order
- multiline_arguments
- multiline_function_chains
#- multiline_parameters
- non_overridable_class_declaration
#- no_empty_block
#- number_separator
- operator_usage_whitespace
- optional_data_string_conversion
- optional_enum_case_matching
- overridden_super_call
- period_spacing
- prefer_self_in_static_references
- prefer_self_type_over_type_of_self
- prefer_zero_over_explicit_init
- private_action
- private_outlet
- private_swiftui_state
- prohibited_super_call
- reduce_into
- redundant_nil_coalescing
- redundant_self_in_closure
- redundant_type_annotation
- return_value_from_void_function
- self_binding
- shorthand_optional_binding
- sorted_enum_cases
- sorted_first_last
- static_operator
- superfluous_else
#- switch_case_on_newline
- toggle_bool
- trailing_closure
- unavailable_condition
- unhandled_throwing_task
- unneeded_parentheses_in_closure_argument
- unowned_variable_capture
- untyped_error_in_catch
#- unused_parameter
- vertical_parameter_alignment_on_call
- vertical_whitespace_closing_braces
- vertical_whitespace_opening_braces
- weak_delegate
- yoda_condition
allow_zero_lintable_files: true
# These should be updated after the code has been refactored.
closure_body_length:
warning: 50 # default: 30
error: 405 # default: 100
cyclomatic_complexity:
warning: 60
error: 70
ignores_case_statements: true

# TODO: should review
# Changed severity from error (default) to warning as there are just too many errors.
# This should be reverted back to error when all issues are fixed.
empty_count:
severity: warning
file_header:
required_pattern: |
\/\/
\/\/ .*?\.swift
\/\/ .*?
\/\/
\/\/ Created by .*? on \d{1,2}\/\d{1,2}\/(?:\d{4}|\d{2})\.
\/\/ Copyright (C) \d{4} .*? and the .*? project authors.
\/\/
\/\/ This program is free software: you can redistribute it and/or modify
\/\/ it under the terms of the GNU General Public License as published by
\/\/ the Free Software Foundation, either version 3 of the License, or
\/\/ (at your option) any later version.
\/\/
\/\/ This program is distributed in the hope that it will be useful,
\/\/ but WITHOUT ANY WARRANTY; without even the implied warranty of
\/\/ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\/\/ GNU General Public License for more details.
\/\/
\/\/ You should have received a copy of the GNU General Public License
\/\/ along with this program. If not, see https:\/\/www.gnu.org\/licenses\/.
\/\/
\/\/ SPDX-License-Identifier: GPL-3.0-or-later
\/\/
file_length:
ignore_comment_only_lines: true
# There are normally errors, as they are a source of application crashes. However, as there is an overwhelming amount
# of errors there have for the time being been lowered to warnings. This should be reverted when the all occurences
# have been fixed!
force_cast: warning
force_try: warning
force_unwrapping: warning
# These should be updated after the code has been refactored.
function_body_length:
warning: 200

# TODO: should review
warning: 50 # default: 50
error: 445 # default: 100
identifier_name:
excluded:
- x
- y
- z
# 30 chars wider than Xcode's default page guide, still readable on a MacBook Pro 16" with 'minimap' shown.
line_length:
warning: 190 # default: 120
error: 410 # default: 200
ignores_comments: true
ignores_interpolated_strings: true
ignores_urls: true
type_body_length:
warning: 400

# TODO: should review
disabled_rules: # rule identifiers to exclude from running
- operator_whitespace
- multiple_closures_with_trailing_closure
- todo

# TODO: should review
nesting:
type_level:
warning: 3

warning: 250 # default: 250
error: 475 # default: 350
custom_rules:
disable_print:
included: ".*\\.swift"
name: "Disable `print()`"
regex: "((\\bprint)|(Swift\\.print))\\s*\\("
message: "Consider using a dedicated log message or the Xcode debugger instead of using `print`. ex. logger.debug(...)"
severity: warning
disable_print:
included: ".*\\.swift"
name: "Disable `print()`"
regex: "((\\bprint)|(Swift\\.print))\\s*\\("
message: "Consider using a dedicated log message or the Xcode debugger instead of using `print`. ex. logger.debug(...)"
severity: warning
Loading