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

'operator_usage_whitespace' rule conflicts with Image Literal #1028

Closed
mylifeasdog opened this issue Dec 22, 2016 · 7 comments
Closed

'operator_usage_whitespace' rule conflicts with Image Literal #1028

mylifeasdog opened this issue Dec 22, 2016 · 7 comments
Labels
bug Unexpected and reproducible misbehavior.

Comments

@mylifeasdog
Copy link

When using image literal, It's should not triggered

@jpsim
Copy link
Collaborator

jpsim commented Dec 22, 2016

How are you triggering this rule with an image literal?

@mylifeasdog
Copy link
Author

mylifeasdog commented Dec 22, 2016

Anywhere in code.

imageView.image = #imageLiteral(resourceName: "image")   // Triggered

button.setImage(#imageLiteral(resourceName: "image"), for: .normal)   // Triggered
button.setImage(#imageLiteral(resourceName: "image") , for: .normal)   // Triggered
button.setImage( #imageLiteral(resourceName: "image"), for: .normal)   // Triggered
button.setImage( #imageLiteral(resourceName: "image") , for: .normal)   // Triggered

let imageView = UIImageView(image: #imageLiteral(resourceName: "image"))   // Triggered
let imageView = UIImageView(image: #imageLiteral(resourceName: "image") )   // Triggered

let images = [ #imageLiteral(resourceName: "image-1"), #imageLiteral(resourceName: "image-2") ]   // Triggered

@jpsim
Copy link
Collaborator

jpsim commented Dec 22, 2016

I'm sorry I can't reproduce this with the code you've shared.

$ swiftlint version
0.14.0
$ cat .swiftlint.yml
whitelist_rules:
  - operator_usage_whitespace
$ cat imageliteral.swift
imageView.image = #imageLiteral(resourceName: "image")   // Triggered

button.setImage(#imageLiteral(resourceName: "image"), for: .normal)   // Triggered
button.setImage(#imageLiteral(resourceName: "image") , for: .normal)   // Triggered
button.setImage( #imageLiteral(resourceName: "image"), for: .normal)   // Triggered
button.setImage( #imageLiteral(resourceName: "image") , for: .normal)   // Triggered

let imageView = UIImageView(image: #imageLiteral(resourceName: "image"))   // Triggered
let imageView = UIImageView(image: #imageLiteral(resourceName: "image") )   // Triggered

let images = [ #imageLiteral(resourceName: "image-1"), #imageLiteral(resourceName: "image-2") ]   // Triggered

let a  = 0 // I added this to show the rule is working...
$ swiftlint lint --path imageliteral.swift
Loading configuration from '.swiftlint.yml'
Linting Swift files at path imageliteral.swift
Linting 'imageliteral.swift' (1/1)
imageliteral.swift:13:6: warning: Operator Usage Whitespace Violation: Operators should be surrounded by a single whitespace when they are being used. (operator_usage_whitespace)
Done linting! Found 1 violation, 0 serious in 1 file.

@mylifeasdog
Copy link
Author

mylifeasdog commented Dec 22, 2016

My bad.
The images name I used was just meant for this example.
But the real images name I used was something like this "icon-bar-save", "icon-share", "image-logo-small".
And because of "-" in the images name that made it triggered.
Maybe we should consider ignoring the operator in image name ?

@mylifeasdog
Copy link
Author

$ swiftlint version
0.14.0

$ cat .swiftlint.yml
whitelist_rules:
  - operator_usage_whitespace

$ cat test.swift 
imageView.image = #imageLiteral(resourceName: "image-1")   // Triggered

button.setImage(#imageLiteral(resourceName: "image-1"), for: .normal)   // Triggered
button.setImage(#imageLiteral(resourceName: "image-1") , for: .normal)   // Triggered
button.setImage( #imageLiteral(resourceName: "image-1"), for: .normal)   // Triggered
button.setImage( #imageLiteral(resourceName: "image-1") , for: .normal)   // Triggered

let imageView = UIImageView(image: #imageLiteral(resourceName: "image-1"))   // Triggered
let imageView = UIImageView(image: #imageLiteral(resourceName: "image-1") )   // Triggered

let images = [ #imageLiteral(resourceName: "image-1"), #imageLiteral(resourceName: "image-2") ]   // Triggered

$ swiftlint lint --path test.swift
Loading configuration from '.swiftlint.yml'
Linting Swift files at path test.swift
Linting 'test.swift' (1/1)
test.swift:1:53: warning: Operator Usage Whitespace Violation: Operators should be surrounded by a single whitespace when they are being used. (operator_usage_whitespace)
test.swift:3:51: warning: Operator Usage Whitespace Violation: Operators should be surrounded by a single whitespace when they are being used. (operator_usage_whitespace)
test.swift:4:51: warning: Operator Usage Whitespace Violation: Operators should be surrounded by a single whitespace when they are being used. (operator_usage_whitespace)
test.swift:5:52: warning: Operator Usage Whitespace Violation: Operators should be surrounded by a single whitespace when they are being used. (operator_usage_whitespace)
test.swift:6:52: warning: Operator Usage Whitespace Violation: Operators should be surrounded by a single whitespace when they are being used. (operator_usage_whitespace)
test.swift:8:70: warning: Operator Usage Whitespace Violation: Operators should be surrounded by a single whitespace when they are being used. (operator_usage_whitespace)
test.swift:9:70: warning: Operator Usage Whitespace Violation: Operators should be surrounded by a single whitespace when they are being used. (operator_usage_whitespace)
test.swift:11:50: warning: Operator Usage Whitespace Violation: Operators should be surrounded by a single whitespace when they are being used. (operator_usage_whitespace)
test.swift:11:90: warning: Operator Usage Whitespace Violation: Operators should be surrounded by a single whitespace when they are being used. (operator_usage_whitespace)
Done linting! Found 9 violations, 0 serious in 1 file.

@marcelofabri marcelofabri added the bug Unexpected and reproducible misbehavior. label Dec 22, 2016
@marcelofabri
Copy link
Collaborator

@mylifeasdog Thanks so much for detailing it, I was able to reproduce it. I believe #1030 fixes this issue, could you please verify?

@mylifeasdog
Copy link
Author

It's fixed. Thanks.

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

No branches or pull requests

3 participants