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

Prefer Swift constructors to legacy ones #242

Merged
merged 3 commits into from
Nov 30, 2015
Merged

Prefer Swift constructors to legacy ones #242

merged 3 commits into from
Nov 30, 2015

Conversation

marcelofabri
Copy link
Collaborator

What do you think, @jpsim?

]
)

public func validateFile(file: File) -> [StyleViolation] {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I have a few suggestions:

  1. It's more performant to only scan the file for matches once, which can be done by merging all the regular expressions into one.
  2. Instead of excluding comments and strings, we should check if the match is a SyntaxKind.Identifier which is more semantically correct, even though it probably won't make a difference in practice.

So this function could be refactored to this:

public func validateFile(file: File) -> [StyleViolation] {
    let constructors = ["CGRectMake", "CGPointMake", "CGSizeMake", "CGVectorMake",
        "NSMakeRange"]

    let pattern = "\\b(" + constructors.joinWithSeparator("|") + ")\\b"

    return file.matchPattern(pattern, withSyntaxKinds: [.Identifier]).map {
        StyleViolation(ruleDescription: self.dynamicType.description,
            location: Location(file: file, offset: $0.location))
    }
}

@jpsim
Copy link
Collaborator

jpsim commented Nov 29, 2015

This is great @marcelofabri! I only had a few minor suggestions regarding the implementation.

Could you also add an entry for this to the changelog?

Thanks for doing this.

//

import SourceKittenFramework
import SwiftXPC
Copy link
Collaborator

Choose a reason for hiding this comment

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

We don't use SwiftXPC in this file, so this import statement can be removed.

@marcelofabri marcelofabri changed the title [WIP] Prefer Swift constructors to legacy ones Prefer Swift constructors to legacy ones Nov 29, 2015
@marcelofabri
Copy link
Collaborator Author

🎉

@jpsim
Copy link
Collaborator

jpsim commented Nov 30, 2015

👍 awesome work!

jpsim added a commit that referenced this pull request Nov 30, 2015
Prefer Swift constructors to legacy ones
@jpsim jpsim merged commit 8bb9809 into realm:master Nov 30, 2015
@jpsim jpsim mentioned this pull request Nov 30, 2015
5 tasks
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.

2 participants