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

Range literal constant mistakenly flagged as magic number #5430

Closed
2 tasks done
rberggreen opened this issue Jan 19, 2024 · 0 comments · Fixed by #5431
Closed
2 tasks done

Range literal constant mistakenly flagged as magic number #5430

rberggreen opened this issue Jan 19, 2024 · 0 comments · Fixed by #5431
Assignees
Labels
bug Unexpected and reproducible misbehavior.

Comments

@rberggreen
Copy link

New Issue Checklist

Describe the bug

The rule no_magic_numbers mistakenly flags a range literal, e.g. 7...8, as a magic number, even though it is declared as a static property. Other types of literal values declared in the same way, such as Ints, are not flagged.

Environment

  • SwiftLint version (run swiftlint version to be sure)?: 0.54
  • Installation method used (Homebrew, CocoaPods, building from source, etc)?: CocoaPods
  • Paste your configuration file:
only_rules:
  - array_init
  - attributes
  - block_based_kvo
  - class_delegate_protocol
  - closing_brace
  - closure_end_indentation
  - closure_parameter_position
  - collection_alignment
  - colon
  - comma
  - comment_spacing
  - compiler_protocol_init
  - computed_accessors_order
  - contains_over_filter_count
  - contains_over_filter_is_empty
  - contains_over_first_not_nil
  - contains_over_range_nil_comparison
  - control_statement
  - convenience_type
  - cyclomatic_complexity
  - deployment_target
  - direct_return
  - discouraged_direct_init
  - discouraged_none_name
  - duplicate_conditions
  - duplicate_enum_cases
  - duplicate_imports
  - duplicated_key_in_dictionary_literal
  - dynamic_inline
  - empty_collection_literal
  - empty_count
  - empty_enum_arguments
  - empty_parameters
  - empty_parentheses_with_trailing_closure
  - empty_string
  - empty_xctest_method
  - enum_case_associated_values_count
  - fallthrough
  - fatal_error_message
  - file_length
  - file_name_no_space
  - first_where
  - for_where
  - force_cast
  - force_try
  - force_unwrapping
  - function_body_length
  - function_default_parameter_at_end
  - function_parameter_count
  - generic_type_name
  - identical_operands
  - identifier_name
  - implicit_getter
  - implicit_return
  - implicitly_unwrapped_optional
  - inclusive_language
  - invalid_swiftlint_command
  - is_disjoint
  - joined_default_parameter
  - last_where
  - leading_whitespace
  - legacy_cggeometry_functions
  - legacy_constant
  - legacy_constructor
  - legacy_hashing
  - legacy_multiple
  - legacy_nsgeometry_functions
  - legacy_objc_type
  - legacy_random
  - line_length
  - literal_expression_end_indentation
  - local_doc_comment
  - lower_acl_than_parent
  - mark
  - modifier_order
  - multiline_arguments
  - multiline_arguments_brackets
  - multiline_function_chains
  - multiline_literal_brackets
  - multiline_parameters
  - multiline_parameters_brackets
  - multiple_closures_with_trailing_closure
  - no_extension_access_modifier
  - no_fallthrough_only
  - no_magic_numbers
  - no_space_in_method_call
  - ns_number_init_as_function_reference
  - nsobject_prefer_isequal
  - number_separator
  - opening_brace
  - operator_usage_whitespace
  - operator_whitespace
  - optional_enum_case_matching
  - orphaned_doc_comment
  - 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_over_fileprivate
  - private_subject
  - private_swiftui_state
  - private_unit_test
  - prohibited_super_call
  - protocol_property_accessors_order
  - reduce_boolean
  - redundant_discardable_let
  - redundant_objc_attribute
  - redundant_optional_initialization
  - redundant_self_in_closure
  - redundant_set_access_control
  - redundant_string_enum_value
  - redundant_type_annotation
  - redundant_void_return
  - return_arrow_whitespace
  - return_value_from_void_function
  - self_binding
  - self_in_property_initialization
  - shorthand_operator
  - shorthand_optional_binding
  - sorted_first_last
  - statement_position
  - superfluous_disable_command
  - switch_case_alignment
  - syntactic_sugar
  - test_case_accessibility
  - todo
  - toggle_bool
  - trailing_closure
  - trailing_comma
  - trailing_newline
  - trailing_semicolon
  - trailing_whitespace
  - type_body_length
  - type_name
  - unavailable_condition
  - unhandled_throwing_task
  - unneeded_break_in_switch
  - unneeded_override
  - unneeded_parentheses_in_closure_argument
  - unneeded_synthesized_initializer
  - unowned_variable_capture
  - untyped_error_in_catch
  - unused_closure_parameter
  - unused_control_flow_label
  - unused_enumerated
  - unused_optional_binding
  - unused_setter_value
  - valid_ibinspectable
  - vertical_parameter_alignment
  - vertical_parameter_alignment_on_call
  - vertical_whitespace
  - vertical_whitespace_closing_braces
  - vertical_whitespace_opening_braces
  - void_function_in_ternary
  - void_return
  - weak_delegate
  - xct_specific_matcher
  - xctfail_message
  - yoda_condition

excluded:
  - Pods
  - CAPPAssets/CAPPAssets/R.generated.swift

# Rule configurations
cyclomatic_complexity:
  warning: 20
  ignores_case_statements: true

empty_count:
  severity: warning

file_length:
  warning: 1000

force_cast:
  severity: warning

force_try:
  severity: warning

function_body_length:
  warning: 60

function_parameter_count:
  warning: 5
  ignores_default_parameters: true

generic_type_name:
  max_length:
    warning: 50

identifier_name:
  max_length: 
    warning: 50

line_length:
  warning: 140
  ignores_interpolated_strings: true

no_extension_access_modifier:
  severity: warning

trailing_comma:
  mandatory_comma: false

type_body_length:
  warning: 1000

reporter: "xcode"
  • Which Xcode version are you using (check xcodebuild -version)?: Xcode 15.1, Build version 15C65
  • Do you have a sample that shows the issue? Run echo "[string here]" | swiftlint lint --no-cache --use-stdin --enable-all-rules
    to quickly test if your example is really demonstrating the issue. If your example is more
    complex, you can use swiftlint lint --path [file here] --no-cache --enable-all-rules.
enum Constants {
    static let validBookingNumberLengthRange = 7...8 // This triggers a violation
}

Skärmavbild 2024-01-19 kl  11 43 03

@SimplyDanny SimplyDanny added the bug Unexpected and reproducible misbehavior. label Jan 19, 2024
@SimplyDanny SimplyDanny self-assigned this Jan 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected and reproducible misbehavior.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants