# See all available rules: https://realm.github.io/SwiftLint/rule-directory.html

# Don't use `included` parameter even though we'd like to limit which paths should be linted.
# When it's set, all paths passed as arguments to the command are ignored.

# SwiftLint by default isn't efficient in excluding, `--use-alternative-excluding` flag makes it faster.
excluded:
  - .direnv
  - android
  - apps
  - bin
  - docs
  - exponent-view-template
  - fastlane
  - guides
  - home
  - ios/Pods
  - ios/vendored
  - ios/versioned
  - ios/versioned-react-native
  - node_modules
  - packages/*/ios/Tests
  - packages/*/ios/UITests
  - packages/expo-module-template
  - packages/expo-module-template-local
  - packages/expo-dev-menu/ios/OverlayContainer
  - react-native-lab
  - scripts
  - secrets
  - template-files
  - tools

# Enable rules that are turned off by default. Run `swiftlint rules` to see what's available to opt-in.
opt_in_rules:
  - anyobject_protocol
  - array_init
  - closure_body_length
  - closure_end_indentation
  - closure_spacing
  - collection_alignment
  - comma_inheritance
  - conditional_returns_on_newline
  - direct_return
  - discouraged_object_literal
  - empty_collection_literal
  - empty_count
  - empty_string
  - enum_case_associated_values_count
  - fatal_error_message
  - file_name_no_space
  - force_unwrapping
  - identical_operands
  - implicitly_unwrapped_optional
  - indentation_width
  - legacy_objc_type
  - literal_expression_end_indentation
  - local_doc_comment
  - lower_acl_than_parent
  - multiline_arguments
  - multiline_function_chains
  - multiline_literal_brackets
  - multiline_parameters
  - multiline_parameters_brackets
  - no_grouping_extension
  - number_separator
  - operator_usage_whitespace
  - overridden_super_call
  - prefer_zero_over_explicit_init
  - prohibited_super_call
  - redundant_nil_coalescing
  - static_operator
  - superfluous_else
  - unavailable_function
  - unneeded_parentheses_in_closure_argument
  - unowned_variable_capture
  - unused_capture_list
  - vertical_parameter_alignment_on_call
  - vertical_whitespace_closing_braces
  - vertical_whitespace_opening_braces
  - yoda_condition

# Disable some rules that are turned on by default.
disabled_rules:
  - reduce_boolean
  - todo
  - weak_delegate

# Rules run by `swiftlint analyze`.
analyzer_rules:
  - capture_variable
  - unused_declaration
  - unused_import

# Prefer using AnyObject over class for class-only protocols.
anyobject_protocol: warning

# Prefer using `Array(seq)` over `seq.map { $0 }` to convert a sequence into an Array.
array_init: warning

# Non-constant variables should not be listed in a closure’s capture list
# to avoid confusion about closures capturing variables at creation time.
capture_variable: warning

# Closure bodies should not span too many lines.
closure_body_length:
  warning: 30
  error: 50

# Closure end should have the same indentation as the line that started it.
closure_end_indentation: warning

# Closure expressions should have a single space inside each brace.
closure_spacing: warning

# All elements in a collection literal should be vertically aligned.
collection_alignment:
  severity: warning
  align_colons: false

# Use commas to separate types in inheritance lists.
comma_inheritance: warning

# if, for, guard, switch, while, and catch statements shouldn’t unnecessarily wrap their conditionals or arguments in parentheses.
control_statement: warning

# Limits the complexity of function bodies.
cyclomatic_complexity:
  warning: 12
  error: 20
  ignores_case_statements: true

# Directly return the expression instead of assigning it to a variable first.
direct_return: warning

# Prefer initializers over object literals.
discouraged_object_literal:
  severity: error
  image_literal: true
  color_literal: true

# Prefer checking `isEmpty` over comparing collection to an empty array or dictionary literal.
empty_collection_literal: warning

# Prefer checking `isEmpty` over comparing count to zero.
empty_count:
  severity: warning
  only_after_dot: true

# When using trailing closures, empty parentheses should be avoided after the method call.
empty_parentheses_with_trailing_closure: warning

# Prefer checking `isEmpty` over comparing string to an empty string literal.
empty_string: warning

# Number of associated values in an enum case should be low.
enum_case_associated_values_count:
  warning: 5
  error: 6

# A `fatalError` call should have a message.
fatal_error_message: error

# Files should not span too many lines.
file_length:
  warning: 850
  error: 900
  ignore_comment_only_lines: true

# File name should not contain any whitespace.
file_name_no_space:
  severity: error

# Force casts should be avoided.
force_cast: error

# Force tries should be avoided.
force_try: error

# Force unwrapping should be avoided.
force_unwrapping: error

# Functions bodies should not span too many lines.
function_body_length:
  warning: 250
  error: 300

# Comparing two identical operands is likely a mistake.
identical_operands: error

# Identifier names should only contain alphanumeric characters and start with a lowercase character or should only
# contain capital letters. In an exception to the above, variable names may start with a capital letter when they are
# declared static and immutable. Variable names should not be too long or too short.
identifier_name:
  min_length: 1
  max_length:
    warning: 35
    error: 50
  validates_start_with_lowercase: warning
  # Ignore Sweet API components as they intentionally start with the uppercase letter.
  allowed_symbols:
    [
      '_',
      'AsyncFunction',
      'Class',
      'Constants',
      'Constructor',
      'Events',
      'Function',
      'Name',
      'OnAppBecomesActive',
      'OnAppContextDestroys',
      'OnAppEntersBackground',
      'OnAppEntersForeground',
      'OnCreate',
      'OnDestroy',
      'OnStartObserving',
      'OnStopObserving',
      'Prop',
      'Property',
      'View',
      'ViewManager',
    ]

