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

Added hash_value_overflow rule #2496

Merged
merged 14 commits into from
Dec 5, 2018
Merged
Prev Previous commit
Next Next commit
Updated name from HashFunctionRule to LegacyHashingRule to match othe…
…r rules in same family
  • Loading branch information
kimdv committed Dec 5, 2018
commit ad8b2685824f71ece1bdbeb92ee73c45e5bac468
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
for large files.
[Niil Öhlin](https://github.com/niilohlin)

* Add new opt-in rule `hash_function` to warn against empty wrong hashValue
implementation.
* Add new `legacy_hashing` rule to encourage the use of Swift 4.2's new hashing
interface.
[Kim de Vos](https://github.com/kimdv)
[#2108](https://github.com/realm/SwiftLint/issues/2108)

Expand Down
178 changes: 89 additions & 89 deletions Rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
* [Function Default Parameter at End](#function-default-parameter-at-end)
* [Function Parameter Count](#function-parameter-count)
* [Generic Type Name](#generic-type-name)
* [Hash Function](#hash-function)
* [Identical Operands](#identical-operands)
* [Identifier Name](#identifier-name)
* [Implicit Getter](#implicit-getter)
Expand All @@ -68,6 +67,7 @@
* [Legacy CGGeometry Functions](#legacy-cggeometry-functions)
* [Legacy Constant](#legacy-constant)
* [Legacy Constructor](#legacy-constructor)
* [Legacy Hashing](#legacy-hashing)
* [Legacy NSGeometry Functions](#legacy-nsgeometry-functions)
* [Legacy Random](#legacy-random)
* [Variable Declaration Whitespace](#variable-declaration-whitespace)
Expand Down Expand Up @@ -7981,94 +7981,6 @@ enum Foo<↓type> {}



## Hash Function

Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version
--- | --- | --- | --- | --- | ---
`hash_function` | Enabled | No | lint | No | 4.2.0

Prefer using the `hash(into:)` function instead of overriding `hashValue`

### Examples

<details>
<summary>Non Triggering Examples</summary>

```swift
struct Foo: Hashable {
let bar: Int = 10

func hash(into hasher: inout Hasher) {
hasher.combine(bar)
}
}
```

```swift
class Foo: Hashable {
let bar: Int = 10

func hash(into hasher: inout Hasher) {
hasher.combine(bar)
}
}
```

```swift
var hashValue: Int { return 1 }
class Foo: Hashable {
}
```

```swift
class Foo: Hashable {
let bar: String = "Foo"

public var hashValue: String {
return bar
}
}
```

```swift
class Foo: Hashable {
let bar: String = "Foo"

public var hashValue: String {
get { return bar }
set { bar = newValue }
}
}
```

</details>
<details>
<summary>Triggering Examples</summary>

```swift
struct Foo: Hashable {
let bar: Int = 10

public ↓var hashValue: Int {
return bar
}
}
```

```swift
class Foo: Hashable {
let bar: Int = 10

public ↓var hashValue: Int {
return bar
}
}
```

</details>



## Identical Operands

Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version
Expand Down Expand Up @@ -9961,6 +9873,94 @@ UIOffset(horizontal: horizontal, vertical: vertical)



## Legacy Hashing

Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version
--- | --- | --- | --- | --- | ---
`legacy_hashing` | Enabled | No | idiomatic | No | 4.2.0

Prefer using the `hash(into:)` function instead of overriding `hashValue`

### Examples

<details>
<summary>Non Triggering Examples</summary>

```swift
struct Foo: Hashable {
let bar: Int = 10

func hash(into hasher: inout Hasher) {
hasher.combine(bar)
}
}
```

```swift
class Foo: Hashable {
let bar: Int = 10

func hash(into hasher: inout Hasher) {
hasher.combine(bar)
}
}
```

```swift
var hashValue: Int { return 1 }
class Foo: Hashable {
}
```

```swift
class Foo: Hashable {
let bar: String = "Foo"

public var hashValue: String {
return bar
}
}
```

```swift
class Foo: Hashable {
let bar: String = "Foo"

public var hashValue: String {
get { return bar }
set { bar = newValue }
}
}
```

</details>
<details>
<summary>Triggering Examples</summary>

```swift
struct Foo: Hashable {
let bar: Int = 10

public ↓var hashValue: Int {
return bar
}
}
```

```swift
class Foo: Hashable {
let bar: Int = 10

public ↓var hashValue: Int {
return bar
}
}
```

</details>



## Legacy NSGeometry Functions

Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ public struct HashFunctionRule: ASTRule, ConfigurationProviderRule, AutomaticTes
public init() {}

public static let description = RuleDescription(
identifier: "hash_function",
name: "Hash Function",
identifier: "legacy_hashing",
name: "Legacy Hashing",
description: "Prefer using the `hash(into:)` function instead of overriding `hashValue`",
kind: .lint,
kind: .idiomatic,
minSwiftVersion: .fourDotTwo,
nonTriggeringExamples: [
"""
Expand Down
10 changes: 5 additions & 5 deletions SwiftLint.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@
C2B3C1612106F78C00088928 /* ConfigurationAliasesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C2B3C15F2106F78100088928 /* ConfigurationAliasesTests.swift */; };
C328A2F71E6759AE00A9E4D7 /* ExplicitTypeInterfaceRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = C328A2F51E67595500A9E4D7 /* ExplicitTypeInterfaceRule.swift */; };
C3DE5DAC1E7DF9CA00761483 /* FatalErrorMessageRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3DE5DAA1E7DF99B00761483 /* FatalErrorMessageRule.swift */; };
C3EF547821B5A4000009262F /* HashFunctionRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3EF547521B5A2190009262F /* HashFunctionRule.swift */; };
C3EF547821B5A4000009262F /* LegacyHashingRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3EF547521B5A2190009262F /* LegacyHashingRule.swift */; };
C946FECB1EAE67EE007DD778 /* LetVarWhitespaceRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = C946FEC91EAE5E20007DD778 /* LetVarWhitespaceRule.swift */; };
C9802F2F1E0C8AEE008AB27F /* TrailingCommaRuleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9802F2E1E0C8AEE008AB27F /* TrailingCommaRuleTests.swift */; };
CC26ED07204DEB510013BBBC /* RuleIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC26ED05204DE86E0013BBBC /* RuleIdentifier.swift */; };
Expand Down Expand Up @@ -630,7 +630,7 @@
C2B3C15F2106F78100088928 /* ConfigurationAliasesTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConfigurationAliasesTests.swift; sourceTree = "<group>"; };
C328A2F51E67595500A9E4D7 /* ExplicitTypeInterfaceRule.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExplicitTypeInterfaceRule.swift; sourceTree = "<group>"; };
C3DE5DAA1E7DF99B00761483 /* FatalErrorMessageRule.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FatalErrorMessageRule.swift; sourceTree = "<group>"; };
C3EF547521B5A2190009262F /* HashFunctionRule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HashFunctionRule.swift; sourceTree = "<group>"; };
C3EF547521B5A2190009262F /* LegacyHashingRule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LegacyHashingRule.swift; sourceTree = "<group>"; };
C946FEC91EAE5E20007DD778 /* LetVarWhitespaceRule.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LetVarWhitespaceRule.swift; sourceTree = "<group>"; };
C9802F2E1E0C8AEE008AB27F /* TrailingCommaRuleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TrailingCommaRuleTests.swift; sourceTree = "<group>"; };
CC26ED05204DE86E0013BBBC /* RuleIdentifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RuleIdentifier.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -999,7 +999,6 @@
E315B83B1DFA4BC500621B44 /* DynamicInlineRule.swift */,
62A3E95B209E078000547A86 /* EmptyXCTestMethodRule.swift */,
626B01B420A1735900D2C42F /* EmptyXCTestMethodRuleExamples.swift */,
C3EF547521B5A2190009262F /* HashFunctionRule.swift */,
D4E92D1E2137B4C9002EDD48 /* IdenticalOperandsRule.swift */,
D4441A27213279950020896F /* InertDeferRule.swift */,
C26330352073DAA200D7B4FD /* LowerACLThanParentRule.swift */,
Expand Down Expand Up @@ -1139,7 +1138,9 @@
006ECFC31C44E99E00EF6364 /* LegacyConstantRule.swift */,
00B8D9771E2D0FBD004E0EEC /* LegacyConstantRuleExamples.swift */,
D44AD2741C0AA3730048F7B0 /* LegacyConstructorRule.swift */,
C3EF547521B5A2190009262F /* LegacyHashingRule.swift */,
F22314AE1D4F7C77009AD165 /* LegacyNSGeometryFunctionsRule.swift */,
A3184D55215BCEFF00621EA2 /* LegacyRandomRule.swift */,
D4DAE8BB1DE14E8F00B0AE7A /* NimbleOperatorRule.swift */,
1E18574A1EADBA51004F89F7 /* NoExtensionAccessModifierRule.swift */,
ED641C3620AA070700212C62 /* NoFallthroughOnlyRule.swift */,
Expand All @@ -1166,7 +1167,6 @@
181D9E162038343D001F6887 /* UntypedErrorInCatchRule.swift */,
D43B04631E0620AB004016AF /* UnusedEnumeratedRule.swift */,
626D02961F31CBCC0054788D /* XCTFailMessageRule.swift */,
A3184D55215BCEFF00621EA2 /* LegacyRandomRule.swift */,
);
path = Idiomatic;
sourceTree = "<group>";
Expand Down Expand Up @@ -1898,7 +1898,7 @@
006ECFC41C44E99E00EF6364 /* LegacyConstantRule.swift in Sources */,
82FE254120F604CB00295958 /* VerticalWhitespaceClosingBracesRule.swift in Sources */,
429644B61FB0A9B400D75128 /* SortedFirstLastRule.swift in Sources */,
C3EF547821B5A4000009262F /* HashFunctionRule.swift in Sources */,
C3EF547821B5A4000009262F /* LegacyHashingRule.swift in Sources */,
31F1B6CC1F60BF4500A57456 /* SwitchCaseAlignmentRule.swift in Sources */,
E88DEA731B0984C400A66CB0 /* String+SwiftLint.swift in Sources */,
E88198591BEA95F100333A11 /* LeadingWhitespaceRule.swift in Sources */,
Expand Down