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

Throwing unnecessary empty_count #3488

Closed
2 tasks done
lalkrishna opened this issue Jan 12, 2021 · 2 comments
Closed
2 tasks done

Throwing unnecessary empty_count #3488

lalkrishna opened this issue Jan 12, 2021 · 2 comments

Comments

@lalkrishna
Copy link

New Issue Checklist

Describe the bug

I'm getting Empty Count Violation:

Prefer checking isEmpty over comparing count to zero. (empty_count)

for the below code.

guard let count = notify.object as? Int else { fatalError() }
if count == 0 {
}
Complete output when running SwiftLint, including the stack trace and command used
$ swiftlint lint

Environment

#  SwiftLint Rules Configuration
#  https://github.com/realm/SwiftLint
#
# By default, SwiftLint uses a set of sensible default rules you can adjust:
disabled_rules: # rule identifiers turned on by default to exclude from running
#  - colon
#  - comma
#  - control_statement
  - trailing_whitespace
  - unused_optional_binding
  - multiple_closures_with_trailing_closure
  - unused_capture_list
  
opt_in_rules: # some rules are turned off by default, so you need to opt-in
  - empty_count # Find all the available rules by running: `swiftlint rules`

line_length: 200
function_body_length: 60

#type_body_length:
#  - 300 # warning
#  - 400 # error
## or they can set both explicitly
#file_length:
#  warning: 500
#  error: 1200

nesting:
   type_level: 3
identifier_name:
#  min_length: # only min_length
#    error: 4 # only error
  excluded: # excluded via string array
    - id
    - URL
    - GlobalAPIKey
    - km
cyclomatic_complexity:
  ignores_case_statements: true
type_name:
  min_length: 3 # only warning
  max_length: # warning and error
    warning: 50
    error: 60
@davidpasztor
Copy link

davidpasztor commented Mar 22, 2022

Unfortunately this seems like an intentional decision as described in this comment on #827

@jpsim
Copy link
Collaborator

jpsim commented Mar 23, 2022

@davidpasztor is exactly right. There's only so much information SwiftLint has at the pre-typechecked stage. Consider writing an analyzer rule similar to #3914 if you'd like a more accurate, typechecked version of the empty_count rule.

@jpsim jpsim closed this as completed Mar 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants