From 295da2d19be4aceea80252fe8bfe2e555fb3d5ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dog=CC=86ukaan=20K=C4=B1l=C4=B1c=CC=A7arslan?= Date: Thu, 25 Apr 2024 23:40:13 +0300 Subject: [PATCH] Add swiftlint script and configuration --- .swiftlint.yml | 208 +++++++++++++++++++++++++++++++++++++++++++ Project.swift | 3 +- Scripts/swiftlint.sh | 13 +++ 3 files changed, 223 insertions(+), 1 deletion(-) create mode 100755 .swiftlint.yml create mode 100755 Scripts/swiftlint.sh diff --git a/.swiftlint.yml b/.swiftlint.yml new file mode 100755 index 0000000..96689bd --- /dev/null +++ b/.swiftlint.yml @@ -0,0 +1,208 @@ +disabled_rules: + - conditional_returns_on_newline + - attributes + - custom_rules + - cyclomatic_complexity + - extension_access_modifier + - explicit_type_interface + - file_header + - identifier_name + - implicit_return + - large_tuple + - multiline_parameters + - nesting + - no_extension_access_modifier + - number_separator + - explicit_top_level_acl + - switch_case_alignment + - type_body_length + - trailing_whitespace + - statement_position + - weak_delegate + - sorted_imports + +opt_in_rules: + - closure_parameter_position + - class_delegate_protocol + - closing_brace + - closure_end_indentation + - compiler_protocol_init + - closure_spacing + - control_statement + - colon + - comma + - discarded_notification_center_observer + - dynamic_inline + - empty_count + - empty_enum_arguments + - empty_parameters + - empty_parentheses_with_trailing_closure + - explicit_init + - fatal_error_message + - file_length + - first_where + - last_where + - for_where + - force_cast + - force_try + - force_unwrapping + - function_body_length + - function_parameter_count + - generic_type_name + - implicit_getter + - leading_whitespace + - legacy_cggeometry_functions + - legacy_constant + - legacy_constructor + - legacy_nsgeometry_functions + - line_length + - mark + - nimble_operator + - notification_center_detachment + - opening_brace + - operator_usage_whitespace + - operator_whitespace + - overridden_super_call + - private_outlet + - private_unit_test + - prohibited_super_call + - protocol_property_accessors_order + - redundant_discardable_let + - redundant_nil_coalescing + - redundant_optional_initialization + - redundant_string_enum_value + - redundant_void_return + - return_arrow_whitespace + - shorthand_operator + - switch_case_on_newline + - syntactic_sugar + - todo + - trailing_comma + - trailing_newline + - trailing_semicolon + - type_name + - unused_enumerated + - unused_optional_binding + - valid_ibinspectable + - vertical_parameter_alignment + - vertical_whitespace + - void_return + - collection_alignment + - computed_accessors_order + - convenience_type + - discouraged_direct_init + - discouraged_object_literal + - duplicate_imports + - empty_string + - literal_expression_end_indentation + - multiple_closures_with_trailing_closure + - no_space_in_method_call + - private_action + - unneeded_break_in_switch + - toggle_bool + + +included: + - Buddies + - SwiftBuddiesIOS + +# Configurable Rules +#force_cast: error +#force_unwrapping: error +#sorted_imports: error +#comma: error +#closing_brace: error +#closure_end_indentation: error +#closure_parameter_position: error +#closure_spacing: error +#collection_alignment: +# severity: error +#colon: +# severity: error +#compiler_protocol_init: error +#computed_accessors_order: +# severity: error +#control_statement: error +#convenience_type: error +#discouraged_direct_init: +# severity: error +#discouraged_object_literal: +# severity: error +#duplicate_imports: error +#empty_count: +# severity: error +#empty_enum_arguments: error +#empty_parameters: error +#empty_parentheses_with_trailing_closure: error +#empty_string: error +#fatal_error_message: error +#first_where: error +#last_where: error +#for_where: error +#force_try: error +#implicit_getter: error +#leading_whitespace: error +#literal_expression_end_indentation: error +#multiple_closures_with_trailing_closure: error +#no_space_in_method_call: error +#operator_usage_whitespace: +# severity: error +#operator_whitespace: error +#overridden_super_call: +# severity: error +#private_action: error +#private_outlet: +# severity: error +#protocol_property_accessors_order: error +#redundant_discardable_let: error +#redundant_string_enum_value: error +#return_arrow_whitespace: error +#shorthand_operator: error +#unused_optional_binding: +# severity: error +#unneeded_break_in_switch: error +#trailing_comma: +# severity: error +#toggle_bool: error +#opening_brace: +# severity: error +#switch_case_on_newline: error +#trailing_newline: error +#unused_closure_parameter: error + + +# Length Rules +file_length: + warning: 1000 + error: 1500 + +function_body_length: + warning: 200 + error: 300 + +line_length: + warning: 150 + error: 750 + +# Name Rules +type_name: + min_length: 1 + max_length: 100 + warning: 40 + error: 45 + allowed_symbols: "_" + +vertical_whitespace: + max_empty_lines: 2 + +identifier_name: + min_length: 2 + excluded: + - id + +function_parameter_count: + warning: 10 + error: 20 + +# Reporter Rules +reporter: "xcode" diff --git a/Project.swift b/Project.swift index 3e87537..45c68b6 100644 --- a/Project.swift +++ b/Project.swift @@ -208,7 +208,8 @@ enum Modules: CaseIterable { productName: "LocalizationCodegen", bundleId: "com.swiftbuddies.localization", sources: ["SwiftBuddiesIOS/Targets/ScriptsModule/LocalizationCodegen/**"], - scripts: [], + scripts: [TargetScript.pre(path: "Scripts/swiftlint.sh", + name: "SwiftLint Script")], dependencies: [.package(product: "ArgumentParser", type: .runtime, condition: .none)], coreDataModels: [], environmentVariables: [:], diff --git a/Scripts/swiftlint.sh b/Scripts/swiftlint.sh new file mode 100755 index 0000000..bed319b --- /dev/null +++ b/Scripts/swiftlint.sh @@ -0,0 +1,13 @@ +if test -d "/opt/homebrew/bin/"; then + PATH="/opt/homebrew/bin/:${PATH}" +fi + +export PATH + +SOURCES_PATH="SwiftBuddiesIOS/Targets" + +if which swiftlint >/dev/null; then + swiftlint --config .swiftlint.yml --quiet $SOURCES_PATH +else + echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint" +fi