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

Add minimum_fraction_length to number_separator #1202

Merged
merged 5 commits into from
Jan 17, 2017

Conversation

bjarkehs
Copy link
Contributor

This adds minimum_fraction_length as a configuration to number_separator. If specified it overrules minimum_length.

Closes #1200

@bjarkehs bjarkehs force-pushed the decimal_number_separator branch from 9d66167 to ad749ac Compare January 16, 2017 17:40
@SwiftLintBot
Copy link

SwiftLintBot commented Jan 16, 2017

12 Warnings
⚠️ This PR introduced a violation in swift: /stdlib/public/SDK/Foundation/Decimal.swift#L194:17: error: Shorthand Operator Violation: Prefer shorhand operators (+=, -=, *=, /=) over doing the operation and assigning. (shorthand_operator)
⚠️ This PR introduced a violation in swift: /stdlib/public/SDK/Dispatch/Data.swift#L257:3: error: Shorthand Operator Violation: Prefer shorhand operators (+=, -=, *=, /=) over doing the operation and assigning. (shorthand_operator)
⚠️ This PR introduced a violation in swift: /stdlib/public/SDK/Foundation/Date.swift#L192:9: error: Shorthand Operator Violation: Prefer shorhand operators (+=, -=, *=, /=) over doing the operation and assigning. (shorthand_operator)
⚠️ This PR introduced a violation in swift: /stdlib/public/SDK/Foundation/Date.swift#L199:9: error: Shorthand Operator Violation: Prefer shorhand operators (+=, -=, *=, /=) over doing the operation and assigning. (shorthand_operator)
⚠️ This PR introduced a violation in swift: /stdlib/public/SDK/Foundation/Decimal.swift#L180:17: error: Shorthand Operator Violation: Prefer shorhand operators (+=, -=, *=, /=) over doing the operation and assigning. (shorthand_operator)
⚠️ This PR introduced a violation in swift: /stdlib/public/SDK/Foundation/Decimal.swift#L182:17: error: Shorthand Operator Violation: Prefer shorhand operators (+=, -=, *=, /=) over doing the operation and assigning. (shorthand_operator)
⚠️ This PR introduced a violation in swift: /stdlib/public/core/Collection.swift#L1088:7: error: Shorthand Operator Violation: Prefer shorhand operators (+=, -=, *=, /=) over doing the operation and assigning. (shorthand_operator)
⚠️ This PR introduced a violation in swift: /stdlib/public/SDK/Foundation/Decimal.swift#L186:17: error: Shorthand Operator Violation: Prefer shorhand operators (+=, -=, *=, /=) over doing the operation and assigning. (shorthand_operator)
⚠️ This PR introduced a violation in swift: /stdlib/public/SDK/Foundation/Decimal.swift#L188:17: error: Shorthand Operator Violation: Prefer shorhand operators (+=, -=, *=, /=) over doing the operation and assigning. (shorthand_operator)
⚠️ This PR introduced a violation in swift: /stdlib/public/SDK/Foundation/Decimal.swift#L190:17: error: Shorthand Operator Violation: Prefer shorhand operators (+=, -=, *=, /=) over doing the operation and assigning. (shorthand_operator)
⚠️ This PR introduced a violation in swift: /stdlib/public/SDK/Foundation/Decimal.swift#L192:17: error: Shorthand Operator Violation: Prefer shorhand operators (+=, -=, *=, /=) over doing the operation and assigning. (shorthand_operator)
⚠️ This PR introduced a violation in swift: /stdlib/public/SDK/Foundation/Decimal.swift#L184:17: error: Shorthand Operator Violation: Prefer shorhand operators (+=, -=, *=, /=) over doing the operation and assigning. (shorthand_operator)
18 Messages
📖 Linting realm-cocoa with this PR took 4.25s vs 4.81s on master (11% faster)
📖 This PR fixed a violation in swift: /stdlib/public/SDK/Dispatch/Data.swift#L257:3: error: Shorthand Operator Violation: Prefer shorthand operators (+=, -=, *=, /=) over doing the operation and assigning. (shorthand_operator)
📖 This PR fixed a violation in swift: /stdlib/public/SDK/Foundation/Date.swift#L192:9: error: Shorthand Operator Violation: Prefer shorthand operators (+=, -=, *=, /=) over doing the operation and assigning. (shorthand_operator)
📖 This PR fixed a violation in swift: /stdlib/public/SDK/Foundation/Date.swift#L199:9: error: Shorthand Operator Violation: Prefer shorthand operators (+=, -=, *=, /=) over doing the operation and assigning. (shorthand_operator)
📖 This PR fixed a violation in swift: /stdlib/public/SDK/Foundation/Decimal.swift#L180:17: error: Shorthand Operator Violation: Prefer shorthand operators (+=, -=, *=, /=) over doing the operation and assigning. (shorthand_operator)
📖 This PR fixed a violation in swift: /stdlib/public/SDK/Foundation/Decimal.swift#L182:17: error: Shorthand Operator Violation: Prefer shorthand operators (+=, -=, *=, /=) over doing the operation and assigning. (shorthand_operator)
📖 This PR fixed a violation in swift: /stdlib/public/SDK/Foundation/Decimal.swift#L184:17: error: Shorthand Operator Violation: Prefer shorthand operators (+=, -=, *=, /=) over doing the operation and assigning. (shorthand_operator)
📖 This PR fixed a violation in swift: /stdlib/public/SDK/Foundation/Decimal.swift#L186:17: error: Shorthand Operator Violation: Prefer shorthand operators (+=, -=, *=, /=) over doing the operation and assigning. (shorthand_operator)
📖 This PR fixed a violation in swift: /stdlib/public/SDK/Foundation/Decimal.swift#L188:17: error: Shorthand Operator Violation: Prefer shorthand operators (+=, -=, *=, /=) over doing the operation and assigning. (shorthand_operator)
📖 This PR fixed a violation in swift: /stdlib/public/core/Collection.swift#L1088:7: error: Shorthand Operator Violation: Prefer shorthand operators (+=, -=, *=, /=) over doing the operation and assigning. (shorthand_operator)
📖 This PR fixed a violation in swift: /stdlib/public/SDK/Foundation/Decimal.swift#L192:17: error: Shorthand Operator Violation: Prefer shorthand operators (+=, -=, *=, /=) over doing the operation and assigning. (shorthand_operator)
📖 This PR fixed a violation in swift: /stdlib/public/SDK/Foundation/Decimal.swift#L194:17: error: Shorthand Operator Violation: Prefer shorthand operators (+=, -=, *=, /=) over doing the operation and assigning. (shorthand_operator)
📖 Linting Alamofire with this PR took 3.82s vs 4.03s on master (5% faster)
📖 Linting swift with this PR took 12.71s vs 14.77s on master (13% faster)
📖 Linting Aerial with this PR took 0.49s vs 0.54s on master (9% faster)
📖 Linting SourceKitten with this PR took 1.69s vs 1.97s on master (14% faster)
📖 Linting Moya with this PR took 0.5s vs 0.55s on master (9% faster)
📖 This PR fixed a violation in swift: /stdlib/public/SDK/Foundation/Decimal.swift#L190:17: error: Shorthand Operator Violation: Prefer shorthand operators (+=, -=, *=, /=) over doing the operation and assigning. (shorthand_operator)