# Implicitly unwrapped optionals should be avoided when possible.
implicitly_unwrapped_optional:
  severity: error

# Indent code using either one tab or the configured amount of spaces,
# unindent to match previous indentations. Don’t indent the first line.
indentation_width:
  severity: warning
  indentation_width: 2
  include_comments: false
  include_compiler_directives: false
  include_multiline_strings: true

# Tuples shouldn’t have too many members. Create a custom type instead.
large_tuple:
  warning: 10
  error: 10

# Files should not contain leading whitespace.
leading_whitespace: warning

# Struct-scoped constants are preferred over legacy global constants.
legacy_constant: warning

# Swift constructors are preferred over legacy convenience functions.
legacy_constructor: warning

# Prefer Swift value types to bridged Objective-C reference types.
legacy_objc_type: warning

# Lines should not span too many characters.
line_length:
  warning: 160
  error: 200
  ignores_urls: true
  ignores_function_declarations: false
  ignores_comments: false
  ignores_interpolated_strings: true

# Array and dictionary literal end should have the same indentation as the line that started it.
literal_expression_end_indentation: warning

# Doc comments shouldn’t be used in local scopes. Use regular comments.
local_doc_comment: warning

# Ensure declarations have a lower access control level than their enclosing parent.
lower_acl_than_parent: warning

# MARK comment should be in valid format. e.g. `// MARK: ...` or `// MARK: - ...`
mark: warning

# Arguments should be either on the same line, or one per line.
multiline_arguments:
  severity: warning

# Chained function calls should be either on the same line, or one per line.
multiline_function_chains: warning

# Multiline literals should have their surrounding brackets in a new line.
multiline_literal_brackets: warning

# Functions and methods parameters should be either on the same line, or one per line.
multiline_parameters:
  severity: warning

# Types should be nested at most 1 level deep, and functions should be nested at most 2 levels deep.
nesting:
  type_level: 1
  function_level: 2

# Multiline parameters should have their surrounding brackets in a new line.
multiline_parameters_brackets: warning

# Extensions shouldn’t be used to group code within the same source file.
no_grouping_extension: warning

# Underscores should be used as thousand separator in large decimal numbers.
number_separator:
  severity: warning
  minimum_length: 5

# Operators should be surrounded by a single whitespace when they are being used.
operator_usage_whitespace:
  severity: warning

# A doc comment should be attached to a declaration.
orphaned_doc_comment: warning

# Some overridden methods should always call super.
overridden_super_call:
  severity: warning

# Prefer `.zero` over explicit init with zero parameters (e.g. `CGPoint(x: 0, y: 0)`).
prefer_zero_over_explicit_init: warning

# Some methods should not call super.
prohibited_super_call:
  severity: warning

# When declaring properties in protocols, the order of accessors should be `get set`.
protocol_property_accessors_order: warning

# nil coalescing operator is only evaluated if the lhs is nil, coalescing operator with nil as rhs is redundant.
redundant_nil_coalescing: warning

# Initializing an optional variable with nil is redundant.
redundant_optional_initialization: warning

# Operators should be declared as static functions, not free functions.
static_operator: warning

# Else branches should be avoided when the previous if-block exits the current scope.
superfluous_else: warning

# Files should have a single trailing newline.
trailing_newline: warning

# Lines should not have trailing semicolons.
trailing_semicolon: warning

# Lines should not have trailing whitespace.
trailing_whitespace:
  severity: warning
  ignores_empty_lines: false
  ignores_comments: false

# Type bodies should not span too many lines.
type_body_length:
  warning: 750
  error: 800

# Type name should only contain alphanumeric characters, start with an uppercase character and span between 3 and 35 characters in length.
type_name:
  min_length: 3
  max_length:
    warning: 40
    error: 50

# Unimplemented functions should be marked as unavailable.
unavailable_function: warning

# Parentheses are not needed when declaring closure arguments.
unneeded_parentheses_in_closure_argument: warning

# Prefer capturing references as weak to avoid potential crashes.
unowned_variable_capture: warning

# Unused reference in a capture list should be removed.
unused_capture_list: warning

# Unused parameter in a closure should be replaced with `_`.
unused_closure_parameter: warning

# Declarations should be referenced at least once within all files linted.
unused_declaration:
  severity: warning
  include_public_and_open: false

# When the index or the item is not used, `.enumerated()` can be removed.
unused_enumerated: warning

# All imported modules should be required to make the file compile.
unused_import:
  severity: warning

# Prefer `!= nil` over `let _ =`
unused_optional_binding:
  severity: warning
  ignore_optional_try: false

# Setter value is not used.
unused_setter_value: warning

# Function parameters should be aligned vertically if they’re in multiple lines in a method call.
vertical_parameter_alignment_on_call: warning

# Limit vertical whitespace to a single empty line.
vertical_whitespace:
  severity: warning
  max_empty_lines: 1

# Don’t include vertical whitespace (empty line) before closing braces.
vertical_whitespace_closing_braces:
  severity: warning
  only_enforce_before_trivial_lines: false

# Don’t include vertical whitespace (empty line) after opening braces.
vertical_whitespace_opening_braces: warning

# Prefer `-> Void` over `-> ()`.
void_return: warning

# The variable should be placed on the left, the constant on the right of a comparison operator.
yoda_condition: warning
