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

Adding SyntacticSugar rule #851

Closed
wants to merge 3 commits into from
Closed

Adding SyntacticSugar rule #851

wants to merge 3 commits into from

Conversation

marcelofabri
Copy link
Collaborator

I've implemented the "Syntactic Sugar" from https://github.com/raywenderlich/swift-style-guide#syntactic-sugar (also mentioned in #319).

It should be easy to make this rule correctable, but I think it's better to do that on a later PR.

Also, should this be opt-in? (It's not currently)

@@ -77,7 +77,8 @@ extension File {
}
set {
if newValue {
responseCache.values[cacheKey] = Optional<[String: SourceKitRepresentable]>.None
let value: [String: SourceKitRepresentable]? = nil
responseCache.values[cacheKey] = value
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried just using responseCache.values[cacheKey] = nil or responseCache.values[cacheKey] = .None but a test started to fail 😬

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we are using Optional.None as failed state of response from SourceKit.

@codecov-io
Copy link

codecov-io commented Oct 21, 2016

Current coverage is 85.75% (diff: 100%)

No coverage report found for master at 1b82909.

Powered by Codecov. Last update 1b82909...c1a02fc

Copy link
Collaborator

@norio-nomura norio-nomura left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this! 🙏
Looks good to me other than I commented. 👍

should this be opt-in?

IMO, I can accept this rule as opt-out.

public func validateFile(file: File) -> [StyleViolation] {
let types = ["Optional", "ImplicitlyUnwrappedOptional", "Array", "Dictionary"]

let pattern = "\\b(" + types.joinWithSeparator("|") + ")\\b\\s*<.*?>"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Second \\b would not be needed.

@marcelofabri
Copy link
Collaborator Author

I've updated the regex in ab7ede0 🚀

Thanks for reviewing this 💯

@norio-nomura
Copy link
Collaborator

Could you please resolve conflicts?

@marcelofabri
Copy link
Collaborator Author

Done!

@norio-nomura
Copy link
Collaborator

should this be opt-in?

IMO, I can accept this rule as opt-out.

@realm/swiftlint: How do you think of that this rule should be opt-in or opt-out?

@jpsim
Copy link
Collaborator

jpsim commented Nov 25, 2016

This looks great, and I think it's fine to keep on-by-default. I'll address the merge conflict and make an new PR.

@jpsim jpsim mentioned this pull request Nov 25, 2016
@jpsim
Copy link
Collaborator

jpsim commented Nov 25, 2016

Merged in #896.

@jpsim jpsim closed this Nov 25, 2016
@marcelofabri marcelofabri deleted the syntatic-sugar-rule branch November 25, 2016 22:15
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

Successfully merging this pull request may close these issues.

4 participants