realm / SwiftLint

A tool to enforce Swift style and conventions.
https://realm.github.io/SwiftLint
MIT License
18.67k stars 2.22k forks source link

Colon rule - apply_to_dictionaries: false is not respected #1901

Closed DG0BAB closed 3 years ago

DG0BAB commented 7 years ago

New Issue Checklist

Bug Report

Since version 0.23.0 the "apply_to_dictionaries: false" for the colon rule isn't respected anymore. In our Project we specify dictionaries like [key : value]. The bug only appears if value is of type Any. This worked fine until version 0.23.0 with "apply_to_dictionaries: false"

Environment

line_length:
  warning: 180
  ignores_comments: true

colon:
  apply_to_dictionaries: false

identifier_name:
  min_length:
    error: 3
  max_length:
    warning: 60
  excluded:     # excluded via string array
    - qa
    - QA
    - id
    - i
    - iD
  allowed_symbols:
    - _

vertical_whitespace:
    max_empty_lines: 5

function_body_length:
    warning: 80
    error: 150

disabled_rules:
    todo

excluded: # paths to ignore during linting. overridden by `included`.
  - Carthage
echo "[String : Any]" | swiftlint lint --no-cache --use-stdin --enable-all-rules
Loading configuration from '.swiftlint.yml'
<nopath>:1:2: warning: Colon Violation: Colons should be next to the identifier when specifying a type and next to the key in dictionary literals. (colon)
// This triggers a violation:
let foo: [String : Any]

// This does not trigger a violation:
let foo: [String : Int]
echo "[String : Int]" | swiftlint lint --no-cache --use-stdin --enable-all-rules
Loading configuration from '.swiftlint.yml'
Done linting! Found 0 violations, 0 serious in 1 file.
serges147 commented 7 years ago

+1

marcelofabri commented 7 years ago

apply_to_dictionaries is only verified for dictionary literals. In terms of language, literals and dictionary type declarations are different things. Feel free to submit a PR to improve this, but my initial guess is that it might be tricky to get it right.

DG0BAB commented 7 years ago

Yeah, you are right. Only dictionary literals are ignored and not dictionary declarations. But that changed with version 0.23.x. In former versions even dictionary declarations were ignored. So currently we are still using version 0.22 as a workaround.

broadwaylamb commented 7 years ago

+1

marcelofabri commented 7 years ago

PRs are welcome 😉

jakewelton commented 7 years ago

+1

gcrevell commented 6 years ago

+1

ArthurMaroulier commented 6 years ago

+1

guidomb commented 6 years ago

@marcelofabri I've just tested this on master and the issue seems to solved. Based on the commit history from version 0.25.0 to master it seems that https://github.com/realm/SwiftLint/commit/dddb0f6cdd0f486e41257406e9cdc2d07f8f131c fixed it.

Should this issue be closed? Do you have an ETA for the next release?

marcelofabri commented 6 years ago

@guidomb I think this is still valid. dddb0f6 is about another issue and I don't believe it would affect this one.

guidomb commented 6 years ago

@marcelofabri Yeap my bad! I was using the wrong build. I'd like to help fixing this issue. Any tips where to take a look?

I guess this method and probably this are good starting points.

guidomb commented 6 years ago

@marcelofabri Here is a first attempt of fixing this issue but some tests are failing I'd like to see if my patch makes sense

vanics commented 6 years ago

+1

p4checo commented 6 years ago

+1 😇

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had any recent activity. Please comment to prevent this issue from being closed. Thank you for your contributions!