Generated by 🚫 danger

@codecov-io
Copy link

codecov-io commented Jan 16, 2017

Current coverage is 82.09% (diff: 59.25%)

Merging #1202 into master will decrease coverage by 0.08%

@@             master      #1202   diff @@
==========================================
  Files           165        165          
  Lines          8182       8201    +19   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
+ Hits           6724       6733     +9   
- Misses         1458       1468    +10   
  Partials          0          0          

Powered by Codecov. Last update 706d572...4a9d354

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.

Seems good other than some small comments 👍

@@ -13,6 +13,11 @@
[Aaron McTavish](https://github.com/aamctustwo)
[#1169](https://github.com/realm/SwiftLint/issues/1169)

* Update `number_separator` rule to allow for specifying
minimum length of fraction.
Copy link
Collaborator

Choose a reason for hiding this comment

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

missing two trailing whitespaces

@@ -113,10 +113,18 @@ public struct NumberSeparatorRule: OptInRule, CorrectableRule, ConfigurationProv
return prefixes.filter { lowercased.hasPrefix($0) }.isEmpty
}

private func isValid(number: String, reversed: Bool) -> (Bool, String) {
private func isValid(number: String, reversed: Bool, isFraction: Bool) -> (Bool, String) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

you can remove the reversed parameter now, since it's always equivalent to !isFraction

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah right, for some reason my tests wouldn't pass locally even without changing anything. So I decided not to touch it.


public var consoleDescription: String {
return severityConfiguration.consoleDescription + ", minimum_length: \(minimumLength)"
let minimumFractionLengthDescription: String
if let minimumFractionLength = self.minimumFractionLength {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think you need to use self. here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, my bad. Code style from current project 😄

@marcelofabri
Copy link
Collaborator

This seems good to me, but as we're complicating the configuration would you mind adding some tests to make sure we don't break it in the future?

@bjarkehs
Copy link
Contributor Author

Yeah that sounds good. I'll give it a try.

@bjarkehs
Copy link
Contributor Author

So I'm not entirely sure how to write the tests. But I added some triggering and non-triggering examples.

@marcelofabri
Copy link
Collaborator

So I'm not entirely sure how to write the tests. But I added some triggering and non-triggering examples.

I hope you don't mind, but I've pushed dc2ebdf which does some improvements. Basically:

  • Extract testNumberSeparator to another class to avoid the 200-line body length limit error
  • Add violation marks on triggering examples
  • Add corrections to the tested rule configurations

@marcelofabri marcelofabri merged commit 0b268ad into realm:master Jan 17, 2017
@bjarkehs
Copy link
Contributor Author

That's perfectly fine, I'll just have a look at your commit to see how its done for the future 👍 Thanks for the help.

@bjarkehs bjarkehs deleted the decimal_number_separator branch January 17, 2017 08:25
@revolter
Copy link
Contributor

revolter commented Mar 3, 2022

Why doesn't this configuration item show up on the website?

https://realm.github.io/SwiftLint/number_separator.html

@jpsim
Copy link
Collaborator

jpsim commented Mar 3, 2022

Why doesn't this configuration item show up on the website?

Because nothing was being included in the configuration description when the field was unset. Fixed in 54a2463.

@revolter
Copy link
Contributor

revolter commented Mar 3, 2022

Oh, I thought that it extracts the configuration items automatically (e.g. using reflection). Thanks for the quick fix!

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.

Configure number_separator for minimum length for either side of decimal
6 participants