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

Add swiftlint script and configuration #29

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
208 changes: 208 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -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"
3 changes: 2 additions & 1 deletion Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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: [:],
Expand Down
13 changes: 13 additions & 0 deletions Scripts/swiftlint.sh
Original file line number Diff line number Diff line change
@@ -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