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

Update legacy_constant to support CGFloat.pi #1205

Merged
merged 3 commits into from Jan 18, 2017
Merged

Update legacy_constant to support CGFloat.pi #1205

merged 3 commits into from Jan 18, 2017

Conversation

ghost
Copy link

@ghost ghost commented Jan 17, 2017

Resolves #1198 Prefer CGFloat.pi to CGFloat(M_PI).

Summary

  • Moved examples for legacy_constant into its own file, similar to type_name, to allow for Swift 2 vs Swift 3 configurations
  • Added CGFloat.pi and Float.pi support to legacy_constant
    • Adjusted validation to only look for word boundary at the beginning rather than also anchoring at the end, to support finding a multiple word pattern such as CGFloat(M_PI)
    • Adjusted validation to ensure that the set of SyntaxKind found is a subset of the set of SyntaxKind desired, rather than equal as arrays (as you now have two identifiers rather than only one being matched on occasion).
    • Adjust correction to ensure initial word boundary
  • Added Swift 2 specific tests for legacy_constant in addition to the regular Swift 3 ones

Resolves #1198 `Prefer CGFloat.pi to CGFloat(M_PI)`.
@SwiftLintBot
Copy link

SwiftLintBot commented Jan 17, 2017

1 Warning
⚠️ This PR may need tests.
6 Messages
📖 Linting Alamofire with this PR took 3.29s vs 3.32s on master (0% faster)
📖 Linting swift with this PR took 11.86s vs 11.57s on master (2% slower)
📖 Linting Aerial with this PR took 0.43s vs 0.43s on master (0% slower)
📖 Linting SourceKitten with this PR took 1.49s vs 1.48s on master (0% slower)
📖 Linting Moya with this PR took 0.45s vs 0.44s on master (2% slower)
📖 Linting realm-cocoa with this PR took 4.0s vs 3.92s on master (2% slower)

Generated by 🚫 danger

@ghost
Copy link
Author

ghost commented Jan 17, 2017

@marcelofabri @jpsim Could you re-run the Travis build without cache? They're all passing for me locally.

@marcelofabri
Copy link
Collaborator

@aamctustwo It's failing when using the swiftlint with Swift 2.3 scheme.

@codecov-io
Copy link

codecov-io commented Jan 17, 2017

Current coverage is 82.16% (diff: 100%)

Merging #1205 into master will decrease coverage by 0.01%

@@             master      #1205   diff @@
==========================================
  Files           166        166          
  Lines          8255       8249     -6   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
- Hits           6784       6778     -6   
  Misses         1471       1471          
  Partials          0          0          

Powered by Codecov. Last update 0b268ad...980b8ff


let pattern = "\\b(" + constants.joined(separator: "|") + ")\\b"
private static let legacyConstants: [String] = {
switch SwiftVersion.current {
Copy link
Collaborator

Choose a reason for hiding this comment

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

could this be refactored to return Array(legacyPatterns.keys)?

}()

public func validate(file: File) -> [StyleViolation] {
let pattern = "\\b(" + LegacyConstantRule.legacyConstants.joined(separator: "|") + ")"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know this was already in this way, but you can use a non-capture group here for a performance boost

@@ -245,7 +245,7 @@ extension File {
typealias RangePatternTemplate = (NSRange, String, String)
let matches: [RangePatternTemplate]
matches = patterns.flatMap({ pattern, template -> [RangePatternTemplate] in
return match(pattern: pattern).filter { range, kinds in
return match(pattern: "\\b" + pattern).filter { range, kinds in
Copy link
Collaborator

Choose a reason for hiding this comment

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

shouldn't this be changed on the caller?

Copy link
Collaborator

@marcelofabri marcelofabri 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 implementing this! 🙇

@marcelofabri marcelofabri merged commit 0e426b4 into realm:master Jan 18, 2017
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.

3 participants