Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit 94da429

Browse files
committed
Merge branch 'deploy/1.4.1' into productive
2 parents c93650a + 7810e26 commit 94da429

File tree

10 files changed

+261
-67
lines changed

10 files changed

+261
-67
lines changed

.swiftlint.yml

Lines changed: 151 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
opt_in_rules:
2+
- attributes
3+
- closure_end_indentation
4+
- closure_spacing
25
- empty_count
3-
# - missing_docs
4-
5-
disabled_rules:
6-
- vertical_whitespace
7-
- cyclomatic_complexity
6+
- explicit_init
7+
- fatal_error_message
8+
- file_header
9+
- first_where
10+
- implicit_return
11+
- implicitly_unwrapped_optional
12+
- nimble_operator
13+
- no_extension_access_modifier
14+
- number_separator
15+
- operator_usage_whitespace
16+
- overridden_super_call
17+
- private_outlet
18+
- prohibited_super_call
19+
- redundant_nil_coalescing
20+
- switch_case_on_newline
821

922
included:
1023
- Sources
@@ -14,4 +27,136 @@ excluded:
1427
- Carthage
1528
- Sources/Code/Extensions/ColorSpaces.swift
1629

17-
line_length: 150
30+
line_length: 180
31+
32+
file_header:
33+
required_pattern: |
34+
\/\/
35+
\/\/ .*?\.swift
36+
\/\/ [\S ]+
37+
\/\/
38+
\/\/ Created by .*? on \d{1,2}\.\d{1,2}\.\d{2}\.
39+
\/\/ Copyright © \d{4} [\S ]+\. All rights reserved\.
40+
\/\/
41+
42+
custom_rules:
43+
closing_brace_whitespace:
44+
included: ".*.swift"
45+
regex: '(?:\n| {2,})\}\)? *\n *[^ \n\})\]]'
46+
name: "Closing Brace Whitespace"
47+
message: "Empty line required after closing curly braces if code with same indentation follows."
48+
severity: warning
49+
closure_params_parantheses:
50+
included: ".*.swift"
51+
regex: '\{\s*\([^):]+\)\s*in'
52+
name: "Unnecessary Closure Params Parantheses"
53+
message: "Don't use parantheses around non-typed parameters in a closure."
54+
severity: warning
55+
ending_closure:
56+
included: ".*.swift"
57+
regex: '(?:\(|, | *\S+ *: *)\{[^\}]+\}\) *\n'
58+
name: "Ending Closure"
59+
message: "Don't use '(' and ')' on the last closure of a method – remove them instead."
60+
severity: warning
61+
if_as_guard:
62+
included: ".*.swift"
63+
regex: '\n *if [^\{]+\{\s*return[^\n]*\n *\}(?! *else)'
64+
name: "If as Guard"
65+
message: "Don't use an if statement to just return – use guard for such cases instead."
66+
severity: warning
67+
late_force_unwrapping:
68+
included: ".*.swift"
69+
regex: '\(\S+\?\.\S+\)!'
70+
name: "Late Force Unwrapping"
71+
message: "Don't use ? first to force unwrap later – directly unwrap within the parantheses."
72+
severity: warning
73+
long_switch_case:
74+
included: ".*.swift"
75+
regex: 'case (?:let )?\.[^\n]+\n((?!\s*switch)[^\n\}]+\n){5,}?\s*(case|\})'
76+
name: "Long Switch Cases"
77+
message: "Use a maximum of 3 lines within each case."
78+
severity: warning
79+
missing_docs:
80+
included: ".*.swift"
81+
regex: '\n *(?!\/\/\/)(\/\/)?[^\n\/]*\n *(?:public|open)'
82+
name: "Missing Docs"
83+
message: "Types, properties and methods with public or open access level should be documented."
84+
severity: warning
85+
multiple_closure_params:
86+
included: ".*.swift"
87+
regex: '\} *\) *\{'
88+
name: "Multiple Closure Params"
89+
message: "Don't use multiple in-line closures – save one or more of them to variables instead."
90+
severity: warning
91+
return_whitespace:
92+
included: ".*.swift"
93+
regex: '( {4}\S[^\n]+\n){2,} {4}return|( {8}\S[^\n]+\n){2,} {8}return|( {12}\S[^\n]+\n){2,} {12}return|( {16}\S[^\n]+\n){2,} {16}return|( {20}\S[^\n]+\n){2,} {20}return|( {24}\S[^\n]+\n){2,} {24}return'
94+
name: "Return Whitespace"
95+
message: "Put an empty line before the return line if two or more other lines in closure."
96+
severity: warning
97+
single_line_guard:
98+
included: ".*.swift"
99+
regex: 'guard[^\{]{2,100}else\s*\{\s*\n\s*return.{2,60}\}'
100+
name: "Single Line Guard"
101+
message: "Use a single line guard for simple checks."
102+
severity: warning
103+
space_before_comment:
104+
included: ".*.swift"
105+
regex: '\n[ ]{0}[^\/ \n][^\n]*\n[ ]{0}\/\/|\n[ ]{4}[^\/ \n][^\n]*\n[ ]{4}\/\/|\n[ ]{8}[^\/ \n][^\n]*\n[ ]{8}\/\/|\n[ ]{16}[^\/ \n][^\n]*\n[ ]{16}\/\/|\n[ ]{20}[^\/ \n][^\n]*\n[ ]{20}\/\/|\n[ ]{24}[^\/ \n][^\n]*\n[ ]{24}\/\/'
106+
name: "Space Before Comment"
107+
message: "Always put a space line before a comment line and always comment code beforehand."
108+
severity: warning
109+
too_much_indentation:
110+
included: ".*.swift"
111+
regex: '\n {0}[^\s\/][^\n]*[^,|&]\n+ {5,}\S|\n {4}[^\s\/][^\n]*[^,|&]\n+ {9,}\S|\n {8}[^\s\/][^\n]*[^,|&]\n+ {13,}\S|\n {12}[^\s\/][^\n]*[^,|&]\n+ {17,}\S|\n {16}[^\s\/][^\n]*[^,|&]\n+ {21,}\S|\n {20}[^\s\/][^\n]*[^,|&]\n+ {25,}\S'
112+
name: "Too Much Indentation"
113+
message: "Don't indent code by more than 4 whitespaces."
114+
severity: warning
115+
too_much_unindentation:
116+
included: ".*.swift"
117+
regex: ' {28}\S(.|[^\n]*[^\)][^\ ][^\}])\n+ {0,23}[^\s\/]| {24}\S(.|[^\n]*[^\)][^\ ][^\}])\n+ {0,19}[^\s\/]| {20}\S(.|[^\n]*[^\)][^\ ][^\}])\n+ {0,15}[^\s\/]| {16}\S(.|[^\n]*[^\)][^\ ][^\}])\n+ {0,11}[^\s\/]| {12}\S(.|[^\n]*[^\)][^\ ][^\}])\n+ {0,7}[^\s\/]| {8}\S(.|[^\n]*[^\)][^\ ][^\}])\n+ {0,3}[^\s\/]'
118+
name: "Too Much Unindentation"
119+
message: "Don't unindent code by more than 4 whitespaces."
120+
severity: warning
121+
unnecessary_case_break:
122+
included: ".*.swift"
123+
regex: '(case |default)(?:[^\n\}]+\n){2,}\s*break|\n *\n *break(?:\n *\n|\n *\})'
124+
name: "Unnecessary Case Break"
125+
message: "Don't use break in switch cases – Swift breaks by default."
126+
severity: warning
127+
unnecessary_nil_assignment:
128+
included: ".*.swift"
129+
regex: 'var \S+\s*:\s*[^\s]+\?\s*=\s*nil'
130+
name: "Unnecessary Nil Assignment"
131+
message: "Don't assign nil as a value when defining an optional type – it's nil by default."
132+
severity: warning
133+
vertical_whitespace_between_cases:
134+
included: ".*.swift"
135+
regex: '[^\n{][ \t]*\n[ \t]*(?:case[^\n]+|default):[ \t]*\n'
136+
name: "Vertical Whitespace Between Cases"
137+
message: "Include a vertical whitespace (empty line) between cases in switch statements."
138+
severity: warning
139+
vertical_whitespaces_around_mark:
140+
included: ".*.swift"
141+
regex: '\/\/\s*MARK:[^\n]*(\n\n)|(\n\n\n)[ \t]*\/\/\s*MARK:|[^\s{]\n[^\n\/]*\/\/\s*MARK:'
142+
name: "Vertical Whitespaces Around MARK:"
143+
message: "Include a single vertical whitespace (empty line) before and none after MARK: comments."
144+
severity: warning
145+
vertical_whitespace_opening_braces:
146+
included: ".*.swift"
147+
regex: '[{(\[][ \t]*\n[ \t]*\n'
148+
name: "Vertical Whitespace after Opening Braces"
149+
message: "Don't include vertical whitespace (empty line) after opening braces."
150+
severity: warning
151+
vertical_whitespace_closing_braces:
152+
included: ".*.swift"
153+
regex: '\n[ \t]*\n[ \t]*[)}\]]'
154+
name: "Vertical Whitespace before Closing Braces"
155+
message: "Don't include vertical whitespace (empty line) before closing braces."
156+
severity: warning
157+
whitespace_comment_start:
158+
included: ".*.swift"
159+
regex: '[^:]\/\/[^\s\/]'
160+
name: "Whitespace Comment Start"
161+
message: "A comment should always start with a whitespace."
162+
severity: warning

HandyUIKit.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22

33
s.name = "HandyUIKit"
4-
s.version = "1.4.0"
4+
s.version = "1.4.1"
55
s.summary = "Handy UI features that should have been part of UIKit in the first place."
66

77
s.description = <<-DESC

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ alt="Build Status">
1313
alt="codebeat badge">
1414
</a>
1515
<a href="https://github.com/Flinesoft/HandyUIKit/releases">
16-
<img src="https://img.shields.io/badge/Version-1.4.0-blue.svg"
17-
alt="Version: 1.4.0">
16+
<img src="https://img.shields.io/badge/Version-1.4.1-blue.svg"
17+
alt="Version: 1.4.1">
1818
</a>
1919
<img src="https://img.shields.io/badge/Swift-3.0-FFAC45.svg"
2020
alt="Swift: 3.0">
@@ -48,6 +48,8 @@ Currently the recommended way of installing this library is via [Carthage](https
4848

4949
You can of course also just include this framework manually into your project by downloading it or by using git submodules.
5050

51+
*Note: This project is ready for Swift 4. Until Xcode 9 is officially released though, you need to use the branch "work/swift4".*
52+
5153
### Carthage
5254

5355
Place the following line to your Cartfile:
@@ -168,7 +170,7 @@ view.backgroundColor = .blue
168170
subview.backgroundColor = .red
169171

170172
let fullSizeContent = view.toImage() // => <UIImage: width: 500, height: 500>
171-
let downSizedContent = view.toImage(size: CGSize(width: 80, height: 80))
173+
let downSizedContent = view.toImage(size: CGSize(width: 80, height: 80))
172174
// => <UIImage: width: 80, height: 80>
173175
```
174176

@@ -233,7 +235,7 @@ let originZeroRect2 = CGRect(width: 100, height: 50)
233235

234236

235237
### StringExtension
236-
#### .width(for fixedHeight:font:)
238+
#### .height(forFixedWidth:font:)
237239
Calculates and returns the height needed to fit the text into a width-constrained rect.
238240

239241
``` Swift
@@ -243,7 +245,7 @@ loremIpsum.height(forFixedWidth: 300, font: UIFont.systemFont(ofSize: 14, weight
243245
// => 183.77734375
244246
```
245247

246-
#### .height(for fixedWidth:font:)
248+
#### .width(forFixedHeight:font:)
247249
Calculates and returns the width needed to fit the text into a height-constrained rect.
248250

249251
``` Swift

Sources/Code/Extensions/ColorSpaces.swift

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,17 @@
88
// Original source: https://github.com/timrwood/ColorSpaces
99
//
1010

11-
// swiftlint:disable
12-
1311
import UIKit
1412

1513
// MARK: - Constants
14+
private let RAD_TO_DEG = 180 / CGFloat.pi
1615

17-
private let RAD_TO_DEG = 180 / CGFloat(M_PI)
18-
19-
private let LAB_E: CGFloat = 0.008856
20-
private let LAB_16_116: CGFloat = 0.1379310
21-
private let LAB_K_116: CGFloat = 7.787036
22-
private let LAB_X: CGFloat = 0.95047
16+
private let LAB_E: CGFloat = 0.008_856
17+
private let LAB_16_116: CGFloat = 0.137_931_0
18+
private let LAB_K_116: CGFloat = 7.787_036
19+
private let LAB_X: CGFloat = 0.950_47
2320
private let LAB_Y: CGFloat = 1
24-
private let LAB_Z: CGFloat = 1.08883
21+
private let LAB_Z: CGFloat = 1.088_83
2522

2623
// MARK: - RGB
2724

@@ -40,17 +37,17 @@ struct RGBColor {
4037

4138
fileprivate func sRGBCompand(_ v: CGFloat) -> CGFloat {
4239
let absV = abs(v)
43-
let out = absV > 0.04045 ? pow((absV + 0.055) / 1.055, 2.4) : absV / 12.92
40+
let out = absV > 0.040_45 ? pow((absV + 0.055) / 1.055, 2.4) : absV / 12.92
4441
return v > 0 ? out : -out
4542
}
4643

4744
func toXYZ() -> XYZColor {
4845
let R = sRGBCompand(r)
4946
let G = sRGBCompand(g)
5047
let B = sRGBCompand(b)
51-
let x: CGFloat = (R * 0.4124564) + (G * 0.3575761) + (B * 0.1804375)
52-
let y: CGFloat = (R * 0.2126729) + (G * 0.7151522) + (B * 0.0721750)
53-
let z: CGFloat = (R * 0.0193339) + (G * 0.1191920) + (B * 0.9503041)
48+
let x: CGFloat = (R * 0.412_456_4) + (G * 0.357_576_1) + (B * 0.180_437_5)
49+
let y: CGFloat = (R * 0.212_672_9) + (G * 0.715_152_2) + (B * 0.072_175_0)
50+
let z: CGFloat = (R * 0.019_333_9) + (G * 0.119_192_0) + (B * 0.950_304_1)
5451
return XYZColor(x: x, y: y, z: z, alpha: alpha)
5552
}
5653

@@ -99,14 +96,14 @@ struct XYZColor {
9996

10097
fileprivate func sRGBCompand(_ v: CGFloat) -> CGFloat {
10198
let absV = abs(v)
102-
let out = absV > 0.0031308 ? 1.055 * pow(absV, 1 / 2.4) - 0.055 : absV * 12.92
99+
let out = absV > 0.003_130_8 ? 1.055 * pow(absV, 1 / 2.4) - 0.055 : absV * 12.92
103100
return v > 0 ? out : -out
104101
}
105102

106103
func toRGB() -> RGBColor {
107-
let r = (x * 3.2404542) + (y * -1.5371385) + (z * -0.4985314)
108-
let g = (x * -0.9692660) + (y * 1.8760108) + (z * 0.0415560)
109-
let b = (x * 0.0556434) + (y * -0.2040259) + (z * 1.0572252)
104+
let r = (x * 3.240_454_2) + (y * -1.537_138_5) + (z * -0.498_531_4)
105+
let g = (x * -0.969_266_0) + (y * 1.876_010_8) + (z * 0.041_556_0)
106+
let b = (x * 0.055_643_4) + (y * -0.204_025_9) + (z * 1.057_225_2)
110107
let R = sRGBCompand(r)
111108
let G = sRGBCompand(g)
112109
let B = sRGBCompand(b)

Sources/Code/Extensions/CoreGraphicsExtension.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import UIKit
1010

1111
// MARK: - CGSize Extension
12-
1312
extension CGSize {
1413
/// Returns a new CGSize object with the width and height converted to true pixels on the main screen.
1514
public var inPixels: CGSize { return inPixels(.main) }
@@ -23,9 +22,7 @@ extension CGSize {
2322
}
2423
}
2524

26-
2725
// MARK: - CGPoint Extension
28-
2926
extension CGPoint {
3027
/// Returns a new CGPoint object with the x and y converted to true pixels on the main screen.
3128
public var inPixels: CGPoint { return inPixels(.main) }
@@ -39,9 +36,7 @@ extension CGPoint {
3936
}
4037
}
4138

42-
4339
// MARK: - CGRect Extension
44-
4540
extension CGRect {
4641
/// Creates a new CGRect object from origin zero with given size.
4742
///

Sources/Code/Extensions/NSAttributedStringExtension.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ extension NSAttributedString {
3232
}
3333

3434
private func rect(for constraintSize: CGSize, font: UIFont) -> CGRect {
35-
let copy = mutableCopy() as! NSMutableAttributedString
36-
copy.addAttribute(NSFontAttributeName, value: font, range: NSMakeRange(0, length))
35+
let copy = mutableCopy() as! NSMutableAttributedString // swiftlint:disable:this force_cast
36+
copy.addAttribute(NSFontAttributeName, value: font, range: NSRange(location: 0, length: length))
37+
3738
return copy.boundingRect(with: constraintSize, options: .usesLineFragmentOrigin, context: nil)
3839
}
3940
}

0 commit comments

Comments
 (0)